effect pixel shader not working

Started by
1 comment, last by mvtapia 17 years, 9 months ago
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
Marco Tapia
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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
Marco Tapia

This topic is closed to new replies.

Advertisement