Jump to content
  • Advertisement
Sign in to follow this  
mvtapia

effect pixel shader not working

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

Hello everyone. I'm writing an effect to do lighting, but even though it does all the vertex shading, it doesn't do any of the pixel shading. I tested it with Direct3D debug and it breaks perfectly on the vertex shader routing but it completly skips the pixel one. I don't know if I have to set a flag in order to get this to work. this is the fx file I took it from gamasutra
//------------------------------------
// Game Engine Effects.
//------------------------------------

//------------------------------------
// TECHNIQUE VARIBLES.
//------------------------------------
bool Monochrome = false; 

//------------------------------------
// Lighting variables.
//------------------------------------
int		lig_Num = 0;
bool		lig_enable[8];
float3	lig_Color[8];
float3	lig_Pos[8];

//------------------------------------
// Input Variables.
//------------------------------------
float4x4 matWorldViewProj; 
float4x4 matWorld; 
float4 vecLightDir;
float4 vecEye;

//------------------------------------
// Vertex Shader Output.
//------------------------------------
struct VS_OUTPUT
{
    float4 Pos : POSITION;
    float3 Light : TEXCOORD0;
    float3 Norm : TEXCOORD1;
    float3 View : TEXCOORD2;
};

//------------------------------------
// Vertex Shader Routine.
//------------------------------------
VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL)
{
    VS_OUTPUT Out = (VS_OUTPUT)0; 
    Out.Pos = mul(Pos, matWorldViewProj); // transform Position
    Out.Light = vecLightDir;              // L
    float3 PosWorld = normalize(mul(Pos, matWorld)); 
    Out.View = vecEye - PosWorld;         // V
    Out.Norm = mul(Normal, matWorld);     // N

    return Out;
}

//------------------------------------
// Pixel Shader Routine.
//------------------------------------
float4 PS(float3 Light: TEXCOORD0, float3 Norm : TEXCOORD1, 
        float3 View : TEXCOORD2) : COLOR
{
  float4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f};
  float4 ambient = {0.1, 0.0, 0.0, 1.0}; 

  float3 Normal = normalize(Norm);
  float3 LightDir = normalize(Light);
  float3 ViewDir = normalize(View); 
  float4 diff = saturate(dot(Normal, LightDir)); // diffuse component

  // compute self-shadowing term
  float shadow = saturate(4* diff);

  float3 Reflect = normalize(2 * diff * Normal - LightDir); // R
  float4 specular = pow(saturate(dot(Reflect, ViewDir)), 8); // R.V^n 
  // I = ambient + shadow * (Dcolor * N.L + (R.V)n)
  return ambient + shadow * (diffuse * diff + specular); 

}

//------------------------------------
// Technique: TECH
// Desc: Performes the technique for the 
// engine effects on a mesh.
//------------------------------------
technique ENGINE_FX
{
    pass p0
    {
        VertexShader = compile vs_2_0 VS();
        PixelShader = compile ps_2_0 PS();
    }
}




Any suggestions. Thanx

Share this post


Link to post
Share on other sites
Advertisement
What debug output are you getting?

Is it definitely not using your shader? if you put a return float4( 1.0f, 0.0f, 0.0f, 1.0f ); do you get a solid red output?

Have you tried using the latest builds of PIX (in the June SDK) for the "Pixel History" feature? You should be able to determine what (if any) shaders are being applied to a given pixel.

If you're running on one of the Intel IGP's they haven't always supported ps_2_0 but will happily run vs_2_0 (iirc). What hardware are you running on, and are you sure you've dont appropriate enumeration?

hth
Jack

Share this post


Link to post
Share on other sites
There is another weird thing, if I put:

VertexShader = null;
PixelShader = compile ps_2_0 PS();

it does the pixel shader with no problem. why is that

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!