Advertisement

Light Indexed Deferred Rendering: Point Light Source does Incorrect shading

Started by November 08, 2020 08:10 PM
20 comments, last by ddlox 3 years, 11 months ago

Hi, I'm trying to port original OpenGL 2.0 demo of Light Indexed Deferred Rendering to Direct3D12:

During applying light sources from Light Buffer it produces incorect shading:

My modification of original demo, also produces the same bug

see Source\DeferredLighting\App.cpp line 838

#if 0

glMatrixMode(GL_MODELVIEW);

outGLError();

// TO DO !!!!! Why does it need ?

//glLoadTransposeMatrixfARB(modelviewMatrix);

glLoadMatrixf(transpose(modelviewMatrix));

outGLError();

#endif

If we try to comment glLoadMatrixf we see the same problem:

how to fix it ?

Thank you.

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

1/ why is it incorrect?

2/ also, in converting your code from OGL to D3D, have u remembered to flip the Y and Z axis values ? (or u could just use …*RH( ) functions in D3D and then keep an eye on the triangle verts winding order and cull mode)

Until then ?

Advertisement

Hi, @ddlox Thank you for your reply!

ddlox said:

1/ why is it incorrect?

We see half of circle instead of full circle for point light. You can run executable form github and you will see this bug

ddlox said:
2/ also, in converting your code from OGL to D3D, have u remembered to flip the Y and Z axis values ? (or u could just use …*RH( ) functions in D3D

I use Projection matrix for D3D see Matrix4x4 class, may be I'm wrong, i will check it again

ddlox said:
and then keep an eye on the triangle verts winding order and cull mode)

Ok, i will try to recheck it

Thank you for your suggestions!

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

ah ok this:

I use Projection matrix for D3D see Matrix4x4 class, may be I'm wrong, i will check it again

is a transposed left-handed perspective projection matrix, so it's like what this one D3DXMatrixPerspectiveFovLH produces but transposed. I'm guessing you're transposing so u can also use it transposed in your shader…

So that means for a right-handed system you want to use what this one D3DXMatrixPerspectiveFovRH produces but transposed, so u want to change your code to:

Matrix[0] = yScale / aspect;
Matrix[1] = 0.0f;
Matrix[2] = 0.0f;
Matrix[3] = 0.0f;

Matrix[4] = 0.0f;
Matrix[5] = yScale;
Matrix[6] = 0.0f;
Matrix[7] = 0.0f;

Matrix[8] = 0.0f;
Matrix[9] = 0.0f;
Matrix[10] = zFar / (zNear - zFar);// new code change
Matrix[11] = -1.0f;	 // new code change

Matrix[12] = 0.0f;
Matrix[13] = 0.0f;
Matrix[14] = zNear * zFar / (zNear - zFar);
Matrix[15] = 0.0f;

also, depending on how your vertices were stored (or exported) you may or not need to negate their Z values. If needed you could put it in here:

Matrix[10] = -zFar .... // just add minus in front to flip z values

So this should get you past any hurdle of uncertainty. If u still have a problem then maybe we need to look at the shader code next.

Until then ?

Hi @ddlox Thank you for you time!

ddlox said:
then keep an eye on the triangle verts winding order and cull mode

Working with some combination D3D12_RASTERIZER_DESC FrontCounterClockwise and CullMode, we see the same half of circle or nothing.

ddlox said:
So that means for a right-handed system you want to use what this one D3DXMatrixPerspectiveFovRH produces but transposed, so u want to change your code to:

I tried to used new Perspective Right Handled matrix but I still have the same problem.

ddlox said:
also, depending on how your vertices were stored (or exported) you may or not need to negate their Z values. If needed you could put it in here: Matrix[10] = -zFar .... // just add minus in front to flip z values

doesn't work at all.

ddlox said:
If u still have a problem then maybe we need to look at the shader code next.

Yes.

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

is this ok?

Advertisement

it looks good to me ?

@ddlox Yes, try to run my modification of original demo https://www.dropbox.com/s/9a5htmjrgdlotjw/Light%20Indexed%20Deferred%20Shading_ok.7z?dl=0

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

mod looks good too ?

@ddlox ,Hi Sorry! try another (corrected) modification

see Source\DeferredLighting\App.cpp line 838:

#if 1
  glMatrixMode(GL_MODELVIEW);
  outGLError();
  // TO DO !!!!! Why does it need ?
  //glLoadTransposeMatrixfARB(modelviewMatrix);
  glLoadMatrixf(transpose(modelviewMatrix));
  outGLError();
#endif

If we try to comment glLoadMatrixf we see the same problem:

lidr_gl_bug

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

This topic is closed to new replies.

Advertisement