Here is a shader:

cbuffer ConstantBufferMatrices : register(b0) { float4x4 World: packoffset(c0); float4x4 View: packoffset(c4); float4x4 Projection: packoffset(c8); } struct VS_INPUT { float3 Pos : POSITION; float2 Tex : TEXCOORD0; float3 Norm : TEXCOORD1; }; struct VS_OUTPUT { float4 Pos : SV_POSITION; float3 Norm : TEXCOORD0; }; VS_OUTPUT main(VS_INPUT input) { VS_OUTPUT output = (VS_OUTPUT)0; float4 Pos1 = float4(input.Pos.x, input.Pos.y, input.Pos.z, 1); float4x4 FinalMatrix = mul(Projection, mul(View,World)); output.Pos = mul(FinalMatrix, Pos1); float4 Normal_4 = float4(input.Norm, 0); float4 Normal_4_b = mul(Normal_4,World); output.Norm = normalize(float3(Normal_4_b.xyz)); return output; } 

I study his third hour in a row. It is necessary to translate the normals into the world coordinate system, so that when you rotate the teapot, the normals apparently glide over it. A world matrix is ​​put (only rotation along the Y axis), a specific matrix (once at the start of the program, the PerspectiveLookAt function), the projection matrix can be disregarded. Normal translate to float4 with w=0 (since this is the direction), normalize and in the pixel shader I simply output as a color (with alpha 1.0f). I get the result: the normals rotate with the teapot. When they swim a little at the very beginning and freeze, it probably does not mean anything. The teapot is green-red, the bottom is blue. All this is intended for lighting tied to the camera, but for now I’m doing normals. Why do the normals rotate with the teapot? The only thing that changes is the matrix of the world, but I multiply it into it!

    1 answer 1

    The kettle was imported from 3ds max, you had to do three things:

    1. Reverse the normals (multiply by -1 each component).
    2. Reverse the order of the indices in triangles.
    3. Change the order of components in normals (swap y and z ).

    Here is the third I missed. Already checked, everything works.

    • Why does not the author of the post give the answer? I do not understand what is happening already. @arhad, you registered an account for it? - strangeqargo 9:10 pm
    • @strangeqargo, I have nothing to do with IlyaIvanov. Yes, and the account was registered significantly earlier than the question was asked (2 days ago and 10 hours ago, respectively). Now the account, by the way, has been deleted. - ߊߚߤߘ
    • @strangeqargo, my mistake is that I didn’t pay attention to the differences in writing nicknames and, thinking that the author’s answer, formatted it. - ߊߚߤߘ
    • @Arhad did not understand what the problem was. You made a good edit, formatted the list. For this, do not banyat) - Nick Volynkin
    • one
      I apologize. I will continue to give answers myself. While shy. This was me. I do not have an account on the phone, otherwise I would have entered it from my own. You saw rubbish after my attempts yesterday. It's ok. - Ilia Ivanov