A lightweight 3D rendering engine 100% written in Java (no hardware dependency) and providing a java API to build world geometry, define graphic and rendering parameters and render the scene on any java application display.
It could be interesting to visualize the ligthing Vector(s) (there can be several Lights), an to center them to the origin. A context parameter could allow to set this option (not default).
This would allow to diagnose and investigate lighting.
The RenderEngine should be abstracted from how translating (homogeneous) coordinates of triangles into the pixel coordinates of the view. This requires to create a class that performs this abstraction.
This can be a new class e.g. RenderView or to make View class more "intelligent". To be investigated.
In current implementation the shaded color incorporates the specular reflection hence texture color is also multiplied with specular color however the right formula should be:
Color K = DTA + CDT + S = DT(A+C) + S
D: diffuse color, T: texture, A: Ambient color, C: color of the light source, S: Specular color
-> So the implementation should be modified to reflect the right formula and Specular Color should not be multiplied with Texture mapping color.
Similarly to the normal calculation, we could separate the calculation of triangles in all Elements (a generic method can be proposed in the Element class that will need to be overriden in each Element).
This would allow to re-generate triangles at run-time of an application that, for example, would modify the structure of an Element, e.g. Trellis -> modifications of the altitudes to create a landscape -> need to regenerate the Triangles after creation of the initial default Trellis. Etc.
To reproduce the issue, use the TestSphereTexture program and switch between the 2 Rendering types (disabling texture will show the result with even more evidence).
It is like the light would be at opposite direction.
Quick analysis shows that the switch between the 2 rendering types is in the method render() of RenderEngine class.
It is indicated that :
// Draw triangles with shading full face, no interpolation.
// This forces the mode to be normal at Triangle level even if the normals are at Vertex level
This likely means that the Triangle normals for the Sphere are opposite side than Vertex normals.
Is this a problem of normal calculation or Triangle orientation?
Is it a problem specific to Sphere?
To be investigated.
Create a context information to draw Triangle normals (in addition and separately from Vertex normals).
This should help to have a visual representation of all triangle normals.
Optionally the color of these triangles could be set (and by default it should be a different color than Vertex normals), and it could be e.g. YELLOW by default.
The fact that the perspective Matrix is contained in GraphicContext leads to some complexity.
In particular while updating the context or creating a new context from one of the default contexts, this implies that the perspective Matrix is sometimes created multiple times.
This can be avoided by simplifying the context to only contain the elementary data (width, height, etc.) and delegating the creation of the matrix to other party TBD and to be investigated.