Question regarding my first shader steps

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
woalexan
Posts: 17
Joined: Wed May 28, 2025 6:22 pm
Location: Austria

Question regarding my first shader steps

Post by woalexan »

Hello,

I am currently doing my first steps regarding basic shader learning using GLSL and Irrlicht. I started with an Irrlicht example which worked great, did some modifications to the shaders, everything worked and I had fun doing this. Now I want to continue by applying and trying out the great lightning examples under https://learnopengl.com/Lighting/Basic-Lighting

The issue for me is that this author seems to use a newer version of GLSL, which is needed for example for the "out" directive. When I also change my shaders to this version then many attributes are deprecated. So I searched on the internet, through the Irrlicht forum etc..., and I updated my shader code to use in/outs. Problem is now, the shaders still compile, but my texture coordinates seem to have a problem, regardless what I do or try.

Does someone have maybe a clue where my problem is? Or does it not work together with Irrlicht 1.8.4 which I use? According to Irrlicht Forum topics I found higher GLSL versions should also work together with Irrlicht. Thank you very much for any help, and please excuse me if this is a very basic question.

My rather simply Vertex and Fragment shader which works:

Code: Select all

uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 mLightPos;
uniform vec4 mLightColor;

void main(void)
{
	gl_Position = mWorldViewProj * gl_Vertex;
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
}

Code: Select all

uniform sampler2D myTexture;

void main (void)
{    
   vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0]));
 
   gl_FragColor = col;
}
Working output:
Image

After updating shader code to newer version:

Code: Select all

#version 420 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTextCoord0;

/*
alternative layout I did find on Irrlicht Forum, which would
make sense according to order of variables in S3DVertex.h struct
but does also not work
layout ( location = 0 ) in vec3 aPos;
layout ( location = 1 ) in vec3 aNormal;
layout ( location = 2 ) in vec4 color;
layout ( location = 3 ) in vec2 aTextCoord0;*/

uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 mLightPos;
uniform vec4 mLightColor;

out vec2 TexCoord;

void main(void)
{
	gl_Position = mWorldViewProj * vec4(aPos, 1.0);
	
	TexCoord = aTextCoord0;
}

Code: Select all

#version 420 core

layout(location=0) out vec4 FragColor;

//found this new kind of binding in another Irrlicht Forum Topic,
//but also does not fix the issue, and does not solve the problem
layout(binding = 0) uniform sampler2D ColoredTextureSampler;	// texture 0 
layout(binding = 2) uniform sampler2D ReflectionMapSampler;	// texture 2

in vec2 TexCoord;

void main (void)
{   
    vec4 col = texture2D(ColoredTextureSampler, TexCoord);
    
    FragColor = col;
}
The updated shaders also compile and run, but something is completely off:

Image
woalexan
Posts: 17
Joined: Wed May 28, 2025 6:22 pm
Location: Austria

Re: Question regarding my first shader steps

Post by woalexan »

In the meantime I got it working using the old GLSL version, and changing other "things" in the shader code to adjust for the old version syntax. But it would still be great to understand what I did wrong, and how the newer version would work as well.

Image
CuteAlien
Admin
Posts: 9928
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Question regarding my first shader steps

Post by CuteAlien »

I have to admit that I still use the outdated gl_Vertex, gl_Normal, gl_Color, gl_MultiTexCoord[x]. My trick is to use #version 430 compatibility instead of core, then those are still available. Thought I probably should switch at some point. Anyway - the alternative layout looks good to me on first view.

Thought you are not yet transforming your normals and your texture coordinates. But maybe not necessary for first test (normals will soon be needed for light, but texture matrix only matters if you actually have set it in your materials).

Maybe the problem is on Irrlicht side because it still uses glColorPointer instead of working with glVertexAttribPointer. Not sure if that could create a conflict with using core profile.
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
woalexan
Posts: 17
Joined: Wed May 28, 2025 6:22 pm
Location: Austria

Re: Question regarding my first shader steps

Post by woalexan »

Hi CuteAlien, Thanks a lot for your response, I was not even aware of the compatibility possibility, I just took core from the examples on the tutorial page and ran into my problem. I think I will also use your trick in the future :)
But may I ask you, how exactly I am supposed to transform my normals and texture coordinates, I assume in the vertex shader?
Identical to gl_Position? Because until now I believed my results looked ok, but maybe I did not even notice something is completely wrong...
Post Reply