• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cifa

UE4 IBL glsl

3 posts in this topic

************** UPDATE ********************** 

 

I had a stupid issue due to the resolution of the texture, not the code below works as it should. 

 

***********************************************

 

 

Hi there!

 

I'm trying to implement the IBL technique described in here: http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf

 

 

Now I'm still trying to get the envBRDF LUT (roughness / NdotV) to render properly as shown in the paper: 

 

TDb6Dhh.png?1

 

What I have now is: 

 

the usual Hammersley functions:


float radicalInverse_VdC(uint bits) {
     bits = (bits << 16u) | (bits >> 16u);
     bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
     bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
     bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
     bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
     return float(bits) * 2.3283064365386963e-10; // / 0x100000000
 }
 // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
 vec2 Hammersley(uint i, uint N) {
     return vec2(float(i)/float(N), radicalInverse_VdC(i));
 }
 

The ImportanceSampleGGX practically as reported in the paper:

vec3 importanceSampleGGX(vec2 sample, float m, vec3 N){
	float phi = sample.x * 2.0f * PI;
	float cosTheta = sqrt( (1.0f - sample.y) / 1.0f + (m*m - 1.0f) * sample.y ); 
	float sinTheta = sqrt(1.0f - cosTheta*cosTheta);

	vec3 vector = vec3(
		sinTheta * cos(phi),
		sinTheta * sin(phi),
		cosTheta
		);


	return vector;
	vec3 up = abs(N.z) < 0.999 ? vec3(0.0,0.0,1.0) : vec3(1.0,0.0,0.0);
	vec3 tangentX = normalize(cross(up,N));
	vec3 tangentY = normalize(cross(N,tangentX));
	// Project 
	return tangentX * vector.x + tangentY * vector.y + N * vector.z;
}

The integrateBRDF

 vec2 IntegrateBRDF( float Roughness, float NoV ){
 vec3 V;
 V.x = sqrt( 1.0f - NoV * NoV ); // sin
 V.y = 0.0;
 V.z = NoV;
 // cos
 float A = 0.0;
 float B = 0.0;

 for( uint i = 0u; i < NUMBER_OF_SAMPLES; i++ )
 {
 vec2 Xi = Hammersley( i, NUMBER_OF_SAMPLES );
 vec3 H = ImportanceSampleGGX( Xi, Roughness, vec3(0.0,0.0,1.0) );
 vec3 L = 2.0 * dot( V, H ) * H - V;
 float NoL = max( L.z, 0.0 );
 float NoH = max( H.z, 0.0 );
 float VoH = max( dot( V, H ), 0.0 );

 	if( NoL > 0 )
 	{
	 float G = G_Smith( Roughness, NoV, NoL );
	 float G_Vis = G * VoH / (NoH * NoV);
	 float Fc = pow( 1.0 - VoH, 5.0 );
	 A += (1.0 - Fc) * G_Vis;
	 B += Fc * G_Vis;
 	}
 }
return vec2(  (A)/float(NUMBER_OF_SAMPLES), (B)/float(NUMBER_OF_SAMPLES)) ;
}

 

 

 

As you can see they're almost a copy-paste from the reference, but what I got is completely different: 

 

6b9aXlD.png

 

 

The roughness is the uv.x and uv.y of a quad that are calculated in the VS as: 

	vTextureCoordinate = (aVertexPosition.xy+vec2(1,1))/2.0;

Am I missin something very stupid? 

Edited by cifa
0

Share this post


Link to post
Share on other sites

He is using Disney's roughness which is squared so that would be m*m inside the importanceSampleGGX function.

My HLSL code:

float3 ImportanceSampleGGX(float2 Xi, float Roughness, float3 N)
{
	float a = Roughness * Roughness; // DISNEY'S ROUGHNESS [see Burley'12 siggraph]

	// Compute distribution direction
	float Phi = 2 * PI * Xi.x;
	float CosTheta = sqrt((1 - Xi.y) / (1 + (a*a - 1) * Xi.y));		
	float SinTheta = sqrt(1 - CosTheta * CosTheta);

	// Convert to spherical direction
	float3 H;
	H.x = SinTheta * cos(Phi);
	H.y = SinTheta * sin(Phi);
	H.z = CosTheta;

	float3 UpVector = abs(N.z) < 0.999 ? float3(0, 0, 1) : float3(1, 0, 0);
	float3 TangentX = normalize(cross(UpVector, N));
	float3 TangentY = cross(N, TangentX);

	// Tangent to world space
	return TangentX * H.x + TangentY * H.y + N * H.z;
}

For completeness sake here's how I do G_Smith:

// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
float GGX(float NdotV, float a)
{
	float k = a / 2;
	return NdotV / (NdotV * (1.0f - k) + k);
}

// http://graphicrants.blogspot.com.au/2013/08/specular-brdf-reference.html
float G_Smith(float a, float nDotV, float nDotL)
{
	return GGX(nDotL, a * a) * GGX(nDotV, a * a);
}

Not sure about the TexCoord code you are using but you just need to render a regular post process quad and simply pass through the TexCoords as they are and then use them as inputs to the integrateBRDF function like so:

return IntegrateBRDF(input.TexCoord.x, input.TexCoord.y);

Probably unrelated but I'm using an R16G16_FLOAT texture like Brian Karis is suggesting.

Edited by lipsryme
0

Share this post


Link to post
Share on other sites

Would you guys be able to share some details on how you're filtering your IBL cubemaps?
What roughness are you using at each mip?
What format do you use?

How do you put it all together?

 

Thanks!

0

Share this post


Link to post
Share on other sites

Hi REF_Cracker. Sorry for the late answer I just happened to stumble upon the thread again (hadn't been following it).

The format I'm using is R16G16B16A16_FLOAT for each cube map face.

I calculate the roughness in the shader like this:

float Roughness = (CubeLOD) / (CubeLODCount);

Which would give you values like these:

0 (256x256)

0.166667 (128x128)

0.333333 (64x64)

0.5 (32x32)

0.666667 (16x16)

0.833333 (8x8)

1 (4x4)

CubeLOD is starting at 256x256 and going down 6 levels (so 7 in total / original + 6 mip levels) to 4x4 for the roughest one.

Maybe you should use less mips and make it end at 16x16 or so haven't done much testing here.

Edited by lipsryme
0

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  
Followers 0