Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active May 18, 2026 01:40
Show Gist options
  • Select an option

  • Save amirrajan/39bd92bb04dbed8cfa741b62f2d2ae25 to your computer and use it in GitHub Desktop.

Select an option

Save amirrajan/39bd92bb04dbed8cfa741b62f2d2ae25 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - Hot-loaded shaders while retaining game state. (https://youtu.be/pc7Jj6c9pNs)
Texture2D scene : register(t0);
Texture2D displacement_map : register(t1);
SamplerState sampler0 : register(s0);
struct Input {
float4 tex_color : COLOR0;
float2 tex_coord : TEXCOORD0;
};
struct Output {
float4 frag_color : SV_Target;
};
Output main(Input input) {
Output output;
float4 tex1_color = displacement_map.Sample(
sampler0,
input.tex_coord
);
float displacement_perc = 0.02;
float2 displacement_uv = float2(
input.tex_coord.x + (tex1_color.r * displacement_perc - displacement_perc / 2.0),
input.tex_coord.y + (tex1_color.r * displacement_perc - displacement_perc / 2.0)
);
float2 resolved_displacement_uv = float2(
clamp(displacement_uv.x, 0.0, 1.0),
clamp(displacement_uv.y, 0.0, 1.0)
);
float4 tex0_color = scene.Sample(sampler0, resolved_displacement_uv);
output.frag_color = tex0_color;
return output;
}
def tick args
args.outputs[:water].set w: 1280, h: 720, background_color: [255, 255, 255]
args.outputs[:water].primitives << 3.map do |i|
sprite_size = 720
[
{
x: 0,
y: Grid.h / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water.png",
a: 128,
},
{
x: 720,
y: Grid.h / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water.png",
a: 128,
},
{
x: Grid.w / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
y: 0,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water.png",
a: 128,
},
]
end
args.outputs[:displacement].set w: 1280, h: 720, background_color: [255, 255, 255]
args.outputs[:displacement].primitives << 3.map do |i|
sprite_size = 720
[
{
x: Grid.w / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
y: 0,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water-displacement.png",
a: 128
},
{
x: 0,
y: Grid.h / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water-displacement.png",
a: 128
},
{
x: 720,
y: Grid.h / 2 - i * sprite_size + Kernel.tick_count % sprite_size,
w: sprite_size, h: sprite_size,
path: "sprites/flow-like-water/water-displacement.png",
a: 128
}
]
end
args.outputs.shader = {
path: "shaders/effect.frag.hlsl",
textures: [
:displacement
]
}
args.outputs.primitives << { x: 0, y: 0, w: 1280, h: 720, path: :water }
args.outputs.primitives << { x: args.state.tick_count % 1280,
y: args.state.tick_count % 720,
text: "flow like water",
anchor_x: 0.5,
anchor_y: 0.5,
size_px: 100,
r: 1,
g: 1,
b: 1 }
args.outputs.primitives << { x: args.inputs.mouse.x,
y: args.inputs.mouse.y,
w: 64, h: 64,
path: "sprites/square/blue.png",
anchor_x: 0.5 , anchor_y: 0.5 }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment