


Texture_set_stage(distortion_stage, surface_texture_page) Var surface_texture_page = surface_get_texture(surface_distort) Anything we draw here will distort the screenĭraw_sprite(spr_example_distort,0,500,500) Surface_distort = surface_create(room_width,room_height) name of what you want it to be called in the shaderĭistortion_stage = shader_get_sampler_index(shader_fullscreen, "distortion_texture_page") Now that we have the shader we need to apply it to something Gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord+distort_amount) If (distort_amount.x > 0.5) // wrap around normal maps have green pointing the wrong way)ĭistort_amount.x = 1.0 - distort_amount.x while you dont need to worry about it in GM more FOR NORMAL MAPS: ( either directX or OpenGL flip the green channel, Vec2 distort_amount = vec2( (v_vColour * texture2D( distortion_texture_page, v_vTexcoord)).xy) find the offset colour for this location (this is where the magic happens) Uniform sampler2D distortion_texture_page // the name of the surface in the shader This shader will look at the surface and for every pixel on the surface the colour will tell the shader where to offset when selecting what colour to draw.
#Game maker studio 2 shaders code#
We will only be using the Fragment Shader which in GameMaker is the second tab along, this code runs on the graphics card for every pixel on the screen. This works just like a lens.įirst we are going to make a new shader with Alt+A and you will notice it comes as two files, the Vertex Shader and the Fragment Shader. The concept is very simple, we are going to pass a Surface into the shader with all the information about where each pixel should actually draw to the screen.
#Game maker studio 2 shaders how to#
Today I will show you how to make a shader to warp your screen and add ripples and other distortions to your games. I know shaders can seem like a scary world for some however in just a few lines of code I want to give you an easy to implement and impressive shader that will be a great starting point for learning your first shader.
