- vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
DGL https://delphigl.com/forum/ |
|
normals in vertex shader with opengl3.x https://delphigl.com/forum/viewtopic.php?f=20&t=8900 |
Seite 1 von 1 |
Autor: | noeska [ Mo Dez 28, 2009 16:04 ] |
Betreff des Beitrags: | normals in vertex shader with opengl3.x |
Is there a best way for normals in glsl? E.g. on modifying the brick shader from the orange book i stumbled upon this line: Code:
So with opengl 3.x we no longer have gl_NormalMatrix so better provide my own. And have a look on the delphigl wiki on the go: Code: But i do not fully understand it, eg: Code:
What is the endresult? tnmat or m_NormalMatrix? But when using it with the following in the vertex shader: Code:
Some sides of the cube look to dark e.g. are pitch black. This is how my normal matrix and determinant code looks like: Code:
Going away from that i decided to use something more simple: Code:
And everything looks like i expect it to be. So is there somthing wrong with my code? Or can i always use the last regarding to normals or is a normalmatrix a must need? |
Autor: | Coolcat [ Mo Dez 28, 2009 16:32 ] |
Betreff des Beitrags: | Re: normals in vertex shader with opengl3.x |
Probably that method should return m_NormalMatrix ![]() However, if that doesn't work, you may try this Java code: Code:
Zitat: Going away from that i decided to use something more simple: Code:
And everything looks like i expect it to be. That will work only in a (common) special case: The upper left part of your modelViewMatrix needs to be orthonormal. The NormalMatrix is the transpose of the inverse of modelViewMatrix. So, if modelViewMatrix is orthonormal, you can invert it just by transposing it. The transpose of the transpose is again the matrix you started with. The upper left part of your modelViewMatrix is orthonormal, if modelViewMatrix does ONLY contain rotation and/or translation, NO scaling or shearing. |
Autor: | noeska [ Mo Dez 28, 2009 20:32 ] |
Betreff des Beitrags: | Re: normals in vertex shader with opengl3.x |
both m_normalmatrix and tmat give wrong results making some faces of my cube black. while looking at your java example i discovered at typo in my determinant code. The last 8 should have been a 6. But as it turned out that was not the solution. Ok then further with the java example and compare that with the normalmapmatrix calculation itself. A quick comparision tells met that there are differences, so on with the hard job of renumbering the indices. Now i have the following source: Code:
And this actualy seems to work ... (at least i do not get pitch black sides anymore ![]() |
Autor: | noeska [ Mo Dez 28, 2009 22:32 ] |
Betreff des Beitrags: | Re: normals in vertex shader with opengl3.x |
The complete example: http://www.noeska.net/downloads/ogl3brick.zip |
Seite 1 von 1 | Alle Zeiten sind UTC + 1 Stunde |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |