Jump to content
  • Advertisement
Sign in to follow this  
sunsflower

Direct11 change texture coordinates in vertex shader

This topic is 1152 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

I've learned form a book that we can change texture coordinate in .fx file to avoid using dynamic vertex buffer. But I cannot get more information on how to do this...I've tried to use a constant buffer which passing a matrix to effect file but it doesn't work or sometimes work in an odd way. So how should I achieve this exactly? thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
cbuffer cbChangesPerFrame : register( b0 )
{
    matrix mvp_;
};

cbuffer cbChangeFrequently : register(b1)
{
//transform matrix
//1  0  0
//0  1  0
//tx ty 1
//translation only
	float3x3 texco_;

}

Texture2D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );


struct VS_Input
{
    float4 pos  : POSITION;
    float2 tex0 : TEXCOORD0;
};

struct PS_Input
{
    float4 pos  : SV_POSITION;
    float2 tex0 : TEXCOORD0;
};


PS_Input VS_Main( VS_Input vertex )
{
    PS_Input vsOut = ( PS_Input )0;
    vsOut.pos = mul( vertex.pos, mvp_ );

    float3x1 coord = {vertex.tex0.x, vertex.tex0.y, 1)};
    coord = mul(coord, texco_);
    vsOut = float2(coord.x, coord.y);

	
    return vsOut;
}


float4 PS_Main( PS_Input frag ) : SV_TARGET
{
    return colorMap_.Sample( colorSampler_, frag.tex0 );
}

Share this post


Link to post
Share on other sites
cbuffer cbChangesPerFrame : register( b0 )
{
    matrix mvp_;
};

cbuffer cbChangeFrequently : register(b1)
{
//transform matrix
//1  0  0
//0  1  0
//tx ty 1
//translation only
	float3x3 texco_;

}

Texture2D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );


struct VS_Input
{
    float4 pos  : POSITION;
    float2 tex0 : TEXCOORD0;
};

struct PS_Input
{
    float4 pos  : SV_POSITION;
    float2 tex0 : TEXCOORD0;
};


PS_Input VS_Main( VS_Input vertex )
{
    PS_Input vsOut = ( PS_Input )0;
    vsOut.pos = mul( vertex.pos, mvp_ );

    float3x1 coord = {vertex.tex0.x, vertex.tex0.y, 1)};
    coord = mul(coord, texco_);
    vsOut = float2(coord.x, coord.y);

	
    return vsOut;
}


float4 PS_Main( PS_Input frag ) : SV_TARGET
{
    return colorMap_.Sample( colorSampler_, frag.tex0 );
}

Share this post


Link to post
Share on other sites


vsOut = float2(coord.x, coord.y);
vsOut is a struct PS_Input. You should get a compile error, pointing you at this line, saying that it's not valid to assign a float2 to a PS_Input.

You probably want:

vsOut.tex0 = float2(coord.x, coord.y);

Share this post


Link to post
Share on other sites
Oh, I've fixed it, but still nothing happed...Or I should say that the texture do change but it seems to be streched very long vertically. So right now I just use simple change on the value of vertex.tex0 instead of using matrix.(forgive my poor english)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!