This topic is 5211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, here is my vertex shader:
float4x4 World : WORLD;
float4x4 ViewProjection : VIEWPROJECTION;

struct VS_OUTPUT
{
float4  Pos: POSITION;
float4  Diff : COLOR;
float2  TextureUV : TEXCOORD0;
};

VS_OUTPUT VS(
float3 InPos  : POSITION,
float3 InNormal : NORMAL,
float2 InTexCoord : TEXCOORD0
)
{
VS_OUTPUT Out = (VS_OUTPUT)0;

// Transform the position and normal
float4 Pos = mul(float4(InPos, 1), World);
float3 Normal = normalize(mul(InNormal, (float3x3)World));

Out.Pos  = mul(Pos, ViewProjection);
Out.Diff = LightAmbientIntensity;
Out.TextureUV = InTexCoord;
return Out;
}


I apply scaling and rotation/translation and multiply it with the world matrix, and set it (the matrices are coming in properly). However, the vertices are rendered as is, no scaling, no rot or translation. The world matrix is constructed ok as the transforms work when used with the ffp. what o what could it be?

##### Share on other sites
Firstly if you are using scaling you want to multiply the normals by the inverse of the world matrix, if you use any other kind of world transform (such as chear) you want the inverse transpose. When you rotate or translate the normal then its fine, but when you scale a model then the normals may end up being off if you dont use the inverse.

Anyway you problem might be this. Are you using column or row based transformations? Try swaping your multiplications around:

float4 Pos = mul(float4(InPos, 1), World);

to

float4 Pos = mul(World,float4(InPos, 1));

etc. That got me when I started shaders, doh!!!!

Lastly, since you dont use pos for anything, just pass in a worldviewprojection matrix and do

float4 Pos = mul(float4(InPos, 1), World);
Out.Pos = mul(Pos, ViewProjection);

all at once (then again you might be using it I suppose and removed it to try getting it working, if so I aplogise).

##### Share on other sites
I tried exactly what u said and there was no change. Yea I did concatenate all 3 transform matrices too (you were right I was doing something before viewproj but I disabled that), but still the same behavior. The vertices are shaded just as they come in, they go thru projection (because my view is identity) but the world transform seems to be ignored, any ideas?

##### Share on other sites
I am setting my transform matrices like so:
effect->SetValue("World", &matWorld, sizeof(D3DXMATRIX));effect->SetValue("ViewProjection", &matProj, sizeof(D3DXMATRIX));

(the view matrix is set to identity and so is left out).

Is anything wrong with passing it this way? They are all 4x4 matrices..

##### Share on other sites
- Can you paste the asm listing? (Compile with the /Fc option)
- Have you transposed the matrices?

##### Share on other sites
Hi, thanks for ur reply. No I wasnt transposing! I then did a transpose of the world matrix only and it fixed the scaling issue. However, transposing projection is causing strange results, and the object is not rotated or translated.

I also switched from:
float4 Pos = mul(float4(InPos, 1), World);

to:
float3 Pos = mul((float4x3)World, float4(InPos, 1));

I will try and get the asm soon! .NET is complaining that asm output from multiple source files is not allowed.

Is it any issue that I concatenate my world and view matrices and set view to identity (in effect my REAL world matrix is also identity then), so in reality world = view and viewproj = proj.
So when I use the transpose of world I am really using the transpose of worldview. Should this matter?
(this optimization works fine on non-transposed worldview transforms on the ffp, btw).

EDIT: when I say fixed the scaling, it actually cuts off half my view (shows only the top half of the shaded object).

##### Share on other sites
I am unable to get the asm output.. can anyone help or see a cause for this problem?
I am using ID3DXEffect which the sdk docs say will automatically transpose matrices when set.

##### Share on other sites
Quote:
 Original post by dhanjiI am unable to get the asm output.. can anyone help or see a cause for this problem?

Use:
fxc /E VS /T vs_1_1 /Fc asm.txt HLSL-filename

Quote:
 I am using ID3DXEffect which the sdk docs say will automatically transpose matrices when set.

- This only happens on SetMatrix calls. It can never do it on SetValue calls (because it doesn't know the value's a matrix)
- There's a bug in the summer 2004 update: Matrices aren't transposed by the effects interface...but with the FFP IIRC, so this shouldn't affect you (if you use SetMatrix).

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013294
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!