Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Mar 2010
Offline Last Active Oct 28 2014 06:57 AM

Posts I've Made

In Topic: Forward+ Rendering - best way to updating light buffer ?

06 October 2014 - 12:44 PM

Ah so I can just basically do the same as with constant buffers ! smile.png

Having some issues copying the data due to heap corruption but that might be related to something else.

Is this the correct way of doing it ?


Update: yep that heap corruption was something else. Seems to be working now smile.png

if (!pointLights_center_and_radius.empty())
	this->numActiveLights = static_cast<unsigned int>(pointLights_center_and_radius.size());
	D3D11_MAPPED_SUBRESOURCE pointLightResource = {};
	if (SUCCEEDED(this->context->Map(this->pointLightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &pointLightResource)))
		DirectX::XMFLOAT4 *pData = (DirectX::XMFLOAT4*)pointLightResource.pData;
		memcpy(pData, &pointLights_center_and_radius[0], sizeof(DirectX::XMFLOAT4) * numActiveLights);
		this->context->Unmap(this->pointLightBuffer, 0);

In Topic: Alpha-Test and Forward+ Rendering (Z-prepass questions)

10 August 2014 - 07:17 AM


Alpha-tested geometry tends to mess up z-buffer compression and hierarchical z representations. So usually you want to render it after your "normal" opaques, so that the normal geometry can get the benefit of full-speed depth testing.


As for why they return a color from their pixel shader...I have no idea. In our engine we use a void return type for our alpha-tested depth-only pixel shader.


Could it be beneficial to skip z prepass for alpha tested geometry compleatly to avoid that z-buffer compression mess ups?


The issue here is you can't since you need the depth information for light culling in the compute shader.

By the way it seems they have alpha-to-coverage enabled in the AMD sample so maybe the color return type has something to do with that ?

In Topic: UE4 IBL glsl

09 August 2014 - 01:13 PM

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.

In Topic: UE4 IBL glsl

14 July 2014 - 05:13 PM

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.

In Topic: UE4 IBL / shading confusion

30 June 2014 - 05:41 AM

Thanks for those links, that answers it.

I find the FresnelReflectance(they call it Specular) * 0.5 peculiar...

I guess they did it to limit the range of non-metals to something that was foolproof.