Precision loss in non-design and reprogramming

I am implementing a version of the shadow rendering technique, but I (think) suffer from exact losses.

That's what I'm doing:

  • I draw my scene from the eyepiece to fill the depth buffer.
  • I do not design these points using gluUnproject
  • I will reprogram these points from my light source as an eyepoint using gluProject
  • Then I iterate over all my triangles, project them from my light source as an eyepoint.

-> For points (from the first step) that overlap with the triangle, I compare the depth. I compare the interpolated depth in the triangle pixel with the depth I reprogrammed in step 2, if the triangle is closer, it is displayed in shadow.

I use barycentric coordinates to interpolate depth in an irregular place. This means comparing three float values ​​with zero, comparing two floats to see which one is smaller .. I used the offset in all comparisons without any big effects (eps = 0.00001)

The algorithm works well, but I still have some artifacts, and I think they can be attributed to un-and reprojecting. Could it be?

I use perspective projection, my near = 1.0 and my far = 20.0. What can I do to improve this?

I would be happy to show some kind of code, but that is pretty much. So let's see what suggestions come out first.

Artifact http://img849.imageshack.us/img849/4420/artifactk.png

I read my pixels and did not design this way:

//Get the original pixels glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[0]); glReadPixels( 0, 0,800, 300, GL_DEPTH_COMPONENT,GL_FLOAT, BUFFER_OFFSET(0)); glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[1]); glReadPixels( 0, 300, 800, 300, GL_DEPTH_COMPONENT,GL_FLOAT, BUFFER_OFFSET(0)); //Process the first batch of pixels glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[0]); GLfloat *pixels1 = (GLfloat*)glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); processPixels( pixels1, lightPoints, modelview, projection, viewport, 0); //Process the second batch of pixels glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[1]); GLfloat *pixels2 = (GLfloat*)glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); processPixels( pixels2, lightPoints, modelview, projection, viewport, 1); //Unamp buffers and restore default buffer glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pboIds[0]); glUnmapBuffer(GL_PIXEL_PACK_BUFFER); glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, pboIds[1]); glUnmapBufferARB(GL_PIXEL_PACK_BUFFER); glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); //Projecting the original points to lightspace glLoadIdentity(); gluLookAt( light_position[0], light_position[1], light_position[2], 0.0,0.0,0.0,0.0,1.0,0.0); //We get the new modelview matrix - Lightspace glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //std::cout <<"Reprojecting" << std::endl; GLdouble winX, winY, winZ; Vertex temp; //Projecting the points into lightspace and saving the sample points for(vector<Vertex>::iterator vertex = lightPoints.begin(); vertex != lightPoints.end(); ++vertex){ gluProject( vertex->x, vertex->y, vertex->z,modelview, projection, viewport, &winX, &winY, &winZ ); temp.x = winX; temp.y = winY; temp.z = winZ; // std::cout << winX << " " << winY << " " << winZ << std::endl; samplePoints.push_back(temp); } 

My depth buffer is 24 bits, which I cannot change afaik (ATI Radeon HD4570 and I use GLUT).

I compare my depth:

 if(rasterizer.interpolateDepth(A, B, C, baryc) < sample->z - 0.00001*sample->z){ stencilBits[(((int)sample->y*800 +(int)sample->x )) ] = 1; 

both are floats.

The floats must be accurate, and in the article I'm based on, they also use floats. }

+4
source share
2 answers

Try to put the long-range plan further: http://www.codermind.com/files/small_wnear.gif

0
source

A few suggestions: - perform regular shadow mapping without processor operations first - read the opengl pipeline math very, very carefully and make sure everything is correct, including rounding - you say interpolating depth. it sounds very wrong - you just can't linearly interpolate the depth as it is (you can build a square, but I don't think you do it)

0
source

Source: https://habr.com/ru/post/1369076/


All Articles