3 types of lights

supported number of n lights
This commit is contained in:
devZoGok
2021-10-18 19:03:19 +03:00
parent 0083f9e5b8
commit aebc069053
16 changed files with 350 additions and 23 deletions
+2
View File
@@ -4,6 +4,7 @@ project(vb01)
include_directories(/usr/include/GLFW)
include_directories(/usr/include/glm)
include_directories(/usr/include/glad)
include_directories(/usr/include/assimp)
set(CMAKE_BUILD_TYPE Debug)
set(math quaternion.cpp vector.cpp)
@@ -13,3 +14,4 @@ link_directories(/usr/lib)
add_executable(vb01 main.cpp ${math} ${render})
target_link_libraries(vb01 glfw)
target_link_libraries(vb01 glad)
target_link_libraries(vb01 assimp)
+66
View File
@@ -0,0 +1,66 @@
#include"light.h"
#include"node.h"
#include"root.h"
#include"material.h"
#include"mesh.h"
#include<glm/glm.hpp>
using namespace glm;
using namespace std;
namespace vb01{
Light::Light(){
}
Light::~Light(){}
void Light::update(){
Node *rootNode=Root::getSingleton()->getRootNode();
std::vector<Node*> descendants=rootNode->getDescendants();
descendants.push_back(rootNode);
std::vector<Material*> materials;
int numLights=0,thisId=-1;
for(Node *n : descendants){
std::vector<Light*> lights=n->getLights();
if(n->getMesh()){
Material *mat=n->getMesh()->getMaterial();
if(mat&&mat->isLightingEnabled())
materials.push_back(mat);
}
for(Light *l : lights){
if(l){
numLights++;
if(l==this)
thisId=numLights-1;
}
}
}
for(Material *m : materials){
Shader *shader=m->getShader();
shader->use();
shader->setInt((int)type,"light["+to_string(thisId)+"].type");
shader->setVec3(vec3(color.x,color.y,color.z),"light["+to_string(thisId)+"].color");
switch(type){
case POINT:
shader->setVec3(vec3(pos.x,pos.y,pos.z),"light["+to_string(thisId)+"].pos");
shader->setFloat(attenuationValues.x,"light["+to_string(thisId)+"].a");
shader->setFloat(attenuationValues.y,"light["+to_string(thisId)+"].b");
shader->setFloat(attenuationValues.z,"light["+to_string(thisId)+"].c");
break;
case DIRECTIONAL:
shader->setVec3(vec3(direction.x,direction.y,direction.z),"light["+to_string(thisId)+"].direction");
break;
case SPOT:
shader->setVec3(vec3(pos.x,pos.y,pos.z),"light["+to_string(thisId)+"].pos");
shader->setVec3(vec3(direction.x,direction.y,direction.z),"light["+to_string(thisId)+"].direction");
shader->setFloat(attenuationValues.x,"light["+to_string(thisId)+"].a");
shader->setFloat(attenuationValues.y,"light["+to_string(thisId)+"].b");
shader->setFloat(attenuationValues.z,"light["+to_string(thisId)+"].c");
shader->setFloat(innerAngle,"light["+to_string(thisId)+"].innerAngle");
shader->setFloat(outerAngle,"light["+to_string(thisId)+"].outerAngle");
break;
}
}
}
}
+23
View File
@@ -1,7 +1,11 @@
#ifndef LIGHT_H
#define LIGHT_H
#include"vector.h"
namespace vb01{
class Node;
class Light{
public:
enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};
@@ -9,8 +13,27 @@ namespace vb01{
Light();
~Light();
void update();
inline void setNode(Node *node){this->node=node;}
inline void setPosition(Vector3 pos){this->pos=pos;}
inline void setColor(Vector3 color){this->color=color;}
inline void setDirection(Vector3 dir){this->direction=dir;}
inline void setAttenuationValues(float a, float b, float c){
attenuationValues.x=a;
attenuationValues.y=b;
attenuationValues.z=c;
}
inline void setType(Type t){this->type=t;}
inline void setInnerAngle(float innerAngle){this->innerAngle=innerAngle;}
inline void setOuterAngle(float outerAngle){this->outerAngle=outerAngle;}
inline Vector3 getDirection(){return direction;}
inline Vector3 getAttenuationValues(){return attenuationValues;}
inline float getInnerAngle(){return innerAngle;}
inline float getOuterAngle(){return outerAngle;}
private:
Type type;
Node *node=nullptr;
Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;
float innerAngle=.707,outerAngle=.714;
};
}
+25 -8
View File
@@ -3,6 +3,8 @@
#include"node.h"
#include"quad.h"
#include"material.h"
#include"light.h"
#include<glm.hpp>
using namespace vb01;
using namespace std;
@@ -11,14 +13,29 @@ int main(){
Root *root=Root::getSingleton();
root->start(800,600);
Quad *q=new Quad(Vector3(.5,.5,.5));
Node *node=new Node(Vector3(0,0,2));
node->setObject(q);
Material *mat=new Material();
mat->setDiffuseMap("/home/dominykas/c++/FSim/woodChips.jpg");
mat->setLightingEnabled(true);
q->setMaterial(mat);
root->getRootNode()->attachChild(node);
Vector3 v1[]={Vector3(2,2,.5),Vector3(.5,.5,.5)};
Vector3 v2[]={Vector3(-.0,0,2),Vector3(.5,0,-2)};
for(int i=0;i<1;i++){
Quad *q=new Quad(v1[i]);
Node *node=new Node(v2[i]);
node->setObject(q);
Material *mat=new Material();
mat->setDiffuseMap("/home/dominykas/c++/FSim/woodChips.jpg");
mat->setLightingEnabled(true);
q->setMaterial(mat);
root->getRootNode()->attachChild(node);
}
Camera *cam=Root::getSingleton()->getCamera();
cam->setPosition(Vector3(0,0,-4));
Light *l1=new Light();
l1->setPosition(Vector3(-.5,.1,0));
l1->setColor(Vector3(0,1,0));
l1->setAttenuationValues(.07,.14,1);
l1->setDirection(Vector3(0,-1,0));
l1->setInnerAngle(glm::radians(40.));
l1->setOuterAngle(glm::radians(60.));
l1->setType(Light::POINT);
root->getRootNode()->addLight(l1);
while(true)
root->update();
return 0;
+1 -1
View File
@@ -15,7 +15,7 @@ namespace vb01{
void setSpecularMap(std::string specularMap){this->specularMap=new Texture(specularMap);}
inline void setLightingEnabled(bool lighting){this->lightingEnabled=lighting;}
inline Shader* getShader(){return shader;}
inline bool isLighting(){return lightingEnabled;}
inline bool isLightingEnabled(){return lightingEnabled;}
private:
bool lightingEnabled=false;
Texture *diffuseMap=nullptr,*normalMap=nullptr,*specularMap=nullptr;
+13 -1
View File
@@ -4,12 +4,23 @@
#include<glfw3.h>
#include<glm.hpp>
#include<ext.hpp>
#include<Importer.hpp>
#include<postprocess.h>
#include<iostream>
#include<cstdlib>
using namespace std;
using namespace glm;
using namespace Assimp;
namespace vb01{
Mesh::Mesh(string path){
Importer importer;
const aiScene *scene=importer.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
if(!scene||scene->mFlags&AI_SCENE_FLAGS_INCOMPLETE||!scene->mRootNode){
cout<<"Failed to load model\n";
exit(-1);
}
construct();
}
@@ -48,12 +59,13 @@ namespace vb01{
Vector3 dir=cam->getDirection(),up=cam->getUp(),camPos=cam->getPosition();
mat4 model=translate(mat4(1.),vec3(pos.x,pos.y,pos.z));
model=rotate(model,45.f,vec3(1,0,0));
model=rotate(model,38.f,vec3(1,0,0));
mat4 view=lookAt(vec3(camPos.x,camPos.y,camPos.z),vec3(camPos.x+dir.x,camPos.y+dir.y,camPos.z+dir.z),vec3(up.x,up.y,up.z));
mat4 proj=perspective(radians(fov),width/height,nearPlane,farPlane);
//proj=ortho(0.f,800.f,0.f,-600.f,nearPlane,farPlane);
material->update();
material->getShader()->setVec3(vec3(camPos.x,camPos.y,camPos.z),"camPos");
material->getShader()->setMat4(model,"model");
material->getShader()->setMat4(view,"view");
material->getShader()->setMat4(proj,"proj");
+5
View File
@@ -5,6 +5,8 @@
#include<vector>
#include<string>
#include"material.h"
#include<scene.h>
namespace vb01{
class Node;
@@ -28,8 +30,11 @@ namespace vb01{
void setMaterial(Material *mat){this->material=mat;}
inline void setNode(Node *node){this->node=node;}
inline Node* getNode(){return node;}
inline Material* getMaterial(){return material;}
private:
Material *material=nullptr;
void processNode(aiNode*,const aiScene*);
void processMesh(aiMesh*, const aiScene*);
};
}
+28
View File
@@ -1,5 +1,9 @@
#include"root.h"
#include"node.h"
#include"mesh.h"
#include"light.h"
using namespace std;
namespace vb01{
Node::Node(Vector3 pos){
@@ -11,16 +15,40 @@ namespace vb01{
void Node::update(){
if(mesh)
mesh->update();
for(Light *l : lights)
l->update();
for(Node *c : children)
c->update();
}
void Node::attachChild(Node *child){
Node *parent=getParent();
while(parent){
parent->getDescendants().push_back(child);
parent=parent->getParent();
}
children.push_back(child);
descendants.push_back(child);
}
void Node::setObject(Mesh *mesh){
this->mesh=mesh;
mesh->setNode(this);
}
void Node::addLight(Light *light){
lights.push_back(light);
light->setNode(this);
Node *rootNode=Root::getSingleton()->getRootNode();
vector<Node*> descendants=rootNode->getDescendants();
descendants.push_back(rootNode);
int numLights=0;
for(Node *n : descendants)
numLights+=n->getNumLights();
for(Node *n : descendants)
if(n->getMesh())
if(n->getMesh()->getMaterial())
n->getMesh()->getMaterial()->getShader()->setNumLights(numLights>0?numLights:1);
}
}
+9 -1
View File
@@ -7,6 +7,7 @@
namespace vb01{
class Mesh;
class Light;
class Node{
public:
@@ -15,12 +16,19 @@ namespace vb01{
void setObject(Mesh*);
void update();
void attachChild(Node*);
void addLight(Light*);
inline Mesh* getMesh(){return mesh;}
inline Node* getParent(){return parent;}
inline Vector3 getPosition(){return pos;}
inline std::vector<Node*>& getDescendants(){return descendants;}
inline std::vector<Light*>& getLights(){return lights;}
inline Light* getLight(int i){return lights[i];}
inline int getNumLights(){return lights.size();}
private:
Vector3 pos;
Mesh *mesh=nullptr;
std::vector<Node*> children;
std::vector<Node*> children,descendants;
std::vector<Light*> lights;
Node *parent=nullptr;
};
}
+6 -6
View File
@@ -4,27 +4,27 @@ namespace vb01{
Quad::Quad(Vector3 size) : Mesh(){
Vertex v1,v2,v3,v4,v5,v6;
v1.pos=Vector3(size.x/2,size.y/2,0);
v1.norm=Vector3(0,0,1);
v1.norm=Vector3(0,0,-1);
v1.texCoords=Vector2(1,1);
v2.pos=Vector3(-size.x/2,size.y/2,0);
v2.norm=Vector3(0,0,1);
v2.norm=Vector3(0,0,-1);
v2.texCoords=Vector2(0,1);
v3.pos=Vector3(-size.x/2,-size.y/2,0);
v3.norm=Vector3(0,0,1);
v3.norm=Vector3(0,0,-1);
v3.texCoords=Vector2(0,0);
v4.pos=Vector3(-size.x/2,-size.y/2,0);
v4.norm=Vector3(0,0,1);
v4.norm=Vector3(0,0,-1);
v4.texCoords=Vector2(0,0);
v5.pos=Vector3(size.x/2,-size.y/2,0);
v5.norm=Vector3(0,0,1);
v5.norm=Vector3(0,0,-1);
v5.texCoords=Vector2(1,0);
v6.pos=Vector3(size.x/2,size.y/2,0);
v6.norm=Vector3(0,0,1);
v6.norm=Vector3(0,0,-1);
v6.texCoords=Vector2(1,1);
numTris=2;
+2
View File
@@ -40,6 +40,8 @@ namespace vb01{
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_FRONT_AND_BACK);
}
void Root::update(){
+31 -4
View File
@@ -23,11 +23,23 @@ namespace vb01{
vertShaderFile.close();
fragShaderFile.close();
string v=vertShaderStream.str();
string f=fragShaderStream.str();
vString=vertShaderStream.str();
fString=fragShaderStream.str();
setNumLights(1);
}
const char *vertShaderSource=v.c_str();
const char *fragShaderSource=f.c_str();
void Shader::setNumLights(int numLights){
int firstCharId=-1,secondCharId=-1;
for(int i=0;i<fString.length()&&(firstCharId==-1||secondCharId==-1);i++){
if(fString.c_str()[i]=='=')
firstCharId=i;
if(fString.c_str()[i]==';')
secondCharId=i;
}
fString=fString.substr(0,firstCharId+1)+to_string(numLights)+fString.substr(secondCharId,string::npos);
const char *vertShaderSource=vString.c_str();
const char *fragShaderSource=fString.c_str();
unsigned int vert,frag;
vert=glCreateShader(GL_VERTEX_SHADER);
@@ -79,8 +91,23 @@ namespace vb01{
glUniformMatrix4fv(uniformLoc,1,GL_FALSE,value_ptr(mat));
}
void Shader::setFloat(float fl, string var){
int uniformLoc=glGetUniformLocation(id,var.c_str());
glUniform1f(uniformLoc,fl);
}
void Shader::setVec3(vec3 vec, string var){
int uniformLoc=glGetUniformLocation(id,var.c_str());
glUniform3f(uniformLoc,vec.x,vec.y,vec.z);
}
void Shader::setBool(bool b, string var){
int uniformLoc=glGetUniformLocation(id,var.c_str());
glUniform1i(uniformLoc,(int)b);
}
void Shader::setInt(int i, string var){
int uniformLoc=glGetUniformLocation(id,var.c_str());
glUniform1i(uniformLoc,i);
}
}
+5
View File
@@ -8,13 +8,18 @@ namespace vb01{
class Shader{
public:
Shader(std::string,std::string);
void setNumLights(int);
void use();
void setMat4(glm::mat4,std::string);
void setVec3(glm::vec3,std::string);
void setFloat(float,std::string);
void setBool(bool,std::string);
void setInt(int,std::string);
private:
enum ErrorType{VERTEX,FRAGMENT,PROGRAM};
void checkCompileErrors(unsigned int,ErrorType);
unsigned int id;
std::string vString,fString;
};
}
+49 -2
View File
@@ -5,16 +5,21 @@
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 0.0.0 /3fdf28bc/
AMBIENT light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" e enum:vb01::Light::Type
BOX_H box.h /^#define BOX_H$/;" d
Box box.cpp /^ Box::Box(){$/;" f class:vb01::Box
Box box.h /^ class Box : public Mesh{$/;" c namespace:vb01
CAMERA_H camera.h /^#define CAMERA_H$/;" d
Camera camera.cpp /^ Camera::Camera(){$/;" f class:vb01::Camera
Camera camera.h /^ class Camera{$/;" c namespace:vb01
DIRECTIONAL light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" e enum:vb01::Light::Type
EBO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
ErrorType shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" g class:vb01::Shader
FAST_BITS stb_image.h /^#define FAST_BITS /;" d
FRAGMENT shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" e enum:vb01::Shader::ErrorType
LIGHT_H light.h /^#define LIGHT_H$/;" d
Light light.cpp /^ Light::Light(){$/;" f class:vb01::Light
Light light.h /^ class Light{$/;" c namespace:vb01
MATERIAL_H material.h /^#define MATERIAL_H$/;" d
MESH_H mesh.h /^#define MESH_H$/;" d
Material material.cpp /^ Material::Material(){$/;" f class:vb01::Material
@@ -25,6 +30,7 @@ Mesh mesh.h /^ class Mesh{$/;" c namespace:vb01
NODE_H node.h /^#define NODE_H$/;" d
Node node.cpp /^ Node::Node(Vector3 pos){$/;" f class:vb01::Node
Node node.h /^ class Node{$/;" c namespace:vb01
POINT light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" e enum:vb01::Light::Type
PROGRAM shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" e enum:vb01::Shader::ErrorType
QUAD_H quad.h /^#define QUAD_H$/;" d
QUATERNION_H quaternion.h /^#define QUATERNION_H$/;" d
@@ -40,6 +46,7 @@ ROOT_H root.h /^#define ROOT_H$/;" d
Root root.cpp /^ Root::Root(){$/;" f class:vb01::Root
Root root.h /^ class Root{$/;" c namespace:vb01
SHADER_H shader.h /^#define SHADER_H$/;" d
SPOT light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" e enum:vb01::Light::Type
STBIDEF stb_image.h /^#define STBIDEF /;" d
STBI_ASSERT stb_image.h /^#define STBI_ASSERT(/;" d
STBI_EXTERN stb_image.h /^#define STBI_EXTERN /;" d
@@ -100,6 +107,7 @@ Shader shader.h /^ class Shader{$/;" c namespace:vb01
TEXTURE_H texture.h /^#define TEXTURE_H$/;" d
Texture texture.cpp /^ Texture::Texture(string path){$/;" f class:vb01::Texture
Texture texture.h /^ class Texture{$/;" c namespace:vb01
Type light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" g class:vb01::Light
VAO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
VBO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
VECTOR_H vector.h /^#define VECTOR_H$/;" d
@@ -145,9 +153,11 @@ __anon84e4e8861008 stb_image.h /^{$/;" s
__anon84e4e8861108 stb_image.h /^{$/;" s
__anon84e4e8861208 stb_image.h /^{$/;" s
__anon84e4e8861308 stb_image.h /^{$/;" s
addLight node.cpp /^ void Node::addLight(Light *light){$/;" f class:vb01::Node typeref:typename:void
all_a stb_image.h /^ unsigned int mr,mg,mb,ma, all_a;$/;" m struct:__anon84e4e8861008 typeref:typename:unsigned int
app14_color_transform stb_image.h /^ int app14_color_transform; \/\/ Adobe APP14 tag$/;" m struct:__anon84e4e8860808 typeref:typename:int
attachChild node.cpp /^ void Node::attachChild(Node *child){$/;" f class:vb01::Node typeref:typename:void
attenuationValues light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;$/;" m class:vb01::Light typeref:typename:Vector3
background stb_image.h /^ stbi_uc *background; \/\/ The current "background" as far as a gif is concerned$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc *
bgindex stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
bits_per_channel stb_image.h /^ int bits_per_channel;$/;" m struct:__anon84e4e8860508 typeref:typename:int
@@ -158,7 +168,7 @@ camera root.h /^ Camera *camera;$/;" m class:vb01::Root typeref:typename:Camer
channel stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc
channel_order stb_image.h /^ int channel_order;$/;" m struct:__anon84e4e8860508 typeref:typename:int
checkCompileErrors shader.cpp /^ void Shader::checkCompileErrors(unsigned int shader, ErrorType type){$/;" f class:vb01::Shader typeref:typename:void
children node.h /^ std::vector<Node*> children;$/;" m class:vb01::Node typeref:typename:std::vector<Node * >
children node.h /^ std::vector<Node*> children,descendants;$/;" m class:vb01::Node typeref:typename:std::vector<Node * >
code stb_image.h /^ stbi__uint16 code[256];$/;" m struct:__anon84e4e8860708 typeref:typename:stbi__uint16[256]
code_bits stb_image.h /^ int code_bits; \/\/ number of valid bits$/;" m struct:__anon84e4e8860808 typeref:typename:int
code_buffer stb_image.h /^ stbi__uint32 code_buffer; \/\/ jpeg entropy-coded buffer$/;" m struct:__anon84e4e8860808 typeref:typename:stbi__uint32
@@ -167,6 +177,7 @@ codes stb_image.h /^ stbi__gif_lzw codes[8192];$/;" m struct:__anon84e4e886130
coeff stb_image.h /^ short *coeff; \/\/ progressive only$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:short *
coeff_h stb_image.h /^ int coeff_w, coeff_h; \/\/ number of 8x8 coefficient blocks$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
coeff_w stb_image.h /^ int coeff_w, coeff_h; \/\/ number of 8x8 coefficient blocks$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
color light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;$/;" m class:vb01::Light typeref:typename:Vector3
color_table stb_image.h /^ stbi_uc *color_table;$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc *
conj quaternion.h /^ inline vb01::quaternion conj(){return (*this+vb01::quaternion(0,1,0,0)*(*this)*vb01::quaterni/;" f class:vb01::quaternion typeref:typename:vb01::quaternion
construct mesh.cpp /^ void Mesh::construct(){$/;" f class:vb01::Mesh typeref:typename:void
@@ -202,14 +213,17 @@ delay stb_image.h /^ int delay;$/;" m struct:__anon84e4e8861308 typeref:typena
delta stb_image.h /^ int delta[17]; \/\/ old 'firstsymbol' - old 'firstcode'$/;" m struct:__anon84e4e8860708 typeref:typename:int[17]
depth stb_image.h /^ int depth;$/;" m struct:__anon84e4e8860e08 typeref:typename:int
dequant stb_image.h /^ stbi__uint16 dequant[4][64];$/;" m struct:__anon84e4e8860808 typeref:typename:stbi__uint16[4][64]
descendants node.h /^ std::vector<Node*> children,descendants;$/;" m class:vb01::Node typeref:typename:std::vector<Node * >
diffuseMap material.h /^ Texture *diffuseMap=nullptr,*normalMap=nullptr,*specularMap=nullptr;$/;" m class:vb01::Material typeref:typename:Texture *
direction camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3::VEC_K,left=Vector3::VEC_I,up=Vector3::VEC_/;" m class:vb01::Camera typeref:typename:Vector3
direction light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;$/;" m class:vb01::Light typeref:typename:Vector3
dot vector.h /^ float dot(Vector2 v){return x*v.x+y*v.y;}$/;" f struct:vb01::Vector2 typeref:typename:float
dot vector.h /^ float dot(Vector3 v){return x*v.x+y*v.y+z*v.z;}$/;" f struct:vb01::Vector3 typeref:typename:float
eflags stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
eob_run stb_image.h /^ int eob_run;$/;" m struct:__anon84e4e8860808 typeref:typename:int
eof stb_image.h /^ int (*eof) (void *user); \/\/ returns nonzero if we are at end o/;" m struct:__anon84e4e8860208 typeref:typename:int (*)(void * user)
expanded stb_image.h /^ stbi_uc *idata, *expanded, *out;$/;" m struct:__anon84e4e8860e08 typeref:typename:stbi_uc **
fString shader.h /^ std::string vString,fString;$/;" m class:vb01::Shader typeref:typename:std::string
farPlane camera.h /^ float fov=45,nearPlane=.1,farPlane=100;$/;" m class:vb01::Camera typeref:typename:float
fast stb_image.h /^ stbi__uint16 fast[1 << STBI__ZFAST_BITS];$/;" m struct:__anon84e4e8860b08 typeref:typename:stbi__uint16[]
fast stb_image.h /^ stbi_uc fast[1 << FAST_BITS];$/;" m struct:__anon84e4e8860708 typeref:typename:stbi_uc[]
@@ -223,11 +237,15 @@ foo root.cpp /^ void foo(GLFWwindow *window, int width, int height){$/;" f names
fov camera.h /^ float fov=45,nearPlane=.1,farPlane=100;$/;" m class:vb01::Camera typeref:typename:float
getAngleBetween vector.h /^ float getAngleBetween(Vector2 v){return std::acos(dot(v));}$/;" f struct:vb01::Vector2 typeref:typename:float
getAngleBetween vector.h /^ float getAngleBetween(Vector3 v){return std::acos(dot(v));}$/;" f struct:vb01::Vector3 typeref:typename:float
getAttenuationValues light.h /^ inline Vector3 getAttenuationValues(){return attenuationValues;}$/;" f class:vb01::Light typeref:typename:Vector3
getCamera root.h /^ inline Camera* getCamera(){return camera;}$/;" f class:vb01::Root typeref:typename:Camera *
getDescendants node.h /^ inline std::vector<Node*>& getDescendants(){return descendants;}$/;" f class:vb01::Node typeref:typename:std::vector<Node * > &
getDirection camera.h /^ inline Vector3 getDirection(){return direction;}$/;" f class:vb01::Camera typeref:typename:Vector3
getDirection light.h /^ inline Vector3 getDirection(){return direction;}$/;" f class:vb01::Light typeref:typename:Vector3
getFarPlane camera.h /^ inline float getFarPlane(){return farPlane;}$/;" f class:vb01::Camera typeref:typename:float
getFov camera.h /^ inline float getFov(){return fov;}$/;" f class:vb01::Camera typeref:typename:float
getHeight root.h /^ inline int getHeight(){return height;}$/;" f class:vb01::Root typeref:typename:int
getInnerAngle light.h /^ inline float getInnerAngle(){return innerAngle;}$/;" f class:vb01::Light typeref:typename:float
getLeft camera.h /^ inline Vector3 getLeft(){return left;}$/;" f class:vb01::Camera typeref:typename:Vector3
getLength quaternion.h /^ inline float getLength(){return std::sqrt(getLengthSq());}$/;" f class:vb01::quaternion typeref:typename:float
getLength vector.h /^ float getLength(){return std::sqrt(getLengthSq());}$/;" f struct:vb01::Vector2 typeref:typename:float
@@ -235,8 +253,14 @@ getLength vector.h /^ float getLength(){return std::sqrt(getLengthSq());}$/;" f
getLengthSq quaternion.h /^ inline float getLengthSq(){return w*w+x*x+y*y+z*z;}$/;" f class:vb01::quaternion typeref:typename:float
getLengthSq vector.h /^ float getLengthSq(){return x*x+y*y+z*z;}$/;" f struct:vb01::Vector3 typeref:typename:float
getLengthSq vector.h /^ float getLengthSq(){return x*x+y*y;}$/;" f struct:vb01::Vector2 typeref:typename:float
getLight node.h /^ inline Light* getLight(int i){return lights[i];}$/;" f class:vb01::Node typeref:typename:Light *
getLights node.h /^ inline std::vector<Light*>& getLights(){return lights;}$/;" f class:vb01::Node typeref:typename:std::vector<Light * > &
getMaterial mesh.h /^ inline Material* getMaterial(){return material;}$/;" f class:vb01::Mesh typeref:typename:Material *
getMesh node.h /^ inline Mesh* getMesh(){return mesh;}$/;" f class:vb01::Node typeref:typename:Mesh *
getNearPlane camera.h /^ inline float getNearPlane(){return nearPlane;}$/;" f class:vb01::Camera typeref:typename:float
getNode mesh.h /^ inline Node* getNode(){return node;}$/;" f class:vb01::Mesh typeref:typename:Node *
getNumLights node.h /^ inline int getNumLights(){return lights.size();}$/;" f class:vb01::Node typeref:typename:int
getOuterAngle light.h /^ inline float getOuterAngle(){return outerAngle;}$/;" f class:vb01::Light typeref:typename:float
getParent node.h /^ inline Node* getParent(){return parent;}$/;" f class:vb01::Node typeref:typename:Node *
getPosition camera.h /^ inline Vector3 getPosition(){return position;}$/;" f class:vb01::Camera typeref:typename:Vector3
getPosition node.h /^ inline Vector3 getPosition(){return pos;}$/;" f class:vb01::Node typeref:typename:Vector3
@@ -277,14 +301,16 @@ img_v_max stb_image.h /^ int img_h_max, img_v_max;$/;" m struct:__anon84e4e886
img_x stb_image.h /^ stbi__uint32 img_x, img_y;$/;" m struct:__anon84e4e8860308 typeref:typename:stbi__uint32
img_y stb_image.h /^ stbi__uint32 img_x, img_y;$/;" m struct:__anon84e4e8860308 typeref:typename:stbi__uint32
indices mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
innerAngle light.h /^ float innerAngle=.707,outerAngle=.714;$/;" m class:vb01::Light typeref:typename:float
io stb_image.h /^ stbi_io_callbacks io;$/;" m struct:__anon84e4e8860308 typeref:typename:stbi_io_callbacks
io_user_data stb_image.h /^ void *io_user_data;$/;" m struct:__anon84e4e8860308 typeref:typename:void *
isLighting material.h /^ inline bool isLighting(){return lightingEnabled;}$/;" f class:vb01::Material typeref:typename:bool
isLightingEnabled material.h /^ inline bool isLightingEnabled(){return lightingEnabled;}$/;" f class:vb01::Material typeref:typename:bool
jfif stb_image.h /^ int jfif;$/;" m struct:__anon84e4e8860808 typeref:typename:int
left camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3::VEC_K,left=Vector3::VEC_I,up=Vector3::VEC_/;" m class:vb01::Camera typeref:typename:Vector3
length stb_image.h /^ stbi__uint32 length;$/;" m struct:__anon84e4e8860d08 typeref:typename:stbi__uint32
lflags stb_image.h /^ int lflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
lightingEnabled material.h /^ bool lightingEnabled=false;$/;" m class:vb01::Material typeref:typename:bool
lights node.h /^ std::vector<Light*> lights;$/;" m class:vb01::Node typeref:typename:std::vector<Light * >
line0 stb_image.h /^ stbi_uc *line0,*line1;$/;" m struct:__anon84e4e8860a08 typeref:typename:stbi_uc *
line1 stb_image.h /^ stbi_uc *line0,*line1;$/;" m struct:__anon84e4e8860a08 typeref:typename:stbi_uc **
line_size stb_image.h /^ int line_size;$/;" m struct:__anon84e4e8861308 typeref:typename:int
@@ -305,6 +331,7 @@ mesh node.h /^ Mesh *mesh=nullptr;$/;" m class:vb01::Node typeref:typename:Mes
mg stb_image.h /^ unsigned int mr,mg,mb,ma, all_a;$/;" m struct:__anon84e4e8861008 typeref:typename:unsigned int
mr stb_image.h /^ unsigned int mr,mg,mb,ma, all_a;$/;" m struct:__anon84e4e8861008 typeref:typename:unsigned int
nearPlane camera.h /^ float fov=45,nearPlane=.1,farPlane=100;$/;" m class:vb01::Camera typeref:typename:float
node light.h /^ Node *node=nullptr;$/;" m class:vb01::Light typeref:typename:Node *
node mesh.h /^ Node *node=nullptr;$/;" m class:vb01::Mesh typeref:typename:Node *
nomore stb_image.h /^ int nomore; \/\/ flag if we saw a marker so must stop$/;" m struct:__anon84e4e8860808 typeref:typename:int
norm mesh.h /^ Vector3 pos,norm;$/;" m struct:vb01::Mesh::Vertex typeref:typename:Vector3
@@ -334,9 +361,11 @@ operator / vector.h /^ template<typename T>Vector3 operator\/(T s){return Vecto
order stb_image.h /^ int scan_n, order[4];$/;" m struct:__anon84e4e8860808 typeref:typename:int[4]
out stb_image.h /^ stbi_uc *idata, *expanded, *out;$/;" m struct:__anon84e4e8860e08 typeref:typename:stbi_uc ***
out stb_image.h /^ stbi_uc *out; \/\/ output buffer (always 4 components)$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc *
outerAngle light.h /^ float innerAngle=.707,outerAngle=.714;$/;" m class:vb01::Light typeref:typename:float
pal stb_image.h /^ stbi_uc pal[256][4];$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc[256][4]
parent node.h /^ Node *parent=nullptr;$/;" m class:vb01::Node typeref:typename:Node *
parse stb_image.h /^ int parse, step;$/;" m struct:__anon84e4e8861308 typeref:typename:int
pos light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;$/;" m class:vb01::Light typeref:typename:Vector3
pos mesh.h /^ Vector3 pos,norm;$/;" m struct:vb01::Mesh::Vertex typeref:typename:Vector3
pos node.h /^ Vector3 pos;$/;" m class:vb01::Node typeref:typename:Vector3
position camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3::VEC_K,left=Vector3::VEC_I,up=Vector3::VEC_/;" m class:vb01::Camera typeref:typename:Vector3
@@ -363,16 +392,28 @@ s stb_image.h /^ stbi__context *s;$/;" m struct:__anon84e4e8860808 typeref:typ
s stb_image.h /^ stbi__context *s;$/;" m struct:__anon84e4e8860e08 typeref:typename:stbi__context *
scan_n stb_image.h /^ int scan_n, order[4];$/;" m struct:__anon84e4e8860808 typeref:typename:int
select texture.cpp /^ void Texture::select(){$/;" f class:vb01::Texture typeref:typename:void
setAttenuationValues light.h /^ inline void setAttenuationValues(float a, float b, float c){$/;" f class:vb01::Light typeref:typename:void
setBool shader.cpp /^ void Shader::setBool(bool b, string var){$/;" f class:vb01::Shader typeref:typename:void
setColor light.h /^ inline void setColor(Vector3 color){this->color=color;}$/;" f class:vb01::Light typeref:typename:void
setDiffuseMap material.h /^ void setDiffuseMap(std::string diffuseMap){this->diffuseMap=new Texture(diffuseMap);}$/;" f class:vb01::Material typeref:typename:void
setDirection light.h /^ inline void setDirection(Vector3 dir){this->direction=dir;}$/;" f class:vb01::Light typeref:typename:void
setFloat shader.cpp /^ void Shader::setFloat(float fl, string var){$/;" f class:vb01::Shader typeref:typename:void
setInnerAngle light.h /^ inline void setInnerAngle(float innerAngle){this->innerAngle=innerAngle;}$/;" f class:vb01::Light typeref:typename:void
setInt shader.cpp /^ void Shader::setInt(int i, string var){$/;" f class:vb01::Shader typeref:typename:void
setLightingEnabled material.h /^ inline void setLightingEnabled(bool lighting){this->lightingEnabled=lighting;}$/;" f class:vb01::Material typeref:typename:void
setMat4 shader.cpp /^ void Shader::setMat4(mat4 mat, string var){$/;" f class:vb01::Shader typeref:typename:void
setMaterial mesh.h /^ void setMaterial(Material *mat){this->material=mat;}$/;" f class:vb01::Mesh typeref:typename:void
setNode light.h /^ inline void setNode(Node *node){this->node=node;}$/;" f class:vb01::Light typeref:typename:void
setNode mesh.h /^ inline void setNode(Node *node){this->node=node;}$/;" f class:vb01::Mesh typeref:typename:void
setNormalMap material.h /^ void setNormalMap(std::string normalMap){this->normalMap=new Texture(normalMap);}$/;" f class:vb01::Material typeref:typename:void
setNumLights shader.cpp /^ void Shader::setNumLights(int numLights){$/;" f class:vb01::Shader typeref:typename:void
setObject node.cpp /^ void Node::setObject(Mesh *mesh){$/;" f class:vb01::Node typeref:typename:void
setOuterAngle light.h /^ inline void setOuterAngle(float outerAngle){this->outerAngle=outerAngle;}$/;" f class:vb01::Light typeref:typename:void
setPosition camera.h /^ void setPosition(Vector3 position){this->position=position;}$/;" f class:vb01::Camera typeref:typename:void
setPosition light.h /^ inline void setPosition(Vector3 pos){this->pos=pos;}$/;" f class:vb01::Light typeref:typename:void
setSpecularMap material.h /^ void setSpecularMap(std::string specularMap){this->specularMap=new Texture(specularMap);}$/;" f class:vb01::Material typeref:typename:void
setType light.h /^ inline void setType(Type t){this->type=t;}$/;" f class:vb01::Light typeref:typename:void
setVec3 shader.cpp /^ void Shader::setVec3(vec3 vec, string var){$/;" f class:vb01::Shader typeref:typename:void
shader material.h /^ Shader *shader;$/;" m class:vb01::Material typeref:typename:Shader *
size stb_image.h /^ stbi_uc size[257];$/;" m struct:__anon84e4e8860708 typeref:typename:stbi_uc[257]
size stb_image.h /^ stbi_uc size[288];$/;" m struct:__anon84e4e8860b08 typeref:typename:stbi_uc[288]
@@ -660,17 +701,20 @@ texture texture.h /^ unsigned int texture;$/;" m class:vb01::Texture typeref:t
todo stb_image.h /^ int restart_interval, todo;$/;" m struct:__anon84e4e8860808 typeref:typename:int
tq stb_image.h /^ int tq;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
transparent stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
type light.h /^ Type type;$/;" m class:vb01::Light typeref:typename:Type
type stb_image.h /^ stbi__uint32 type;$/;" m struct:__anon84e4e8860d08 typeref:typename:stbi__uint32
type stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc
up camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3::VEC_K,left=Vector3::VEC_I,up=Vector3::VEC_/;" m class:vb01::Camera typeref:typename:Vector3
update box.cpp /^ void Box::update(){$/;" f class:vb01::Box typeref:typename:void
update camera.cpp /^ void Camera::update(){$/;" f class:vb01::Camera typeref:typename:void
update light.cpp /^ void Light::update(){$/;" f class:vb01::Light typeref:typename:void
update material.cpp /^ void Material::update(){$/;" f class:vb01::Material typeref:typename:void
update mesh.cpp /^ void Mesh::update(){$/;" f class:vb01::Mesh typeref:typename:void
update node.cpp /^ void Node::update(){$/;" f class:vb01::Node typeref:typename:void
update root.cpp /^ void Root::update(){$/;" f class:vb01::Root typeref:typename:void
use shader.cpp /^ void Shader::use(){glUseProgram(id);}$/;" f class:vb01::Shader typeref:typename:void
v stb_image.h /^ int h,v;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
vString shader.h /^ std::string vString,fString;$/;" m class:vb01::Shader typeref:typename:std::string
validate_uint32 stb_image.h /^typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];$/;" t typeref:typename:unsigned char[sizeof (stbi__uint32)==4?1:-1]
value stb_image.h /^ stbi__uint16 value[288];$/;" m struct:__anon84e4e8860b08 typeref:typename:stbi__uint16[288]
values stb_image.h /^ stbi_uc values[256];$/;" m struct:__anon84e4e8860708 typeref:typename:stbi_uc[256]
@@ -678,6 +722,8 @@ vb01 box.cpp /^namespace vb01{$/;" n file:
vb01 box.h /^namespace vb01{$/;" n
vb01 camera.cpp /^namespace vb01{$/;" n file:
vb01 camera.h /^namespace vb01{$/;" n
vb01 light.cpp /^namespace vb01{$/;" n file:
vb01 light.h /^namespace vb01{$/;" n
vb01 material.cpp /^namespace vb01{$/;" n file:
vb01 material.h /^namespace vb01{$/;" n
vb01 mesh.cpp /^namespace vb01{$/;" n file:
@@ -726,6 +772,7 @@ zout stb_image.h /^ char *zout;$/;" m struct:__anon84e4e8860c08 typeref:typena
zout_end stb_image.h /^ char *zout_end;$/;" m struct:__anon84e4e8860c08 typeref:typename:char *
zout_start stb_image.h /^ char *zout_start;$/;" m struct:__anon84e4e8860c08 typeref:typename:char *
~Camera camera.cpp /^ Camera::~Camera(){}$/;" f class:vb01::Camera
~Light light.cpp /^ Light::~Light(){}$/;" f class:vb01::Light
~Material material.cpp /^ Material::~Material(){}$/;" f class:vb01::Material
~Mesh mesh.cpp /^ Mesh::~Mesh(){}$/;" f class:vb01::Mesh
~Node node.cpp /^ Node::~Node(){}$/;" f class:vb01::Node
+65
View File
@@ -0,0 +1,65 @@
#version 330 core
const int numLights=1;
in vec3 fragPos;
in vec3 norm;
in vec2 texCoords;
out vec4 FragColor;
//0-POINT,1-DIRECTIONAL,2-SPOT
struct Light{
int type;
vec3 pos,color,direction;
float innerAngle,outerAngle;
float a,b,c;
};
uniform Light light[numLights];
uniform sampler2D tex;
uniform bool lightingEnabled;
uniform vec3 camPos;
void main(){
vec4 finalColor=texture(tex,texCoords);
if(lightingEnabled){
vec3 diffuseColor=vec3(0),specularColor;
for(int i=0;i<numLights;i++){
vec3 specularColor,lightDir,reflectVec,viewDir=normalize(camPos-fragPos);
float attenuation=1.0;
float coef=1.0;
float factor;
float a=light[i].a,b=light[i].b,c=light[i].c,dist=length(fragPos-light[i].pos);
if(light[i].type==0){
lightDir=normalize(light[i].pos-fragPos);
attenuation=1.0/(a*dist*dist+b*dist+c);
}
else if(light[i].type==1){
lightDir=-normalize(light[i].direction);
}
else if(light[i].type==2){
lightDir=normalize(light[i].pos-fragPos);
float innerAngle=light[i].innerAngle;
float angle=acos(dot(lightDir,norm));
float outerAngle=light[i].outerAngle;
if(light[i].innerAngle<=angle&&angle<=light[i].outerAngle){
coef=(angle-outerAngle)/(innerAngle-outerAngle);
}
if(angle>light[i].outerAngle){
coef=0;
}
}
float specularStrength=.5;
reflectVec=reflect(lightDir,norm);
float spec=pow(max(dot(viewDir,reflectVec),0),32);
specularColor+=vec3(1)*spec*specularStrength;
factor=max(dot(lightDir,norm),0.);
diffuseColor+=light[i].color*factor*attenuation*coef;
}
finalColor*=vec4(diffuseColor+specularColor,1);
}
FragColor=finalColor;
}
+20
View File
@@ -0,0 +1,20 @@
#version 330 core
layout (location=0) in vec3 aPos;
layout (location=1) in vec3 aNorm;
layout (location=2) in vec2 aTexCoords;
out vec3 fragPos;
out vec3 norm;
out vec2 texCoords;
uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
void main(){
gl_Position=proj*view*model*vec4(aPos,1);
fragPos=vec3(model*vec4(aPos,1));
texCoords=aTexCoords;
norm=mat3(transpose(inverse(model)))*aNorm;
}