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

Commit

Permalink
Shadows fully implemented in Tessellator. Fixes in main loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed Dec 11, 2015
1 parent abda0d8 commit 4c88c6d
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 148 deletions.
6 changes: 3 additions & 3 deletions assets/game/settings.conf
@@ -1,7 +1,7 @@
#Voxel Settings
#Thu Dec 10 13:59:14 CST 2015
#Thu Dec 10 20:28:56 CST 2015
useHQWater=false
TESTXMOD=Hello Voxel
useShadows=true
useFXAA=false
useShadows=false
useVolumetricLight=false
useVolumetricLight=true
4 changes: 3 additions & 1 deletion assets/shaders/FragmentComposite2.glsl
Expand Up @@ -92,7 +92,9 @@ void main(void){
if(data.b != 1) {
normal = normalize(normal);
vec3 vHalfVector = normalize(lightDir.xyz+eyeDir);
image = ((max(dot(normal.xyz,lightDir),0.2) + data1.a) - data.a) * image;
float b = ((max(dot(normal.xyz,lightDir),0.2) + data1.a) - data.a);
b = clamp(b,0.2,1.0);
image = b * image;
if(data.r == 1){
if(data.a <= 0)
image += pow(max(dot(normal.xyz,vHalfVector),0.0), 100) * 8;
Expand Down
35 changes: 32 additions & 3 deletions assets/shaders/FragmentTessellator.glsl
Expand Up @@ -28,25 +28,54 @@ in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec4 pass_position;
in vec4 pass_Data;
in vec4 ShadowCoord;

out vec4 [5] out_Color;

uniform sampler2D texture0;
uniform sampler2DShadow depth;

vec2 poissonDisk[16] = vec2[](
vec2( -0.94201624, -0.39906216 ),
vec2( 0.94558609, -0.76890725 ),
vec2( -0.094184101, -0.92938870 ),
vec2( 0.34495938, 0.29387760 ),
vec2( -0.91588581, 0.45771432 ),
vec2( -0.81544232, -0.87912464 ),
vec2( -0.38277543, 0.27676845 ),
vec2( 0.97484398, 0.75648379 ),
vec2( 0.44323325, -0.97511554 ),
vec2( 0.53742981, -0.47373420 ),
vec2( -0.26496911, -0.41893023 ),
vec2( 0.79197514, 0.19090188 ),
vec2( -0.24188840, 0.99706507 ),
vec2( -0.81409955, 0.91437590 ),
vec2( 0.19984126, 0.78641367 ),
vec2( 0.14383161, -0.14100790 )
);

void main(void) {
vec4 data = pass_Data;
float id = data.x;
float bright = data.y;
int id = int(data.x + 0.5f);

float shadow = -0.4;
float bias = 0.0001;
for (int i=0;i<16;i++){
if (texture(depth, vec3(ShadowCoord.xy + poissonDisk[i]/1600.0 , 128.0), 0) < ShadowCoord.z-bias ){
shadow += 0.05;
}
}

vec4 textureColour = texture(texture0, pass_textureCoords);
if(textureColour.a < 0.5)
discard;
out_Color[0] = textureColour;
out_Color[1] = vec4(pass_position.xyz,0);
out_Color[2] = vec4(surfaceNormal.xyz,0);
out_Color[3] = vec4(0.0, 0.0, 0.0, 0.0);
out_Color[3] = vec4(0.0,1.0,0.0,shadow);
out_Color[4] = vec4(0.0, 0.0, 0.0, bright);
if(abs(id - 13) < 0.01 || abs(id - 8) < 0.01)
if(id == 8 || id == 13)
out_Color[3].r = 1.0;

}
28 changes: 28 additions & 0 deletions assets/shaders/FragmentTessellatorShadow.glsl
@@ -0,0 +1,28 @@
//
// 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

void main(void) {
}
8 changes: 8 additions & 0 deletions assets/shaders/VertexTessellator.glsl
Expand Up @@ -33,10 +33,14 @@ out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec4 pass_position;
out vec4 pass_Data;
out vec4 ShadowCoord;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 cameraPos;
uniform mat4 projectionLightMatrix;
uniform mat4 viewLightMatrix;
uniform mat4 biasMatrix;

void main() {
vec3 pos = position - cameraPos;
Expand All @@ -47,4 +51,8 @@ void main() {
pass_position = vec4(position, 1.0);
surfaceNormal = normal;
pass_Data = data;

vec4 posLight = viewLightMatrix * vec4(position, 1.0);
vec4 a = projectionLightMatrix * posLight;
ShadowCoord = biasMatrix * a;
}
38 changes: 38 additions & 0 deletions assets/shaders/VertexTessellatorShadow.glsl
@@ -0,0 +1,38 @@
//
// 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

in vec3 position;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 cameraPos;

void main() {
vec3 pos = position - cameraPos;
vec4 worldPosition = vec4(pos, 1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;
}
86 changes: 0 additions & 86 deletions src/main/java/net/guerra24/voxel/client/core/UpdateThread.java

This file was deleted.

21 changes: 11 additions & 10 deletions src/main/java/net/guerra24/voxel/client/core/Voxel.java
Expand Up @@ -56,8 +56,6 @@ public class Voxel {
/**
* Game Threads
*/
public static UpdateThread worldThread2;

/**
* Game Data
*/
Expand Down Expand Up @@ -122,13 +120,10 @@ private void init() {
worldsHandler.setActiveWorld("Infinity");
Logger.log("Initializing Threads");
/*
* worldThread2 = new UpdateThread(this); worldThread2.setName(
* "Voxel World 1"); worldThread2.start();
*//*
* new Thread(new Runnable() { public void run() {
* Thread.currentThread().setName("Voxel-Client"); client = new
* DedicatedClient(gameResources); } }).start();
*/api.getMoltenAPI().setMobManager(gameResources.getPhysics().getMobManager());
* new Thread(new Runnable() { public void run() {
* Thread.currentThread().setName("Voxel-Client"); client = new
* DedicatedClient(gameResources); } }).start();
*/api.getMoltenAPI().setMobManager(gameResources.getPhysics().getMobManager());
try {
api.init();
} catch (VersionException e) {
Expand Down Expand Up @@ -164,6 +159,8 @@ public void mainLoop() {
init();
postInit();
float delta = 0;
float accumulator = 0f;
float interval = 1f / VoxelVariables.UPS;
while (gameResources.getGlobalStates().loop) {
if (Display.timeCountRender > 1f) {
Logger.log("FPS: " + Display.fps);
Expand All @@ -176,7 +173,11 @@ public void mainLoop() {
Display.timeCountRender -= 1f;
}
delta = Display.getDeltaRender();
update(delta);
accumulator += delta;
while (accumulator >= interval) {
update(interval);
accumulator -= interval;
}
render(delta);
}
dispose();
Expand Down
Expand Up @@ -35,6 +35,7 @@ public class VoxelVariables {
* Display Data
*/
public static int FPS = 60;
public static int UPS = 30;
public static boolean VSYNC = false;
public static final String Title = "Voxel";
/**
Expand Down Expand Up @@ -110,6 +111,8 @@ public class VoxelVariables {
public static final String FRAGMENT_FILE_COMPOSITE = "FragmentComposite";
public static final String VERTEX_FILE_TESSELLATOR = "VertexTessellator.glsl";
public static final String FRAGMENT_FILE_TESSELLATOR = "FragmentTessellator.glsl";
public static final String VERTEX_FILE_TESSELLATOR_SHADOW = "VertexTessellatorShadow.glsl";
public static final String FRAGMENT_FILE_TESSELLATOR_SHADOW = "FragmentTessellatorShadow.glsl";
/**
* World Folder Path
*/
Expand Down
Expand Up @@ -81,6 +81,7 @@ public void render(Voxel voxel, GlobalStates states, float delta) {

gm.getRenderer().prepare();
gm.getDeferredShadingRenderer().render(gm);

}

}

0 comments on commit 4c88c6d

Please sign in to comment.