Chicken-Bones / CodeChickenLib

GNU Lesser General Public License v2.1
65 stars 51 forks source link

Rendering model with a rotation op yields incorrect results. #45

Open MrTJP opened 9 years ago

MrTJP commented 9 years ago

Unless I am mistaken, applying a transformation to a model should be the same as rendering it with the transformation in-line. If you apply a rotation and then render the model with the light matrix, it works correctly. The model is properly shaded on the correct sides. However, if you render the model without the transformation pre-applied, it seems that the rotation will actually rotate the light matrix's shading.

This is for static rendering, by the way.

Correct results: 1) Reset renderstate 2) Locate renderstate lightmatrix 3) Apply rotation to model 4) Render model with (uv transformation, light matrix)

Incorrect results: 1) Reset renderstate 2) Locate renderstate lightmatrix 3) Render model with (rotation, uv transformation, light matrix)

I don't have a complete understanding of how the lighting works, but I think its because the light matrix applies colour shading based on vertex order, so when you rotate a model, the first four vertexes are thought to be the first side while in actuality they could be any side.

Chicken-Bones commented 9 years ago

Do you have some code I can run to verify this?

On Wed, Jun 24, 2015 at 7:32 AM, MrTJP notifications@github.com wrote:

Unless I am mistaken, applying a transformation to a model should be the same as rendering it with the transformation in-line. If you apply a rotation and then render the model with the light matrix, it works correctly. The model is properly shaded on the correct sides. However, if you render the model without the transformation pre-applied, it seems that the rotation will actually rotate the light matrix's shading.

Correct results: 1) Locate renderstate lightmatrix 2) Apply rotation to model 3) Render model with (uv transformation, light matrix)

Incorrect results: 1) Locate renderstate lightmatrix 2) Render model with (rotation, uv transformation, light matrix)

— Reply to this email directly or view it on GitHub https://github.com/Chicken-Bones/CodeChickenLib/issues/45.

MrTJP commented 9 years ago

Not in production, at the moment. I will leave a comment in my code and link you to it when I push the commit.

MrTJP commented 9 years ago

Here is a link to a piece of code that can produce the problem.

https://github.com/MrTJP/ProjectRed/blob/57cded5ca6f448727f635256e81bc20a1429b4ba/src/mrtjp/projectred/fabrication/tileicprinter.scala#L677