multiple fixes and shadows shaders are now in files
This commit is contained in:
parent
2b191afd9f
commit
501ec75dd8
@ -3,7 +3,7 @@ uniform vec3 lightColor;
|
||||
uniform float materialNs;
|
||||
uniform uint objectId;
|
||||
|
||||
#ifdef INSTANCING
|
||||
#ifdef INSTANCED
|
||||
flat in int instanceId;
|
||||
#endif
|
||||
|
||||
@ -118,7 +118,7 @@ void main(void) {
|
||||
outColor = vec4(light*shadow*(1+cos(1.57 + att*1.57)), 1);
|
||||
#endif
|
||||
|
||||
#ifdef INSTANCING
|
||||
#ifdef INSTANCED
|
||||
pickData = vec3(gl_FragCoord.z, gl_FragCoord.w, float(int(objectId) + instanceId));
|
||||
#else
|
||||
pickData = vec3(gl_FragCoord.z, gl_FragCoord.w, float(objectId));
|
||||
|
@ -27,7 +27,7 @@ layout(location = 3)in vec3 inTangent;
|
||||
layout(location = 4)in vec3 inBinormal;
|
||||
#endif
|
||||
|
||||
#ifdef INSTANCING
|
||||
#ifdef INSTANCED
|
||||
layout(location = 5)in vec3 inInstanceOffset;
|
||||
|
||||
flat out int instanceId;
|
||||
@ -48,7 +48,7 @@ out vec4 posInLightSpace;
|
||||
#endif
|
||||
|
||||
void main(void) {
|
||||
#ifdef INSTANCING
|
||||
#ifdef INSTANCED
|
||||
instanceId = gl_InstanceID;
|
||||
vec4 pos = vec4(inPosition + inInstanceOffset, 1.0);
|
||||
#else
|
||||
|
15
shaders/shadow.frag.glsl
Normal file
15
shaders/shadow.frag.glsl
Normal file
@ -0,0 +1,15 @@
|
||||
#ifdef ALPHA_MASK
|
||||
uniform sampler2D alphaMask;
|
||||
in vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
out float fragmentdepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef ALPHA_MASK
|
||||
if(texture(alphaMask, varTexCoord).r < 0.5)
|
||||
discard;
|
||||
#endif
|
||||
fragmentdepth = gl_FragCoord.z;
|
||||
}
|
16
shaders/shadow.vert.glsl
Normal file
16
shaders/shadow.vert.glsl
Normal file
@ -0,0 +1,16 @@
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
|
||||
#ifdef ALPHA_MASK
|
||||
layout(location = 2) in vec2 inTexCoord;
|
||||
out vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef ALPHA_MASK
|
||||
varTexCoord = inTexCoord.xy;
|
||||
#endif
|
||||
gl_Position = MVP * vec4(inPosition, 1.0);
|
||||
}
|
17
src/buffer.h
17
src/buffer.h
@ -52,7 +52,7 @@ public:
|
||||
glBindBuffer(m_typeEnum, 0);
|
||||
}
|
||||
|
||||
T* getPointer();
|
||||
T* getPointer() { return ptr; }
|
||||
};
|
||||
|
||||
TBuffer(const std::vector<T> &data, BufferType type, bool isDynamic = false) :
|
||||
@ -105,19 +105,20 @@ private:
|
||||
|
||||
GLenum getGLEnum()
|
||||
{
|
||||
GLenum typeEnum;
|
||||
GLenum typeEnum;
|
||||
|
||||
switch(m_type)
|
||||
{
|
||||
default:
|
||||
case VBO :
|
||||
typeEnum = GL_ARRAY_BUFFER;
|
||||
break;
|
||||
typeEnum = GL_ARRAY_BUFFER;
|
||||
break;
|
||||
case EBO :
|
||||
typeEnum = GL_ELEMENT_ARRAY_BUFFER;
|
||||
break;
|
||||
typeEnum = GL_ELEMENT_ARRAY_BUFFER;
|
||||
break;
|
||||
case UBO :
|
||||
typeEnum = GL_UNIFORM_BUFFER;
|
||||
break;
|
||||
typeEnum = GL_UNIFORM_BUFFER;
|
||||
break;
|
||||
}
|
||||
|
||||
return typeEnum;
|
||||
|
@ -48,7 +48,7 @@ void Chunk::generate(glm::vec3 pos)
|
||||
// calling terrainFunction only once per cube corner
|
||||
float* top = new float[162];
|
||||
float* bottom = top + 81;
|
||||
//INFO: 9*9*9*3 = 2187 (only 9*9*8*3 = 1944 are used, but the hash algorithm is easier to write with 2187 ids)
|
||||
// INFO: 9*9*9*3 = 2187 (only 9*9*8*3 = 1944 are used, but the hash algorithm is easier to write with 2187 ids)
|
||||
m_vertexHashTable = new short[2187];
|
||||
glm::ivec3 p;
|
||||
|
||||
|
@ -59,4 +59,29 @@ private:
|
||||
int height;
|
||||
};
|
||||
|
||||
class PassScheduler
|
||||
{
|
||||
struct Pass
|
||||
{
|
||||
Shader* shader;
|
||||
const std::vector<GeometryNode*> &geometry;
|
||||
const std::vector<Light*> &lights;
|
||||
|
||||
Pass(Shader *myShader,
|
||||
const std::vector<GeometryNode*> &geomIt,
|
||||
const std::vector<Light*> &lightIt) :
|
||||
shader(myShader),
|
||||
geometry(geomIt),
|
||||
lights(lightIt)
|
||||
{}
|
||||
};
|
||||
|
||||
std::unordered_map<unsigned int, std::vector<GeometryNode*>> geometry;
|
||||
std::unordered_map<unsigned int, std::vector<Light*>> lights;
|
||||
ShaderSource* shaderSources;
|
||||
|
||||
public:
|
||||
void compileShaders(Scene *scene, std::vector<Pass> &passes);
|
||||
};
|
||||
|
||||
#endif // FORWARDMODULE_H
|
||||
|
@ -6,9 +6,11 @@
|
||||
#include "shadersource.h"
|
||||
#include "phongmaterial.h"
|
||||
#include "mesh.h"
|
||||
|
||||
#include <resource.h>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
RESOURCE_PACK(shaders)
|
||||
|
||||
const char* Light::flagStr[] = {
|
||||
"AMBIENT_LIGHT",
|
||||
"DIRECTIONNAL_LIGHT",
|
||||
@ -97,8 +99,10 @@ void Light::initShadowMap(int resWidth, int resHeight, glm::vec3 dim)
|
||||
shadowMap->initColorAttachments();
|
||||
|
||||
ShaderSource source;
|
||||
source.setSource(shadowVertSource, ShaderSource::VERTEX);
|
||||
source.setSource(shadowFragSource, ShaderSource::FRAGMENT);
|
||||
Resource::ResourceMap shaderMap;
|
||||
Resource::getResourcePack_shaders(shaderMap);
|
||||
source.setSource(shaderMap["shaders/shadow.vert.glsl"], ShaderSource::VERTEX);
|
||||
source.setSource(shaderMap["shaders/shadow.frag.glsl"], ShaderSource::FRAGMENT);
|
||||
shaders[0] = source.compile(Mesh::MESH_3D, getFlags());
|
||||
shaders[1] = source.compile(Mesh::MESH_3D & Mesh::MATERIAL_ALPHA_MASK, getFlags());
|
||||
}
|
||||
@ -163,33 +167,3 @@ unsigned int Light::getFlags()
|
||||
flags |= 1 << SHADOWMAP_FLAG;
|
||||
return flags;
|
||||
}
|
||||
|
||||
const char* Light::shadowVertSource =
|
||||
"layout(location = 0)in vec3 inPosition;\n\
|
||||
#ifdef ALPHA_MASK\n\
|
||||
layout(location = 2)in vec2 inTexCoord;\n\
|
||||
out vec2 varTexCoord;\n\
|
||||
#endif\n\
|
||||
uniform mat4 MVP;\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
#ifdef ALPHA_MASK\n\
|
||||
varTexCoord = inTexCoord.xy;\n\
|
||||
#endif\n\
|
||||
gl_Position = MVP * vec4(inPosition, 1.0);\n\
|
||||
}\n";
|
||||
|
||||
const char* Light::shadowFragSource =
|
||||
"#ifdef ALPHA_MASK\n\
|
||||
uniform sampler2D alphaMask;\n\
|
||||
in vec2 varTexCoord;\n\
|
||||
#endif\n\
|
||||
out float fragmentdepth;\n\
|
||||
void main()\n\
|
||||
{\n\
|
||||
#ifdef ALPHA_MASK\n\
|
||||
if(texture(alphaMask, varTexCoord).r < 0.5)\n\
|
||||
discard;\n\
|
||||
#endif\n\
|
||||
fragmentdepth = gl_FragCoord.z;\n\
|
||||
}\n";
|
||||
|
@ -84,8 +84,6 @@ private:
|
||||
Shader* shaders[2];
|
||||
glm::mat4 viewMatrix;
|
||||
glm::mat4 projectionMatrix;
|
||||
static const char* shadowVertSource;
|
||||
static const char* shadowFragSource;
|
||||
};
|
||||
|
||||
#endif // LIGHT_H
|
||||
|
@ -173,6 +173,11 @@ void Shader::bindMat4(GLuint location, glm::mat4 mat)
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(mat));
|
||||
}
|
||||
|
||||
void Shader::bindVec2(GLuint location, glm::vec2 vec)
|
||||
{
|
||||
glUniform2fv(location, 1, glm::value_ptr(vec));
|
||||
}
|
||||
|
||||
void Shader::bindVec3(GLuint location, glm::vec3 vec)
|
||||
{
|
||||
glUniform3fv(location, 1, glm::value_ptr(vec));
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
void bindFloat(GLuint location, float val);
|
||||
void bindMat3(GLuint location, glm::mat3 mat);
|
||||
void bindMat4(GLuint location, glm::mat4 mat);
|
||||
void bindVec2(GLuint location, glm::vec2 vec);
|
||||
void bindVec3(GLuint location, glm::vec3 vec);
|
||||
void bindVec4(GLuint location, glm::vec4 vec);
|
||||
void bindVec3Array(GLuint location, glm::vec3* vec, int nb_elements);
|
||||
|
Loading…
x
Reference in New Issue
Block a user