1er commit
This commit is contained in:
73
src/render/shaders/WorldShader.cpp
Normal file
73
src/render/shaders/WorldShader.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* WorldShader.cpp
|
||||
*
|
||||
* Created on: 4 nov. 2020
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#include "render/shaders/WorldShader.h"
|
||||
|
||||
static const char vertexSource[] = R"(
|
||||
#version 330
|
||||
|
||||
layout(location = 0) in vec2 position;
|
||||
layout(location = 1) in int color;
|
||||
|
||||
uniform vec2 camPos = vec2(0, 0);
|
||||
uniform float zoom = 1;
|
||||
uniform float aspectRatio = 0;
|
||||
uniform float isometricView;
|
||||
|
||||
flat out int pass_color;
|
||||
|
||||
void main(void){
|
||||
float x = (position.x - camPos.x + (position.y - camPos.y) * isometricView) / aspectRatio * zoom;
|
||||
float y = ((-0.5 * (position.x - camPos.x) + 0.5 * (position.y - camPos.y)) * isometricView + (position.y - camPos.y) * (1 - isometricView)) * zoom;
|
||||
pass_color = color;
|
||||
gl_Position = vec4(x, -y, 0.0, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char fragmentSource[] = R"(
|
||||
#version 330
|
||||
|
||||
flat in int pass_color;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
|
||||
float r = float(pass_color >> 24 & 0xFF) / 255.0;
|
||||
float g = float(pass_color >> 16 & 0xFF) / 255.0;
|
||||
float b = float(pass_color >> 8 & 0xFF) / 255.0;
|
||||
float a = float(pass_color & 0xFF) / 255.0;
|
||||
out_color = vec4(r, g, b, a);
|
||||
|
||||
}
|
||||
)";
|
||||
|
||||
WorldShader::WorldShader(): ShaderProgram(){}
|
||||
|
||||
void WorldShader::loadShader(){
|
||||
ShaderProgram::loadProgram(vertexSource, fragmentSource);
|
||||
}
|
||||
|
||||
void WorldShader::getAllUniformLocation(){
|
||||
location_aspect_ratio = getUniformLocation("aspectRatio");
|
||||
location_zoom = getUniformLocation("zoom");
|
||||
location_cam = getUniformLocation("camPos");
|
||||
location_viewtype = getUniformLocation("isometricView");
|
||||
}
|
||||
|
||||
void WorldShader::setCamPos(const glm::vec2& camPos){
|
||||
loadVector(location_cam, camPos);
|
||||
}
|
||||
void WorldShader::setZoom(float zoom){
|
||||
loadFloat(location_zoom, zoom);
|
||||
}
|
||||
void WorldShader::setAspectRatio(float aspectRatio){
|
||||
loadFloat(location_aspect_ratio, aspectRatio);
|
||||
}
|
||||
void WorldShader::setIsometricView(float isometric){
|
||||
loadFloat(location_viewtype, isometric);
|
||||
}
|
||||
Reference in New Issue
Block a user