Skip to content

Commit 6e7b8d4

Browse files
committed
Fix DPM shaders
1 parent 07e3590 commit 6e7b8d4

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

CodeWalker/Rendering/Shaders/BasicShader.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,27 @@ public override void SetGeomVars(DeviceContext context, RenderableGeometry geom)
793793
PSGeomVars.Vars.wetnessMultiplier = geom.wetnessMultiplier;
794794
PSGeomVars.Vars.SpecOnly = geom.SpecOnly ? 1u : 0u;
795795
PSGeomVars.Vars.TextureAlphaMask = textureAlphaMask;
796+
// Disable POM for wind-displaced geometry - wind moves vertices without
797+
// updating the tangent frame, causing POM to displace in the wrong direction
798+
if (windflag != 0)
799+
{
800+
useheight = false;
801+
}
796802
PSGeomVars.Vars.EnableHeightMap = useheight ? 1u : 0u;
797-
PSGeomVars.Vars.heightScale = geom.heightScale;
798-
PSGeomVars.Vars.heightBias = geom.heightBias;
803+
804+
// DPM shaders store heightScale/heightBias calibrated for tessellation vertex
805+
// displacement (default 0.4 / -0.5, range -10 to 10). POM needs much smaller
806+
// positive values (default 0.03 / 0.015, range 0.01-0.05). Detect tessellation-
807+
// range values and convert them to POM range to prevent excessive UV warping.
808+
float hs = geom.heightScale;
809+
float hb = geom.heightBias;
810+
if (Math.Abs(hs) > 0.1f || hb < 0.0f)
811+
{
812+
hs = Math.Abs(hs) * 0.075f; // DPM(0.4) -> POM(0.03)
813+
hb = hs * 0.5f; // POM convention: bias = scale/2
814+
}
815+
PSGeomVars.Vars.heightScale = hs;
816+
PSGeomVars.Vars.heightBias = hb;
799817
PSGeomVars.Vars.Pad0 = 0.0f;
800818
PSGeomVars.Update(context);
801819
PSGeomVars.SetPSCBuffer(context, 2);

0 commit comments

Comments
 (0)