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

Deferredshading with skinnedSample problem

Last post 9/28/2009 8:32 AM by Sorcerer. 6 replies.
  • 9/26/2009 7:46 AM

    Deferredshading with skinnedSample problem

    I am trying to mix Deferredshading from ziggware with the skinnedsample, but I am having this problem  ( http://www.youtube.com/watch?v=FgGrLn2aHgw )

    And this is my RenderSkinnedGBuffer.fx:
    #define MaxBones 59  
     
    float4x4 Bones[MaxBones];  
    float4x4 View;  
    float4x4 Projection;  
     
    float specPow = 30;  
    float Kdiffuse = 1;  
    float Kspecular = 2;  
    float Kreflection = 1;  
     
    texture Diffuse_Texture;  
    sampler diffuse_Sampler = sampler_state  
    {  
      Texture = <Diffuse_Texture>;  
      MinFilter = Linear;  
      MagFilter = Linear;  
      MipFilter = Linear;  
      AddressU = Wrap;  
      AddressV = Wrap;  
    };  
     
    texture Specular_Texture;  
    sampler specular_Sampler = sampler_state  
    {  
        Texture = (Specular_Texture);  
        MagFilter = LINEAR;  
        MinFilter = LINEAR;  
        Mipfilter = LINEAR;  
        AddressU = Wrap;  
        AddressV = Wrap;  
    };  
     
    texture Normal_Texture;  
    sampler normal_Sampler = sampler_state  
    {  
        Texture = (Normal_Texture);  
        MagFilter = LINEAR;  
        MinFilter = LINEAR;  
        Mipfilter = LINEAR;  
        AddressU = Wrap;  
        AddressV = Wrap;  
    };  
     
    texture Env_Texture;  
    sampler env_Sampler = sampler_state  
    {  
        Texture = <Env_Texture>;  
        MinFilter = Linear;  
        MagFilter = Linear;  
        MipFilter = Linear;  
        AddressU = Wrap;  
        AddressV = Wrap;  
    };   
     
    struct VS_INPUT  
    {  
        float4 Position : POSITION0;  
        float3 Normal : NORMAL0;  
        float2 TexCoord : TEXCOORD0;  
        //float3 Binormal : BINORMAL0;  
        float3 Tangent : TANGENT0;     
          float4 BoneIndices : BLENDINDICES0;  
          float4 BoneWeights : BLENDWEIGHT0;  
    };  
     
    struct VS_OUTPUT  
    {  
        float4 Position : POSITION0;  
        float2 TexCoord : TEXCOORD0;  
        float2 Depth : TEXCOORD1;  
        float3x3 TangentToWorld : TEXCOORD2;  
        //float3 Data1 : TEXCOORD3;  
    };  
     
    VS_OUTPUT VS_Function(VS_INPUT input)  
    {  
        VS_OUTPUT output;  
          float4x4 skinTransform = 0;  
            
          skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x;  
          skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y;  
          skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z;  
          skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w;  
            
          float4 pos = mul(input.Position, skinTransform);  
          float3 eyeLoc = mul(View._m30_m31_m32, transpose(View));  
          float3 eyeDir = eyeLoc - pos;  
          pos = mul(pos, View);  
          pos = mul(pos, Projection);  
            
          float3x3 tangentSpace;  
        tangentSpace[0] = mul(input.Tangent, skinTransform);  
        tangentSpace[1] = mul(cross(input.Tangent, input.Normal), skinTransform);  
        //tangentSpace[1] = mul(input.Binormal, skinTransform);  
        tangentSpace[2] = mul(input.Normal, skinTransform);  
             
          output.Position = pos;  
          output.TangentToWorld = tangentSpace;  
          output.TexCoord = input.TexCoord;  
        output.Depth.x = output.Position.z;  
        output.Depth.y = output.Position.w;  
          //output.Data1 = normalize(mul(tangentSpace, eyeDir));  
            
          return output;  
    }  
     
    struct PS_Output  
    {  
        half4 Color : COLOR0;  
        half4 Normal : COLOR1;  
        half4 Depth : COLOR2;  
    };  
     
    PS_Output PS_Function(VS_OUTPUT input)  
    {  
        PS_Output output;  
        float4 outColor = tex2D(diffuse_Sampler, input.TexCoord);  
          
        float4 specularAttributes = tex2D(specular_Sampler, input.TexCoord);  
        //specular Intensity  
        outColor.a = specularAttributes.r;    
          
        // read the normal from the normal map  
        float3 normalFromMap = tex2D(normal_Sampler, input.TexCoord);  
            
        //tranform to [-1,1]  
        normalFromMap = 2.0f * normalFromMap - 1.0f;  
        //transform into world space  
        normalFromMap = mul(normalFromMap, input.TangentToWorld);  
        //normalize the result  
        normalFromMap = normalize(normalFromMap);  
        //output the normal, in [0,1] space  
        output.Normal.rgb = 0.5f * (normalFromMap + 1.0f);  
          
        //specular Power  
        output.Normal.a = specularAttributes.a;  
     
        output.Depth = input.Depth.x / input.Depth.y;  
          
        output.Color = outColor;  
          
        return output;  
    }  
     
    technique Technique1  
    {  
        pass Pass1  
        {  
            VertexShader = compile vs_2_0 VS_Function();  
            PixelShader = compile ps_2_0 PS_Function();  
        }  



    Can you see what am I doing wrong?
    http://www.youtube.com/alexmbr
  • 9/26/2009 4:24 PM In reply to

    Re: Deferredshading with skinnedSample problem

    You're probably passing in bad data. Either the vertex stream has a bad index or weight in the BoneIndices/BoneWeights semantic, or one or more of the Bones matrices is bad.
    You can easily debug this problem with PIX for Windows.

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 9/26/2009 9:42 PM In reply to

    Re: Deferredshading with skinnedSample problem


    I am downloading the DXSDK to try this, but I never used PIX before.

    http://www.youtube.com/alexmbr
  • 9/26/2009 10:55 PM In reply to

    Re: Deferredshading with skinnedSample problem

    The skinning part is not working and I don't know why.

    Here is a new video showing better the problem:http://www.youtube.com/watch?v=ccJN1Ft4pjw

    But the video doesn't show that some parts of the model disappear sometimes:


    Anyway, if anyone is kind enough to take a look at this, I will leave the project here: DeferredShading w/ skinnedmodel animations problem ( 18MB ).
    http://www.youtube.com/alexmbr
  • 9/27/2009 4:59 AM In reply to

    Re: Deferredshading with skinnedSample problem

    Did you verify the following suggestions?

    Either the vertex stream has a bad index or weight in the BoneIndices/BoneWeights semantic, or one or more of the Bones matrices is bad.


    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 9/27/2009 11:21 PM In reply to

    Re: Deferredshading with skinnedSample problem

    not yet, because I am trying to understand PIX and trying to see where I can look for that in there.
    http://www.youtube.com/alexmbr
  • 9/28/2009 8:32 AM In reply to

    Re: Deferredshading with skinnedSample problem

    Nevermind, thanks. I finally made it to work as you can see here: http://www.youtube.com/watch?v=9AkuQf0bvns

    And here is the new Effect code:

    #define MaxBones 59  
     
    float4x4 Bones[MaxBones];  
    float4x4 View;  
    float4x4 Projection;  
     
    float Kdiffuse = 1;  
    float Kspecular = 2;  
     
     
    texture Diffuse_Texture;  
    sampler diffuse_Sampler = sampler_state  
    {  
      Texture = <Diffuse_Texture>;  
      MinFilter = Linear;  
      MagFilter = Linear;  
      MipFilter = Linear;  
      AddressU = Wrap;  
      AddressV = Wrap;  
    };  
     
    texture Specular_Texture;  
    sampler specular_Sampler = sampler_state  
    {  
        Texture = (Specular_Texture);  
        MagFilter = LINEAR;  
        MinFilter = LINEAR;  
        MipFilter = LINEAR;  
        AddressU = Wrap;  
        AddressV = Wrap;  
    };  
     
    texture Normal_Texture;  
    sampler normal_Sampler = sampler_state  
    {  
        Texture = (Normal_Texture);  
        MagFilter = LINEAR;  
        MinFilter = LINEAR;  
        MipFilter = LINEAR;  
        AddressU = Wrap;  
        AddressV = Wrap;  
    };  
     
    struct VS_INPUT  
    {  
        float4 Position : POSITION0;  
        float2 TexCoord : TEXCOORD0;  
        float3 Normal : NORMAL0;  
        float3 Tangent : TANGENT0;  
        float4 BoneIndices : BLENDINDICES0;  
        float4 BoneWeights : BLENDWEIGHT0;  
    };  
     
    struct VS_OUTPUT  
    {  
        float4 Position : POSITION0;  
        float2 TexCoord : TEXCOORD0;  
        float2 Depth : TEXCOORD1;   
        float3x3 tangentToWorld : TEXCOORD2;  
    };  
     
     
    ///////////////  Vertex Shaders   ///////////////////////  
     
    VS_OUTPUT VS_Function(VS_INPUT input)  
    {  
        VS_OUTPUT output;  
        float4x4 skinTransform = 0;  
          
        skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x;  
        skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y;  
        skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z;  
        skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w;  
          
        float4 pos = mul(input.Position, skinTransform);  
        float3 eyeLoc = mul(View._m30_m31_m32, transpose(View));  
        float3 eyeDir = eyeLoc - pos;  
        pos = mul(pos, View);  
        pos = mul(pos, Projection);  
          
      output.tangentToWorld[0] = mul(input.Tangent, skinTransform);  
      output.tangentToWorld[1] = mul(cross( input.Normal, input.Tangent), skinTransform);  
      output.tangentToWorld[2] = mul(input.Normal, skinTransform);  
        
        output.Position = pos;  
        output.TexCoord = input.TexCoord;  
      output.Depth.x = output.Position.z;  
      output.Depth.y = output.Position.w;  
          
        return output;  
    }  
     
    ///////////////  Pixel Shaders   ///////////////////////  
     
    struct PS_Output  
    {  
        half4 Color : COLOR0;  
        half4 Normal : COLOR1;  
        half4 Depth : COLOR2;  
    };  
     
    PS_Output PS_Function(VS_OUTPUT input)  
    {  
        PS_Output output;  
        output.Color = tex2D(diffuse_Sampler, input.TexCoord);  
     
        float4 specularAttributes = tex2D(specular_Sampler, input.TexCoord);  
        //specular Intensity  
        output.Color.a = specularAttributes.r * Kspecular;  
     
        // read the normal from the normal map  
        float3 normalFromMap = tex2D(normal_Sampler, input.TexCoord);  
          
        //tranform to [-1,1]  
        normalFromMap = 2.0f * normalFromMap - 1.0f;  
        //transform into world space  
        normalFromMap = mul(normalFromMap, input.tangentToWorld);  
        //normalize the result  
        normalFromMap = normalize(normalFromMap);  
        //output the normal, in [0,1] space  
        output.Normal.rgb = 0.5f * (normalFromMap + 1.0f);  
     
        //specular Power  
        output.Normal.a = specularAttributes.a * Kspecular;  
        output.Depth = input.Depth.x / input.Depth.y;  
          
        return output;  
    }  
     
    ///////////////  Techniques   ///////////////////////  
     
    technique technique1  
    {  
      pass Pass1  
      {  
        VertexShader = compile vs_1_1 VS_Function();  
        PixelShader = compile ps_2_0 PS_Function();  
      }  


    http://www.youtube.com/alexmbr
Page 1 of 1 (7 items) Previous Next