Sign in to follow this  

texture projection

Recommended Posts

maxest    622
I have just solved my problem. The problem was that I was passing vertex's position to the vertex shader as float3, whereas position.w was not defined. That was the only problem :) If anybody is interested in texture projection, I present my code here Code that comes from application
void UpdateMatrices()
	D3DXMATRIX proj_matrix, view_matrix;
	D3DXMATRIX tex_proj_matrix, tex_view_matrix, tex_normalize_matrix;


		tex_normalize_matrix(0, 0) = 0.5f;
		tex_normalize_matrix(1, 0) = 0.0f;
		tex_normalize_matrix(2, 0) = 0.0f;
		tex_normalize_matrix(3, 0) = 0.5f;

		tex_normalize_matrix(0, 1) = 0.0f;
		tex_normalize_matrix(1, 1) = 0.5f;
		tex_normalize_matrix(2, 1) = 0.0f;
		tex_normalize_matrix(3, 1) = 0.5f;

		tex_normalize_matrix(0, 2) = 0.0f;
		tex_normalize_matrix(1, 2) = 0.0f;
		tex_normalize_matrix(2, 2) = 0.5f;
		tex_normalize_matrix(3, 2) = 0.5f;

		tex_normalize_matrix(0, 3) = 0.0f;
		tex_normalize_matrix(1, 3) = 0.0f;
		tex_normalize_matrix(2, 3) = 0.0f;
		tex_normalize_matrix(3, 3) = 1.0f;

	D3DXMATRIX mWorldViewProj = view_matrix * proj_matrix;
	D3DXMATRIX mTexture = tex_view_matrix * tex_proj_matrix * tex_normalize_matrix;

	vs_constant_table->SetMatrix(device3d, "mWorldViewProj", &mWorldViewProj);
	vs_constant_table->SetMatrix(device3d, "mTexture", &mTexture);
Vertex shader:
uniform float4x4 mWorldViewProj;
uniform float4x4 mTexture;

struct VS_OUTPUT
    float4 position: POSITION;
    float4 diffuse: COLOR;
    float4 texCoordProj: TEXCOORD0;

VS_OUTPUT main(in float4 position: POSITION, in float4 diffuse: COLOR, in float2 texCoord: TEXCOORD0)
    VS_OUTPUT output;

    output.position = mul(float4(, 1.0f), mWorldViewProj);
    output.diffuse = diffuse;
    output.texCoordProj = mul(position, mTexture);
    return output;
Pixel shader:
struct PS_OUTPUT
    float4 color: COLOR;

uniform sampler2D decal0;

PS_OUTPUT main(in float4 texCoordProj: TEXCOORD0)
    PS_OUTPUT output;
    output.color = tex2Dproj(decal0, texCoordProj);
    return output;
[Edited by - Maxest on May 8, 2007 6:27:11 PM]

Share this post

Link to post
Share on other sites

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