Add torus shadow render example.
This commit is contained in:
@@ -154,6 +154,7 @@ TinyRendererSetup::TinyRendererSetup(struct GUIHelperInterface* gui)
|
||||
|
||||
const char* fileName = "textured_sphere_smooth.obj";
|
||||
fileName = "cube.obj";
|
||||
fileName = "torus/torus_with_plane.obj";
|
||||
|
||||
{
|
||||
|
||||
@@ -342,7 +343,44 @@ void TinyRendererSetup::stepSimulation(float deltaTime)
|
||||
render->getActiveCamera()->getCameraViewMatrix(viewMat);
|
||||
render->getActiveCamera()->getCameraProjectionMatrix(projMat);
|
||||
|
||||
|
||||
for (int o=0;o<this->m_internalData->m_renderObjects.size();o++)
|
||||
{
|
||||
|
||||
const btTransform& tr = m_internalData->m_transforms[o];
|
||||
tr.getOpenGLMatrix(modelMat2);
|
||||
|
||||
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
m_internalData->m_renderObjects[o]->m_modelMatrix[i][j] = float(modelMat2[i+4*j]);
|
||||
m_internalData->m_renderObjects[o]->m_viewMatrix[i][j] = viewMat[i+4*j];
|
||||
m_internalData->m_renderObjects[o]->m_projectionMatrix[i][j] = projMat[i+4*j];
|
||||
|
||||
btVector3 lightDirWorld;
|
||||
switch (m_app->getUpAxis())
|
||||
{
|
||||
case 1:
|
||||
lightDirWorld = btVector3(-50.f,100,30);
|
||||
break;
|
||||
case 2:
|
||||
lightDirWorld = btVector3(-50.f,30,100);
|
||||
break;
|
||||
default:{}
|
||||
};
|
||||
|
||||
m_internalData->m_renderObjects[o]->m_lightDirWorld = lightDirWorld.normalized();
|
||||
|
||||
btVector3 lightColor(1.0,1.0,1.0);
|
||||
m_internalData->m_renderObjects[o]->m_lightColor = lightColor;
|
||||
|
||||
m_internalData->m_renderObjects[o]->m_lightDistance = 10.0;
|
||||
|
||||
}
|
||||
}
|
||||
TinyRenderer::renderObjectDepth(*m_internalData->m_renderObjects[o]);
|
||||
}
|
||||
|
||||
for (int o=0;o<this->m_internalData->m_renderObjects.size();o++)
|
||||
{
|
||||
@@ -375,6 +413,8 @@ void TinyRendererSetup::stepSimulation(float deltaTime)
|
||||
|
||||
btVector3 lightColor(1.0,1.0,1.0);
|
||||
m_internalData->m_renderObjects[o]->m_lightColor = lightColor;
|
||||
|
||||
m_internalData->m_renderObjects[o]->m_lightDistance = 10.0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,6 @@ IShader::~IShader() {}
|
||||
|
||||
Matrix viewport(int x, int y, int w, int h)
|
||||
{
|
||||
/*
|
||||
Matrix Viewport;
|
||||
Viewport = Matrix::identity();
|
||||
Viewport[0][3] = x+w/2.f;
|
||||
Viewport[1][3] = y+h/2.f;
|
||||
Viewport[2][3] = 1.f;
|
||||
Viewport[0][0] = w/2.f;
|
||||
Viewport[1][1] = h/2.f;
|
||||
Viewport[2][2] = 0;
|
||||
return Viewport;
|
||||
*/
|
||||
|
||||
Matrix Viewport;
|
||||
Viewport = Matrix::identity();
|
||||
Viewport[0][3] = x+w/2.f;
|
||||
@@ -29,7 +17,6 @@ Matrix viewport(int x, int y, int w, int h)
|
||||
Viewport[1][1] = h/2.f;
|
||||
Viewport[2][2] = .5f;
|
||||
return Viewport;
|
||||
|
||||
}
|
||||
|
||||
Matrix projection(float coeff) {
|
||||
@@ -40,23 +27,6 @@ Matrix projection(float coeff) {
|
||||
}
|
||||
|
||||
Matrix lookat(Vec3f eye, Vec3f center, Vec3f up) {
|
||||
/*
|
||||
Vec3f z = (eye-center).normalize();
|
||||
Vec3f x = cross(up,z).normalize();
|
||||
Vec3f y = cross(z,x).normalize();
|
||||
Matrix Minv = Matrix::identity();
|
||||
Matrix Tr = Matrix::identity();
|
||||
for (int i=0; i<3; i++) {
|
||||
Minv[0][i] = x[i];
|
||||
Minv[1][i] = y[i];
|
||||
Minv[2][i] = z[i];
|
||||
Tr[i][3] = -center[i];
|
||||
}
|
||||
Matrix ModelView;
|
||||
ModelView = Minv*Tr;
|
||||
return ModelView;
|
||||
*/
|
||||
|
||||
Vec3f f = (center - eye).normalize();
|
||||
Vec3f u = up.normalize();
|
||||
Vec3f s = cross(f,u).normalize();
|
||||
@@ -85,7 +55,6 @@ Matrix lookat(Vec3f eye, Vec3f center, Vec3f up) {
|
||||
ModelView[3][3] = 1.f;
|
||||
|
||||
return ModelView;
|
||||
|
||||
}
|
||||
|
||||
Vec3f barycentric(Vec2f A, Vec2f B, Vec2f C, Vec2f P) {
|
||||
@@ -113,7 +82,6 @@ void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zb
|
||||
if (pts[0][3]<0 || pts[1][3] <0 || pts[2][3] <0)
|
||||
return;
|
||||
|
||||
|
||||
mat<3,2,float> pts2;
|
||||
for (int i=0; i<3; i++) pts2[i] = proj<2>(pts[i]/pts[i][3]);
|
||||
|
||||
@@ -128,15 +96,11 @@ void triangle(mat<4,3,float> &clipc, IShader &shader, TGAImage &image, float *zb
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vec2i P;
|
||||
TGAColor color;
|
||||
for (P.x=bboxmin.x; P.x<=bboxmax.x; P.x++) {
|
||||
for (P.y=bboxmin.y; P.y<=bboxmax.y; P.y++) {
|
||||
Vec3f bc_screen = barycentric(pts2[0], pts2[1], pts2[2], P);
|
||||
|
||||
|
||||
Vec3f bc_clip = Vec3f(bc_screen.x/pts[0][3], bc_screen.y/pts[1][3], bc_screen.z/pts[2][3]);
|
||||
bc_clip = bc_clip/(bc_clip.x+bc_clip.y+bc_clip.z);
|
||||
float frag_depth = -1*(clipc[2]*bc_clip);
|
||||
|
||||
Reference in New Issue
Block a user