Jump to content

  • Log In with Google      Sign In   
  • Create Account


Adapting Luminance Map - No adaptation according to my eye

  • You cannot reply to this topic
5 replies to this topic

#1 Migi0027   Crossbones+   -  Reputation: 1662

Like
0Likes
Like

Posted 17 August 2014 - 05:28 AM

Hi guys. wink.png

 

so I'm currently having a minor issue here. I generate my luminance map, then attempt to adapt it and then use it for other purposes, such as the bloom pass. But the problem is that theres no visible adaptation for some reason. Someone might find the shader code familiar, well thats because I based it on a sample from MJP (Thanks btw. Great samples you have there.)

 

Logic in the high level render when rendering & adapting the luminance map, DX11 is my own small wrapper, it should work as intended:

void CE_NAMESPACE::CEPostLuminance::Render(DX11 *pD3D11, float dTime, DX11Resource *p, DX11RenderTarget *pOut)
{
	// Set DTIME
	Buffer.fTimeDelta = dTime;

	// Map Data
	pD3D11->BufferConstantMap(m_vBuffers[0]->p, &Buffer);

	// Upload the data
	SetData(pD3D11);

	// Calculate new luminance
	{
		pD3D11->RTVSet(&m_pLum->pRTV, 1, false);

		// Bind Shader
		ApplyPost(pD3D11, &m_pPasses[0]);

		// Upload Texture
		pD3D11->Bind(p, 0);

		// Render the quad
		pD3D11->Render(3, 0);

		// Unbind
		pD3D11->Unbind(PS, 0);
	}

	// Adapt it, no effect
	{
		pD3D11->RTVSet(&m_pTemp->pRTV, 1, false);

		// Bind Shader
		ApplyPost(pD3D11, &m_pPasses[1]);

		// Upload Texture
		pD3D11->Bind(m_pLumLast, 1);

		// Upload Texture
		pD3D11->Bind(m_pLum, 2);

		// Render the quad
		pD3D11->Render(3, 0);
	}

	// Swappy Times!
	m_pLumLast = m_pLum;
	m_pLum = m_pTemp;
	m_pTemp = m_pLumLast;

        .... Some more unrelated stuff

The actual shader code for the adaptation: ( Tau: 1.25f )

 
 
...
Texture2D<float> lum_old : register(t1);
Texture2D<float> lum : register(t2);

...

float AdaptLuminancePS(VS_Output input) : SV_Target
{
	float lastLum = exp(lum_old.Sample(ss, input.Tex));
	float currentLum = lum.Sample(ss, input.Tex);

	// Adapt the luminance using Pattanaik's technique    
	float adaptedLum = lastLum + (currentLum - lastLum) * (1 - exp(-TimeDelta * Tau));

	return log(adaptedLum);
}

The mistake is most likely obvious but theres no change in the luminance map according to my eyes.

 

Thank you for your time. I appreciate it.

-MIGI0027


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

Sponsor:

#2 Juliean   GDNet+   -  Reputation: 2455

Like
0Likes
Like

Posted 17 August 2014 - 06:15 AM


float adaptedLum = lastLum + (currentLum - lastLum) * (1 - exp(-TimeDelta * Tau));

 

Probably this line. Just quessing, but thats what caused problems at my end more than once. try to replace the exp()-statement with a constant, like

 


float adaptedLum = lastLum + (currentLum - lastLum) * 0.75f;

 

and see if it works.



#3 Migi0027   Crossbones+   -  Reputation: 1662

Like
0Likes
Like

Posted 17 August 2014 - 07:38 AM

Tried replacing the exp with 0.75f, still, no change, its most likely a simple mistake, which are the worst.


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!

#4 Juliean   GDNet+   -  Reputation: 2455

Like
0Likes
Like

Posted 17 August 2014 - 08:38 AM

Visualize the content of your render-targets then. How does the current/last/blended luminance looks like?Try to see if there is any change here at all first, maybe the luminance isn't even calculated properly to begin with.



#5 joeblack   Members   -  Reputation: 261

Like
0Likes
Like

Posted 18 August 2014 - 03:07 AM

Hi, can you show how are you computing luminance ?

and also your bloom pass ?

 

Log and exp should be used during generation of luminance, so instead of :

float lastLum = exp(lum_old.Sample(ss, input.Tex));
float currentLum = lum.Sample(ss, input.Tex);

 // Adapt the luminance using Pattanaik's technique 
 float adaptedLum = lastLum + (currentLum - lastLum) * (1 - exp(-TimeDelta * Tau));

    return log(adaptedLum);

you should have :

float lastLum = lum_old.Sample(ss, input.Tex);
float currentLum = exp(lum.Sample(ss, input.Tex));

// Adapt the luminance using Pattanaik's technique 
 float adaptedLum = lastLum + (currentLum - lastLum) * (1 - exp(-TimeDelta * Tau));

 return adaptedLum;

and use Log during generation of luminance.

 

Or first you can try you luminance without any log/exp and see if it works.


Edited by joeblack, 18 August 2014 - 03:07 AM.


#6 Migi0027   Crossbones+   -  Reputation: 1662

Like
0Likes
Like

Posted 19 August 2014 - 02:21 PM

Thanks for all the valuable help, the problem lied deeper due to a flaw in my logic and naive assumptions.

 

The problem was the swapping part. Im not sure when or how or why I did it like that.

 

WRONG: (I must have been under some sort of hallucinating drug blink.png )

// Adapt it, no effect
	{
		pD3D11->RTVSet(&m_pTemp->pRTV, 1, false);

		// Bind Shader
		ApplyPost(pD3D11, &m_pPasses[1]);

		// Upload Texture
		pD3D11->Bind(m_pLumLast, 1);

		// Upload Texture
		pD3D11->Bind(m_pLum, 2);

		// Render the quad
		pD3D11->Render(3, 0);
	}

	// Swappy Times! Like wtf is this!?
	m_pLumLast = m_pLum;
	m_pLum = m_pTemp;
	m_pTemp = m_pLumLast;

The solution was two have an array called m_pLumLast of 2 elements, then casually swap them after usage:

	// Blend it
	{
		pD3D11->RTVSet(&m_ppLumLast[1]->pRTV, 1, false);

		// Bind Shader
		ApplyPost(pD3D11, &m_pPasses[1]);

		// Upload Texture
		pD3D11->Bind(m_ppLumLast[0], 1);

		// Upload Texture
		pD3D11->Bind(m_pLum, 2);

		// Render the quad
		pD3D11->Render(3, 0);

		// Unbind
		pD3D11->Unbind(PS, 0);
	}

	// Swap Old Luminance Maps
	DX11RenderTarget *pRCPY = m_ppLumLast[0];
	m_ppLumLast[0] = m_ppLumLast[1];
	m_ppLumLast[1] = pRCPY;

Ohh, and for anyone wondering, its a good idea to clear the last luminance textures after youve created them to a value, might be 0.

 

And thanks joeblack + juliean. But the problem was on my side, I apologize for the trouble. But thanks for the awesome help.

 

Perhaps someone will find this valuable at some point.

 

EDIT: Sorry for the long delay, but its hard finding time to test...

 

-MIGI0027


Edited by Migi0027, 19 August 2014 - 02:22 PM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to kill everyone you meet, ohh, AND STEAL ALL ZE TRIANGLES FROM ZHEM!





PARTNERS