Revisão | a16dd4c656369f10ef6f3423bbcc80585b918071 (tree) |
---|---|
Hora | 2018-09-23 08:44:28 |
Autor | Matias N. Goldberg <dark_ <sylinc@yaho...> |
Commiter | Matias N. Goldberg <dark_ |
Fixed Area Lights LTC compiler errors with HLSL. It works now!
@@ -35,6 +35,7 @@ | ||
35 | 35 | #define mul( x, y ) ((x) * (y)) |
36 | 36 | #define saturate(x) clamp( (x), 0.0, 1.0 ) |
37 | 37 | #define lerp mix |
38 | +#define rsqrt inversesqrt | |
38 | 39 | #define INLINE |
39 | 40 | |
40 | 41 | #define finalDrawId drawId |
@@ -67,7 +67,7 @@ | ||
67 | 67 | float b = 3.4175940 + (4.1616724 + y)*y; |
68 | 68 | float v = a / b; |
69 | 69 | |
70 | - float theta_sintheta = (x > 0.0) ? v : 0.5*inversesqrt(max(1.0 - x*x, 1e-7)) - v; | |
70 | + float theta_sintheta = (x > 0.0) ? v : 0.5*rsqrt(max(1.0 - x*x, 1e-7)) - v; | |
71 | 71 | |
72 | 72 | return cross( v1, v2 ) * theta_sintheta; |
73 | 73 | } |
@@ -188,7 +188,7 @@ | ||
188 | 188 | L[4] = L[0]; |
189 | 189 | } |
190 | 190 | |
191 | -INLINE float LTC_Evaluate( float3 N, float3 V, float3 P, mat3 Minv, float3 points[4], bool twoSided ) | |
191 | +INLINE float LTC_Evaluate( float3 N, float3 V, float3 P, float3x3 Minv, float3 points[4], bool twoSided ) | |
192 | 192 | { |
193 | 193 | // construct orthonormal basis around N |
194 | 194 | float3 T1, T2; |
@@ -196,7 +196,7 @@ | ||
196 | 196 | T2 = cross(N, T1); |
197 | 197 | |
198 | 198 | // rotate area light in (T1, T2, N) basis |
199 | - Minv = mul( Minv, transpose( mat3( T1, T2, N ) ) ); | |
199 | + Minv = mul( Minv, transpose( float3x3( T1, T2, N ) ) ); | |
200 | 200 | |
201 | 201 | // polygon (allocate 5 vertices for clipping) |
202 | 202 | float3 L[5]; |
@@ -246,7 +246,7 @@ | ||
246 | 246 | ClipQuadToHorizon( L, n ); |
247 | 247 | |
248 | 248 | if( n == 0 ) |
249 | - return float3(0, 0, 0); | |
249 | + return 0; | |
250 | 250 | // project onto sphere |
251 | 251 | L[0] = normalize( L[0] ); |
252 | 252 | L[1] = normalize( L[1] ); |
@@ -283,7 +283,7 @@ | ||
283 | 283 | float4 ltc0 = OGRE_SampleArray2DLevel( ltcMatrix, ltcSampler, ltcUV, 0, 0 ); |
284 | 284 | float4 ltc1 = OGRE_SampleArray2DLevel( ltcMatrix, ltcSampler, ltcUV, 1, 0 ); |
285 | 285 | |
286 | - mat3 Minv = mat3( | |
286 | + float3x3 Minv = float3x3( | |
287 | 287 | float3(ltc0.x, 0, ltc0.y), |
288 | 288 | float3( 0, 1, 0), |
289 | 289 | float3(ltc0.z, 0, ltc0.w) |
@@ -306,8 +306,9 @@ | ||
306 | 306 | ltcSpecular.xyz *= @insertpiece( F0 ).xyz * ltc1.x + (1.0 - @insertpiece( F0 ).xyz) * ltc1.y; |
307 | 307 | @end |
308 | 308 | |
309 | - float ltcDiffuse = LTC_Evaluate( nNormal.xyz, viewDir.xyz, inPs.pos.xyz, mat3(1), | |
310 | - passBuf.areaLtcLights[@n].points, doubleSidedLtc ); | |
309 | + float ltcDiffuse = LTC_Evaluate( nNormal.xyz, viewDir.xyz, inPs.pos.xyz, | |
310 | + float3x3( float3( 1, 0, 0 ), float3( 0, 1, 0 ), float3( 0, 0, 1 ) ), | |
311 | + passBuf.areaLtcLights[@n].points, doubleSidedLtc ); | |
311 | 312 | |
312 | 313 | finalColour += passBuf.areaLtcLights[@n].diffuse.xyz * ltcDiffuse * @insertpiece( kD ).xyz; |
313 | 314 | finalColour += passBuf.areaLtcLights[@n].specular.xyz * ltcSpecular * @insertpiece( kS ).xyz; |
@@ -41,6 +41,14 @@ | ||
41 | 41 | float4 doubleSided; |
42 | 42 | }; |
43 | 43 | |
44 | +struct AreaLtcLight | |
45 | +{ | |
46 | + float4 position; //.w contains the objLightMask | |
47 | + float4 diffuse; //.w contains attenuation range | |
48 | + float4 specular; //.w contains doubleSided | |
49 | + float3 points[4]; | |
50 | +}; | |
51 | + | |
44 | 52 | @insertpiece( DeclCubemapProbeStruct ) |
45 | 53 | |
46 | 54 | //Uniforms that change per pass |
@@ -94,6 +102,7 @@ | ||
94 | 102 | float pssmFadePoint;@end |
95 | 103 | @property( hlms_lights_spot )Light lights[@value(hlms_lights_spot)];@end |
96 | 104 | @property( hlms_lights_area_approx )AreaLight areaApproxLights[@value(hlms_lights_area_approx)];@end |
105 | + @property( hlms_lights_area_ltc )AreaLtcLight areaLtcLights[@value(hlms_lights_area_ltc)];@end | |
97 | 106 | @end @property( hlms_shadowcaster ) |
98 | 107 | //Vertex shader |
99 | 108 | @property( exponential_shadow_maps )float4 viewZRow;@end |
@@ -41,6 +41,14 @@ | ||
41 | 41 | float4 doubleSided; |
42 | 42 | }; |
43 | 43 | |
44 | +struct AreaLtcLight | |
45 | +{ | |
46 | + float4 position; //.w contains the objLightMask | |
47 | + float4 diffuse; //.w contains attenuation range | |
48 | + float4 specular; //.w contains doubleSided | |
49 | + float3 points[4]; | |
50 | +}; | |
51 | + | |
44 | 52 | @insertpiece( DeclCubemapProbeStruct ) |
45 | 53 | |
46 | 54 | //Uniforms that change per pass |
@@ -91,6 +99,7 @@ | ||
91 | 99 | float pssmFadePoint;@end |
92 | 100 | @property( hlms_lights_spot )Light lights[@value(hlms_lights_spot)];@end |
93 | 101 | @property( hlms_lights_area_approx )AreaLight areaApproxLights[@value(hlms_lights_area_approx)];@end |
102 | + @property( hlms_lights_area_ltc )AreaLtcLight areaLtcLights[@value(hlms_lights_area_ltc)];@end | |
94 | 103 | @end @property( hlms_shadowcaster ) |
95 | 104 | //Vertex shader |
96 | 105 | @property( exponential_shadow_maps )float4 viewZRow;@end |