Browse Source

Simple GLSL Depth fog

testing
= 3 years ago
parent
commit
3fb6df22ca

+ 1
- 1
res/config.conf View File

@@ -5,7 +5,7 @@ graphics {
x = 1600 ; horizontal resolution
y = 900 ; vertical resolution
}
fov = 90.0
fov = 90
vsync = 1
}


+ 0
- 1
res/shaders/skybox.vert View File

@@ -1,7 +1,6 @@
#version 150

in vec3 position;
in vec3 color;

out vec4 wSpacePos;


+ 18
- 0
res/shaders/voxelfrag.frag.glsl View File

@@ -3,12 +3,30 @@

in vec3 texCoordInterp;
in vec3 lightDataInterp;
in vec4 eyeSpacePos;

out vec4 outColor;

uniform sampler2DArray texture;

const vec4 fogColor = vec4(0.46f, 0.8f, 0.99f, 1.0f);
const float fogDensity = 0.005f;

float getFogFactor(float fogCoord) {
//get factor
float fResult = 0.0f;
fResult = exp(-fogDensity*fogCoord);
fResult = 1.0-clamp(fResult, 0.0, 1.0);
return fResult;
}

void main() {
//fog calculations

vec4 texel = texture2DArray(texture, texCoordInterp);
outColor = texel * vec4(lightDataInterp, 1.0f);

float fogCoord = abs(eyeSpacePos.z/eyeSpacePos.w);
outColor = mix(outColor, fogColor, getFogFactor(fogCoord));
}

+ 4
- 1
res/shaders/voxelvert.vert.glsl View File

@@ -8,9 +8,12 @@ uniform mat4 proj, view, model; //transform matrix

out vec3 texCoordInterp;
out vec3 lightDataInterp;
out vec4 eyeSpacePos;

void main() {
gl_Position = proj * view * model * vec4(position, 1.0);
vec4 eyeSpacePosVert = view * model * vec4(position, 1.0);
gl_Position = proj * eyeSpacePosVert;
texCoordInterp = texCoord;
lightDataInterp = lightData;
eyeSpacePos = eyeSpacePosVert;
}

+ 2
- 2
src/scenes/testscene.cpp View File

@@ -124,9 +124,9 @@ void TestScene::init() {
std::cout << std::endl;

int chunkCount = 1;
for (int i = 0; i < 20; i++) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 8; j++) {
for (int k = 0; k < 20; k++) {
for (int k = 0; k < 10; k++) {
std::cout << "\rGenerating chunks (" << chunkCount << "/" << 8*8*8 << ")" << std::flush;
world.generateChunk(i,j,k);
chunkCount++;

+ 1
- 1
src/window.cpp View File

@@ -59,7 +59,7 @@ void Window::setFOV(const float& angle) {
}

glm::mat4 Window::getProjectionMatrix() {
return glm::perspective(fov, getAspect(), 0.1f, 1000.0f);
return glm::perspective(glm::radians(fov), getAspect(), 0.1f, 500.0f);
}

}

Loading…
Cancel
Save