Jump to content
  • Advertisement
Sign in to follow this  
maya18222

Shader help

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

This is drving me insane, for some reason my if() statments arent working, and it always just goes to return float4(1, 0, 0, 1); Even when i hard code the ID tp something like 2
uniform extern texture  gTex0;
uniform extern texture  gTex1;
uniform extern texture  gTex2;

sampler TexS0 = sampler_state
{
	Texture = <gTex0>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = POINT;
	AddressU  = CLAMP;
    AddressV  = CLAMP;
};

sampler TexS1 = sampler_state
{
	Texture = <gTex1>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = POINT;
	AddressU  = CLAMP;
    AddressV  = CLAMP;
};

sampler TexS2 = sampler_state
{
	Texture = <gTex2>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = POINT;
	AddressU  = CLAMP;
    AddressV  = CLAMP;
};

float4	GetTextureData(float ID, float2 UV)
{


	if(ID > -0.1f && ID < 0.1f)
		 return tex2D(TexS0, UV);
		 
	if(ID > 0.9f && ID < 1.1f)
		 return tex2D(TexS1, UV);
		 
	if(ID > 1.9f && ID < 2.1f)
		 return tex2D(TexS2, UV);
		 


	//get here if something went wrong
	return float4(1,0,0,1);
}





#include "Tex.fx"

uniform extern float4x4 gWVP;

struct OutputVS
{
    float4 posH		: POSITION0;
    float4 Col		: COLOR0;
    float  pSize	: PSIZE;
    float2 tex0		: TEXCOORD0;
    float  TexID	: TEXCOORD1;
};

OutputVS VS(float3 posL		: POSITION0,
			float4 Col		: COLOR0,
			float  pSize	: PSIZE,
			float  TexID	: TEXCOORD0)
{
    // Zero out our output.
	OutputVS outVS = (OutputVS)0;
	
	// Transform to homogeneous clip space.
	outVS.posH = mul(float4(posL, 1.0f), gWVP);
	outVS.Col = Col;
	outVS.TexID = 2.0f;
	outVS.pSize = pSize;
	 
	// Done--return the output.
    return outVS;
}

float4 PS(OutputVS In_Ps) : COLOR
{
	return GetTextureData(In_Ps.TexID, In_Ps.tex0);
}

technique Tech
{
    pass P0
    {
        vertexShader = compile vs_3_0 VS();
        pixelShader  = compile ps_3_0 PS();
        
        PointSpriteEnable = true;
        AlphaBlendEnable = true;
	    SrcBlend     = SRCALPHA;
	    DestBlend    = one;
	    ZWriteEnable = false;
    }
}





Share this post


Link to post
Share on other sites
Advertisement
ok, i need to read the documentation before asking :)

It turns out that when using pointspriteenable, ALL texcoords are changed so that texure an image maps to the point, not just texcoord0.

SO i had to use a register that doesnt get adjusted. Colour1 seems to work.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!