• 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!

Legacy GM Applying Shader to Rectangle

Imperial

Member
How to Apply a Shader to a Rectangle, I tried this code but It shows a black screen and nothing happen

Code:
if surface_exists(Surface)
{
    Time += 0.04;
    shader_set(Shader);
    shader_set_uniform_f(shader_get_uniform(Shader,"time"),Time);
    shader_set_uniform_f(shader_get_uniform(Shader,"mouse_pos"),mouse_x,mouse_y);
    shader_set_uniform_f(shader_get_uniform(Shader,"resolution"),room_width,room_height);
    shader_set_uniform_f(shader_get_uniform(Shader,"wave_amount"),wave_amount);
    shader_set_uniform_f(shader_get_uniform(Shader,"wave_distortion"),wave_distortion);
    shader_set_uniform_f(shader_get_uniform(Shader,"wave_speed"),wave_speed);
    draw_set_color(c_aqua);
    draw_set_alpha(0.5);
    draw_rectangle(0,0,room_width,room_height,0);
    shader_reset();
}
else
{
    Surface = surface_create(room_width,room_height);
}
 

jo-thijs

Member
You already have a topic like this open.
Applying shaders to rectangles is done exactly the same as any other drawing operation.
The code you gave looks just fine, so the problem lies somewhere else.
To find what's causing the issue, please respond to your previous topic.
 
If you're applying a shader to draw_rectangle, weird things happen with the textcoord.

draw a rectangle with this fragment shader and you'll see what I mean.
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
  float red = v_vTexcoord.x;
  float green = v_vTexcoord.y;
  gl_FragColor = vec4(red,green,0.0,1.0);
}
However, drawing a rectangle with draw_rectangle_colour seems to produce the results that you would expect.

However, do you have the "surface" set as the rendering target? It appears that you are intending to draw upon it, but you don't set it as the target in the code you posted here.
 
Top