Saturation Shader [SOLVED]

Moth27

Member
I have a de-saturation shader that works on instances.
I want to draw the same shader over the floor to cover the floor tiles.

I only want the shader to cover the walls and the floor, so drawing on the application surface is out.

I've tried using surfaces but no luck.
Any ideas on how to go about this?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Set the shader before drawing the layers you want to affect, unset it after being done with those layers. "Layer begin/end scripts" could work for this, or if you want more control, you could create instances with a depth -1 / +1 to the things you want to affect at the start of the room.
 
Run this in the Create event of an object in the room:
Code:
desaturate_layer_begin = function() {
    shader_set(shader_name);
}
desaturate_layer_end = function() {
    shader_reset();
}

var lay_id = layer_get_id("layer name");
layer_script_begin(lay_id,desaturate_layer_begin);
layer_script_end(lay_id,desaturate_layer_end);
Obviously you can change the function names, add uniforms into the shader after the shader_set and you'll have to replace the names for the layer and shader and stuff, but this should work AFAIK.

EDIT: @muki I didn't even know that function existed, that's quite useful.
 

Moth27

Member
Set the shader before drawing the layers you want to affect, unset it after being done with those layers. "Layer begin/end scripts" could work for this, or if you want more control, you could create instances with a depth -1 / +1 to the things you want to affect at the start of the room.
trying this now
 

Moth27

Member
Run this in the Create event of an object in the room:
Code:
desaturate_layer_begin = function() {
    shader_set(shader_name);
}
desaturate_layer_end = function() {
    shader_reset();
}

var lay_id = layer_get_id("layer name");
layer_script_begin(lay_id,desaturate_layer_begin);
layer_script_end(lay_id,desaturate_layer_end);
Obviously you can change the function names, add uniforms into the shader after the shader_set and you'll have to replace the names for the layer and shader and stuff, but this should work AFAIK.

EDIT: @muki I didn't even know that function existed, that's quite useful.
going to attempt this
 

muki

Member
Run this in the Create event of an object in the room:
Code:
desaturate_layer_begin = function() {
    shader_set(shader_name);
}
desaturate_layer_end = function() {
    shader_reset();
}

var lay_id = layer_get_id("layer name");
layer_script_begin(lay_id,desaturate_layer_begin);
layer_script_end(lay_id,desaturate_layer_end);
Obviously you can change the function names, add uniforms into the shader after the shader_set and you'll have to replace the names for the layer and shader and stuff, but this should work AFAIK.

EDIT: @muki I didn't even know that function existed, that's quite useful.

layer_shader is simple, but I actually like your method better, since it gives us more flexibility.

layer_shader also has a limitation in that it applies a shader to tiles individually, rather than the visible tilemap as a whole. fine for saturation/hue shaders, but bad for blur/distortion or anything else that "bleeds" one tile's pixels into neighboring tiles.

have a hunch OP might have to add a view-sized surface set and reset to your example, if their alpha problem continues...
 
Last edited:

Moth27

Member
Set the shader before drawing the layers you want to affect, unset it after being done with those layers. "Layer begin/end scripts" could work for this, or if you want more control, you could create instances with a depth -1 / +1 to the things you want to affect at the start of the room.
This works by adding the shader but doesn't respond to the alpha changes
 

Moth27

Member
Run this in the Create event of an object in the room:
Code:
desaturate_layer_begin = function() {
    shader_set(shader_name);
}
desaturate_layer_end = function() {
    shader_reset();
}

var lay_id = layer_get_id("layer name");
layer_script_begin(lay_id,desaturate_layer_begin);
layer_script_end(lay_id,desaturate_layer_end);
Obviously you can change the function names, add uniforms into the shader after the shader_set and you'll have to replace the names for the layer and shader and stuff, but this should work AFAIK.

EDIT: @muki I didn't even know that function existed, that's quite useful.

Okay so this worked as well, but when the alpha changes, the tile layer fades to all black. It must be a shader issue :-(
 

Moth27

Member
Run this in the Create event of an object in the room:
Code:
desaturate_layer_begin = function() {
    shader_set(shader_name);
}
desaturate_layer_end = function() {
    shader_reset();
}

var lay_id = layer_get_id("layer name");
layer_script_begin(lay_id,desaturate_layer_begin);
layer_script_end(lay_id,desaturate_layer_end);
Obviously you can change the function names, add uniforms into the shader after the shader_set and you'll have to replace the names for the layer and shader and stuff, but this should work AFAIK.

EDIT: @muki I didn't even know that function existed, that's quite useful.

I got it to work!
Okay so I realized a mistake. The layer faded to black because black is the background color underneath the floor layer.

I simply copied the floor layer into a 2nd floor layer and placed the shader onto the 2nd (higher) layer. Now the higher layer fades as I adjust the alpha to reveal the original floor layer underneath.
It works great. Not sure how optimal that is, but it certainly works.

Muki, Yal, and Refresher Towel thanks so much.
 
Top