don't render objects with zero alpha color (RGBA)

This commit is contained in:
Erwin Coumans
2017-05-13 07:38:00 -07:00
parent f692973f47
commit 7cb763e4c8
4 changed files with 22 additions and 9 deletions

View File

@@ -26,6 +26,8 @@ void main(void)
vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);
vec3 ct,cf;
float intensity,at,af;
if (fragment.color.w==0)
discard;
intensity = 0.5+0.5*clamp( dot( normalize(normal),lightDir ), -1,1 );
@@ -45,6 +47,5 @@ void main(void)
intensity = 0.7*intensity + 0.3*intensity*visibility;
cf = intensity*(vec3(1.0,1.0,1.0)-ambient)+ambient;
color = vec4(ct * cf, fragment.color.w);
}

View File

@@ -20,7 +20,8 @@ static const char* useShadowMapInstancingFragmentShader= \
" vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);\n"
" vec3 ct,cf;\n"
" float intensity,at,af;\n"
" \n"
" if (fragment.color.w==0)\n"
" discard;\n"
" intensity = 0.5+0.5*clamp( dot( normalize(normal),lightDir ), -1,1 );\n"
" \n"
" af = 1.0;\n"
@@ -37,7 +38,6 @@ static const char* useShadowMapInstancingFragmentShader= \
" intensity = 0.7*intensity + 0.3*intensity*visibility;\n"
" \n"
" cf = intensity*(vec3(1.0,1.0,1.0)-ambient)+ambient;\n"
" \n"
" color = vec4(ct * cf, fragment.color.w);\n"
"}\n"
;

View File

@@ -26,7 +26,7 @@ B3_ATTRIBUTE_ALIGNED16(struct) SimpleGL2Instance
int m_shapeIndex;
b3Vector3 m_position;
b3Quaternion orn;
b3Vector3 m_rgbColor;
b3Vector4 m_rgbColor;
b3Vector3 m_scaling;
void clear()
{
@@ -182,6 +182,10 @@ void SimpleOpenGL2Renderer::drawOpenGL(int instanceIndex)
const SimpleGL2Instance& inst = *instPtr;
const SimpleGL2Shape* shape = m_data->m_shapes[inst.m_shapeIndex];
if (inst.m_rgbColor[3]==0)
{
return;
}
glPushMatrix();
b3Transform tr;
@@ -475,6 +479,8 @@ int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const double
instance.m_rgbColor[0] = color[0];
instance.m_rgbColor[1] = color[1];
instance.m_rgbColor[2] = color[2];
instance.m_rgbColor[3] = color[3];
instance.m_scaling[0] = scaling[0];
instance.m_scaling[1] = scaling[1];
instance.m_scaling[2] = scaling[2];
@@ -496,6 +502,8 @@ int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const float*
instance.m_rgbColor[0] = color[0];
instance.m_rgbColor[1] = color[1];
instance.m_rgbColor[2] = color[2];
instance.m_rgbColor[3] = color[3];
instance.m_scaling[0] = scaling[0];
instance.m_scaling[1] = scaling[1];
instance.m_scaling[2] = scaling[2];

View File

@@ -487,6 +487,9 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
Model* model = renderData.m_model;
if (0==model)
return;
//discard invisible objects (zero alpha)
if (model->getColorRGBA()[3]==0)
return;
renderData.m_viewportMatrix = viewport(0,0,width, height);
@@ -507,6 +510,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
Shader shader(model, light_dir_local, light_color, modelViewMatrix, lightModelViewMatrix, renderData.m_projectionMatrix,renderData.m_modelMatrix, renderData.m_viewportMatrix, localScaling, model->getColorRGBA(), width, height, shadowBufferPtr, renderData.m_lightAmbientCoeff, renderData.m_lightDiffuseCoeff, renderData.m_lightSpecularCoeff);
for (int i=0; i<model->nfaces(); i++)
{
B3_PROFILE("face");