TinyRenderer: discard pixels beyond farplane

pybullet: printf build date/time
This commit is contained in:
Erwin Coumans
2017-05-25 17:25:14 -07:00
parent dcdb3d40ba
commit 2b9c67b07c
4 changed files with 12 additions and 3 deletions

View File

@@ -91,7 +91,8 @@ struct Shader : public IShader {
mat<4,3,float> varying_tri_light_view;
mat<3,3,float> varying_nrm; // normal per vertex to be interpolated by FS
mat<4,3,float> world_tri; // model triangle coordinates in the world space used for backface culling, written by VS
Shader(Model* model, Vec3f light_dir_local, Vec3f light_color, Matrix& modelView, Matrix& lightModelView, Matrix& projectionMat, Matrix& modelMat, Matrix& viewportMat, Vec3f localScaling, const Vec4f& colorRGBA, int width, int height, b3AlignedObjectArray<float>* shadowBuffer, float ambient_coefficient=0.6, float diffuse_coefficient=0.35, float specular_coefficient=0.05)
:m_model(model),
m_light_dir_local(light_dir_local),
@@ -112,6 +113,9 @@ struct Shader : public IShader {
m_height(height)
{
m_nearPlane = m_projectionMat.col(3)[2]/(m_projectionMat.col(2)[2]-1);
m_farPlane = m_projectionMat.col(3)[2]/(m_projectionMat.col(2)[2]+1);
//printf("near=%f, far=%f\n", m_nearPlane, m_farPlane);
m_invModelMat = m_modelMat.invert_transpose();
m_projectionModelViewMat = m_projectionMat*m_modelView1;
m_projectionLightViewMat = m_projectionMat*m_lightModelView;
@@ -576,7 +580,7 @@ void TinyRenderer::renderObjectDepth(TinyRenderObjectData& renderData)
Vec3f localScaling(renderData.m_localScaling[0],renderData.m_localScaling[1],renderData.m_localScaling[2]);
DepthShader shader(model, lightModelViewMatrix, lightViewProjectionMatrix,renderData.m_modelMatrix, localScaling, light_distance);
shader.m_farPlane=1e30;
for (int i=0; i<model->nfaces(); i++)
{
for (int j=0; j<3; j++) {