@@ -467,19 +467,32 @@ float ComputeCaustic(float3 V, float3 positionOS, float3 lightDirOS, BSDFData bs
467467
468468// This is a test coming from Heretic demo. It is way more expensive
469469// and is sometimes better, sometime not than the "else" codee and don't support caustic.
470- void LightEyeTransform (PositionInputs posInput, BSDFData bsdfData, inout float3 positionRWS, inout float3 forward, inout float3 right, inout float3 up )
470+ void LightEyeTransform (PositionInputs posInput, BSDFData bsdfData, inout LightData lightData )
471471{
472- float3 L = normalize (positionRWS - posInput.positionWS);
472+ float3 L = normalize (lightData. positionRWS - posInput.positionWS);
473473 float3 refractL = -refract (-L, bsdfData.geomNormalWS, 1.0 / bsdfData.IOR);
474474
475475 float3 axis = normalize (cross (L, refractL));
476476
477477 float angle = acos (dot (L, refractL));
478478
479- positionRWS = Rotate (posInput.positionWS, positionRWS, axis, angle);
480- forward = Rotate (float3 (0 , 0 , 0 ), forward, axis, angle);
481- right = Rotate (float3 (0 , 0 , 0 ), right, axis, angle);
482- up = Rotate (float3 (0 , 0 , 0 ), up, axis, angle);
479+ lightData.positionRWS = Rotate (posInput.positionWS, lightData.positionRWS, axis, angle);
480+ lightData.forward = Rotate (float3 (0 , 0 , 0 ), lightData.forward, axis, angle);
481+ lightData.right = Rotate (float3 (0 , 0 , 0 ), lightData.right, axis, angle);
482+ lightData.up = Rotate (float3 (0 , 0 , 0 ), lightData.up, axis, angle);
483+ }
484+ void LightEyeTransform (PositionInputs posInput, BSDFData bsdfData, inout DirectionalLightData lightData)
485+ {
486+ float3 L = -lightData.forward;
487+ float3 refractL = -refract (-L, bsdfData.geomNormalWS, 1.0 / bsdfData.IOR);
488+
489+ float3 axis = normalize (cross (L, refractL));
490+
491+ float angle = acos (dot (L, refractL));
492+
493+ lightData.forward = Rotate (float3 (0 , 0 , 0 ), lightData.forward, axis, angle);
494+ lightData.right = Rotate (float3 (0 , 0 , 0 ), lightData.right, axis, angle);
495+ lightData.up = Rotate (float3 (0 , 0 , 0 ), lightData.up, axis, angle);
483496}
484497//-----------------------------------------------------------------------------
485498// EvaluateBSDF_Directional
@@ -502,7 +515,7 @@ DirectLighting EvaluateBSDF_Directional(LightLoopContext lightLoopContext,
502515 c = ComputeCausticFromLUT (preLightData.irisPlanePosition, bsdfData.irisPlaneOffset, lightPosOS, bsdfData.causticIntensity);
503516 }
504517 // Evaluate a second time the light but for a different position and for diffuse only.
505- LightEyeTransform (posInput, bsdfData, lightData.positionRWS, lightData.forward, lightData.right, lightData.up );
518+ LightEyeTransform (posInput, bsdfData, lightData);
506519
507520 DirectLighting dlIris = ShadeSurface_Directional ( lightLoopContext, posInput, builtinData,
508521 preLightData, lightData, bsdfData, V);
@@ -541,7 +554,7 @@ DirectLighting EvaluateBSDF_Punctual(LightLoopContext lightLoopContext,
541554 c = ComputeCausticFromLUT (preLightData.irisPlanePosition, bsdfData.irisPlaneOffset, TransformWorldToObject (lightData.positionRWS), bsdfData.causticIntensity);
542555 }
543556 // Evaluate a second time the light but for a different position and for diffuse only.
544- LightEyeTransform (posInput, bsdfData, lightData.positionRWS, lightData.forward, lightData.right, lightData.up );
557+ LightEyeTransform (posInput, bsdfData, lightData);
545558
546559 DirectLighting dlIris = ShadeSurface_Punctual ( lightLoopContext, posInput, builtinData,
547560 preLightData, lightData, bsdfData, V);
@@ -696,7 +709,7 @@ DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext,
696709 c = ComputeCausticFromLUT (preLightData.irisPlanePosition, bsdfData.irisPlaneOffset, TransformWorldToObject (lightData.positionRWS), bsdfData.causticIntensity);
697710 }
698711
699- LightEyeTransform (posInput, bsdfData, lightData.positionRWS, lightData.forward, lightData.right, lightData.up );
712+ LightEyeTransform (posInput, bsdfData, lightData);
700713
701714 DirectLighting dl2 = EvaluateBSDF_Area2 (lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData);
702715
0 commit comments