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

Pixel Shader Not Returning Flat Texture

Last post 26/07/2009 14:57 by Duckocide. 3 replies.
  • 26/07/2009 11:17

    Pixel Shader Not Returning Flat Texture

    I hope someone can help me. I'm having difficulty on 360 with my pixel shader. I have been adapting the normalmap sample, but have come across a problem where the texture appears to be lit oddly. That is, it's as if there is some light behind the view / camera.

    It's got to the stage where I commented out all the PixelShader code and left the following line only...

     

    return tex2D(DiffuseTextureSampler, input.texCoord);

     

    I hacked the input.texCoord to pick the same texture value all the time and I get a solid colour all over.

    input.texCoord = float2(1,1);
    return tex2D(DiffuseTextureSampler, input.texCoord);

     

    So, I'm guessing(!) tex2D is filtering somehow and blacking out the colour relative viewer position. I don't get this on the PC by the way.

    Any ideas?

     

     

     

    Resplicing some XNA...

    Play: Rail Gun Charlie (2009)

    Play: Tail Gun Charlie (2008)

    Duckocide
  • 26/07/2009 13:06 In reply to

    Re: Pixel Shader Not Returning Flat Texture

    Duckocide:

    It's got to the stage where I commented out all the PixelShader code and left the following line only...

     

    return tex2D(DiffuseTextureSampler, input.texCoord);

     

    I hacked the input.texCoord to pick the same texture value all the time and I get a solid colour all over.

    input.texCoord = float2(1,1);
    return tex2D(DiffuseTextureSampler, input.texCoord);

     

    So, I'm guessing(!) tex2D is filtering somehow and blacking out the colour relative viewer position. I don't get this on the PC by the way.

    Any ideas?

    Please show us the definition of DiffuseTextureSampler in the shader, and where you bind a texture to it in your C#.

    It might also help to know what your render states are (blend function, etc) and what else you are drawing in the scene (both behind and in front of the oddly-lit surface).

    Have you tried disabling the rendering of everything else in your scene to see if the lighting remains incorrect?

    Kevin Gadd, Squared Interactive
    Development Blog | Twitter
    Help playtest my game, Inferus!
  • 26/07/2009 14:31 In reply to

    Re: Pixel Shader Not Returning Flat Texture

    texture2D Texture;
    sampler2D DiffuseTextureSampler = sampler_state
    {
    Texture = <Texture>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
    AddressU = Wrap;
    AddressV = Wrap;
    };

    And the C# binding...

    // Set-up ground generated texture (should be only one, but loop in case)
    foreach (ModelMesh mesh in GroundModel.Meshes)
    {
        
    foreach (Effect effect in mesh.Effects)
        {
            effect.CurrentTechnique = effect.Techniques[
    "NormalMapping"];
            effect.Parameters[
    "Texture"].SetValue(Rock1Texture);
        }

     

    Model drawing is as follows (although with the shader practically commented apart from Vertex element, parameter settings are a little rundundant. 
     

     

     

    // Draw the model.

     

     

     

    Matrix[] transforms = new Matrix[model.Bones.Count];
    model.CopyAbsoluteBoneTransformsTo(transforms);
    foreach (ModelMesh mesh in model.Meshes)
    {
        
    foreach (Effect effect in mesh.Effects)
        {
            
    Matrix w = transforms[mesh.ParentBone.Index];
            effect.Parameters[
    "World"].SetValue(transforms[mesh.ParentBone.Index] * world * Matrix.CreateTranslation(position));
            effect.Parameters[
    "View"].SetValue(game.MatrixContainer.ViewMatrix);
            effect.Parameters[
    "Projection"].SetValue(game.MatrixContainer.ProjectionMatrix);
            effect.Parameters[
    "TextureOffset"].SetValue(textureOffset);
            effect.Parameters[
    "AmbientLightColor"].SetValue(ambientLightColor);
            effect.Parameters[
    "LightColor"].SetValue(lightColour);
            effect.Parameters[
    "LightPosition"].SetValue(lightPosition);
            effect.Parameters[
    "Shininess"].SetValue(shininess);
            effect.Parameters[
    "SpecularPower"].SetValue(specularPower);
            effect.Parameters[
    "Alpha"].SetValue(alpha);
            effect.Parameters[
    "NormalMapOffset"].SetValue(normalMapOffset);
        }
        mesh.Draw();
    }

     

     

     

    From the debug, the Renderstate blend values:

      AlphaBlendEnable false bool
      AlphaBlendOperation Add Microsoft.Xna.Framework.Graphics.BlendFunction
      AlphaDestinationBlend InverseSourceAlpha Microsoft.Xna.Framework.Graphics.Blend
      AlphaFunction Greater Microsoft.Xna.Framework.Graphics.CompareFunction
      AlphaSourceBlend One Microsoft.Xna.Framework.Graphics.Blend
      AlphaTestEnable false bool
    +  BlendFactor {R:255 G:255 B:255 A:255} Microsoft.Xna.Framework.Graphics.Color
      BlendFunction Add Microsoft.Xna.Framework.Graphics.BlendFunction
      CullMode CullCounterClockwiseFace Microsoft.Xna.Framework.Graphics.CullMode
      DestinationBlend InverseSourceAlpha Microsoft.Xna.Framework.Graphics.Blend
      SeparateAlphaBlendEnabled false bool


    Interestingly, if I leave the models original texture on, things are fine. I get the flat texture back. However, when I use my procedurally generated one, I get the problem. Is this a MIP issue?

    rockRT1 = Render.CreateRenderTarget(GraphicsDevice, 4, SurfaceFormat.Color, 384, 384);

     

     

     

     

     

     

     

     

     

     

    Resplicing some XNA...

    Play: Rail Gun Charlie (2009)

    Play: Tail Gun Charlie (2008)

    Duckocide
  • 26/07/2009 14:57 In reply to

    Re: Pixel Shader Not Returning Flat Texture

    Answer
    Reply Quote
    I think thats it. It's a MIP issue. I created the texture target with 4 levels. When I create it with

    rockRT1 = Render.CreateRenderTarget(GraphicsDevice, 1, SurfaceFormat.Color, 384, 384);

    instead, I get the flat Texture!   Phew!...  Now to re-enable the shader code and see if it's cracked :)
    Resplicing some XNA...

    Play: Rail Gun Charlie (2009)

    Play: Tail Gun Charlie (2008)

    Duckocide
Page 1 of 1 (4 items) Previous Next