22layout : post
33title : " Neural Graphics in an Afternoon"
44date : 2025-04-04 17:00:00
5- categories : [ "blog", "featured" ]
5+ categories : [ "blog" ]
66tags : [slang]
77author : " Shannon Woods, NVIDIA, Slang Working Group Chair"
88image : /images/posts/2025-04-04-splatterjeep.webp
@@ -206,15 +206,15 @@ float4 simpleSplatBlobs(GradInOutTensor<float, 1> blobsBuffer, uint2 pixelCoord,
206206 for (uint i = 0; i < SIMPLE_BLOBCOUNT; i++)
207207 {
208208 // first, calculate the color of the current blob
209- Gaussian2D gaussian = Gaussian2D.load(blobs, i);
210- blobColor = gaussian.eval(pixelCoord * (1.0/texSize));
211-
212- // then, blend with the blobs we've accumulated so far
213- result = alphaBlend(result, blobColor);
214- }
215-
216- // Blend with background
217- return float4(result.rgb * (1.0 - result.a) + result.a, 1.0);
209+ Gaussian2D gaussian = Gaussian2D.load(blobs, i);
210+ blobColor = gaussian.eval(pixelCoord * (1.0/texSize));
211+
212+ // then, blend with the blobs we've accumulated so far
213+ result = alphaBlend(result, blobColor);
214+ }
215+
216+ // Blend with background
217+ return float4(result.rgb * (1.0 - result.a) + result.a, 1.0);
218218}
219219
220220//
@@ -224,27 +224,27 @@ float4 simpleSplatBlobs(GradInOutTensor<float, 1> blobsBuffer, uint2 pixelCoord,
224224[Differentiable]
225225float loss(uint2 pixelCoord, int2 imageSize, Blobs blobs, Texture2D<float4> targetTexture)
226226{
227- int texWidth;
228- int texHeight;
229- targetTexture.GetDimensions(texWidth, texHeight);
230- int2 texSize = int2(texWidth, texHeight);
231-
232- // Splat the blobs and calculate the color for this pixel.
233- float4 color = simpleSplatBlobs(blobs.blobsBuffer, pixelCoord, imageSize);
234- float4 targetColor;
235-
236- float weight;
237- if (pixelCoord.x >= imageSize.x || pixelCoord.y >= imageSize.y)
238- {
239- return 0.f;
240- }
241- else
242- {
243- targetColor = no_diff targetTexture[pixelCoord];
244- return dot(color.rgb - targetColor.rgb, color.rgb - targetColor.rgb);
245- }
246-
247- return 0.f;
227+ int texWidth;
228+ int texHeight;
229+ targetTexture.GetDimensions(texWidth, texHeight);
230+ int2 texSize = int2(texWidth, texHeight);
231+
232+ // Splat the blobs and calculate the color for this pixel.
233+ float4 color = simpleSplatBlobs(blobs.blobsBuffer, pixelCoord, imageSize);
234+ float4 targetColor;
235+
236+ float weight;
237+ if (pixelCoord.x >= imageSize.x || pixelCoord.y >= imageSize.y)
238+ {
239+ return 0.f;
240+ }
241+ else
242+ {
243+ targetColor = no_diff targetTexture[pixelCoord];
244+ return dot(color.rgb - targetColor.rgb, color.rgb - targetColor.rgb);
245+ }
246+
247+ return 0.f;
248248}
249249
250250// Differentiable function to compute per-pixel loss
@@ -255,14 +255,14 @@ float loss(uint2 pixelCoord, int2 imageSize, Blobs blobs, Texture2D<float4> targ
255255
256256[Differentiable]
257257void perPixelLoss(GradInOutTensor<float4, 2> output,
258- uint2 pixelCoord,
259- GradInOutTensor<float, 1> blobsBuffer,
260- Texture2D<float4> targetTexture)
258+ uint2 pixelCoord,
259+ GradInOutTensor<float, 1> blobsBuffer,
260+ Texture2D<float4> targetTexture)
261261{
262- uint2 imageSize;
263- targetTexture.GetDimensions(imageSize.x, imageSize.y);
264- output.set( {pixelCoord.x, pixelCoord.y},
265- loss(pixelCoord, imageSize, {blobsBuffer}, targetTexture));
262+ uint2 imageSize;
263+ targetTexture.GetDimensions(imageSize.x, imageSize.y);
264+ output.set( {pixelCoord.x, pixelCoord.y},
265+ loss(pixelCoord, imageSize, {blobsBuffer}, targetTexture));
266266}
267267```
268268
@@ -290,9 +290,9 @@ The other piece of the equation is the Adam update algorithm:
290290
291291``` hlsl
292292void adamUpdate(inout float val,
293- inout float dVal,
294- inout float firstMoment,
295- inout float secondMoment)
293+ inout float dVal,
294+ inout float firstMoment,
295+ inout float secondMoment)
296296{
297297 // Read & reset the derivative
298298 float g_t = dVal;
0 commit comments