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/learnmip.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/learnmip.slang')
| -rw-r--r-- | examples/autodiff-texture/learnmip.slang | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/autodiff-texture/learnmip.slang b/examples/autodiff-texture/learnmip.slang new file mode 100644 index 000000000..1434f1a66 --- /dev/null +++ b/examples/autodiff-texture/learnmip.slang @@ -0,0 +1,22 @@ +// A compute shader to add gradients to a mip-map texture. + +cbuffer Uniforms +{ + uint dstWidth; + uint dstHeight; + float learningRate; + RWTexture2D dstTexture; + RWTexture2D srcTexture; +} + +[shader("compute")] +[numthreads(16, 16, 1)] +void computeMain(uint3 threadIdx : SV_DispatchThreadID) +{ + uint x = threadIdx.x; + uint y = threadIdx.y; + if (x >= dstWidth) return; + if (y >= dstHeight) return; + var val = srcTexture[uint2(x, y)]; + dstTexture[uint2(x, y)] = float4((dstTexture[uint2(x, y)] - val * learningRate).xyz, 1.0); +} |
