Can't replace WorldViewProjection matrix to World and ViewProjection in Max?

hi guys,

I am working on a HLSL shader that requires me to transform vertex postion into Worldspace first, and then transform it into screen space with ViewProjection matrix because I need to offset the vertex in Worldspace.

But I got this strange problem when I do this, the whole mesh seems to be transformed into some unknown place I can’t find. It would always happen even I do absolutely nothing after the first tranformation :?:

I am not farmiliar with the matrix passed from Max, any idea is appreciated :):

P.S
here is the piece of the shader code. I only put the related part here:

float4x4 WorldViewProj : WORLDVIEWPROJ;
float4x4 World : World;
float4x4 ViewProj : VIEWPROJ;

// position get directly transformed into screen space. It works with no problem
Out.Pos = mul(float4(IN.Pos,1),WorldViewProj);

// but if I transform them into world space first, then to screen space. the mesh is immediately gone after this:
float4 worldPos = mul(float4(IN.Pos,1),World);
Out.Pos = mul(float4(IN.Pos,1),ViewProj);

I’m fairly new to HLSL, but I’m wondering if you’re not seeing an issue related to row vs. column matrices. Off hand, I don’t recall which format Max uses.

Your problem is that VIEWPROJ is not actually a valid semantic. See the doc here.

Instead you’ll have to get the view and the projection matrices separately:

float4x4 World	: 	WORLD;
float4x4 View	:	VIEW;
float4x4 Proj	:	PROJECTION;

And break the transform down into more steps:

float4 wPos = mul( float4( Pos, 1 ), World );
float4 vPos = mul( wPos, View );
Out.Pos = mul( vPos, Proj );

thanks guys the problem is solved after I tried Bronwen’s suggestion. the your document is of great help to us as well :slight_smile:

[QUOTE=FreakyJason;10700]
float4 worldPos = mul(float4(IN.Pos,1),World);
Out.Pos = mul(float4(IN.Pos,1),ViewProj);[/QUOTE]

oops, that should be

Out.Pos = mul(worldPos,ViewProj);

regardless of how you derive “ViewProj”