Simple fragment shader that creates a motion blur to the right to anything that is on the specified depth layer.
Last active
September 1, 2020 07:10
-
-
Save RookTKO/da4a1d818c673348c2ea8370ade4f7d7 to your computer and use it in GitHub Desktop.
GameMaker Open Graphics Library Shading layer_shader Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//I had this in the RoomCreationCode | |
global.posXBlur = 0.5; | |
background_layer_id = layer_get_id("Background"); | |
if !layer_get_shader(background_layer_id) | |
{ | |
layer_shader(background_layer_id, sh_motion_blur); | |
layer_script_begin(background_layer_id, shader_blur_start); | |
layer_script_end(background_layer_id, shader_blur_end); | |
} | |
//This was a script named shader_blur_start | |
function shader_blur_start(){ | |
blur_shader = sh_motion_blur; | |
u_blur = shader_get_uniform(blur_shader,"pos") | |
shader_set_uniform_f(u_blur,global.posXBlur,0.5); | |
} | |
//This was a script named shader_blur_end | |
function shader_blur_end(){ | |
shader_reset(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
uniform vec4 uvs;//left,top,width,height | |
uniform vec2 pos;//x,y | |
const int Quality = 2; | |
void main() | |
{ | |
//Normalize coordinates to the 0-1 range. | |
vec2 Norm = (v_vTexcoord-uvs.xy)/uvs.zw; | |
vec4 Color = vec4(0); | |
for( float i=0.0;i<1.0;i+=1.0/float(Quality)) | |
{ | |
//Add the blur sample offset. | |
vec2 Coord = Norm+(0.5-pos)*i; | |
//Skip samples that are outside of this sprite! | |
if ((abs(Coord.x-0.5)>.5) || (abs(Coord.y-0.5)>.5)) continue; | |
//De-normalize the texture coordinates. | |
Coord = Coord*uvs.zw+uvs.xy; | |
Color += texture2D( gm_BaseTexture, Coord); | |
} | |
Color /= float(Quality); | |
gl_FragColor = Color * v_vColour; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Simple passthrough vertex shader | |
// | |
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) | |
attribute vec2 in_TextureCoord; // (u,v) | |
varying vec2 v_vTexcoord; | |
varying vec4 v_vColour; | |
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; | |
v_vColour = in_Colour; | |
v_vTexcoord = in_TextureCoord; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment