Created
September 2, 2026 20:48
-
-
Save amirrajan/81cb4da7c483b9764a6788440cee5f61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| Texture2D scene : register(t0, space2); | |
| Texture2D displacement_map : register(t1, space2); | |
| SamplerState sampler0 : register(s0, space2); | |
| SamplerState sampler1 : register(s1, space2); | |
| 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(sampler1, 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_uv = float2( | |
| clamp(displacement_uv.x, 0.0, 1.0), | |
| clamp(displacement_uv.y, 0.0, 1.0) | |
| ); | |
| output.frag_color = scene.Sample(sampler0, resolved_uv) * input.tex_color; | |
| return output; | |
| } |
This file contains hidden or 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
| struct Input { | |
| @location(0) tex_color: vec4<f32>, | |
| @location(1) tex_coord: vec2<f32>, | |
| }; | |
| struct Output { | |
| @location(0) frag_color: vec4<f32>, | |
| }; | |
| @group(2) @binding(0) var scene: texture_2d<f32>; | |
| @group(2) @binding(1) var displacement_map: texture_2d<f32>; | |
| @group(2) @binding(2) var sampler0: sampler; | |
| @group(2) @binding(3) var sampler1: sampler; | |
| @fragment | |
| fn main(input: Input) -> Output { | |
| var output: Output; | |
| let tex1_color = textureSample(displacement_map, sampler1, input.tex_coord); | |
| let displacement_perc = 0.02; | |
| let displacement_uv = vec2<f32>( | |
| 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) | |
| ); | |
| let resolved_uv = vec2<f32>( | |
| clamp(displacement_uv.x, 0.0, 1.0), | |
| clamp(displacement_uv.y, 0.0, 1.0) | |
| ); | |
| output.frag_color = textureSample(scene, sampler0, resolved_uv) * input.tex_color; | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment