Shaders usage

I was wondering if there was a way to debug a shader

  • I want to know whats in my height variable, cause it seems like it isnt changing at alI

Because i cant really find any documents on the internet that describe these things i wanted to ask what these lines do:

vec4 modelSpacePos = vec4(inPosition, 1.0);
gl_Position = TransformWorldViewProjection(modelSpacePos);
texCoord = inTexCoord;
wPosition = TransformWorld(modelSpacePos).xyz;
height = wPosition.y;

And lastly I wanted to ask how often the shader is being called (and when it is being called)

I’ve told you numerous times to just use inPosition to find your height. You don’t need world space or any other transformation, you just need to know the vertex height so just use inPosition.

You can’t debug a shader but you can get a color output to determine something. Shaders are run every frame that they are visible on the screen.

1 Like

I’ve tried it the moment you said it but i dont know how to get the height from inPosition, or how to use inPosition in general

nvm i’ve adjusted some lines

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
wPosition = inPosition;
height = wPosition.y;

now it seems to work

So i guess learning by doing :slight_smile:

Thank you again for your time and for not giving up on me :laughing:

i think now i just have to do some adjustments on my coloring

Divide the height by the maximum height to get a unit value between 0 and 1. Then lerp the color with the unit value. Mix, I guess.

Dont really know what u mean by that :confused:

vec3 color = mix(green, red, unitValue);

0 will return green, 1 will return red, and anything in between will be a percentage mix of the two.

i assume he is using same as his friend:

gl_FragColor.rgb = vec3(height/20.0 , 1.0 - height/20.0 ,0.0);

so 20 value change should help.

since i see red appear too fast i assume it will help when changed to something like:

gl_FragColor.rgb = vec3(height/100.0 , 1.0 - height/100.0 ,0.0);

like you said it can be even better if they would use your line with something like:

vec3 color = mix(green, red, height/topHeight);

i dont have problem with this, but i assume they have some crazy height values.

my height values arent that crazy my maximum is about 20-ish

i dont really get where i should put this in my code
Because i cant just assign this to my gl_FragColor right?

gl_FragColor = vec4(myColor, 1.0);

I’ve tried 2 ways now

first was to put

vec3 color = mix(green, red, height/topHeight);

in vertShader

and then just assign it to the gl_FragColor in fragShader

the nex way i tried was putting both in the fragShader

i get these errors depending on which way i used

None of what you said you did correlated to the answer I gave you.

Sure did, i’ve made the color with this

vec3 color = mix(green, red, height/topHeight);

and then assigned it to the gl_FragColor with

 void main(){
    gl_FragColor.rgb = vec4(color, 1.0);

or did i not get something?

Remove the .rgb

FragColor is a vec4 or vector4 or in JME ColorRGBA. It’s a component with 4 values. A vec3 or vector3 has 3 values.

So that line is constructing a vec4 from a vec3 + the 4th component.

Red, green, blue, alpha. Alpha is always 1.0 so we just set it as that at the end.

I’ll try to fix it on my own for now :wink:


doesnt change anything

well, like @jayfella said in other topic. Try understand your problem first. You have error in screenshot you provided. there is something like “you try make vec3 from vec4, thats wrong!” the error says.

knowing this you should know where you try make vec3 from vec4

The Big Kahuna.

Topics under the Big Kahuna you may find interesting.