add alpha blendering option (disabled by default) using w component of color

add low-level support function demo (test)
This commit is contained in:
Erwin Coumans
2014-10-15 18:05:11 -07:00
parent ce0ad64475
commit eda1ff77db
8 changed files with 147 additions and 10 deletions

View File

@@ -20,6 +20,7 @@
#include "../ImportSTLDemo/ImportSTLSetup.h"
#include "../../Demos/SerializeDemo/SerializeSetup.h"
#include "../bullet2/MultiBodyDemo/TestJointTorqueSetup.h"
#include "../bullet2/CollisionDetection/SupportFuncDemo.h"
static BulletDemoInterface* TestJointTorqueCreateFunc(CommonGraphicsApp* app)
{
@@ -72,6 +73,8 @@ static BulletDemoInterface* MyImportSTLCreateFunc(CommonGraphicsApp* app)
}
struct BulletDemoEntry
{
int m_menuLevel;
@@ -83,9 +86,13 @@ struct BulletDemoEntry
static BulletDemoEntry allDemos[]=
{
{0,"LowLevel",0},
{1,"SupportFunc", &MySupportFuncDemo::CreateFunc},
//{"emptydemo",EmptyBulletDemo::MyCreateFunc},
{0,"API Demos", 0},
{1,"BasicDemo",BasicDemo::MyCreateFunc},
{ 1, "CcdDemo", MyCcdPhysicsDemoCreateFunc },
{ 1, "Kinematic", MyKinematicObjectCreateFunc },

View File

@@ -0,0 +1,112 @@
#ifndef SUPPORT_FUNC_DEMO_H
#define SUPPORT_FUNC_DEMO_H
#include "Bullet3AppSupport/BulletDemoInterface.h"
#include "OpenGLWindow/CommonGraphicsApp.h"
#include "BulletCollision/CollisionShapes/btSphereShape.h"
class MySupportFuncDemo : public BulletDemoInterface
{
CommonGraphicsApp* m_app;
btSphereShape* m_sphere;
float m_x;
float m_y;
public:
MySupportFuncDemo(CommonGraphicsApp* app)
:m_app(app),
m_x(0),
m_y(0)
{
m_sphere = new btSphereShape(1);
{
int boxId = m_app->registerCubeShape(10,0.1,10);
btVector3 pos(0,-2,0);
btQuaternion orn(0,0,0,1);
btVector4 color(0.3,0.3,0.3,1);
btVector3 scaling(1,1,1);
m_app->m_renderer->registerGraphicsInstance(boxId,pos,orn,color,scaling);
}
{
int sphereId = m_app->registerGraphicsSphereShape(1,false,0,0);
btVector3 pos(0,0,0);
btQuaternion orn(0,0,0,1);
btVector4 color(0,1,0,0.6);
btVector3 scaling(1,1,1);
m_app->m_renderer->registerGraphicsInstance(sphereId,pos,orn,color,scaling);
}
m_app->m_renderer->writeTransforms();
m_app->m_renderer->enableBlend(true);
}
virtual ~MySupportFuncDemo()
{
m_app->m_renderer->enableBlend(false);
delete m_sphere;
}
static BulletDemoInterface* CreateFunc(CommonGraphicsApp* app)
{
return new MySupportFuncDemo(app);
}
virtual void initPhysics()
{
}
virtual void exitPhysics()
{
}
virtual void stepSimulation(float deltaTime)
{
m_x+=0.01f;
m_y+=0.02f;
}
virtual void renderScene()
{
m_app->m_renderer->renderScene();
}
virtual void physicsDebugDraw()
{
int width=3;
btVector3 from(0,0,0);
btVector3 to(10.*btSin(m_x),10.*btCos(m_x),10.*btSin(m_y));
{
btVector3 color(1,0,0);
m_app->m_renderer->drawLine(from,to,color,width);
}
btVector3 dir(to-from);
btVector3 sup = m_sphere->btConvexInternalShape::localGetSupportingVertex(dir);
btVector3 orth0,orth1;
btPlaneSpace1(dir,orth0,orth1);
btVector3 color(0,0,1);
orth0.normalize();
orth1.normalize();
m_app->m_renderer->drawLine(sup,sup+orth0*0.4,color,3);
m_app->m_renderer->drawLine(sup,sup+orth1*0.4,color,3);
}
virtual bool mouseMoveCallback(float x,float y)
{
}
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
}
virtual bool keyboardCallback(int key, int state)
{
}
};
#endif //SUPPORT_FUNC_DEMO

View File

@@ -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;
};

View File

@@ -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

View File

@@ -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:
{

View File

@@ -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;
}
};

View File

@@ -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);
}

View File

@@ -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"
;