mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
beginning of suitting textures for animation
This commit is contained in:
@@ -11,21 +11,21 @@ uniform vec4 diffuseColor;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main(){
|
||||
vec4 c=texturingEnabled?texture(tex,texCoords):diffuseColor;
|
||||
vec4 c = texturingEnabled?texture(tex, texCoords) : diffuseColor;
|
||||
if(diffuseColorEnabled){
|
||||
float alpha=texture(tex,texCoords).w;
|
||||
c=vec4(diffuseColor.xyz,alpha);
|
||||
float alpha = texture(tex, texCoords).w;
|
||||
c = vec4(diffuseColor.xyz, alpha);
|
||||
}
|
||||
if(guiPlane){
|
||||
float gamma=1,exposure=1;
|
||||
float gamma = 1, exposure = 1;
|
||||
|
||||
//Reinhardt
|
||||
//c.rgb=c.rgb/(c.rgb+vec3(1.));
|
||||
//c.rgb = c.rgb / (c.rgb + vec3(1.));
|
||||
|
||||
//Exp
|
||||
c.rgb=vec3(1.)-exp(-c.rgb*exposure);
|
||||
c.rgb = vec3(1.) - exp(-c.rgb * exposure);
|
||||
|
||||
c.rgb=pow(c.rgb,vec3(1/gamma));
|
||||
c.rgb = pow(c.rgb, vec3(1 / gamma));
|
||||
}
|
||||
FragColor=c;
|
||||
FragColor = c;
|
||||
}
|
||||
|
||||
@@ -181,9 +181,9 @@ 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(5, "light[" + to_string(thisId) + "].depthMapCube");
|
||||
shader->setInt(6, "light[" + to_string(thisId) + "].depthMap");
|
||||
depthMap->select(type == POINT ? 5 : 6);
|
||||
shader->setInt(12, "light[" + to_string(thisId) + "].depthMapCube");
|
||||
shader->setInt(13, "light[" + to_string(thisId) + "].depthMap");
|
||||
depthMap->select(type == POINT ? 12 : 13);
|
||||
|
||||
switch(type){
|
||||
case POINT:
|
||||
|
||||
+19
-10
@@ -55,15 +55,20 @@ namespace vb01{
|
||||
void Material::update(){
|
||||
shader->use();
|
||||
shader->setBool(texturingEnabled, "texturingEnabled");
|
||||
const int DIFFUSE_SLOT = Texture::DIFFUSE * 2;
|
||||
const int NORMAL_SLOT = Texture::NORMAL * 2;
|
||||
const int SPECULAR_SLOT = Texture::SPECULAR * 2;
|
||||
const int PARALLAX_SLOT = Texture::PARALLAX * 2;
|
||||
const int ENVIRONMENT_SLOT = Texture::ENVIRONMENT * 2;
|
||||
|
||||
if(type == MATERIAL_2D){
|
||||
shader->setBool(lightingEnabled, "lightingEnabled");
|
||||
shader->setBool(normalMapEnabled, "normalMapEnabled");
|
||||
shader->setInt(0, "diffuseMap");
|
||||
shader->setInt(1, "normalMap");
|
||||
shader->setInt(2, "specularMap");
|
||||
shader->setInt(3, "parallaxMap");
|
||||
shader->setInt(4, "environmentMap");
|
||||
shader->setInt(DIFFUSE_SLOT, "textures["+to_string(DIFFUSE_SLOT)+"].pastTexture");
|
||||
shader->setInt(NORMAL_SLOT, "textures["+to_string(NORMAL_SLOT)+"].pastTexture");
|
||||
shader->setInt(SPECULAR_SLOT, "textures["+to_string(SPECULAR_SLOT)+"].pastTexture");
|
||||
shader->setInt(PARALLAX_SLOT, "textures["+to_string(PARALLAX_SLOT)+"].pastTexture");
|
||||
shader->setInt(ENVIRONMENT_SLOT, "environmentMap");
|
||||
}
|
||||
else if(type == MATERIAL_GUI){
|
||||
shader->setBool(diffuseColorEnabled, "diffuseColorEnabled");
|
||||
@@ -72,14 +77,18 @@ namespace vb01{
|
||||
}
|
||||
|
||||
if(texturingEnabled){
|
||||
for(Texture *t : diffuseMapTextures)
|
||||
t->update(0);
|
||||
int textureSlot = DIFFUSE_SLOT;
|
||||
for(Texture *t : diffuseMapTextures){
|
||||
t->update(textureSlot);
|
||||
if(t->getNumFrames() > 0)
|
||||
shader->setBool(true, "textures[" + to_string(textureSlot) + "].animated");
|
||||
}
|
||||
for(Texture *t : normalMapTextures)
|
||||
t->update(1);
|
||||
t->update(NORMAL_SLOT);
|
||||
for(Texture *t : specularMapTextures)
|
||||
t->update(2);
|
||||
t->update(SPECULAR_SLOT);
|
||||
for(Texture *t : parallaxMapTextures)
|
||||
t->update(3);
|
||||
t->update(PARALLAX_SLOT);
|
||||
}
|
||||
else
|
||||
shader->setVec4(diffuseColor, "diffuseColor");
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform float lifePercentage[500];
|
||||
uniform vec4 startColor,endColor;
|
||||
uniform vec4 startColor, endColor;
|
||||
|
||||
void main(){
|
||||
float alpha = texture(tex, texCoords).r;
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include"root.h"
|
||||
#include"text.h"
|
||||
#include"shader.h"
|
||||
#include"texture.h"
|
||||
#include"node.h"
|
||||
#include<glad.h>
|
||||
#include<glfw3.h>
|
||||
#include<iostream>
|
||||
#include<ft2build.h>
|
||||
#include "root.h"
|
||||
#include "text.h"
|
||||
#include "shader.h"
|
||||
#include "texture.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <glad.h>
|
||||
#include <glfw3.h>
|
||||
#include <iostream>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
using namespace std;
|
||||
|
||||
+4
-4
@@ -150,14 +150,14 @@ namespace vb01{
|
||||
void Texture::update(int id){
|
||||
updateFrame();
|
||||
select(id);
|
||||
if(numFrames > 0)
|
||||
select(id + 1);
|
||||
}
|
||||
|
||||
void Texture::updateFrame(){
|
||||
if(numFrames > 0){
|
||||
if(getTime() - lastUpdateTime > updateRate){
|
||||
frame++;
|
||||
if(frame == numFrames)
|
||||
frame = 0;
|
||||
frame = getNextFrame(frame);
|
||||
lastUpdateTime = getTime();
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,6 @@ namespace vb01{
|
||||
|
||||
void Texture::select(int id){
|
||||
glActiveTexture(GL_TEXTURE0 + id);
|
||||
glBindTexture(type == TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP, texture[numFrames > 0 ? frame : 0]);
|
||||
glBindTexture(type == TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP, texture[frame]);
|
||||
}
|
||||
}
|
||||
|
||||
+54
-51
@@ -8,25 +8,28 @@ in vec3 norm;
|
||||
in vec2 texCoords;
|
||||
in vec4 lightSpaceFragPos;
|
||||
|
||||
layout (location=0) out vec4 FragColor;
|
||||
layout (location=1) out vec4 BrightColor;
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
//0-POINT,1-DIRECTIONAL,2-SPOT
|
||||
|
||||
struct Light{
|
||||
int type;
|
||||
vec3 pos,color,direction;
|
||||
float innerAngle,outerAngle;
|
||||
float a,b,c,near,far;
|
||||
vec3 pos, color, direction;
|
||||
float innerAngle, outerAngle;
|
||||
float a, b, c, near, far;
|
||||
sampler2D depthMap;
|
||||
samplerCube depthMapCube;
|
||||
mat4 lightMat;
|
||||
};
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
uniform sampler2D normalMap;
|
||||
uniform sampler2D specularMap;
|
||||
uniform sampler2D parallaxMap;
|
||||
struct Texture{
|
||||
float mixRatio;
|
||||
sampler2D pastTexture, nextTexture;
|
||||
bool animated;
|
||||
};
|
||||
|
||||
uniform Texture textures[4];
|
||||
uniform samplerCube environmentMap;
|
||||
uniform Light light[numLights];
|
||||
uniform bool lightingEnabled;
|
||||
@@ -72,69 +75,69 @@ float getShadow(int id){
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec4 finalColor=texturingEnabled?texture(diffuseMap,texCoords):diffuseColor;
|
||||
vec3 normal=norm;
|
||||
vec4 finalColor = texturingEnabled?texture(textures[0].pastTexture, texCoords) : diffuseColor;
|
||||
vec3 normal = norm;
|
||||
if(lightingEnabled){
|
||||
if(normalMapEnabled){
|
||||
vec3 n=vec3(texture(normalMap,texCoords));
|
||||
normal=mat3(tan,biTan,norm)*n;
|
||||
vec3 n = vec3(texture(textures[1].pastTexture, texCoords));
|
||||
normal = mat3(tan, biTan, norm) * n;
|
||||
}
|
||||
|
||||
vec3 diffuseColor=vec3(0),specularColor=vec3(0);
|
||||
float coef=1;
|
||||
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;
|
||||
for(int i = 0; i < numLights; i++){
|
||||
vec3 lightDir = vec3(0), reflectVec, viewDir = normalize(camPos - fragPos);
|
||||
float attenuation = 1.0;
|
||||
float factor;
|
||||
float a=light[i].a,b=light[i].b,c=light[i].c,dist=length(fragPos-light[i].pos);
|
||||
coef=1;
|
||||
if(light[i].type==0){
|
||||
lightDir=normalize(light[i].pos-fragPos);
|
||||
attenuation=1.0/(a*dist*dist+b*dist+c);
|
||||
float a = light[i].a, b = light[i].b, c = light[i].c, dist = length(fragPos - light[i].pos);
|
||||
coef = 1;
|
||||
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 == 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,light[i].direction));
|
||||
float outerAngle=light[i].outerAngle;
|
||||
if(light[i].innerAngle<=angle&&angle<=light[i].outerAngle){
|
||||
coef=(angle-outerAngle)/(innerAngle-outerAngle);
|
||||
else if(light[i].type == 2){
|
||||
lightDir = normalize(light[i].pos - fragPos);
|
||||
float innerAngle = light[i].innerAngle;
|
||||
float angle = acos(dot(-lightDir, light[i].direction));
|
||||
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;
|
||||
if(angle > light[i].outerAngle){
|
||||
coef = 0;
|
||||
}
|
||||
}
|
||||
float specularSample=texture(specularMap,texCoords).r;
|
||||
reflectVec=reflect(lightDir,normal);
|
||||
float spec=pow(max(dot(viewDir,reflectVec),0),32);
|
||||
specularColor+=vec3(1)*spec*specularSample;
|
||||
float specularSample = texture(textures[2].pastTexture, texCoords).r;
|
||||
reflectVec = reflect(lightDir, normal);
|
||||
float spec = pow(max(dot(viewDir, reflectVec), 0), 32);
|
||||
specularColor += vec3(1) * spec * specularSample;
|
||||
|
||||
factor=max(dot(lightDir,normal),0.);
|
||||
diffuseColor+=light[i].color*(factor*attenuation*coef);
|
||||
factor = max(dot(lightDir, normal), 0.);
|
||||
diffuseColor += light[i].color * (factor * attenuation * coef);
|
||||
}
|
||||
|
||||
/*
|
||||
for(int i=0;i<numLights;i++){
|
||||
float shadow=getShadow(i);
|
||||
diffuseColor*=(1-shadow);
|
||||
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;
|
||||
vec3 projDir = normalize(fragPos - camPos);
|
||||
projDir = reflect(projDir, norm);
|
||||
vec3 sample = texture(environmentMap, projDir).rgb;
|
||||
diffuseColor.rgb += sample;
|
||||
}
|
||||
finalColor*=vec4(diffuseColor+specularColor,1);
|
||||
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);
|
||||
FragColor=finalColor;
|
||||
if(brightness > 1)
|
||||
BrightColor = vec4(finalColor.rgb, 1);
|
||||
FragColor = finalColor;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef TEXTURE_H
|
||||
#define TEXTURE_H
|
||||
|
||||
#include<string>
|
||||
#include<ft2build.h>
|
||||
#include"util.h"
|
||||
#include <string>
|
||||
#include <ft2build.h>
|
||||
#include "util.h"
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace vb01{
|
||||
@@ -22,6 +22,7 @@ namespace vb01{
|
||||
void update(int = 0);
|
||||
inline unsigned int* getTexture(int i = 0){return &(texture[i]);}
|
||||
inline std::string getPath(){return path;}
|
||||
inline int getNumFrames(){return numFrames;}
|
||||
private:
|
||||
TextureType type = TextureType::TEXTURE_2D;
|
||||
u32 *texture = nullptr;
|
||||
@@ -34,6 +35,7 @@ namespace vb01{
|
||||
|
||||
void createCubemap(bool, bool);
|
||||
void updateFrame();
|
||||
inline int getNextFrame(int frameId){return (frameId + 1 < numFrames ? frameId + 1 : 0);}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user