Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: actor shader woes  (Read 289 times)
AriusEso
Customers
Community Member
*****
Posts: 303

Esoteric


« on: April 25, 2008, 10:07:25 AM »

Hey,

I've started writing up a template for my shaders that work on actors. I've been using Sylvain's example as my reference. But I've gone wrong somewhere and I can't work out where.

This is the result I get:

http://www.azazeldev.org/stuffs/badactor.jpg

As you can see, Alyxs' vertices are being stretched in places. So i'm sure it is something in the TPN function. Ignore the light and tangent/bitangent stuff, that is just skeleton for later when I add stuff.

Code:
        float4x3 m_Bone[52]     : BONES;
        float4x4 m_World        : WORLD;
        float4x4 m_ViewProj     : VIEWPROJ;
        int      i_NumBone      : BONESPERVERTEX;
       
        texture  Diffuse        : TEXTURE0;
       
        sampler2D DiffSample = sampler_state
        {
                Texture = (Diffuse);
        };

        struct vpin
        {
                float3 Position : POSITION0;
                float3 Normal   : NORMAL;
                float3 Tangent  : TANGENT;
                float3 BiTangent: BINORMAL;
                float4 BlendIN  : BLENDINDICES;
                float4 BlendWE  : BLENDWEIGHT;
                float2 UV       : TEXCOORD0;
        };

        struct fpin
        {
                float4 Position: POSITION;
                float2 UV      : TEXCOORD0;
                float3 LightVec: TEXCOORD1;
                float3 Normal  : TEXCOORD2;
        };

        struct tvin
        {
                float4 Colour  : COLOR0;
        };

        void TPN(uniform int NumBones, float3 Pos, float3 Norm, float4 Weights, float4 Indicies, out float3 rPos, out float3 rNorm)
        {
                if(NumBones == 0)
                {
                        rPos           = mul(Pos, m_World);
                        rNorm          = mul(Norm, (float3x3)m_World);
                }
                else
                {
                        int4 Bone      = D3DCOLORtoUBYTE4(Indicies);
                        int  iArray[4] = (int[4])Bone;
                       
                        rPos           = 0;
                        rNorm          = 0;
                       
                        float Last     = 0;
                       
                        for(int i = 0; i < NumBones - 1; i++)
                        {
                                float4x3 m_Temp = m_Bone[iArray[i]];
                                Last            = Last + Weights[i];
                                rPos           += mul(Pos, m_Temp) * Weights[i];
                        }
                       
                        Last            = 1 - Last;
                        float4x3 m_Temp = m_Bone[iArray[NumBones-1]];
                        rPos           += mul(Pos, m_Temp) * Last;
                        rNorm          += mul(rNorm, (float3x3)m_Temp) * Last;
                }
        }

        void vp(uniform int NumBones, in vpin IN, out fpin OUT)
        {
                float3 Pos;
                float3 Norm;
               
                TPN(NumBones, IN.Position, IN.Normal, IN.BlendWE, IN.BlendIN, Pos, Norm);
               
                OUT.Position = mul(Pos, m_ViewProj);
                OUT.Normal   = Norm;
                OUT.LightVec = float3(0, 0, 0);
                OUT.UV       = IN.UV;
        }

        void fp(in fpin IN, out tvin OUT)
        {
                float4 Col = tex2D(DiffSample, IN.UV);
               
                OUT.Colour = Col;
        }

        vertexshader Array[5] = {
                                        compile vs_2_0 vp(0),
                                        compile vs_2_0 vp(1),
                                        compile vs_2_0 vp(2),
                                        compile vs_2_0 vp(3),
                                        compile vs_2_0 vp(4),
                                };

        technique aTechnique
        {
                pass pass0
                {
                        vertexshader = (Array[i_NumBone]);
                        pixelshader  = compile ps_2_0 fp();
                }
        }

Any help would be appreciated. Thanks.
Logged

-...-
Squeeged third eye.

AriusEso
Customers
Community Member
*****
Posts: 303

Esoteric


« Reply #1 on: April 25, 2008, 12:10:46 PM »

Nevermind, must be something wrong with the actual model. Works if I use the rancor as a test.
Logged

-...-
Squeeged third eye.

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks