add alpha blendering option (disabled by default) using w component of color
add low-level support function demo (test)
This commit is contained in:
@@ -44,7 +44,7 @@ struct CommonGraphicsApp
|
||||
virtual void drawText( const char* txt, int posX, int posY) = 0;
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites, int largeSphereThreshold, int mediumSphereThreshold)=0;
|
||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ struct CommonRenderInterface
|
||||
virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0;
|
||||
virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0;
|
||||
virtual void writeTransforms()=0;
|
||||
virtual void enableBlend(bool blend)=0;
|
||||
};
|
||||
#endif//COMMON_RENDER_INTERFACE_H
|
||||
|
||||
|
||||
@@ -380,7 +380,8 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap
|
||||
m_textureinitialized(false),
|
||||
m_screenWidth(0),
|
||||
m_screenHeight(0),
|
||||
m_upAxis(1)
|
||||
m_upAxis(1),
|
||||
m_enableBlend(false)
|
||||
{
|
||||
|
||||
m_data = new InternalDataRenderer;
|
||||
@@ -1593,14 +1594,14 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||
|
||||
// m_data->m_shadowMap->disable();
|
||||
// return;
|
||||
// glEnable(GL_CULL_FACE);
|
||||
// glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
} else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
}
|
||||
|
||||
@@ -1794,6 +1795,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
case B3_USE_SHADOWMAP_RENDERMODE:
|
||||
{
|
||||
if (m_enableBlend)
|
||||
{
|
||||
glEnable (GL_BLEND);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
glUseProgram(useShadowMapInstancingShader);
|
||||
glUniformMatrix4fv(useShadow_ProjectionMatrix, 1, false, &projectionMatrix[0]);
|
||||
glUniformMatrix4fv(useShadow_ModelViewMatrix, 1, false, &modelviewMatrix[0]);
|
||||
@@ -1808,7 +1815,12 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
|
||||
glUniform1i(useShadow_shadowMap,1);
|
||||
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
||||
break;
|
||||
if (m_enableBlend)
|
||||
{
|
||||
glDisable (GL_BLEND);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
@@ -43,7 +43,8 @@ class GLInstancingRenderer : public CommonRenderInterface
|
||||
int m_screenHeight;
|
||||
|
||||
int m_upAxis;
|
||||
|
||||
bool m_enableBlend;
|
||||
|
||||
void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE);
|
||||
|
||||
|
||||
@@ -156,6 +157,10 @@ public:
|
||||
return m_maxNumObjectCapacity;
|
||||
}
|
||||
void enableShadowMap();
|
||||
virtual void enableBlend(bool blend)
|
||||
{
|
||||
m_enableBlend = blend;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -52,5 +52,5 @@ void main(void)
|
||||
if (visibility<0.6)
|
||||
visibility=0.6f;
|
||||
|
||||
color = vec4(ct * visibility, 1.f);//at * af);
|
||||
color = vec4(ct * visibility, fragment.color.w);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,6 @@ static const char* useShadowMapInstancingFragmentShader= \
|
||||
" if (visibility<0.6)\n"
|
||||
" visibility=0.6f;\n"
|
||||
" \n"
|
||||
" color = vec4(ct * visibility, 1.f);//at * af); \n"
|
||||
" color = vec4(ct * visibility, fragment.color.w);\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user