GRP1 discussion

Programming topics can be found here.
bikker
Posts: 67
Joined: Fri Sep 27, 2013 12:40 pm

Re: GRP1 discussion

Post by bikker » Mon Sep 30, 2013 2:46 pm

Well you get barycentric coordinates on the triangle if you used Moller-Trumbore, right? They are typically named 'u' and 'v' (somewhat confusing, because they have nothing to do with texture coordinates). These range from 0..1 over the triangle, and summed they are also 0..1 (therefore they form a triangle). You can use those to weight vertex normals. I use the following code:

Code: Select all

const float f = 1.0f - _U - _V;
_N.x = N2.x * f + N0.x * _U + N1.x * _V;
_N.y = N2.y * f + N0.y * _U + N1.y * _V;
_N.z = N2.z * f + N0.z * _U + N1.z * _V;
You will have to normalize _N after calculating it, since you can't officially do a linear interpolation of normals.
Let me know if that works for you.

User avatar
110157
Posts: 6
Joined: Mon Sep 30, 2013 12:41 am

Re: GRP1 discussion

Post by 110157 » Mon Sep 30, 2013 4:43 pm

Now I want to make another ray/pathtracer!
Sam Hardeman
4GA-1PR

User avatar
122675
Posts: 25
Joined: Mon Sep 30, 2013 9:48 am
Contact:

Re: GRP1 discussion

Post by 122675 » Mon Sep 30, 2013 8:13 pm

Thank you, Jacco. The problem was that I wasn't using the w coordinate at all :P. I have not done normal smoothing yet, but the triangle interpolation is definitely working for the texture coordinates:
Image
Tom Veltmeijer

121649
Posts: 6
Joined: Sun Sep 29, 2013 6:53 pm

Re: GRP1 discussion

Post by 121649 » Thu Oct 03, 2013 7:55 pm

Image
I spent my last five minutes working really hard on creating this, hope you like it jacco. Your picture motivated me.
Hello, I am replicant #121649.

bikker
Posts: 67
Joined: Fri Sep 27, 2013 12:40 pm

Re: GRP1 discussion

Post by bikker » Fri Oct 04, 2013 9:47 am

Yes I like. :) Very nice image!

120448
Posts: 11
Joined: Mon Sep 30, 2013 1:00 pm

Re: GRP1 discussion

Post by 120448 » Mon Oct 07, 2013 6:54 pm

I started on a path tracer with GI this weekend. This image has 500 samples per pixel. It took a while to render though...

Image
Marc Peyré
Programmer - 2nd year
http://twirlbound.com

bikker
Posts: 67
Joined: Fri Sep 27, 2013 12:40 pm

Re: GRP1 discussion

Post by bikker » Mon Oct 07, 2013 9:52 pm

Awesome! We have the first path tracer of the season! You must be very proud. :)

bikker
Posts: 67
Joined: Fri Sep 27, 2013 12:40 pm

Re: GRP1 discussion

Post by bikker » Thu Oct 10, 2013 11:19 am

Three code snippets discussed in the lecture:

Ray direction to point on skydome texture:

Code: Select all

	const float u = fmodf( 0.5f * (1.0f + atan2( _D.x, -_D.z ) * INVPI ) + _Context.skyRotate, 1.0f);
	const float v = saturate( acosf( _D.y ) * INVPI );
	const int pixel =  (int)(u * (float)_Context.skyWidth) + ((int)(v * (float)_Context.skyHeight) * _Context.skyWidth);
	const float4 texel = tex1Dfetch( t_sky, pixel ) * _Context.skyScale;
	return make_float3( texel.x, texel.y, texel.z );
Loading an HDR sky probe through FreeImage:

Code: Select all

	FIBITMAP* dib = FreeImage_Load( FIF_HDR, _File );
	float* buffer = (float*)FreeImage_GetBits( dib );
	scene->skyMapWidth = FreeImage_GetWidth( dib );
	scene->skyMapHeight = FreeImage_GetHeight( dib );
	FREE16( scene->skyMap );
	scene->skyMap = MALLOC16( scene->skyMapWidth * scene->skyMapHeight, float4 );
	for( int y = 0; y < scene->skyMapHeight; y++) 
	{
		float3* line = (float3*)FreeImage_GetScanLine( dib, scene->skyMapHeight - 1 - y );
		for ( int x = 0; x < scene->skyMapWidth; x++ ) 
			scene->skyMap[y * scene->skyMapWidth + x] = float4( line[x].x, line[x].y, line[x].z, 0 );
	}
	FreeImage_Unload( dib );
Ray box intersection:

Code: Select all

			float3 t1 = (node.lmin - O) * idir, t2 = (node.lmax - O) * idir;
			float tminLeft = max( max( min( t1.x, t2.x ), min( t1.y, t2.y ) ), min( t1.z, t2.z ) );
			bool leftHit = (min( min( max( t1.x, t2.x ), max( t1.y, t2.y ) ), max( t1.z, t2.z ) ) >= tminLeft);
- Jacco.

User avatar
122675
Posts: 25
Joined: Mon Sep 30, 2013 9:48 am
Contact:

Re: GRP1 discussion

Post by 122675 » Thu Oct 10, 2013 12:23 pm

Thanks for the code snippets, Jacco, but not all the functions are defined. For example, what does the saturate() function do?
Tom Veltmeijer

090004
Posts: 6
Joined: Sun Sep 29, 2013 3:15 pm

Re: GRP1 discussion

Post by 090004 » Thu Oct 10, 2013 1:23 pm

122675 wrote:Thanks for the code snippets, Jacco, but not all the functions are defined. For example, what does the saturate() function do?
Clamps a value between 0 and 1.
Joey Fladderak
Programmer

Portfolio

Currently: VFX Programmer at Digital Dreams, working on Metrico

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest