diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index b835f9802..d9dc1af73 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -952,6 +952,16 @@ float GetSnowParameterY(float texProjTmp, float alpha) # endif } +float2 ComputeTriplanarUV(float3 InputPosition) +{ + float3 posDDX = ddx(InputPosition.xyz); + float3 posDDY = ddy(InputPosition.xyz); + return (((0.1 * (abs(posDDX.z) + abs(posDDY.z)) < abs(posDDX.x) + abs(posDDY.x)) && + (0.1 * (abs(posDDX.z) + abs(posDDY.z)) < abs(posDDX.y) + abs(posDDY.y))) ? + InputPosition.xy : + ((0.5 * (abs(posDDX.x) + abs(posDDY.x)) < abs(posDDX.y) + abs(posDDY.y)) ? InputPosition.yz : InputPosition.xz)); +} + # if defined(LOD) # undef COMPLEX_PARALLAX_MATERIALS # undef WATER_BLENDING @@ -1149,8 +1159,13 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float2 diffuseUv = uv; # if defined(SPARKLE) +# if defined(VR) diffuseUv = ProjectedUVParams2.yy * input.TexCoord0.zw; -# endif // SPARKLE +# else + float2 triplanarUv = ComputeTriplanarUV(input.InputPosition.xyz); + diffuseUv = ProjectedUVParams2.yy * triplanarUv; +# endif // VR +# endif // SPARKLE # if defined(CPM_AVAILABLE) @@ -1166,7 +1181,11 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif // LANDSCAPE # if defined(SPARKLE) +# if defined(VR) diffuseUv = ProjectedUVParams2.yy * (input.TexCoord0.zw + (uv - uvOriginal)); +# else + diffuseUv = ProjectedUVParams2.yy * (triplanarUv + (uv - uvOriginal)); +# endif // VR # else diffuseUv = uv; # endif // SPARKLE @@ -1440,7 +1459,11 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif // SNOW # else if (ProjectedUVParams3.w > 0.5) { +# if defined(VR) + float2 projNormalUv = ProjectedUVParams3.x * ProjectedUVParams.zz * ComputeTriplanarUV(input.InputPosition.xyz); +# else float2 projNormalUv = ProjectedUVParams3.x * projNoiseUv; +# endif // VR float3 projNormal = TransformNormal(TexProjNormalSampler.Sample(SampProjNormalSampler, projNormalUv).xyz); float2 projDetailUv = ProjectedUVParams3.y * projNoiseUv; float3 projDetail = TexProjDetail.Sample(SampProjDetailSampler, projDetailUv).xyz;