Created
November 12, 2017 01:51
-
-
Save anonymous/18de597ef146faeae1ea8393eec13587 to your computer and use it in GitHub Desktop.
This file contains 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
#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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to use this without the delayed UVs?