1. Very similar issue when SSD is just developed in Ogre 2.1: When only emissive texture is present, the sampler's index will be wrong. Here is Ogre 2.2 generated code:
Code: Select all
SamplerState decalsSampler : register(s0);
Texture2DArray decalsEmissiveTex : register(t4);
Code: Select all
SamplerState decalsSampler : register(s4);
Texture2DArray decalsEmissiveTex : register(t4);
2. However, I workaround this by changing decalsSampler to use decalsEmissiveTex and the sample's index is correct now. However, I still cannot get Decals in my own app shown in Ogre 2.2 (both D3D11 and Metal iOS), but Ogre 2.1 is correct. With RenderDoc, I confirmed that the emissive texture array is uploaded correctly. but with RenderDoc 1.2's HLSL source-level debugging, I suspect decal's absLocalPos.z is wrong (abnormal big value), which might be caused by incorrect InvWorldMatrix. Then I changed
Code: Select all
@property( hlms_decals_emissive )
finalDecalEmissive += (absLocalPos.x > 0.5f || absLocalPos.y > 0.5f ||
absLocalPos.z > 0.5f) ? 0.0f : (decalEmissive.xyz * decalMask);
@end
Code: Select all
@property( hlms_decals_emissive )
finalDecalEmissive += (absLocalPos.x > 0.5f || absLocalPos.y > 0.5f ||
absLocalPos.z > 0.5f) ? 1.0f : 0.0f;
@end
So I looked at the code to upload invWorldMatrix and the alignment is wrong. Here is what I tried:
Code: Select all
OgreMain/src/OgreForwardPlusBase.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/OgreMain/src/OgreForwardPlusBase.cpp b/OgreMain/src/OgreForwardPlusBase.cpp
index 509a3342..a5646e14 100644
--- a/OgreMain/src/OgreForwardPlusBase.cpp
+++ b/OgreMain/src/OgreForwardPlusBase.cpp
@@ -197,6 +197,7 @@ namespace Ogre
if( numDecals > 0u )
accumOffset = alignToNextMultiple( accumOffset, c_ForwardPlusNumFloat4PerDecal );
mDecalFloat4Offset = static_cast<uint16>( accumOffset );
+ accumOffset += numDecals * c_ForwardPlusNumFloat4PerDecal;
if( numCubemapProbes > 0u )
accumOffset = alignToNextMultiple( accumOffset, c_ForwardPlusNumFloat4PerCubemapProbe );
mCubemapProbeFloat4Offset = static_cast<uint16>( accumOffset );
@@ -313,7 +314,7 @@ namespace Ogre
//Align to the start of cubemap probes
//Alignment happens in increments of float4, hence the "<< 2u"
- lightData += (mCubemapProbeFloat4Offset - mDecalFloat4Offset) << 2u;
+ lightData += (mCubemapProbeFloat4Offset - mDecalFloat4Offset - numDecals * c_ForwardPlusNumFloat4PerDecal) << 2u;
viewMatrix = camera->getViewMatrix();
Matrix3 invViewMatrix3 = viewMatrix3.Inverse();