diff --git a/data/teddy_large.urdf b/data/teddy_large.urdf
new file mode 100644
index 000000000..3be8c547b
--- /dev/null
+++ b/data/teddy_large.urdf
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/teddy_vhacd.urdf b/data/teddy_vhacd.urdf
index dd6cb2c40..ca99c9851 100644
--- a/data/teddy_vhacd.urdf
+++ b/data/teddy_vhacd.urdf
@@ -29,4 +29,3 @@
-
diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp
index 1ff4b8fdf..cf7553172 100644
--- a/examples/OpenGLWindow/GLInstancingRenderer.cpp
+++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp
@@ -17,7 +17,6 @@ subject to the following restrictions:
///todo: make this configurable in the gui
bool useShadowMap = true;// true;//false;//true;
-float projectiveTextureViewSize = 10;
bool useProjectiveTexture = false;
int shadowMapWidth= 4096;
int shadowMapHeight= 4096;
@@ -228,9 +227,6 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
b3Vector3 m_lightPos;
b3Vector3 m_lightSpecularIntensity;
-
- b3Vector3 m_projectorPos;
- b3Vector3 m_projectorDir;
GLuint m_defaultTexturehandle;
b3AlignedObjectArray m_textureHandles;
@@ -252,8 +248,6 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
{
m_lightPos=b3MakeVector3(-50,30,40);
m_lightSpecularIntensity.setValue(1,1,1);
-
- m_projectorPos=b3MakeVector3(-50,30,40);
//clear to zero to make it obvious if the matrix is used uninitialized
for (int i=0;i<16;i++)
@@ -336,7 +330,7 @@ static GLint projectiveTexture_cameraPositionIn = 0;
static GLint projectiveTexture_materialShininessIn = 0;
static GLint projectiveTexture_ProjectionMatrix=0;
-static GLint projectiveTexture_DepthBiasModelViewMatrix=0;
+static GLint projectiveTexture_TextureMVP=0;
static GLint projectiveTexture_uniform_texture_diffuse = 0;
static GLint projectiveTexture_shadowMap = 0;
@@ -1241,7 +1235,7 @@ void GLInstancingRenderer::InitShaders()
projectiveTexture_materialSpecularColor = glGetUniformLocation(projectiveTextureInstancingShader, "materialSpecularColorIn");
projectiveTexture_MVP = glGetUniformLocation(projectiveTextureInstancingShader, "MVP");
projectiveTexture_ProjectionMatrix = glGetUniformLocation(projectiveTextureInstancingShader, "ProjectionMatrix");
- projectiveTexture_DepthBiasModelViewMatrix = glGetUniformLocation(projectiveTextureInstancingShader, "DepthBiasModelViewProjectionMatrix");
+ projectiveTexture_TextureMVP = glGetUniformLocation(projectiveTextureInstancingShader, "TextureMVP");
projectiveTexture_uniform_texture_diffuse = glGetUniformLocation(projectiveTextureInstancingShader, "Diffuse");
projectiveTexture_shadowMap = glGetUniformLocation(projectiveTextureInstancingShader,"shadowMap");
projectiveTexture_lightPosIn = glGetUniformLocation(projectiveTextureInstancingShader,"lightPosIn");
@@ -2168,17 +2162,9 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
GLfloat depthBiasMVP[4][4];
b3Matrix4x4Mul(biasMatrix,depthMVP,depthBiasMVP);
- // Compute projection matrix for texture projector
- float textureViewMatrix[4][4];
- b3Vector3 projectorDir = m_data->m_projectorDir.normalize();
- float projectorDist = 0;
- b3CreateLookAt(m_data->m_projectorPos,center,up, &textureViewMatrix[0][0]);
- GLfloat textureModelMatrix[4][4];
- b3CreateDiagonalMatrix(1.f, textureModelMatrix);
- b3Matrix4x4Mul(textureViewMatrix, textureModelMatrix, textureModelViewMatrix);
- b3CreateOrtho(-projectiveTextureViewSize,projectiveTextureViewSize,-projectiveTextureViewSize,projectiveTextureViewSize,1,300,textureProjectionMatrix);
- GLfloat textureMVP[4][4];
- b3Matrix4x4Mul(textureProjectionMatrix, textureModelViewMatrix, textureMVP);
+ // TODO: Expose the projective texture matrix setup. Temporarily set it to be the same as camera view projection matrix.
+ GLfloat textureMVP[16];
+ b3Matrix4x4Mul16(m_data->m_projectionMatrix,m_data->m_viewMatrix,textureMVP);
//float m_frustumZNear=0.1;
//float m_frustumZFar=100.f;
@@ -2576,10 +2562,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
glUniform3f(projectiveTexture_cameraPositionIn,camPos[0],camPos[1],camPos[2]);
glUniform1f(projectiveTexture_materialShininessIn,gfxObj->m_materialShinyNess);
- glUniformMatrix4fv(projectiveTexture_DepthBiasModelViewMatrix, 1, false, &textureMVP[0][0]);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture);
- glUniform1i(projectiveTexture_shadowMap,1);
+ glUniformMatrix4fv(projectiveTexture_TextureMVP, 1, false, &textureMVP[0]);
//sort transparent objects
if ( gfxObj->m_flags&eGfxTransparency)
@@ -2600,8 +2583,6 @@ b3Assert(glGetError() ==GL_NO_ERROR);
glDisable (GL_BLEND);
glDepthMask(true);
}
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D,0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,0);
diff --git a/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.glsl b/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.glsl
index 01d73c2d4..c3417ed55 100644
--- a/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.glsl
+++ b/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.glsl
@@ -11,7 +11,7 @@ layout (location = 5) in vec4 instance_color;
layout (location = 6) in vec3 instance_scale;
-uniform mat4 DepthBiasModelViewProjectionMatrix;
+uniform mat4 TextureMVP;
uniform mat4 MVP;
uniform vec3 lightPosIn;
uniform vec3 cameraPositionIn;
@@ -93,7 +93,7 @@ void main(void)
gl_Position = vertexLoc;
fragment.color = instance_color;
- vec4 projcoords = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);
- vert.texcoord = projcoords.xy;
+ vec4 projcoords = TextureMVP * vec4((instance_position+localcoord).xyz,1);
+ vert.texcoord = projcoords.xy/projcoords.z;
}
diff --git a/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.h b/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.h
index 3f929e44b..b1de7880d 100644
--- a/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.h
+++ b/examples/OpenGLWindow/Shaders/projectiveTextureInstancingVS.h
@@ -9,7 +9,7 @@ static const char* projectiveTextureInstancingVertexShader= \
"layout (location = 4) in vec3 vertexnormal;\n"
"layout (location = 5) in vec4 instance_color;\n"
"layout (location = 6) in vec3 instance_scale;\n"
-"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
+"uniform mat4 TextureMVP;\n"
"uniform mat4 MVP;\n"
"uniform vec3 lightPosIn;\n"
"uniform vec3 cameraPositionIn;\n"
@@ -80,7 +80,7 @@ static const char* projectiveTextureInstancingVertexShader= \
" vec4 vertexLoc = MVP* vec4((instance_position+localcoord).xyz,1);\n"
" gl_Position = vertexLoc;\n"
" fragment.color = instance_color;\n"
-" vec4 projcoords = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);\n"
-" vert.texcoord = projcoords.xy;\n"
+" vec4 projcoords = TextureMVP * vec4((instance_position+localcoord).xyz,1);\n"
+" vert.texcoord = projcoords.xy/projcoords.z;\n"
"}\n"
;
diff --git a/examples/pybullet/examples/projective_texture.py b/examples/pybullet/examples/projective_texture.py
index d339bf5a0..576a7a095 100644
--- a/examples/pybullet/examples/projective_texture.py
+++ b/examples/pybullet/examples/projective_texture.py
@@ -6,34 +6,17 @@ import numpy as np
physicsClient = p.connect(p.GUI)
-p.setGravity(0,0,-10)
-planeId = p.loadURDF("plane.urdf")
-cubeStartPos = [0,0,1]
-cubeStartOrientation = p.getQuaternionFromEuler([0,0,0])
-boxId = p.loadURDF("cube.urdf",cubeStartPos, cubeStartOrientation)
-cubePos, cubeOrn = p.getBasePositionAndOrientation(boxId)
-textureId = p.loadTexture("checker_blue.png")
+p.setGravity(0,0,0)
+bearStartPos1 = [-3.3,0,0]
+bearStartOrientation1 = p.getQuaternionFromEuler([0,0,0])
+bearId1 = p.loadURDF("teddy_large.urdf", bearStartPos1, bearStartOrientation1)
+bearStartPos2 = [0,0,0]
+bearStartOrientation2 = p.getQuaternionFromEuler([0,0,0])
+bearId2 = p.loadURDF("teddy_large.urdf",bearStartPos2, bearStartOrientation2)
+textureId = p.loadTexture("checker_grid.jpg")
p.changeVisualShape(objectUniqueId=0, linkIndex=-1, textureUniqueId=textureId)
p.changeVisualShape(objectUniqueId=1, linkIndex=-1, textureUniqueId=textureId)
-fov = 70
-pixelWidth = 640
-pixelHeight = 512
-aspect = pixelWidth / pixelHeight;
-nearPlane = 0.01
-farPlane = 100
-projectionMatrix = p.computeProjectionMatrixFOV(fov, aspect, nearPlane, farPlane);
-viewMatrixLeft = p.computeViewMatrix(cameraEyePosition=[0.045, 3.0, 3.0], cameraTargetPosition=[0.045,0,0], cameraUpVector=[0,0,1])
-viewMatrixRight = p.computeViewMatrix(cameraEyePosition=[-0.045, 3.0, 3.0], cameraTargetPosition=[-0.045,0,0], cameraUpVector=[0,0,1])
-leftImage = p.getCameraImage(width=640,height=512,viewMatrix=viewMatrixLeft,projectionMatrix=projectionMatrix,renderer=p.ER_BULLET_HARDWARE_OPENGL)
-rightImage = p.getCameraImage(width=640,height=512,viewMatrix=viewMatrixRight,projectionMatrix=projectionMatrix,renderer=p.ER_BULLET_HARDWARE_OPENGL)
-
-left_img = np.reshape(np.asarray(leftImage[2], dtype=np.float32), (512, 640, 4))
-left_img /= 255
-plt.imsave("left_image.png", left_img)
-right_img = np.reshape(np.asarray(rightImage[2], dtype=np.float32), (512, 640, 4))
-right_img /= 255
-plt.imsave("right_image.png", right_img)
useRealTimeSimulation = 1
@@ -42,7 +25,7 @@ if (useRealTimeSimulation):
while 1:
if (useRealTimeSimulation):
- p.setGravity(0,0,-10)
+ p.setGravity(0,0,0)
sleep(0.01) # Time in seconds.
else:
p.stepSimulation()