Sign in to follow this  

Projective Textures - Help!

This topic is 4663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im trying to do projective texturing and I have a grid of vertices to represent water. I render my terrain to a texture, scaled 1, -1, 1 so it is mirrored. I hide the water plane, and enable a clip plane where it is. The water ahs the following shader:
float4x4 matWVP : WORLDVIEWPROJECTION;
float4x4 matV : View;
float4x4 matP : Projection;

float4x4 matRefl = {	.5f, 0, 0, .5f,
						0, .5f, 0, .5f,
						0, 0, .5f, .5f,
						0, 0, 0, 1 };

texture textReflection : TEXTURE;
sampler2D ReflectMap = sampler_state
{
	texture = <textReflection>;
};

struct vsOut
{
	float4 pos : POSITION;
	float4 projCoords : TEXCOORD0;
};

vsOut VP_Projective(float4 inPos : POSITION)
{
	vsOut Out = (vsOut)0;

	Out.pos = mul(inPos, matWVP);
	
	float4x4 refl = matRefl * matP * matV;

	Out.projCoords = mul(refl, Out.pos);
	
	return Out;
}

float4 FP_Projective(vsOut vsIn) : COLOR
{
	return tex2Dproj(ReflectMap, vsIn.projCoords);
}
					
					
technique proj
{
	pass p0
	{
		VertexShader = compile vs_1_1 VP_Projective();
		PixelShader = compile ps_2_0 FP_Projective();
	}
}

However, when I run that, all I see is the water plane flickering between some colours...

Share this post


Link to post
Share on other sites
I think I'm having some kind of progress now.. But it's still really bad :P Anyway, here's what I'm getting:

--------------------

Pretty nasty ey? Anyway, I've checked out the matrices by transforming a point I knew was in the middle of the screen, and I am getting correct UV results (the projective matrix clamps the clipspace from -1 to 1 to 0 to 1). I've included what I think is relevant code below.

The reflection matrix generation, and setting variables in the shader.

MProjText.M11 = .5f; MProjText.M12 = 0; MProjText.M13 = 0; MProjText.M14 = 0;
MProjText.M21 = 0; MProjText.M22 = .5f;MProjText.M23 = 0; MProjText.M24 = 0;
MProjText.M31 = 0; MProjText.M32 = 0; MProjText.M33 = .5f;MProjText.M34 = 0;
MProjText.M41 = 0.5f; MProjText.M42 = .5f;MProjText.M43 = .5f;MProjText.M44 = 1;

shaderProj.SetGlobal("matWVP", water.SceneGraphNode.World * camMain.View * camMain.Projection);
shaderProj.SetGlobal("matRefl", camMain.View * camMain.Projection * MProjText);




The projective texture shader:

float4x4 matWVP : WORLDVIEWPROJECTION;
float4x4 matRefl;

texture textReflection : TEXTURE;
sampler2D ReflectMap = sampler_state
{
texture = <textReflection>;
};

struct vsOut
{
float4 pos : POSITION;
float4 projCoords : TEXCOORD0;
};

vsOut VP_Projective(float4 inPos : POSITION,
float4 inNorm : NORMAL)
{
vsOut Out = (vsOut)0;

Out.pos = mul(inPos, matWVP);
Out.projCoords = mul(inPos, matRefl);

return Out;
}

float4 FP_Projective(vsOut vsIn) : COLOR
{
return tex2Dproj(ReflectMap, vsIn.projCoords);
}


technique proj
{
pass p0
{
VertexShader = compile vs_1_1 VP_Projective();
PixelShader = compile ps_2_0 FP_Projective();
}
}


Share this post


Link to post
Share on other sites

This topic is 4663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this