Skip to content

Commit ab0559b

Browse files
committed
Give decals ability to use pbr lighting
1 parent 79f79a1 commit ab0559b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

effects/terrain.fx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,26 @@ bool ShaderUsesTerrainInfoTexture() {
348348
// The tile value basically says how often the texture gets repeated on the map.
349349
// A value less than one doesn't make sense under normal conditions, so it is
350350
// relatively save to use it as our switch.
351+
// We use the upper layer slot to store the terrain info texture, so we don't need
352+
// the tile value for anything else.
351353

352-
// in order to trigger this you can set the albedo scale to be bigger than the map
353-
// size. Use the value 10000 to be safe for any map
354+
// In order to trigger this you need to set the albedo scale to be bigger than the
355+
// map size. Use the value 10000 to be safe for any map
354356
return UpperAlbedoTile.x < 1.0;
355357
}
356358

359+
bool ShaderUsesPbrRendering() {
360+
// The tile value basically says how often the texture gets repeated on the map.
361+
// A value less than one doesn't make sense under normal conditions, so it is
362+
// relatively save to use it as our switch.
363+
// We use the stratum 7 normal slot to store the roughness texture, so we don't need
364+
// the tile value for anything else.
365+
366+
// In order to trigger this you need to set the normal scale to be bigger than the
367+
// map size. Use the value 10000 to be safe for any map
368+
return Stratum7NormalTile.x < 1.0;
369+
}
370+
357371
bool MapUsesAdvancedWater() {
358372
// LightingMultiplier is one of the few variables that is driven by the map,
359373
// but accessible by the mesh shader.
@@ -1335,7 +1349,13 @@ float4 DecalsPS( VS_OUTPUT inV, uniform bool inShadows) : COLOR
13351349

13361350
float waterDepth = tex2Dproj(UtilitySamplerC, inV.mTexWT * TerrainScale).g;
13371351

1338-
float3 color = CalculateLighting(normal, inV.mTexWT.xyz, decalAlbedo.xyz, decalSpec.r, waterDepth, inV.mShadow, inShadows).xyz;
1352+
float3 color;
1353+
// We want the decals to behave consistently with the rest of the ground
1354+
if (ShaderUsesPbrRendering()) {
1355+
color = PBR(inV, TerrainScale * inV.mTexWT, decalAlbedo.rgb, normal, 1-decalSpec.r, waterDepth);
1356+
} else {
1357+
color = CalculateLighting(normal, inV.mTexWT.xyz, decalAlbedo.xyz, decalSpec.r, waterDepth, inV.mShadow, inShadows).xyz;
1358+
}
13391359

13401360
return float4(color.rgb, decalAlbedo.w * decalMask.w * DecalAlpha);
13411361
}
@@ -2021,7 +2041,7 @@ float4 TerrainPBRAlbedoPS ( VS_OUTPUT inV) : COLOR
20212041
color = ApplyWaterColor(-1 * inV.mViewDirection, inV.mTexWT.z, waterDepth, color);
20222042

20232043
return float4(color, 0.01f);
2024-
// SpecularColor.ba, LowerNormalTile, Stratum7AlbedoTile and Stratum7NormalTile are unused now
2044+
// SpecularColor.ba, LowerNormalTile and Stratum7AlbedoTile are unused now
20252045
// Candidates for configurable values are the rotation matrix values
20262046
}
20272047

0 commit comments

Comments
 (0)