Planar environment map with RTSS.

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
Nicker
Gnoblar
Posts: 6
Joined: Tue Jul 23, 2013 11:34 am

Planar environment map with RTSS.

Post by Nicker »

In my quest to find an environment map for a plane in Ogre, I came across 'env_map planar' texture coordinates.
I was creating a plane that uses the following material.

Code: Select all

material PlanarEnv
{
	technique
	{
		pass
		{
			texture_unit
			{
				texture ToastMapOfEarth.jpg
				env_map planar
			}
		}		
	}
}
The material doesn't work at all with RTSS.
I found out that the problem lies in the vertex shading function FFP_GenerateTexCoord_EnvMap_Sphere found in \Media\RTShaderLib\[ShadingLanguage]\FFPLib_Texturing.[ShadingLanguage]

FFP_GenerateTexCoord_EnvMap_Sphere maps UV coordinates as a function of the object's Normal, denoted as 'N' as follows:
U = Nx / 2 + 0.5
V = Ny / 2 + 0.5

The reason it doesn't work is because all the normals in a plane have the same values, hence UV coordinates are the same, hence the problem.

In order To fix the issue I rewrote FFP_GenerateTexCoord_EnvMap_Sphere according to this document http://www.bluevoid.com/opengl/sig00/ad ... de184.html as follows:

Code: Select all

void FFP_GenerateTexCoord_EnvMap_Sphere(in	float4x4	mWorld,
										in	float4x4	mView,
										in	float4x4	mWorldViewIT,
										in	float4		vPos,
										in	float3		vNormal,
										in	float4x4	mTexture,
										out float2		vOut)
{
	float4x4 worldview = mul(mView,mWorld);
	float3 normal = normalize(mul(mWorldViewIT,float4(vNormal,0.0)).xyz); 
	float3 eyedir =  normalize(mul(worldview, vPos)).xyz;
	float3 r = reflect(eyedir, normal);
	float two_p = 2.0 * sqrt( r.x *  r.x +  r.y *  r.y +  (r.z + 1.0) *  (r.z + 1.0));
	vOut = mul(mTexture,float4(0.5 + r.x / two_p,0.5 - r.y / two_p,0.0,0.0)).xy;
}

The file OgreShaderFFPTexturing.cpp also had to be changed according to FFP_GenerateTexCoord_EnvMap_Sphere input parameters.

* notice the change of the input parameter mWorldIT to mWorldViewIT.

* 'ToastMapOfEarth.jpg' can be found here http://www.worldwidetelescope.org/docs/ ... fEarth.jpg
User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: Planar environment map with RTSS.

Post by masterfalcon »

Would you mind submitting a pull request with these changes so they can be reviewed? Thanks!
Nicker
Gnoblar
Posts: 6
Joined: Tue Jul 23, 2013 11:34 am

Re: Planar environment map with RTSS.

Post by Nicker »

These change have already been merged to Ogre.
Post Reply