Terra pixel shader error, normal_map

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Terra pixel shader error, normal_map

Post by Nickak2003 »

When I attempt to add a normal_map detail, the following is thrown:

Code: Select all

Exception thrown at 0x00007FFBBE23A799 in fpsengine_test.exe: Microsoft C++ exception: Ogre::RenderingAPIException at memory location 0x0000004E7EDC9560.
Ogre: High-level program 700000000PixelShader_ps encountered an error during loading and is thus not supported.
OGRE EXCEPTION(-2147467259:RenderingAPIException): Cannot compile D3D11 high-level shader 700000000PixelShader_ps Errors:
C:\Users\Nick\Documents\programming\hobby\bin\Debug\700000000PixelShader_ps.hlsl(1108,41-50): error X3004: undeclared identifier 'geomNormal'
 in D3D11HLSLProgram::compileMicrocode at C:\Users\Nick\Documents\programming\hobby\src\ogre\ogre-next\RenderSystems\Direct3D11\src\OgreD3D11HLSLProgram.cpp (line 569)
Assertion failed!
The load normal maps code in, hlms/terra/any/800.pixelshader_piece_ps.any, isn't called, no clue.

thanks!

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 241
Joined: Wed Apr 23, 2014 3:49 pm
x 45

Re: Terra pixel shader error, normal_map

Post by TaaTT4 »

Senior game programmer at Vae Victis
Working on Racecraft

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

I'm not 100% sure but this seems to be working:

Code: Select all

@piece( LoadNormalData )
	// Geometric normal
	pixelData.geomNormal = OGRE_Sample( terrainNormals, samplerStateTerra, inPs.uv0.xy ).xyz * 2.0 - 1.0;
	//pixelData.geomNormal = mul( pixelData.normal, toFloat3x3( passBuf.view ) );
	@property( normal_map )
		//Get the TBN matrix
		float3 viewSpaceUnitX	= float3( passBuf.view[0].x, passBuf.view[1].x, passBuf.view[2].x );
		float3 vTangent			= normalize( cross( pixelData.geomNormal  , viewSpaceUnitX ) );
		float3 vBinormal		= cross( vTangent, pixelData.geomNormal  );
		float3x3 TBN			= buildFloat3x3( vBinormal, vTangent, pixelData.geomNormal   );
	@end
@end
There were several geomNormal missing the pixelData reference and then mul seems to be wrong, not sure what that line is supposed to be doing

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

OK, that mul in there must have been used for something, IDK. It seems to work at a lot of angles but then there are a couple angles where everything gets really dark

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

I added the mul line back in replacing, pixelData.normal with pixelData.geomNorm, still gets dark at some angles?

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

yeah for some reason when I move the camera, the normal map-terrain lightens or darkens, shouldn't it be constant with a given light direction?

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

Code: Select all

@piece( LoadNormalData )
	// Geometric normal
	pixelData.geomNormal = OGRE_Sample( terrainNormals, samplerStateTerra, inPs.uv0.xy ).xyz * 2.0 - float3(1,1,1);
	pixelData.geomNormal = mul( pixelData.geomNormal, toFloat3x3( passBuf.view ) );

	@property( normal_map )
		//Get the TBN matrix
		float3 viewSpaceUnitX	= float3( passBuf.view[0].x, passBuf.view[1].y, passBuf.view[2].z );
		float3 vTangent			= normalize( cross( pixelData.geomNormal, viewSpaceUnitX ) );
		float3 vBinormal		= normalize( cross( pixelData.geomNormal, vTangent ));
		float3x3 TBN			= buildFloat3x3( vTangent, vBinormal, pixelData.geomNormal );
	@end
@end
also in:HlmsTerra::calculateHashForPreCreate, you need to select the correct normal map type, in my case, unorm!
It seems to be working now

[edit]
nevermind, it seems like at some light angles and view angles the objects are inverted?
[edit]
changed passbuff from xxx to xyz, seems to work now, but i have no idea if that's actually correct or not!

Nickak2003
Gremlin
Posts: 192
Joined: Thu Jun 10, 2004 4:19 am
x 11
Contact:

Re: Terra pixel shader error, normal_map

Post by Nickak2003 »

OK there was a serious problem with the tangents, I'm unsure the source of the original code or mistake.

I ended up creating a pre-generated tangent texture based on the height-map, along with the normal map one. I then sampled this to get the tangent and multiplied it by view.

now it's actually working!


Lax
Orc
Posts: 476
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 30

Re: Terra pixel shader error, normal_map

Post by Lax »

Hi Nickack2003,

I also struggle with terra normal maps. Do you have a code snipped with your final adaptations?

Best Regards
Lax
Image
http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62
Image

Post Reply