Sign in to follow this  
sienaiwun

GPU Gems Chapter 8. "Simulating Diffraction"'s understanding

Recommended Posts

Hi:
All.
I do not quite understand diffraction's code in GPU Gems Chapter 8.[url="http://http.developer.nvidia.com/GPUGems/gpugems_ch08.html"]http://http.develope...ugems_ch08.html[/url].

[b][i]float3[/i][/b][color=#000000][size=3] P = [/size][/color][b][i]mul[/i][/b][color=#000000][size=3](ModelViewMatrix, position).xyz;[/size][/color]
[b][i]float3[/i][/b] L = [b][i]normalize[/i][/b](lightPosition - P);
[b][i]float3[/i][/b] V = [b][i]normalize[/i][/b](eyePosition - P);
[b][i]float3[/i][/b] H = L + V;
[b][i]float3[/i][/b] N = [b][i]mul[/i][/b](([b][i]float3x3[/i][/b])ModelViewMatrixIT, normal);
[b][i]float3[/i][/b] T = [b][i]mul[/i][/b](([b][i]float3x3[/i][/b])ModelViewMatrixIT, tangent);


//from here on,I do not quite understand the parameter u,w,e c. Can you give me some corresponding concept in the equation
[img]http://http.developer.nvidia.com/GPUGems/elementLinks/126equ02.jpg[/img].

[b][i]float[/i][/b] u = [b][i]dot[/i][/b](T, H) * d;
[b][i]float[/i][/b] w = [b][i]dot[/i][/b](N, H);
[b][i]float[/i][/b] e = r * u / w;
[b][i]float[/i][/b] c = [b][i]exp[/i][/b](-e * e);
[b][i]float4[/i][/b] anis = hiliteColor * [b][i]float4[/i][/b](c.x, c.y, c.z, 1);

[b][i]if[/i][/b] (u < 0) u = -u;

[b][i]float4[/i][/b] cdiff = [b][i]float4[/i][/b](0, 0, 0, 1);
[b][i]for[/i][/b] ([b][i]int[/i][/b] n = 1; n < 8; n++)
{
[b][i]float[/i][/b] y = 2 * u / n - 1;
cdiff.xyz += blend3([b][i]float3[/i][/b](4 * (y - 0.75), 4 * (y - 0.5),
4 * (y - 0.25)));
}

And also I do not understand the meaning of the for loop. Edited by sienaiwun

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this