TinyRenderer: discard pixels beyond farplane
pybullet: printf build date/time
This commit is contained in:
@@ -92,6 +92,7 @@ struct Shader : public IShader {
|
|||||||
mat<3,3,float> varying_nrm; // normal per vertex to be interpolated by FS
|
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
|
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)
|
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_model(model),
|
||||||
m_light_dir_local(light_dir_local),
|
m_light_dir_local(light_dir_local),
|
||||||
@@ -112,6 +113,9 @@ struct Shader : public IShader {
|
|||||||
m_height(height)
|
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_invModelMat = m_modelMat.invert_transpose();
|
||||||
m_projectionModelViewMat = m_projectionMat*m_modelView1;
|
m_projectionModelViewMat = m_projectionMat*m_modelView1;
|
||||||
m_projectionLightViewMat = m_projectionMat*m_lightModelView;
|
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]);
|
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);
|
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 i=0; i<model->nfaces(); i++)
|
||||||
{
|
{
|
||||||
for (int j=0; j<3; j++) {
|
for (int j=0; j<3; j++) {
|
||||||
|
|||||||
@@ -180,6 +180,9 @@ void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zb
|
|||||||
zbuffer[P.x+P.y*image.get_width()]>frag_depth)
|
zbuffer[P.x+P.y*image.get_width()]>frag_depth)
|
||||||
continue;
|
continue;
|
||||||
bool discard = shader.fragment(bc_clip, color);
|
bool discard = shader.fragment(bc_clip, color);
|
||||||
|
if (frag_depth<-shader.m_farPlane)
|
||||||
|
discard=true;
|
||||||
|
|
||||||
if (!discard) {
|
if (!discard) {
|
||||||
zbuffer[P.x+P.y*image.get_width()] = frag_depth;
|
zbuffer[P.x+P.y*image.get_width()] = frag_depth;
|
||||||
if (segmentationMaskBuffer)
|
if (segmentationMaskBuffer)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ Matrix projection(float coeff=0.f); // coeff = -1/c
|
|||||||
Matrix lookat(Vec3f eye, Vec3f center, Vec3f up);
|
Matrix lookat(Vec3f eye, Vec3f center, Vec3f up);
|
||||||
|
|
||||||
struct IShader {
|
struct IShader {
|
||||||
|
float m_nearPlane;
|
||||||
|
float m_farPlane;
|
||||||
virtual ~IShader();
|
virtual ~IShader();
|
||||||
virtual Vec4f vertex(int iface, int nthvert) = 0;
|
virtual Vec4f vertex(int iface, int nthvert) = 0;
|
||||||
virtual bool fragment(Vec3f bar, TGAColor &color) = 0;
|
virtual bool fragment(Vec3f bar, TGAColor &color) = 0;
|
||||||
|
|||||||
@@ -6463,7 +6463,7 @@ initpybullet(void)
|
|||||||
SpamError = PyErr_NewException("pybullet.error", NULL, NULL);
|
SpamError = PyErr_NewException("pybullet.error", NULL, NULL);
|
||||||
Py_INCREF(SpamError);
|
Py_INCREF(SpamError);
|
||||||
PyModule_AddObject(m, "error", SpamError);
|
PyModule_AddObject(m, "error", SpamError);
|
||||||
|
printf("pybullet build time: %s %s\n", __DATE__,__TIME__);
|
||||||
|
|
||||||
Py_AtExit( b3pybulletExitFunc );
|
Py_AtExit( b3pybulletExitFunc );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user