mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
Gaussian blur
bug fixes
This commit is contained in:
@@ -10,7 +10,7 @@ uniform sampler2D tex;
|
||||
void main(){
|
||||
int amount=5;
|
||||
float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054,0.016216);
|
||||
vec2 texel=1/textureSize(tex,0);
|
||||
vec2 texel=1.0/textureSize(tex,0);
|
||||
vec3 c=texture(tex,texCoords).rgb*weight[0];
|
||||
|
||||
for(int i=1;i<amount;i++){
|
||||
|
||||
@@ -33,12 +33,10 @@ namespace vb01{
|
||||
}
|
||||
glDrawBuffer(GL_NONE);
|
||||
glReadBuffer(GL_NONE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
else
|
||||
cout<<"Complete\n";
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -139,14 +137,14 @@ namespace vb01{
|
||||
shader->setVec3(color,"light["+to_string(thisId)+"].color");
|
||||
shader->setFloat(nearPlane,"light["+to_string(thisId)+"].near");
|
||||
shader->setFloat(farPlane,"light["+to_string(thisId)+"].far");
|
||||
//shader->setInt(0,"tex");
|
||||
if(type==POINT)
|
||||
shader->setInt(1,"light["+to_string(thisId)+"].depthMapCube");
|
||||
else
|
||||
shader->setInt(1,"light["+to_string(thisId)+"].depthMap");
|
||||
depthMap->select(1);
|
||||
/*
|
||||
*/
|
||||
shader->setInt(0,"diffuseMap");
|
||||
//shader->setInt(1,"normalMap");
|
||||
shader->setInt(2,"specularMap");
|
||||
shader->setInt(3,"parallaxMap");
|
||||
shader->setInt(4,"environmentMap");
|
||||
shader->setInt(5,"light["+to_string(thisId)+"].depthMapCube");
|
||||
shader->setInt(6,"light["+to_string(thisId)+"].depthMap");
|
||||
depthMap->select(type==POINT?5:6);
|
||||
|
||||
switch(type){
|
||||
case POINT:
|
||||
|
||||
+11
-5
@@ -28,7 +28,13 @@ namespace vb01{
|
||||
shaderName="text.";
|
||||
break;
|
||||
}
|
||||
shader=new Shader(basePath+shaderName+"vert",basePath+shaderName+"frag");
|
||||
/*
|
||||
if(type==MATERIAL_2D)
|
||||
//shader=new Shader(basePath+shaderName+"vert",basePath+shaderName+"frag");
|
||||
shader=new Shader(basePath+shaderName+"vert",basePath+shaderName+"frag",basePath+shaderName+"geo");
|
||||
else
|
||||
*/
|
||||
shader=new Shader(basePath+shaderName+"vert",basePath+shaderName+"frag");
|
||||
}
|
||||
|
||||
Material::~Material(){
|
||||
@@ -56,13 +62,13 @@ namespace vb01{
|
||||
}
|
||||
if(texturingEnabled){
|
||||
for(Texture *t : diffuseMapTextures)
|
||||
t->update();
|
||||
t->update(0);
|
||||
for(Texture *t : normalMapTextures)
|
||||
t->update(2);
|
||||
t->update(1);
|
||||
for(Texture *t : specularMapTextures)
|
||||
t->update(3);
|
||||
t->update(2);
|
||||
for(Texture *t : parallaxMapTextures)
|
||||
t->update(4);
|
||||
t->update(3);
|
||||
}
|
||||
else {
|
||||
shader->setVec4(diffuseColor,"diffuseColor");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include"root.h"
|
||||
#include"node.h"
|
||||
#include"mesh.h"
|
||||
#include"box.h"
|
||||
#include"texture.h"
|
||||
#include"skeleton.h"
|
||||
#include<glad.h>
|
||||
#include<glfw3.h>
|
||||
@@ -21,6 +22,7 @@ namespace vb01{
|
||||
this->vertices=vertices;
|
||||
this->indices=indices;
|
||||
this->numTris=numTris;
|
||||
|
||||
construct();
|
||||
}
|
||||
|
||||
@@ -39,6 +41,27 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Mesh::construct(){
|
||||
u32 RBO;
|
||||
string basePath="../../vb01/depthMap.";
|
||||
environmentShader=new Shader(basePath+"vert",basePath+"frag",basePath+"geo");
|
||||
environmentMap=new Texture(width,false);
|
||||
|
||||
glGenFramebuffers(1,&environmentBuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,environmentBuffer);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,*(environmentMap->getTexture()),0);
|
||||
|
||||
/*
|
||||
glGenRenderbuffers(1,&RBO);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER,RBO);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8,width,width);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,RBO);
|
||||
*/
|
||||
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
glGenVertexArrays(1,&VAO);
|
||||
glGenBuffers(1,&VBO);
|
||||
glGenBuffers(1,&EBO);
|
||||
@@ -77,6 +100,49 @@ namespace vb01{
|
||||
camPos=cam->getPosition();
|
||||
}
|
||||
|
||||
if(reflect){
|
||||
glViewport(0,0,width,width);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,environmentBuffer);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
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)
|
||||
};
|
||||
environmentShader->use();
|
||||
Node *rootNode=root->getRootNode();
|
||||
vector<Node*> descendants;
|
||||
rootNode->getDescendants(rootNode,descendants);
|
||||
for(Node *n : descendants){
|
||||
for(Mesh *m : n->getMeshes())
|
||||
if(m!=this){
|
||||
Vector3 position=n->getWorldPosition();
|
||||
Quaternion rotation=n->getWorldOrientation();
|
||||
Vector3 rotAxis=rotation.norm().getAxis();
|
||||
|
||||
if(rotAxis==Vector3::VEC_ZERO)
|
||||
rotAxis=Vector3::VEC_I;
|
||||
float far=100;
|
||||
vec3 p=vec3(position.x,position.y,position.z);
|
||||
mat4 proj=perspective(radians(90.f),1.f,.1f,far);
|
||||
mat4 model=translate(mat4(1.),p);
|
||||
model=rotate(model,rotation.norm().getAngle(),vec3(rotAxis.x,rotAxis.y,rotAxis.z));
|
||||
environmentShader->setMat4(model,"model");
|
||||
environmentShader->setBool(true,"point");
|
||||
environmentShader->setVec3(pos,"lightPos");
|
||||
environmentShader->setFloat(far,"farPlane");
|
||||
for(int i=0;i<6;i++)
|
||||
environmentShader->setMat4(proj*lookAt(p,p+dirs[i],1<i&&i<4?vec3(0,0,-1):vec3(0,-1,0)),"shadowMat["+to_string(i)+"]");
|
||||
m->render();
|
||||
}
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,*(root->getFBO()));
|
||||
glViewport(0,0,root->getWidth(),root->getHeight());
|
||||
}
|
||||
|
||||
Vector3 rotAxis=orient.norm().getAxis();
|
||||
if(rotAxis==Vector3::VEC_ZERO)
|
||||
rotAxis=Vector3::VEC_I;
|
||||
@@ -89,10 +155,16 @@ namespace vb01{
|
||||
material->update();
|
||||
Shader *shader=material->getShader();
|
||||
shader->setBool(castShadow,"castShadow");
|
||||
shader->setBool(false,"environment");
|
||||
shader->setMat4(view,"view");
|
||||
shader->setMat4(proj,"proj");
|
||||
shader->setVec3(camPos,"camPos");
|
||||
shader->setMat4(model,"model");
|
||||
if(reflect){
|
||||
shader->setBool(reflect,"environmentMapEnabled");
|
||||
root->getSkybox()->getMaterial()->getDiffuseMap(0)->select(4);
|
||||
//environmentMap->select(4);
|
||||
}
|
||||
if(skeleton){
|
||||
}
|
||||
if(material->getType()==Material::MATERIAL_GUI){
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MESH_H
|
||||
|
||||
#include"vector.h"
|
||||
#include"util.h"
|
||||
#include<vector>
|
||||
#include<string>
|
||||
#include"material.h"
|
||||
@@ -9,6 +10,8 @@
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
class Shader;
|
||||
class Texture;
|
||||
class Skeleton;
|
||||
|
||||
class Mesh{
|
||||
@@ -31,6 +34,7 @@ namespace vb01{
|
||||
void setMaterial(Material *mat){this->material=mat;}
|
||||
inline void setNode(Node *node){this->node=node;}
|
||||
inline void setCastShadow(bool castShadow){this->castShadow=castShadow;}
|
||||
inline void setReflect(bool r){this->reflect=r;}
|
||||
inline void setWireframe(bool w){this->wireframe=w;}
|
||||
inline Node* getNode(){return node;}
|
||||
inline Material* getMaterial(){return material;}
|
||||
@@ -40,16 +44,20 @@ namespace vb01{
|
||||
inline Vertex* getVerts(){return vertices;}
|
||||
inline unsigned int* getIndices(){return indices;}
|
||||
private:
|
||||
Shader *environmentShader=nullptr;
|
||||
u32 environmentBuffer;
|
||||
Texture *environmentMap;
|
||||
Material *material=nullptr;
|
||||
Node *node=nullptr;
|
||||
std::vector<Mesh*> meshes;
|
||||
std::string name="";
|
||||
int width=800;
|
||||
Skeleton *skeleton=nullptr;
|
||||
protected:
|
||||
Mesh();
|
||||
void construct();
|
||||
|
||||
bool staticVerts=true,castShadow=false,wireframe=false;
|
||||
bool staticVerts=true,castShadow=false,reflect=false,wireframe=false;
|
||||
Vertex *vertices;
|
||||
VertexGroup groups;
|
||||
unsigned int *indices,VAO,VBO,EBO;
|
||||
|
||||
@@ -229,6 +229,15 @@ namespace vb01{
|
||||
this->castShadow=castShadow;
|
||||
}
|
||||
|
||||
void Model::setReflect(bool reflect){
|
||||
vector<Node*> descendants;
|
||||
getDescendants(this,descendants);
|
||||
for(Node *node : descendants)
|
||||
for(Mesh *mesh : node->getMeshes())
|
||||
mesh->setReflect(reflect);
|
||||
this->reflect=reflect;
|
||||
}
|
||||
|
||||
void Model::setWireframe(bool wirefame){
|
||||
vector<Node*> descendants;
|
||||
getDescendants(this,descendants);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace vb01{
|
||||
void update();
|
||||
void setMaterial(Material*);
|
||||
void setCastShadow(bool);
|
||||
void setReflect(bool);
|
||||
void setWireframe(bool);
|
||||
private:
|
||||
void processNode(aiNode*, const aiScene*, Node*);
|
||||
@@ -30,7 +31,7 @@ namespace vb01{
|
||||
void processMaterial();
|
||||
|
||||
Material* material;
|
||||
bool castShadow=false,wireframe=false;
|
||||
bool castShadow=false,reflect=false,wireframe=false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -4,7 +4,8 @@ in vec2 texCoords;
|
||||
|
||||
flat in int id;
|
||||
|
||||
out vec4 FragColor;
|
||||
layout (location=0) out vec4 FragColor;
|
||||
layout (location=1) out vec4 BrightColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform vec4 color[200];
|
||||
@@ -12,6 +13,9 @@ uniform vec4 color[200];
|
||||
void main(){
|
||||
float alpha=texture(tex,texCoords).r;
|
||||
vec4 c=color[id];
|
||||
//FragColor=vec4(1,0,0,1);
|
||||
c=vec4(c.x,c.y,c.z,c.w*alpha);
|
||||
float brightness = dot(c.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness>1)
|
||||
BrightColor=vec4(c.rgb,1);
|
||||
FragColor=vec4(c.x,c.y,c.z,c.w*alpha);
|
||||
}
|
||||
|
||||
+12
-24
@@ -6,38 +6,26 @@ out vec4 FragColor;
|
||||
|
||||
uniform sampler2D frag;
|
||||
uniform sampler2D bright;
|
||||
uniform bool hdr;
|
||||
uniform bool bloom;
|
||||
uniform float exposure;
|
||||
uniform float gamma;
|
||||
|
||||
void main(){
|
||||
vec4 hdrColor=texture(frag,texCoords);
|
||||
vec4 brightColor=texture(bright,texCoords);
|
||||
|
||||
if(bloom){
|
||||
float blurKernel[9]=float[](
|
||||
1.0/16,2.0/16,1.0/16,
|
||||
2.0/16,4.0/16,1.0/16,
|
||||
1.0/16,2.0/16,1.0/16);
|
||||
vec2 texel=1.0/textureSize(bright,0);
|
||||
|
||||
vec3 sum=vec3(0);
|
||||
for(int i=0;i<3;i++){
|
||||
for(int j=0;j<3;j++){
|
||||
vec3 adjSample=texture(frag,texCoords+vec2(texel.x*(j-1),texel.y*(i-1))).rgb;
|
||||
adjSample*=blurKernel[i*3+j];
|
||||
sum+=adjSample;
|
||||
}
|
||||
if(bloom)
|
||||
hdrColor+=brightColor;
|
||||
|
||||
if(hdr){
|
||||
//Reinhardt
|
||||
//c.rgb=c.rgb/(c.rgb+vec3(1.));
|
||||
|
||||
//Exp
|
||||
hdrColor.rgb=vec3(1.)-exp(-hdrColor.rgb*exposure);
|
||||
}
|
||||
hdrColor.rgb=sum;
|
||||
}
|
||||
|
||||
//hdrColor=brightColor;
|
||||
float gamma=1,exposure=1;
|
||||
|
||||
//Reinhardt
|
||||
//c.rgb=c.rgb/(c.rgb+vec3(1.));
|
||||
|
||||
//Exp
|
||||
hdrColor.rgb=vec3(1.)-exp(-hdrColor.rgb*exposure);
|
||||
|
||||
hdrColor.rgb=pow(hdrColor.rgb,vec3(1/gamma));
|
||||
FragColor=hdrColor;
|
||||
|
||||
@@ -76,8 +76,6 @@ namespace vb01{
|
||||
*/
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
else
|
||||
cout<<"Complete\n";
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
|
||||
guiPlane=new Quad(Vector3(width,height,-1),false);
|
||||
@@ -86,16 +84,15 @@ namespace vb01{
|
||||
mat->addDiffuseMap(brightTexture);
|
||||
guiPlane->setMaterial(mat);
|
||||
|
||||
string basePath="../../vb01/";
|
||||
blurShader=new Shader(basePath+"blur.vert",basePath+"blur.frag");
|
||||
string basePath="../../vb01/blur.";
|
||||
blurShader=new Shader(basePath+"vert",basePath+"frag");
|
||||
glGenFramebuffers(2,pingpongBuffers);
|
||||
for(int i=0;i<2;i++){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,pingpongBuffers[i]);
|
||||
pingPongTextures[i]=new Texture(width,height,false);
|
||||
glBindFramebuffer(GL_RENDERBUFFER,pingpongBuffers[i]);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,*(pingPongTextures[i]->getTexture()),0);
|
||||
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)!=GL_FRAMEBUFFER_COMPLETE)
|
||||
cout<<"Not complete\n";
|
||||
glBindFramebuffer(GL_RENDERBUFFER,0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,29 +122,29 @@ namespace vb01{
|
||||
Material *material=guiPlane->getMaterial();
|
||||
Shader *shader=material->getShader();
|
||||
|
||||
/*
|
||||
int ammount=10;
|
||||
bool horizontal=false;
|
||||
blurShader->use();
|
||||
for(int i=0;i<ammount;i++){
|
||||
blurShader->setBool(horizontal,"horizontal");
|
||||
blurShader->setVec2(Vector2(width,height),"screen");
|
||||
for(int i=0;i<blurLevel;i++){
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,pingpongBuffers[horizontal]);
|
||||
blurShader->setBool(horizontal,"horizontal");
|
||||
if(i==0)
|
||||
material->getDiffuseMap(1)->update();
|
||||
glBindTexture(GL_TEXTURE_2D,*(material->getDiffuseMap(1)->getTexture()));
|
||||
else
|
||||
pingPongTextures[!horizontal]->update();
|
||||
pingPongTextures[!horizontal]->select();
|
||||
guiPlane->render();
|
||||
horizontal=!horizontal;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
||||
*/
|
||||
|
||||
shader->use();
|
||||
shader->setVec2(Vector2(width,height),"screen");
|
||||
shader->setBool(bloom,"bloom");
|
||||
material->getDiffuseMap(0)->update();
|
||||
material->getDiffuseMap(1)->update(1);
|
||||
//pingPongTextures[1]->update(1);
|
||||
shader->setBool(hdr,"hdr");
|
||||
shader->setFloat(exposure,"exposure");
|
||||
shader->setFloat(gamma,"gamma");
|
||||
material->getDiffuseMap(0)->select();
|
||||
pingPongTextures[!horizontal]->select(1);
|
||||
shader->setInt(0,"frag");
|
||||
shader->setInt(1,"bright");
|
||||
guiPlane->render();
|
||||
|
||||
@@ -28,15 +28,21 @@ namespace vb01{
|
||||
inline int getHeight(){return height;}
|
||||
inline unsigned int* getFBO(){return &FBO;}
|
||||
inline GLFWwindow* getWindow(){return window;}
|
||||
inline void setHDREnabled(bool hdr){this->hdr=hdr;}
|
||||
inline void setExposure(float exposure){this->exposure=exposure;}
|
||||
inline void setGamma(float gamme){this->gamma=gamma;}
|
||||
inline void setBloom(bool bloom){this->bloom=bloom;}
|
||||
inline void setBlurLevel(bool level){this->blurLevel=level;}
|
||||
inline Box* getSkybox(){return skybox;}
|
||||
void createSkybox(std::string[6]);
|
||||
static Root* getSingleton();
|
||||
int numLights=0;
|
||||
private:
|
||||
bool bloom=false;
|
||||
bool bloom=false,hdr=false;
|
||||
float exposure=1,gamma=1;
|
||||
Box *skybox=nullptr;
|
||||
Quad *guiPlane=nullptr;
|
||||
int width,height;
|
||||
int width,height,blurLevel=10;
|
||||
unsigned int FBO,RBO,pingpongBuffers[2];
|
||||
GLFWwindow *window;
|
||||
Node *rootNode,*guiNode;
|
||||
|
||||
+3
-1
@@ -2,10 +2,12 @@
|
||||
|
||||
in vec3 texCoords;
|
||||
|
||||
out vec4 FragColor;
|
||||
layout (location=0) out vec4 FragColor;
|
||||
layout (location=1) out vec4 BrightColor;
|
||||
|
||||
uniform samplerCube skybox;
|
||||
|
||||
void main(){
|
||||
BrightColor=vec4(0);
|
||||
FragColor=texture(skybox,texCoords);
|
||||
}
|
||||
|
||||
+5
-5
@@ -25,10 +25,10 @@ namespace vb01{
|
||||
glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,borderColor);
|
||||
}
|
||||
else{
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F,width,height,0,GL_RGB,GL_FLOAT,NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F,width,height,0,GL_RGB,GL_FLOAT,NULL);
|
||||
//glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace vb01{
|
||||
|
||||
}
|
||||
|
||||
Texture::Texture(int width){
|
||||
Texture::Texture(int width,bool depth){
|
||||
this->width=width;
|
||||
this->type=TextureType::TEXTURE_CUBEMAP;
|
||||
texture=new u32;
|
||||
@@ -103,7 +103,7 @@ namespace vb01{
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP,texture[0]);
|
||||
|
||||
for(int i=0;i<6;i++)
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,GL_DEPTH_COMPONENT,width,width,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,depth?GL_DEPTH_COMPONENT:GL_RGB,width,width,0,depth?GL_DEPTH_COMPONENT:GL_RGB,GL_FLOAT,NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
+16
-7
@@ -27,12 +27,15 @@ uniform sampler2D diffuseMap;
|
||||
uniform sampler2D normalMap;
|
||||
uniform sampler2D specularMap;
|
||||
uniform sampler2D parallaxMap;
|
||||
uniform samplerCube environmentMap;
|
||||
uniform Light light[numLights];
|
||||
uniform bool lightingEnabled;
|
||||
uniform bool texturingEnabled;
|
||||
uniform bool normalMapEnabled;
|
||||
uniform bool castShadow;
|
||||
uniform bool environmentMapEnabled;
|
||||
uniform vec4 diffuseColor;
|
||||
uniform float specularStrength;
|
||||
uniform vec3 camPos;
|
||||
|
||||
float linDepth(float depth,int i){
|
||||
@@ -44,15 +47,15 @@ float getShadow(int id){
|
||||
int type=light[id].type;
|
||||
|
||||
float shadow=0,closestDepth=0,currentDepth=0,bias=.005,val=.7;
|
||||
/*
|
||||
if(type==0){
|
||||
vec3 projDir=fragPos-light[id].pos;
|
||||
closestDepth=texture(light[id].depthMapCube,projDir).r*light[id].far;
|
||||
currentDepth=length(projDir);
|
||||
shadow=(currentDepth-bias>closestDepth)?val:0;
|
||||
}
|
||||
/*
|
||||
*/
|
||||
if(type!=0){
|
||||
else{
|
||||
vec3 projCoords=(light[id].lightMat*vec4(fragPos,1)).xyz/(light[id].lightMat*vec4(fragPos,1)).w;
|
||||
projCoords=projCoords*.5+.5;
|
||||
closestDepth=texture(light[id].depthMap,projCoords.xy).r;
|
||||
@@ -79,6 +82,8 @@ void main(){
|
||||
|
||||
vec3 diffuseColor=vec3(0),specularColor=vec3(0);
|
||||
float coef=1;
|
||||
|
||||
|
||||
for(int i=0;i<numLights;i++){
|
||||
vec3 lightDir=vec3(0),reflectVec,viewDir=normalize(camPos-fragPos);
|
||||
float attenuation=1.0;
|
||||
@@ -104,10 +109,10 @@ void main(){
|
||||
coef=0;
|
||||
}
|
||||
}
|
||||
float specularStrength=1;
|
||||
float specularSample=texture(specularMap,texCoords).r;
|
||||
reflectVec=reflect(lightDir,normal);
|
||||
float spec=pow(max(dot(viewDir,reflectVec),0),32);
|
||||
specularColor+=vec3(1)*spec*specularStrength;
|
||||
specularColor+=vec3(1)*spec*specularSample;
|
||||
|
||||
factor=max(dot(lightDir,normal),0.);
|
||||
diffuseColor+=light[i].color*(factor*attenuation*coef);
|
||||
@@ -116,12 +121,16 @@ void main(){
|
||||
for(int i=0;i<numLights;i++){
|
||||
float shadow=getShadow(i);
|
||||
diffuseColor*=(1-shadow);
|
||||
/*
|
||||
*/
|
||||
}
|
||||
|
||||
if(environmentMapEnabled){
|
||||
vec3 projDir=normalize(fragPos-camPos);
|
||||
projDir=reflect(projDir,norm);
|
||||
vec3 sample=texture(environmentMap,projDir).rgb;
|
||||
diffuseColor.rgb+=sample;
|
||||
}
|
||||
finalColor*=vec4(diffuseColor+specularColor,1);
|
||||
}
|
||||
|
||||
float brightness = dot(finalColor.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness>1)
|
||||
BrightColor=vec4(finalColor.rgb,1);
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#version 330 core
|
||||
|
||||
/*
|
||||
*/
|
||||
layout (triangles) in;
|
||||
layout (triangle_strip, max_vertices=3) out;
|
||||
|
||||
in VS_OUT{
|
||||
vec2 tCoords;
|
||||
}gs_in[];
|
||||
|
||||
out vec4 FragPos;
|
||||
out vec2 texCoords;
|
||||
|
||||
uniform mat4 shadowMat[6];
|
||||
uniform bool environment;
|
||||
|
||||
void main(){
|
||||
/*
|
||||
if(environment)
|
||||
for(int i=0;i<6;i++){
|
||||
gl_Layer=i;
|
||||
for(int j=0;j<3;j++){
|
||||
FragPos=gl_in[j].gl_Position;
|
||||
gl_Position=shadowMat[i]*FragPos;
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
*/
|
||||
gl_Position=gl_in[0].gl_Position;
|
||||
texCoords=gs_in[0].tCoords;
|
||||
EmitVertex();
|
||||
gl_Position=gl_in[1].gl_Position;
|
||||
texCoords=gs_in[1].tCoords;
|
||||
EmitVertex();
|
||||
gl_Position=gl_in[2].gl_Position;
|
||||
texCoords=gs_in[2].tCoords;
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace vb01{
|
||||
Texture(int,int,bool=true);
|
||||
Texture(std::string[],int,int=0,bool=false);
|
||||
Texture(std::string[6],bool=false);
|
||||
Texture(int);
|
||||
Texture(int,bool=true);
|
||||
Texture(FT_Face&,char);
|
||||
void select(int=0);
|
||||
void update(int=0);
|
||||
|
||||
@@ -15,10 +15,6 @@ out vec2 texCoords;
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
/*
|
||||
uniform vec3 aTan;
|
||||
uniform vec3 aBiTan;
|
||||
*/
|
||||
|
||||
void main(){
|
||||
gl_Position=proj*view*model*vec4(aPos,1);
|
||||
|
||||
Reference in New Issue
Block a user