diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-21 15:44:21 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-21 15:44:21 -0700 |
| commit | 96caba75e8dfbb879eff12cbe1a4c148a259f684 (patch) | |
| tree | 1c7b2f25484ac22c738e006334d4df559bb733a5 /examples/autodiff-texture/draw-quad.slang | |
| parent | 7f11f883d0781952f002b3aa3222a3aa0040f18a (diff) | |
Add texture tri-linear autodiff example. (#2715)
* Add quad texture example.
* delete output image
* remove irrelavent files
* update project files
* fix
* Update example.
* Fix.
* remove out-texture
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'examples/autodiff-texture/draw-quad.slang')
| -rw-r--r-- | examples/autodiff-texture/draw-quad.slang | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/autodiff-texture/draw-quad.slang b/examples/autodiff-texture/draw-quad.slang new file mode 100644 index 000000000..55a33b46b --- /dev/null +++ b/examples/autodiff-texture/draw-quad.slang @@ -0,0 +1,52 @@ +// Vertex and fragment shader to draw a textured quad on screen. + +cbuffer Uniforms +{ + int x; + int y; + int width; + int height; + int viewWidth; + int viewHeight; + Texture2D texture; + SamplerState sampler; +} + +struct AssembledVertex +{ + float3 position : POSITION; +}; + +struct Fragment +{ + float4 color; +}; + +struct VertexStageOutput +{ + float2 uv : UV; + float4 sv_position : SV_Position; +}; + +[shader("vertex")] +VertexStageOutput vertexMain( + AssembledVertex assembledVertex) +{ + VertexStageOutput output; + + float3 position = assembledVertex.position; + + output.uv = position.xy; + output.sv_position.x = (x + position.x * width) / (float)viewWidth * 2.0f - 1.0f; + output.sv_position.y = -((y + position.y * height) / (float)viewHeight * 2.0f - 1.0f); + output.sv_position.z = 0.5; + output.sv_position.w = 1.0; + return output; +} + +[shader("fragment")] +float4 fragmentMain( + float2 uv : UV) : SV_Target +{ + return float4(texture.Sample(sampler, uv).xyz, 1.0); +} |
