Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Volumetric light and Composite1!
Browse files Browse the repository at this point in the history
New Screen Space Volumetric Light, New Composite pass to Deferred
Shading.
  • Loading branch information
Guerra24 committed Nov 23, 2015
1 parent b08bd42 commit e8e2128
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 151 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
language: java
jdk:
- oraclejdk8

before_install:
- chmod +x gradlew

install: gradle assemble
script: gradle test
73 changes: 73 additions & 0 deletions assets/shaders/FragmentComposite1.glsl
@@ -0,0 +1,73 @@
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Guerra24
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

#version 330 core

/*--------------------------------------------------------*/
/*--------------COMPOSITE 1 IN-OUT-UNIFORMS---------------*/
/*--------------------------------------------------------*/

in vec2 textureCoords;
in vec4 posPos;

out vec4 out_Color;

uniform vec2 sunPositionInScreen;
uniform sampler2D gData;

/*--------------------------------------------------------*/
/*------------------COMPOSITE 1 CONFIG--------------------*/
/*--------------------------------------------------------*/

/*--------------------------------------------------------*/
/*------------------COMPOSITE 1 CODE----------------------*/
/*--------------------------------------------------------*/


void main(void){
vec2 texcoord = textureCoords;
vec4 image = vec4(0.0);
vec4 data = texture(gData, texcoord);

if(data.b == 1){
if(gl_FragCoord.x <= sunPositionInScreen.x + 60 && gl_FragCoord.x >= sunPositionInScreen.x - 60 && gl_FragCoord.y <= sunPositionInScreen.y + 60 && gl_FragCoord.y >= sunPositionInScreen.y - 60){
image.rgb = mix(image.rgb,vec3(1, 0.870588, 0.678431),0.2);
image.a = 0.2;
}
if(gl_FragCoord.x <= sunPositionInScreen.x + 40 && gl_FragCoord.x >= sunPositionInScreen.x - 40 && gl_FragCoord.y <= sunPositionInScreen.y + 40 && gl_FragCoord.y >= sunPositionInScreen.y - 40){
image.rgb = mix(image.rgb,vec3(1, 0.870588, 0.678431),0.5);
image.a = 0.5;
}
if(gl_FragCoord.x <= sunPositionInScreen.x + 30 && gl_FragCoord.x >= sunPositionInScreen.x - 30 && gl_FragCoord.y <= sunPositionInScreen.y + 30 && gl_FragCoord.y >= sunPositionInScreen.y - 30){
image.rgb = vec3(1, 0.870588, 0.678431);
image.a = 1;
}
if(gl_FragCoord.x <= sunPositionInScreen.x + 20 && gl_FragCoord.x >= sunPositionInScreen.x - 20 && gl_FragCoord.y <= sunPositionInScreen.y + 20 && gl_FragCoord.y >= sunPositionInScreen.y - 20){
image.rgb = vec3(1,1,1);
image.a = 1;
}
}
out_Color = image;

}
Expand Up @@ -36,10 +36,10 @@ out vec4 out_Color;
uniform int camUnderWater;
uniform float camUnderWaterOffset;
uniform vec2 resolution;
uniform vec2 sunPositionInScreen;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform vec3 lightPosition;
uniform vec2 sunPositionInScreen;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 inverseProjectionMatrix;
Expand All @@ -49,12 +49,14 @@ uniform sampler2D gDiffuse;
uniform sampler2D gPosition;
uniform sampler2D gNormal;
uniform sampler2D gData;
uniform sampler2D composite1;
uniform sampler2DShadow gDepth;

uniform int useFXAA;
uniform int useDOF;
uniform int useMotionBlur;
uniform int useBloom;
uniform int useVolumetricLight;

/*--------------------------------------------------------*/
/*----------------DEFERRED SHADING CONFIG-----------------*/
Expand All @@ -71,7 +73,8 @@ uniform int useBloom;

const float bloom_amount = 2;
const int maxf = 4, maxt = 40;
const float stp = 1.2, ref = 0.1, inc = 2.2;
const float stp = 1.2, ref = 0.1, inc = 2.2;
const int NUM_SAMPLES = 50;

#define rt_w resolution.x
#define rt_h resolution.y
Expand Down Expand Up @@ -137,21 +140,17 @@ void main(void){
vec4 position = texture(gPosition,texcoord);
vec4 normal = texture(gNormal, texcoord);
float depth = texture(gDepth, vec3(texcoord.xy, 0.0), 16);

vec3 light = lightPosition;
vec3 lightDir = light - position.xyz ;
lightDir = normalize(lightDir);
vec3 eyeDir = normalize(cameraPosition-position.xyz);
float lightDirDOTviewDir = dot(-lightDir,eyeDir);
if(data.b != 1) {
if(data.g == 1.0){
image.rgb -= vec3(data.a,data.a,data.a);
}

vec3 light = lightPosition;
vec3 lightDir = light - position.xyz ;

normal = normalize(normal);
lightDir = normalize(lightDir);

vec3 eyeDir = normalize(cameraPosition-position.xyz);
vec3 vHalfVector = normalize(lightDir.xyz+eyeDir);

image = max(dot(normal.xyz,lightDir),0.2) * image;

if(data.r == 1.0){
Expand Down Expand Up @@ -189,16 +188,35 @@ void main(void){
fact = 1.0;
else if (cameraToWorldDist > currentWorldDist)
fact = 1.0;
image = image*fact + newColor*(1-fact) + pow(max(dot(normal.xyz,vHalfVector),0.0), 100) * 1.5;
image = image*fact + newColor*(1-fact) + pow(max(dot(normal.xyz,vHalfVector),0.0), 100) * 8;
}
} else if(data.b == 1){
image+=5;
if(gl_FragCoord.x >= sunPositionInScreen.x + 20 || gl_FragCoord.x <= sunPositionInScreen.x - 20)
image-=5;
else
if(gl_FragCoord.y >= sunPositionInScreen.y + 20 || gl_FragCoord.y <= sunPositionInScreen.y - 20)
image-=5;
}
vec4 raysColor = texture(composite1, texcoord);
image.rgb = mix(image.rgb, raysColor.rgb, raysColor.a);
if(useVolumetricLight == 1){
if (lightDirDOTviewDir>0.0){
float exposure = 0.1/NUM_SAMPLES;
float decay = 1.0;
float density = 1;
float weight = 6.0;
float illuminationDecay = 1.0;
vec2 pos = vec2(0.0);
pos.x = (sunPositionInScreen.x) / resolution.x;
pos.y = (sunPositionInScreen.y) / resolution.y;
vec2 deltaTextCoord = vec2( texcoord - pos);
vec2 textCoo = texcoord;
deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
for(int i=0; i < NUM_SAMPLES ; i++) {
textCoo -= deltaTextCoord;
vec4 tsample = texture(composite1, textCoo );
tsample *= illuminationDecay * weight;
raysColor += tsample;
illuminationDecay *= decay;
}
raysColor *= exposure * lightDirDOTviewDir;
image += raysColor;
}
}

if(camUnderWater == 1){
out_Color = mix(vec4(0.0,0.0,0.3125,1.0),image,0.5);
Expand Down
43 changes: 0 additions & 43 deletions assets/shaders/VertexChunk.glsl

This file was deleted.

Expand Up @@ -24,16 +24,13 @@

#version 330 core

in vec3 color;
in vec2 passTexCoords;
in vec2 passTexCoordsOffset;
in vec2 position;

out vec4 out_Color;
out vec2 textureCoords;

uniform sampler2D texture0;

void main(void) {

out_Color = texture(texture0, passTexCoords);
uniform mat4 transformationMatrix;

void main(void){
gl_Position = transformationMatrix * vec4(position, -0.8, 1.0);
textureCoords = vec2((position.x+1.0)/2.0, (position.y+1.0)/2.0);
}
Expand Up @@ -49,4 +49,5 @@ void main(void){
posPos.xy = textureCoords;
posPos.zw = textureCoords - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT));
}

}
11 changes: 6 additions & 5 deletions src/main/java/net/guerra24/voxel/client/core/VoxelVariables.java
Expand Up @@ -44,7 +44,7 @@ public class VoxelVariables {
public static final String version = "0.0.9";
public static final String apiVersion = "0.0.4";
public static final String state = "ALPHA";
public static final int build = 124;
public static final int build = 125;
public static int FOV = 90;
public static int WIDTH = 1280;
public static int HEIGHT = 720;
Expand All @@ -64,6 +64,7 @@ public class VoxelVariables {
public static boolean useHQWater = false;
public static boolean useMotionBlur = false;
public static boolean useBloom = false;
public static boolean useVolumetricLight = true;
public static float fogDensity = 0.02f;
/**
* World Settings
Expand Down Expand Up @@ -96,14 +97,14 @@ public class VoxelVariables {
public static final String FRAGMENT_FILE_WATER = "FragmentWater.glsl";
public static final String VERTEX_FILE_PARTICLE = "VertexParticle.glsl";
public static final String FRAGMENT_FILE_PARTICLE = "FragmentParticle.glsl";
public static final String VERTEX_FILE_POST = "VertexPost.glsl";
public static final String FRAGMENT_FILE_POST = "FragmentPost.glsl";
public static final String VERTEX_FILE_FINAL = "VertexFinal.glsl";
public static final String FRAGMENT_FILE_FINAL = "FragmentFinal.glsl";
public static final String VERTEX_FILE_FONT = "VertexFont.glsl";
public static final String FRAGMENT_FILE_FONT = "FragmentFont.glsl";
public static final String VERTEX_FILE_SHADOW = "VertexShadow.glsl";
public static final String FRAGMENT_FILE_SHADOW = "FragmentShadow.glsl";
public static final String VERTEX_FILE_CHUNK = "VertexChunk.glsl";
public static final String FRAGMENT_FILE_CHUNK = "FragmentChunk.glsl";
public static final String VERTEX_FILE_COMPOSITE1 = "VertexComposite1.glsl";
public static final String FRAGMENT_FILE_COMPOSITE1 = "FragmentComposite1.glsl";
/**
* World Folder Path
*/
Expand Down
Expand Up @@ -29,7 +29,7 @@
import static org.lwjgl.opengl.GL11.GL_LINEAR;
import static org.lwjgl.opengl.GL11.GL_NEAREST;
import static org.lwjgl.opengl.GL11.GL_NONE;
import static org.lwjgl.opengl.GL11.GL_RGB;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_BORDER_COLOR;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
Expand Down Expand Up @@ -124,7 +124,7 @@ private int createFrameBuffer(boolean depth) {
private int createTextureAttachment(int width, int height) {
int texture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (ByteBuffer) null);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0);
Expand Down

0 comments on commit e8e2128

Please sign in to comment.