• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Small shader problem

jf_knight

Member
I keep receiving a syntax error when I attempt to run this shader
I believe the problem could be something with the lines
Code:
out vec4 c;
in vec2 w ;
It' a small lava lamp shader I found. I'm trying to run it in GM.
I'm relatively new to shaders, so any bit of help is welcome.

//Fragment
Code:
uniform float iTime;
uniform vec2 iResolution;
varying vec2 fragCoord;


void main(void)
{
out vec4 c;
in vec2 w ;

    vec2 p = w/iResolution.xy, a = p*5.; a.y -= iTime;
    vec2 f = fract(a); a -= f; f = f*f*(3.-2.*f);
    vec4 r = fract(sin(vec4(a.x + a.y*1e3) + vec4(0, 1, 1e3, 1001)) * 1e5)*30./p.y;
    c.rgb = p.y + vec3(1,.5,.2) * clamp(mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y)-30., -.2, 1.);

}

//vertex
Code:
attribute vec3 in_Position;                  // (x,y,z)
//attribute vec3 in_Normal;                  // (x,y,z)     unused in this shader.
//attribute vec4 in_Colour;                    // (r,g,b,a) unused in this shader.
//attribute vec2 in_TextureCoord;              // (u,v)     unused in this shader.

varying vec2 fragCoord;


void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
   
    fragCoord = in_Position.xy;
}
Theres an object in a room that has
" shader_set_uniform_f(iTime,get_timer()/1000000);
shader_set_uniform_f(iResolution,720,480,0)" , ect...
 

NightFrost

Member
Seems GLSL ES doesn't want to play with in and out as you suspected. I wrote the fragment shader like:
Code:
void main(){
    vec2 p = fragCoord/iResolution.xy, a = p*5.; a.y -= iTime;
    vec2 f = fract(a); a -= f; f = f*f*(3.-2.*f);
    vec4 r = fract(sin(vec4(a.x + a.y*1e3) + vec4(0, 1, 1e3, 1001)) * 1e5)*30./p.y;
    gl_FragColor.rgb = p.y + vec3(1,.5,.2) * clamp(mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y)-30., -.2, 1.);
    gl_FragColor.a = 1.0;
}
then tested it by calling
Code:
shader_set(sdr_test);
shader_set_uniform_f(Uniform_Resolution, room_width, room_height);
shader_set_uniform_f(Uniform_Time, get_timer()/1000000);
draw_rectangle(0, 0, room_width, room_height, false);
shader_reset();
and everything appears to work.
 

jf_knight

Member
Seems GLSL ES doesn't want to play with in and out as you suspected. I wrote the fragment shader like:
Code:
void main(){
    vec2 p = fragCoord/iResolution.xy, a = p*5.; a.y -= iTime;
    vec2 f = fract(a); a -= f; f = f*f*(3.-2.*f);
    vec4 r = fract(sin(vec4(a.x + a.y*1e3) + vec4(0, 1, 1e3, 1001)) * 1e5)*30./p.y;
    gl_FragColor.rgb = p.y + vec3(1,.5,.2) * clamp(mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y)-30., -.2, 1.);
    gl_FragColor.a = 1.0;
}
then tested it by calling
Code:
shader_set(sdr_test);
shader_set_uniform_f(Uniform_Resolution, room_width, room_height);
shader_set_uniform_f(Uniform_Time, get_timer()/1000000);
draw_rectangle(0, 0, room_width, room_height, false);
shader_reset();
and everything appears to work.
It works!
Thank you so much!
One last question: You wouldn't happen to know which variables i'd have to change in order to render this shader up-side-down? (with the orange lava at the bottom)
 

NightFrost

Member
While the math it does is beyond me, I see that the math is based on relative coordinates, so it should be achievable be reversing the progress on y. After some experimentation, changing the first two lines in fragment shader like this worked:
Code:
vec2 temp = vec2(fragCoord.x, iResolution.y - fragCoord.y);
vec2 p = temp/iResolution.xy, a = p*5.; a.y -= iTime;
which probably works well only when the resolution you send into the shader and the size of the object are the same (as in my example, room size). If they differ you'd probably need to send the object's size in as another uniform.
 

jf_knight

Member
While the math it does is beyond me, I see that the math is based on relative coordinates, so it should be achievable be reversing the progress on y. After some experimentation, changing the first two lines in fragment shader like this worked:
Code:
vec2 temp = vec2(fragCoord.x, iResolution.y - fragCoord.y);
vec2 p = temp/iResolution.xy, a = p*5.; a.y -= iTime;
which probably works well only when the resolution you send into the shader and the size of the object are the same (as in my example, room size). If they differ you'd probably need to send the object's size in as another uniform.
Beautiful! That's exactly how it should look.
Thanks again for you help. I will use this to study and further my knowledge on GLSL shaders.
 
Top