Passing info from SMeshBufferTangents to GLSL 1.1 vertex shader.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Passing info from SMeshBufferTangents to GLSL 1.1 vertex shader.

Post by Andrey01 »

I'm working on an own material whose shaders mainly calculate PBR lighting. GLSL of version 1.1. is used. But I also want to include in them a simple normal mapping implementation. That would require passing normals, tangents and binormals that pre-calculated from createMeshWithTangents() method for each vertex into the vertex shader. It is necessary for a matrix that would transform the normals of the normal map from the tangent space to the world one. However, I don't know a way Irrlicht passes (and whether passes at all?) that info (tangents/binormals) from SMeshBufferTangents during the drawing. I know I can access gl_Position, gl_Normal, gl_TexCoord of a corresponding vertex from vertex shader, but how to access tangents and binormals?
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Passing info from SMeshBufferTangents to GLSL 1.1 vertex shader.

Post by CuteAlien »

It's a bit hidden in the S3DVertexTangents documentation, but those are passed as TEXCOORD1 and TEXCOORD2. Thought it's also possible to directly calculate them in shader. In the following thread look for my code with the struct STangentSpace for an example how to do that: viewtopic.php?p=307008
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Andrey01
Posts: 57
Joined: Mon Jul 27, 2020 9:08 pm

Re: Passing info from SMeshBufferTangents to GLSL 1.1 vertex shader.

Post by Andrey01 »

Wow, thank you. I used the calculations of the new normals from tangent into world space in the fragment shader as in that example and the result is really nice :)
Image
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Passing info from SMeshBufferTangents to GLSL 1.1 vertex shader.

Post by CuteAlien »

Glad it worked and looks good. As a guy used to CPU coding the dFdx/dFdy functions in shaders still feel a bit crazy to me, but they allow for some clever stuff.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply