Skip to content

Instantly share code, notes, and snippets.

Created November 12, 2017 01:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/18de597ef146faeae1ea8393eec13587 to your computer and use it in GitHub Desktop.
Save anonymous/18de597ef146faeae1ea8393eec13587 to your computer and use it in GitHub Desktop.
#include <octane-oslintrin.h>
#define MAX_ITERATIONS 10
#define MAX_KERNEL_SIZE 11 // MAX_ITERATIONS + 1
// OSL sample implementation of gaussian blur for Octane Render
shader GaussianBlur(
color in = 0
[[string label = "Input texture"]],
int iterations = 5
[[int min = 0, int max = MAX_ITERATIONS,
string label = "Step count",
string description = "Number of steps"]],
float stepSize = 0.001
[[float min = 0.00001, float max = 0.01,
string label = "Step size",
string description = "UV distance between steps"]],
output color out = 0)
{
if (iterations == 0)
{
// just return the input with the right UV mapping
out = _evaluateDelayed(in, u, v);
}
else
{
float kernel[MAX_KERNEL_SIZE];
// initialize the kernel
float normFactor = 0;
for (int i = 0; i <= iterations; ++i)
{
// use normal probability density function with sigma = 7
float n = 0.05699175 * exp(-0.01020408 * i * i);
normFactor += i == 0 ? n : 2*n;
kernel[i] = n;
}
// average the neighbours
color c = 0;
for (int i = -iterations; i <= iterations; ++i)
{
float n = kernel[iterations - abs(i)];
for (int j = -iterations; j <= iterations; ++j)
{
float f = n * kernel[iterations - abs(j)];
c += f * _evaluateDelayed(in, u + i * stepSize, v + j * stepSize);
}
}
// calculate the final value
out = c/(normFactor*normFactor);
}
}
@Gioak
Copy link

Gioak commented Nov 5, 2021

Is there a way to use this without the delayed UVs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment