EnvironmentBlur v1.0


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Haarm-Pieter Duiker
A Blink kernel that will blur spherical HDR panoramas.
Requirements:
8.0 or later
19 May 2014
211

Notes

A Blink kernel that will blur spherical HDR panoramas.

This is a heavy/expensive blur so it's recommended that you

  1. Resize your panorama down to 512x256 or less. You can go higher, but the blur will take significantly longer.
  2. Keep the BlinkScript's Settings > 'Percentage of image height per tile' setting to 1. Higher than that and you're likely to crash your graphics driver.

 

Example images

Panorama

example 512

Panorama blurred with Lambertian / Diffuse kernel (exponent = 1)

example 512 blur1

Panorama blurred with exponent = 10

example 512 blur10

Panorama blurred with exponent = 100

example 512 blur100 

 

Relevant snippet of Nuke script

set cut_paste_input [stack 0]
version 8.0 v4
push $cut_paste_input
Dot {
name Dot1
label 'Spherical Panorama goes here'
selected true
xpos -278
ypos -40
}
Reformat {
type 'to box'
box_width 512
name Reformat1
selected true
xpos -312
ypos 25
}
BlinkScript {
kernelSourceFile C:/fakepath/EnvironmentBlur.blink
ProgramGroup 1
KernelDescription '1 \'EnvironmentBlurKernel\' iterate pixelWise c69c56a573044305f522dd18faea0461554c6d62e30f78e79b2727cd58bf1c82 2 \'src\' Read Random \'dst\' Write Point 1 \'phongExponent\' Float 1 AACAPw=='
kernelSource '//\n// A kernel that will blur Spherical environment maps\n//\n\n//\n// Functions specific to spherical panoramas\n//\nfloat3 spherical_tex2dir(float2 tc)\n\{\n float theta, gamma, u, v;\n float3 dir;\n\n u = tc.x*2 - 1;\n v = tc.y*2 - 1;\n\n theta = u*3.14159;\n gamma = v*3.14159f/2.f;\n \n dir.z = cos(theta)*cos(gamma);\n dir.y = sin(gamma);\n dir.x = sin(theta)*cos(gamma);\n\n return dir;\n\}\n\nfloat spherical_solidAngle(int y, int width, int height)\n\{\n float u = (2.f*3.14159f)/width;\n float v = sin(float(y+0.5)/height*3.14159f)*(3.14159f/height);\n return u*v; \n\}\n\n//\n// Add the same functions for other panorama types to support those types\n//\n\n//\n// kernel\n//\nkernel EnvironmentBlurKernel : public ImageComputationKernel\n\{\n Image src;\n Image dst;\n\n param:\n float phongExponent;\n\n void define() \{\n defineParam(phongExponent, \'phongExponent\', 1.f);\n \}\n\n void process(int2 pos) \{\n SampleType(src) valueSum(0);\n ValueType(src) filterSum(0);\n \n ValueType(src) filter, u, v;\n\n float3 centerDir, filterDir;\n\n // The direction for the current pixel\n u = float(pos.x + 0.5f)/src.bounds.width();\n v = float(pos.y + 0.5f)/src.bounds.height();\n centerDir = spherical_tex2dir( float2(u, v) );\n\n // Would be nice to have a min and max range on the parameter definition\n // Not there now, so we just make sure the value doesn't go below 1\n // 1 = Lambertian Diffuse\n float exponent = max(phongExponent, 1.f);\n\n //Iterate over the src image rows\n for(int j = 0; j src.bounds.height(); j++) \{\n\n // solid angle is the same for all pixels in a row\n float dsa = spherical_solidAngle(j, src.bounds.width(), src.bounds.height());\n\n //Iterate over the src image columns\n for(int i = 0; i src.bounds.width(); i++) \{ \n\n // The direction for the pixel to be filtered\n u = float(i + 0.5f)/src.bounds.width();\n v = float(j + 0.5f)/src.bounds.height();\n filterDir = spherical_tex2dir( float2(u, v) );\n\n //Get he filter value\n ValueType(src) filterVal = pow(max(dot(centerDir, filterDir), 0.f), exponent)*dsa;\n\n //Multiply the src value by the corresponding filter weight and accumulate\n valueSum += filterVal * src(i, j);\n\n //Update the filter sum with the current filter value\n filterSum + filterVal;\n \}\n \}\n\n //Normalise the value sum, avoiding division by zero\n if (filterSum != 0) \n valueSum /= filterSum;\n\n dst() = valueSum;\n \}\n\};\n'
rebuild ''
maxTileLines 1
name BlinkScript2
selected true
xpos -312
ypos 192
}

Please login in order to download these files.

You have no rights to post comments

We have 2485 guests and 113 members online