Sign in to follow this  
ajoling

[HLSL] Pointsprite texture coords?

Recommended Posts

I'm porting my particle classes to HLSL. Everything is going fine, except I just cannot find a single source on forums/google how to get the proper texture coordinates! And that, for example, RenderMonkey uses some kind of 3DS model as particle type isn't very comforting either. I'm sure it should be possible, multiplying 1.0 to some value for example. Does anyone have some advice? Remember: I'm using pixelshaders (HLSL). I know how to do it with the 'old' FVF method :).

Share this post


Link to post
Share on other sites
I'm reasonably surprised that no one replied. I guess it really is an unknown thing in DirectX. Do we have to go back to textured quads again for using texture coordinates properly in HLSL? I just can't believe that's the way things should be.

Share this post


Link to post
Share on other sites
Okay, for the record, I found the problem. Seems it was 'quite' simple.

POINTSPRITEENABLE = true;

Has to be put in the effect file. Then texture coordinates are generated perfectly. So, something like this:


VS_OUTPUT VS_Particle_main(float4 Pos: POSITION)
{
VS_OUTPUT Out;

//Multiply with VWP.
Out.Pos = mul(Pos, view_proj_matrix);

Out.vPos = Pos.xz;

return Out;
}

float4 PS_Particle_main(float2 vPos: TEXCOORD0) : COLOR
{
//Simply return texture:
return tex2D(sampler_Particle, vPos);
}

technique Particle
{
pass Normal
{
AlphaBlendEnable = true;
AlphaTestEnable = false;
SrcBlend = ONE;
DestBlend = ONE;

POINTSPRITEENABLE = true;
POINTSIZE = 2.0f;
POINTSIZE_MIN = 20.0f;
POINTSIZE_MAX = 30.0f;

VertexShader = compile vs_1_1 VS_Particle_main();
PixelShader = compile ps_1_4 PS_Particle_main();
}
}

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