1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
//========= Copyright Valve Corporation, All rights reserved. ============//
#if defined( _X360 )
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
{
vResultBase = 0;
vResultBase2 = 0;
vResultBump = 0;
if ( !bBump )
{
vResultBump = float4(0, 0, 1, 1);
}
#if SEAMLESS
vWeights = max( vWeights - 0.3, 0 );
vWeights *= 1.0f / dot( vWeights, float3(1,1,1) );
[branch]
if (vWeights.x > 0)
{
vResultBase += vWeights.x * tex2D( base, coords.zy );
if ( bBase2 )
{
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
}
if ( bBump )
{
vResultBump += vWeights.x * tex2D( bump, coords.zy );
}
}
[branch]
if (vWeights.y > 0)
{
vResultBase += vWeights.y * tex2D( base, coords.xz );
if ( bBase2 )
{
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
}
if ( bBump )
{
vResultBump += vWeights.y * tex2D( bump, coords.xz );
}
}
[branch]
if (vWeights.z > 0)
{
vResultBase += vWeights.z * tex2D( base, coords.xy );
if ( bBase2 )
{
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
}
if ( bBump )
{
vResultBump += vWeights.z * tex2D( bump, coords.xy );
}
}
#else // not seamless
vResultBase = tex2D( base, coords.xy );
if ( bBase2 )
{
vResultBase2 = tex2D( base2, coords.xy );
}
if ( bBump )
{
vResultBump = tex2D( bump, coords.xy );
}
#endif
}
#else // PC
void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights,
out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump )
{
vResultBase = 0;
vResultBase2 = 0;
vResultBump = 0;
if ( !bBump )
{
vResultBump = float4(0, 0, 1, 1);
}
#if SEAMLESS
vResultBase += vWeights.x * tex2D( base, coords.zy );
if ( bBase2 )
{
vResultBase2 += vWeights.x * tex2D( base2, coords.zy );
}
if ( bBump )
{
vResultBump += vWeights.x * tex2D( bump, coords.zy );
}
vResultBase += vWeights.y * tex2D( base, coords.xz );
if ( bBase2 )
{
vResultBase2 += vWeights.y * tex2D( base2, coords.xz );
}
if ( bBump )
{
vResultBump += vWeights.y * tex2D( bump, coords.xz );
}
vResultBase += vWeights.z * tex2D( base, coords.xy );
if ( bBase2 )
{
vResultBase2 += vWeights.z * tex2D( base2, coords.xy );
}
if ( bBump )
{
vResultBump += vWeights.z * tex2D( bump, coords.xy );
}
#else // not seamless
vResultBase = tex2D( base, coords.xy );
if ( bBase2 )
{
vResultBase2 = tex2D( base2, coords.xy );
}
if ( bBump )
{
vResultBump = tex2D( bump, coords.xy );
}
#endif
}
#endif
float3 LightMapSample( sampler LightmapSampler, float2 vTexCoord )
{
# if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) )
{
float3 sample = tex2D( LightmapSampler, vTexCoord );
return sample;
}
# else
{
# if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples
{
float4 sample = tex2D( LightmapSampler, vTexCoord );
return sample.rgb * sample.a;
}
# else
{
float4 Weights;
float4 samples_0; //no arrays allowed in inline assembly
float4 samples_1;
float4 samples_2;
float4 samples_3;
asm {
tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false
getWeights2D Weights, vTexCoord.xy, LightmapSampler
};
Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y );
float3 result;
result.rgb = samples_0.rgb * (samples_0.a * Weights.x);
result.rgb += samples_1.rgb * (samples_1.a * Weights.y);
result.rgb += samples_2.rgb * (samples_2.a * Weights.z);
result.rgb += samples_3.rgb * (samples_3.a * Weights.w);
return result;
}
# endif
}
# endif
}
|