View Full Version : Hello. I have this shader test, originally in HLSL

08-21-2010, 06:49 AM
I have this shader test, originally in HLSL and DirectX, now I tried to convert it to OpenGL and CG.
Is an animation shaders for skinned. I try to set the skinnedmatrix to identity for get the mesh that are equal to as is, without weights and without indexes.
The problem is that appear different stretch and lengthened.
What can 'be?
the same shaders in DirectX HLSL and working properly.
Could be the world view and projection matrices?
work differently in OpenGL?
Thank you.

uniform float4 skinnedMatricesVS20[80*3];
uniform float4 CameraModelPosition;
uniform float4x4 WMatrix;
uniform float4x4 WVPMatrix;
uniform float4x4 VPMatrix;

struct VS_IN
float3 pos : POSITION;
float4 blendWeights : TEXCOORD0;
float4 blendIndices : TEXCOORD1;
float3 normalL : NORMAL;


struct VS_OUT
float4 posH : POSITION;
float3 posW ;
float3 normalW ;
float2 texC : TEXCOORD;


float4x4 RebuildSkinMatrix(float index)
float4x4 mx;
float4 a = skinnedMatricesVS20[index*3+0];
float4 b = skinnedMatricesVS20[index*3+1];
float4 c = skinnedMatricesVS20[index*3+2];

mx = float4x4(
float4(0, 0, 0, 1));
return mx;

VS_OUT v_Skin3(VS_IN vIn)
VS_OUT vOut ;

// First transform position with bones that affect this vertex
// Use the 3 indices and blend weights we have precalculated.
float4x4 skinMatrix =
RebuildSkinMatrix(vIn.blendIndices.x) * vIn.blendWeights.x +
RebuildSkinMatrix(vIn.blendIndices.y) * vIn.blendWeights.y +
RebuildSkinMatrix(vIn.blendIndices.z) * vIn.blendWeights.z;
skinMatrix[0] = float4(1,0,0,0);
skinMatrix[1] = float4(0,1,0,0);
skinMatrix[2] = float4(0,0,1,0);
skinMatrix[3] = float4(0,0,0,1);

// Calculate local world matrix with help of the skinning matrix
float4x4 localWorld = mul(WMatrix, skinMatrix);
float4x4 matrixx = RebuildSkinMatrix(0);
// Now calculate final screen position with world and viewProj matrices.
float4 worldPos = mul(localWorld, float4(vIn.pos, 1));
vOut.posH = mul(worldPos, VPMatrix);
vOut.posW = mul(worldPos, VPMatrix);
return vOut;

float4 p_Skin3(VS_OUT pIn) :COLOR
return float4(1,0,0,1);

08-23-2010, 07:56 AM
I converted my code from DirectX10 to opengl with very little (conceptual) change. The biggest and almost only difference was the left/right handed coordinate system, which was fixed by adding:
glScalef(1.0,1.0,-1.0) to the modelview matrix.

Most likley it is something upstream from your shaders...

Also, if you are building your own modelview and projection matrices you might try using opengl to do the same and then call glGetFloatv(GL_MODELVIEW_MATRIX, mat);
and compare your results. There are some odd differences, such as the flip going from homogeneous to clip coords, etc....

I let opengl create my projection matrix, since it has these differences from directx. I still create my modelview, however...