# 3D Problem transforming vertices in RHW projection

## Recommended Posts

Hello,

I have a big old project that cannot be converted from D3D_XYZRHW to D3D_XYZ.

The problem is whatever polygons around me distort, but everything in the distance is good.

It seems to happen when NDC space vertex.x <= 0.  I guess clipping must be the solution; but I don't know how.

Here is my current code.

VERTEX_DECL LocalToScreen( const Vector& vector ) {
VERTEX_DECL vertex;
vertex.xyz = vector - Game::Eye;
vertex.xyz = Game::CameraOrientation * Game::ProjectionMatrix * vertex.xyz;

vertex.xyz.x = vertex.xyz.x / vertex.xyz.z;
vertex.xyz.y = vertex.xyz.y / vertex.xyz.z;
vertex.xyz.z = 1.0 / vertex.xyz.z;
// This stops polygons around camera distorting; but it fully removes them which
//  is not a proper solution.  I think I need some kind of clamping.
if ( vertex.z <= 0.0 ) {
return vertex;
}

vertex.xyz.x = vertex.xyz.x * Game::HalfViewportWidth + Game::HalfViewportWidth;
vertex.xyz.y = vertex.xyz.y * -Game::HalfViewportHeight + Game::HalfViewportHeight;
vertex.rhw = vertex.xyz.z;
vertex.xyz.z = vertex.xyz.z * 0.000588; // Legacy.  This doesn't seem to do anything.

return vertex;
}

Edited by scragglypoo

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628368
• Total Posts
2982293
• ### Similar Content

• Hello! I am looking for a concept artist for a 3d brawl game. I will need sketches done for characters, and arenas. I would prefer a hobbyist for free, but I will pay if the work i am getting is significantly better than a free hobbyists. If interested, please do email me at JVGameDev@gmail.com

•                          I created this model in Maya and have been practicing on the side while studying for school. This may not be the best picture to show faces or line flow and the resolution does not help things either. Still, I would love some opinions on where I can improve on my 3D modeling. Also, this is just a skin model and I spent no time texturing the model or accounting for clothing. Thank you in advance for any feedback.
• By G-Dot
Hello everybody! I've got a little problem. I need to create jetpack action. The main target is when I will press some button on my keybord my character will fly in the sky and stay here for some time then he will remove to the ground. I'm working with Unreal Engine 4 with blueprints.

• I have a very simple vertex/pixel shader for rendering a bunch of instances with a very simple lighting model.
When testing, I noticed that the instances were becoming dimmer as the world transform scaling was increasing. I determined that this was due to the fact that the the value of float3 normal = mul(input.Normal, WorldInverseTranspose); was shrinking with the increased scaling of the world transform, but the unit portion of it appeared to be correct. To address this, I had to add normal = normalize(normal);.
I do not, for the life of me, understand why. The WorldInverseTranspose contains all of the components of the world transform (SetValueTranspose(Matrix.Invert(world * modelTransforms[mesh.ParentBone.Index]))) and the calculation appears to be correct as is.
Why is the value requiring normalization? under);
);
float4 CalculatePositionInWorldViewProjection(float4 position, matrix world, matrix view, matrix projection) { float4 worldPosition = mul(position, world); float4 viewPosition = mul(worldPosition, view); return mul(viewPosition, projection); } VertexShaderOutput VS(VertexShaderInput input) { VertexShaderOutput output; matrix instanceWorldTransform = mul(World, transpose(input.InstanceTransform)); output.Position = CalculatePositionInWorldViewProjection(input.Position, instanceWorldTransform, View, Projection); float3 normal = mul(input.Normal, WorldInverseTranspose); normal = normalize(normal); float lightIntensity = -dot(normal, DiffuseLightDirection); output.Color = float4(saturate(DiffuseColor * DiffuseIntensity).xyz * lightIntensity, 1.0f); output.TextureCoordinate = SpriteSheetBoundsToTextureCoordinate(input.TextureCoordinate, input.SpriteSheetBounds); return output; } float4 PS(VertexShaderOutput input) : SV_Target { return Texture.Sample(Sampler, input.TextureCoordinate) * input.Color; }

• Hey, Im using directx allocate hierarchy from dx9 to use a skinned mesh system.
one mesh will be only the skeleton with all animations others meshes will be armor, head etc, already skinned with skeleton above. No animation, idle position with skin, thats all I want to use the animation from skeleton to other meshes, so this way I can customize character with different head, armor etc. What I was thinking its copy bone matrices from skeleton mesh to others meshes, but Im a bit confused yet what way I can do this.

Thanks.

• 10
• 9
• 13
• 24
• 11