Skip to content

Commit

Permalink
Fix Decals broken in Terra
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Feb 29, 2024
1 parent dff1598 commit ef5f3e7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Docs/src/manual/Ogre3.0.Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Default material BRDF settings have changed in 3.0; thus materials will look dif

See [PBR / PBS Changes in 3.0](@ref PBSChangesIn30) to how make them look like they did in 2.3 and what these changes mean.

## Hlms Shader piece changes

The piece block `LoadNormalData` got split into `LoadGeomNormalData` & `LoadNormalData` in order to support Decals in Terra.

If you were overriding `LoadNormalData` in a custom piece, make sure to account for the new `LoadGeomNormalData`.

## Move to C++11 and general cleanup

Lots of dead \& long-deprecated code was removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ namespace Ogre
outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Atmosphere" );
#endif
outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Main" );
outLibraryFoldersPaths.push_back( "Hlms/Pbs/" + shaderSyntax );
outLibraryFoldersPaths.push_back( "Hlms/Terra/Any" );

// Fill the data folder path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@
float3 absLocalPos = abs( localPos.xyz );
bool isOutsideDecal = absLocalPos.x > 0.5f || absLocalPos.y > 0.5f || absLocalPos.z > 0.5f;

//Mask away objects looking away from the decal. Please note that inPs.normal is not unit-length
//and is before any TBN for normal mapping. In other words it's the geometric normal
//geomNormal is not available because it gets decalred after decals run
//Mask away objects looking away from the decal.
//We assume invWorldView is orthogonal, thus the transpose = inverse, hance invWorldView1.xyz
//works as the decal's direction
//
//Use a smooth fade to avoid flickering due to floating point precision when the normal
//and the decal are perpendicular to each other. (tolerance set to 0.0002)
midf3 decalDir = normalize( midf3_c( invWorldView1.xyz ) );
//isOutsideDecal = dot( decalDir.xyz, inPs.normal.xyz ) <= 0.0 ? true : isOutsideDecal;
midf normalAway = saturate( (dot( decalDir.xyz, inPs.normal.xyz ) + _h( 0.0002 ) ) / _h( 0.0002 ) );
//isOutsideDecal = dot( decalDir.xyz, pixelData.geomNormal.xyz ) <= 0.0 ? true : isOutsideDecal;
midf normalAway = saturate( (dot( decalDir.xyz, pixelData.geomNormal.xyz ) + _h( 0.0002 ) ) / _h( 0.0002 ) );
normalAway = isOutsideDecal ? _h( 0.0f ) : normalAway;

midf decalMask = normalAway;
Expand Down
13 changes: 9 additions & 4 deletions Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,12 @@
@piece( two_sided_flip_normal )* (gl_FrontFacing ? 1.0 : -1.0)@end
@end
@end
@piece( LoadGeomNormalData )
// Geometric normal
pixelData.geomNormal = normalize( inPs.normal ) @insertpiece( two_sided_flip_normal );
@end
@piece( LoadNormalData )
@property( !normal_map )
// Geometric normal
pixelData.normal = normalize( inPs.normal ) @insertpiece( two_sided_flip_normal );
@else
@property( normal_map )
//Normal mapping.
pixelData.geomNormal = normalize( inPs.normal ) @insertpiece( two_sided_flip_normal );
midf3 vTangent = normalize( inPs.tangent );
Expand Down Expand Up @@ -791,6 +792,10 @@
pixelData.specular.xyz = float3( 0.0f, 0.0f, 0.0f );
@end

@property( !hlms_use_prepass )
@insertpiece( LoadGeomNormalData )
@end

@insertpiece( forwardPlusDoDecals )

@property( !hlms_use_prepass )
Expand Down
2 changes: 2 additions & 0 deletions Samples/Media/Hlms/Terra/Any/800.PixelShader_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
@end
@end

@undefpiece( LoadGeomNormalData )
@undefpiece( LoadNormalData )
@piece( LoadNormalData )
// Geometric normal
Expand Down Expand Up @@ -227,6 +228,7 @@
@insertpiece( LoadDetailWeights )

@property( !hlms_use_prepass )
@insertpiece( LoadGeomNormalData )
@insertpiece( LoadNormalData )
@insertpiece( SampleAndApplyDetailNormalMaps@property( detail_triplanar_normal )Triplanar@end )
@end
Expand Down

0 comments on commit ef5f3e7

Please sign in to comment.