
To do this, you just need to modify the fragment/pixel program of the shader. That means you can render to multiple surfaces simultaneously from within the same shader! Unlike GLSL ES shaders GameMaker uses, HLSL shaders support multiple render targets (or MRT s for short).
Gamemaker studio 2 surfaces code#
When using shader_get_sampler_index(shader, “name”), the name you should pass is the name of the SamplerState, not the Texture2D – though this index will be the same as the register index, it’s good practice to get the index properly, in case the register needs to be changed in code later.

Index 0 is reserved for gm_BaseTexture and gm_BaseTextureObject. The number in the register() function needs to be incremented for each extra texture, as it represents the sampler index (e.g, t1 + s1, t2 + s2. textureObject.Sample(texture, input.uv) īoth a Texture2D and a SamplerState are needed, as one represents a texture, the other represents any settings applied to it (like filtering, mipmaps etc).

To read from multiple textures, you need to define them a little differently to GLSL ES shaders. The SV_POSITION semantic is basically equivalent to gl_Position, and the SV_TARGET semantic is basically equivalent to gl_FragColor Pos = mul(gm_Matrices, pos) įloat4 main(PixelShaderInput input) : SV_TARGETįloat4 texelColour = gm_BaseTextureObject.Sample(gm_BaseTexture, input.uv) įloat4 combinedColour = vertColour * texelColour Transform the vertex position into projected space. VertexShaderOutput main(VertexShaderInput input) So here’s a working version for everyone to enjoy! Click the little clipboards at the top right of code blocks to copy it to your clipboard easily. The HLSL11 passthrough shader is a shader I find myself needing a lot, and GameMaker does not automatically create it for us.
