how to program rotating cube using shader assembler

Started by
5 comments, last by kauna 10 years, 11 months ago

first i substitute a few common vertex shader funtions for SetFVF

then i multiply view/projection/world matrix to substitute SetVertexShaderConstantF for SetTransform

but the rotating effect is odd and if x/y/z's value is lower then zero, it will not be displayed

the shader assembler is as follows

"vs_1_1\n"
"dcl_position v0\n"
"dcl_color v1\n"
"m4x4 oPos, v0, c0\n"
"mov oD0, v1\n"

Advertisement

The problem is not within that shader. That is a simple generic transformation that expects the WVP matrix in the constant registers 0...3, and that the incoming vertex has position and color elements. It doesn't care at all whether the transformation represents rotation or something else entirely.

Have you tried to transpose the WVP matrix before using SetVertexShaderConstantF? The m4x4 is a macro instruction that is implemented as four dp4:s across consecutive float4 registers on the drivers/hardware, and due to this the transpose is needed if using D3DX matrix utility functions to generate the transform.

The transpose is cheaper to do once on the host program, as opposed to running it on each vertex.

Niko Suni

The problem is not within that shader. That is a simple generic transformation that expects the WVP matrix in the constant registers 0...3, and that the incoming vertex has position and color elements. It doesn't care at all whether the transformation represents rotation or something else entirely.

Have you tried to transpose the WVP matrix before using SetVertexShaderConstantF? The m4x4 is a macro instruction that is implemented as four dp4:s across consecutive float4 registers on the drivers/hardware, and due to this the transpose is needed if using D3DX matrix utility functions to generate the transform.

The transpose is cheaper to do once on the host program, as opposed to running it on each vertex.

thanks, and D3DXMatrixTranspose works when below zero statically

but the cube is still missing when rotating, and i use one static variable to set the angle dynamically as fvf

Why are you using shader assembly?

Cheers!

The problem is not within that shader. That is a simple generic transformation that expects the WVP matrix in the constant registers 0...3, and that the incoming vertex has position and color elements. It doesn't care at all whether the transformation represents rotation or something else entirely.

Have you tried to transpose the WVP matrix before using SetVertexShaderConstantF? The m4x4 is a macro instruction that is implemented as four dp4:s across consecutive float4 registers on the drivers/hardware, and due to this the transpose is needed if using D3DX matrix utility functions to generate the transform.

The transpose is cheaper to do once on the host program, as opposed to running it on each vertex.

thanks again

i put the rotating matrix from the third to the second parameter when calling D3DXMatrixMultiply and it works now

Why are you using shader assembly?

Cheers!

it's cool and i have not learned hlsl

The shader assembly isn't supported since SM4.0 (Direct3D 10+), so shader assembly is getting deprecated. Well, of course there is the cool factor and more importantly it is useful to know shader assembly if you are debugging shader code and you want to know what's happening exactly.

Otherwise, learn hlsl for any shader longer than you have written. AFAIK, every SM1.0 level pixel shader can represented using texture stage combinations, because of limited number of instructions.

Cheers!

This topic is closed to new replies.

Advertisement