GLM-related Shader.uniformNf overloads

This commit is contained in:
MihailRis
2023-11-16 21:32:55 +03:00
parent 47e24cb468
commit bcecdc9b60
4 changed files with 22 additions and 5 deletions
+8 -4
View File
@@ -85,10 +85,10 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
shader->uniformMatrix("u_view", camera->getView()); shader->uniformMatrix("u_view", camera->getView());
shader->uniform1f("u_gamma", 1.6f); shader->uniform1f("u_gamma", 1.6f);
shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f); shader->uniform3f("u_skyLightColor", 1.1f,1.1f,1.1f);
shader->uniform3f("u_fogColor", skyColor.r,skyColor.g,skyColor.b); shader->uniform3f("u_fogColor", skyColor);
shader->uniform1f("u_fogFactor", fogFactor); shader->uniform1f("u_fogFactor", fogFactor);
shader->uniform1f("u_fogCurve", fogCurve); shader->uniform1f("u_fogCurve", fogCurve);
shader->uniform3f("u_cameraPos", camera->position.x,camera->position.y,camera->position.z); shader->uniform3f("u_cameraPos", camera->position);
Block* cblock = Block::blocks[level->player->choosenBlock]; Block* cblock = Block::blocks[level->player->choosenBlock];
float multiplier = 0.2f; float multiplier = 0.2f;
@@ -146,8 +146,12 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
float length = 40.f; float length = 40.f;
linesShader->use(); linesShader->use();
glm::mat4 model(glm::translate(glm::mat4(1.f), vec3(Window::width >> 1, -static_cast<int>(Window::height) >> 1, 0.f))); vec3 tsl = vec3(Window::width/2, -((int)Window::height)/2, 0.f);
linesShader->uniformMatrix("u_projview", glm::ortho(0.f, static_cast<float>(Window::width), -static_cast<float>(Window::height), 0.f, -length, length) * model * glm::inverse(camera->rotation)); glm::mat4 model(glm::translate(glm::mat4(1.f), tsl));
linesShader->uniformMatrix("u_projview", glm::ortho(
0.f, (float)Window::width,
-(float)Window::height, 0.f,
-length, length) * model * glm::inverse(camera->rotation));
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
+9
View File
@@ -41,11 +41,20 @@ void Shader::uniform2f(std::string name, float x, float y){
glUniform2f(transformLoc, x, y); glUniform2f(transformLoc, x, y);
} }
void Shader::uniform2f(std::string name, glm::vec2 xy){
GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform2f(transformLoc, xy.x, xy.y);
}
void Shader::uniform3f(std::string name, float x, float y, float z){ void Shader::uniform3f(std::string name, float x, float y, float z){
GLuint transformLoc = glGetUniformLocation(id, name.c_str()); GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform3f(transformLoc, x,y,z); glUniform3f(transformLoc, x,y,z);
} }
void Shader::uniform3f(std::string name, glm::vec3 xyz){
GLuint transformLoc = glGetUniformLocation(id, name.c_str());
glUniform3f(transformLoc, xyz.x, xyz.y, xyz.z);
}
Shader* load_shader(std::string vertexFile, std::string fragmentFile) { Shader* load_shader(std::string vertexFile, std::string fragmentFile) {
+2
View File
@@ -16,7 +16,9 @@ public:
void uniform1i(std::string name, int x); void uniform1i(std::string name, int x);
void uniform1f(std::string name, float x); void uniform1f(std::string name, float x);
void uniform2f(std::string name, float x, float y); void uniform2f(std::string name, float x, float y);
void uniform2f(std::string name, glm::vec2 xy);
void uniform3f(std::string name, float x, float y, float z); void uniform3f(std::string name, float x, float y, float z);
void uniform3f(std::string name, glm::vec3 xyz);
}; };
extern Shader* load_shader(std::string vertexFile, std::string fragmentFile); extern Shader* load_shader(std::string vertexFile, std::string fragmentFile);
+3 -1
View File
@@ -108,7 +108,9 @@ bool ChunksController::loadVisible(){
for (size_t i = 0; i < CHUNK_VOL; i++) { for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = chunk->voxels[i].id; blockid_t id = chunk->voxels[i].id;
if (Block::blocks[id] == nullptr) { if (Block::blocks[id] == nullptr) {
std::cout << "corruped block detected at " << i << " of chunk " << chunk->x << "x" << chunk->z << " -> " << (int)id << std::endl; std::cout << "corruped block detected at " << i << " of chunk ";
std::cout << chunk->x << "x" << chunk->z;
std::cout << " -> " << (int)id << std::endl;
chunk->voxels[i].id = 11; chunk->voxels[i].id = 11;
} }
} }