mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
beginning of .vb reader test
class preparation for testing
This commit is contained in:
@@ -47,48 +47,41 @@ namespace vb01{
|
||||
glDrawBuffer(GL_NONE);
|
||||
glReadBuffer(GL_NONE);
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
cout << "Not complete\n";
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void Light::update(){
|
||||
Root *root = Root::getSingleton();
|
||||
Node *rootNode = root->getRootNode();
|
||||
vector<Node*> descendants;
|
||||
vector<Light*> lights;
|
||||
rootNode->getDescendants(descendants);
|
||||
descendants.push_back(rootNode);
|
||||
std::vector<Material*> materials;
|
||||
Camera *cam=root->getCamera();
|
||||
|
||||
int thisId = -1;
|
||||
Camera *cam=root->getCamera();
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight();
|
||||
|
||||
vector<Node*> descendants;
|
||||
rootNode->getDescendants(descendants);
|
||||
descendants.push_back(rootNode);
|
||||
vector<Light*> lights;
|
||||
vector<Material*> materials;
|
||||
for(Node *d : descendants){
|
||||
for(Light *l : d->getLights())
|
||||
lights.push_back(l);
|
||||
for(Mesh *m : d->getMeshes())
|
||||
materials.push_back(m->getMaterial());
|
||||
}
|
||||
|
||||
int thisId = -1;
|
||||
for(int i = 0; i < lights.size(); i++)
|
||||
if(lights[i] == this)
|
||||
thisId = i;
|
||||
mat4 proj = mat4(1.), view = mat4(1.);
|
||||
|
||||
mat4 proj = mat4(1.), view = mat4(1.);
|
||||
renderShadow(descendants, proj, view);
|
||||
updateShader(materials, thisId, proj, view);
|
||||
|
||||
}
|
||||
|
||||
void Light::renderShadow(std::vector<Node*> descendants, mat4 &proj, mat4 &view){
|
||||
vec3 dirs[]{
|
||||
vec3(1, 0, 0),
|
||||
vec3(-1, 0, 0),
|
||||
vec3(0, 1, 0),
|
||||
vec3(0, -1, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, -1)
|
||||
};
|
||||
Root *root = Root::getSingleton();
|
||||
|
||||
glViewport(0, 0, depthMapSize, depthMapSize);
|
||||
@@ -106,48 +99,49 @@ namespace vb01{
|
||||
|
||||
if(rotAxis == Vector3::VEC_ZERO)
|
||||
rotAxis = Vector3::VEC_I;
|
||||
mat4 model = translate(mat4(1.f), vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, rot.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
|
||||
Vector3 upDir = direction.cross(Vector3(0, 1, 0));
|
||||
if(upDir == Vector3::VEC_ZERO)
|
||||
upDir=Vector3::VEC_I;
|
||||
|
||||
vec3 dir = vec3(direction.x, direction.y, direction.z);
|
||||
vec3 up = vec3(upDir.x, upDir.y, upDir.z);
|
||||
vec3 p;
|
||||
vec3 lightPos, dir = vec3(direction.x, direction.y, direction.z);
|
||||
if(type == DIRECTIONAL){
|
||||
p = vec3(pos.x, pos.y, pos.z) - .5f * farPlane * dir;
|
||||
lightPos = vec3(pos.x, pos.y, pos.z) - .5f * farPlane * dir;
|
||||
float orthoCorner = 10.f;
|
||||
proj = ortho(-orthoCorner, orthoCorner, -orthoCorner, orthoCorner, nearPlane, farPlane);
|
||||
}
|
||||
else{
|
||||
p = vec3(position.x, position.y, position.z);
|
||||
lightPos = vec3(position.x, position.y, position.z);
|
||||
proj = perspective(radians(90.f), 1.f, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
view = lookAt(p, p + dir, up);
|
||||
|
||||
mat4 model = translate(mat4(1.f), vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, rot.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
Vector3 upDir = direction.cross(Vector3(0, 1, 0));
|
||||
if(upDir == Vector3::VEC_ZERO)
|
||||
upDir = Vector3::VEC_I;
|
||||
vec3 up = vec3(upDir.x, upDir.y, upDir.z);
|
||||
view = lookAt(lightPos, lightPos + dir, up);
|
||||
|
||||
depthMapShader->use();
|
||||
depthMapShader->setBool(type == POINT, "point");
|
||||
depthMapShader->setMat4(model, "model");
|
||||
|
||||
depthMapShader->setFloat(farPlane, "farPlane");
|
||||
depthMapShader->setVec3(position, "lightPos");
|
||||
if(type == POINT){
|
||||
depthMapShader->setFloat(farPlane, "farPlane");
|
||||
depthMapShader->setVec3(position, "lightPos");
|
||||
for(int j = 0; j < 6; j++){
|
||||
vec3 v;
|
||||
if(1 < j && j < 4)
|
||||
v = vec3(0, 0, -1);
|
||||
for(int i = 0; i < 6; i++){
|
||||
vec3 upVec;
|
||||
if(1 < i && i < 4)
|
||||
upVec = vec3(0, 0, -1);
|
||||
else
|
||||
v = vec3(0, -1, 0);
|
||||
upVec = vec3(0, -1, 0);
|
||||
|
||||
depthMapShader->setMat4(proj * lookAt(p, p + dirs[j], v), "shadowMat[" + to_string(j) + "]");
|
||||
vec3 dirs[] = {
|
||||
vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)
|
||||
};
|
||||
|
||||
depthMapShader->setMat4(proj * lookAt(lightPos, lightPos + dirs[i], upVec), "shadowMat[" + to_string(i) + "]");
|
||||
}
|
||||
}
|
||||
else
|
||||
depthMapShader->setMat4(proj * view, "lightMat");
|
||||
|
||||
mesh->render();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user