XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Strange Shader Issue HLSL

Last post 23/10/2009 10:00 by Catalin Zima. 1 replies.
  • 23/10/2009 4:06

    Strange Shader Issue HLSL

    Hello,
    I've been adding some simple fog code to all my shaders for my current project, and I've been successful up until now when I'm trying to add it to my billboarded trees.

    Through debugging I'm getting this really weird phenomenon.

    in my pixel shader when I have the code

    BBPixelToFrame BillboardPS(BBVertexToPixel PSIn) : COLOR0
    {
        BBPixelToFrame Output = (BBPixelToFrame)0;        
        Output.Color = tex2D(textureSampler, PSIn.TexCoord);
        float4 dullColor2 = float4(.875f, 0.95f, .973f, 1);
        float Distance = .5f;                                              //ordinarily it would be distance(xCamPos,PSIn.Position) or something and I would divide and clamp it
        Output.Color = lerp(Output.Color, dullColor2,Distance);
        return Output;
    }

    It shades the Trees Fine
    However when I change "float Distance = .5f;" to "float Distance = (1/2)" it doesn't shade the images at all.

    BBPixelToFrame BillboardPS(BBVertexToPixel PSIn) : COLOR0
    {
        BBPixelToFrame Output = (BBPixelToFrame)0;        
        Output.Color = tex2D(textureSampler, PSIn.TexCoord);
        float4 dullColor2 = float4(.875f, 0.95f, .973f, 1);
        float Distance = (1/2);
        Output.Color = lerp(Output.Color, dullColor2,Distance);
        return Output;
    }

    This makes no sense to me.... as this has never been a problem in my other shaders

    -Thanks for any help,
               Justin
  • 23/10/2009 10:00 In reply to

    Re: Strange Shader Issue HLSL

    (1/2) is interpreted by the compiler as a division between the integer value 1 and the integer value 2, which results in the integer value 0
    (1.0f/2.0f) would be correctly computed as 0.5f
Page 1 of 1 (2 items) Previous Next