skybox reflects time of day
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
b70febb678
commit
7ce1ffa359
@ -3,90 +3,45 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
#extension GL_ARB_shading_language_include : require
|
#extension GL_ARB_shading_language_include : require
|
||||||
#include "../../lib/standarduniform.fs"
|
#include "../../lib/standarduniform.fs"
|
||||||
|
#include "../../lib/math.fs"
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Bind points for different SSBOs
|
|
||||||
*/
|
|
||||||
#define DIRECT_LIGHT_SSBO_BIND_POINT 3
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
transparency
|
transparency
|
||||||
*/
|
*/
|
||||||
#define SMALL_EPSILON 0.001
|
#define SMALL_EPSILON 0.001
|
||||||
|
|
||||||
/**
|
#define EASING_POWER 5
|
||||||
The direct global light
|
|
||||||
*/
|
|
||||||
struct DirectLight {
|
|
||||||
vec3 direction;
|
|
||||||
vec3 color;
|
|
||||||
vec3 ambientColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
layout(std430, binding = DIRECT_LIGHT_SSBO_BIND_POINT) restrict buffer dirLightSSBO {
|
|
||||||
DirectLight directLight;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Material {
|
|
||||||
sampler2D diffuse;
|
|
||||||
sampler2D specular;
|
|
||||||
float shininess;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
in vec3 FragPos;
|
in vec3 FragPos;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
in vec2 TexCoord;
|
|
||||||
in vec4 FragPosLightSpace;
|
|
||||||
|
|
||||||
uniform vec3 viewPos;
|
uniform vec3 viewPos;
|
||||||
uniform Material material;
|
|
||||||
|
|
||||||
//texture stuff
|
|
||||||
// uniform sampler2D ourTexture;
|
|
||||||
uniform int hasTransparency;
|
|
||||||
// uniform sampler2D specularTexture;
|
|
||||||
|
|
||||||
//light depth map
|
//light depth map
|
||||||
uniform sampler2D shadowMap;
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
// function prototypes
|
out vec4 FragColor;
|
||||||
float calcLightIntensityTotal(vec3 normal);
|
|
||||||
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
if(hasTransparency == 1){
|
|
||||||
if(texture(material.diffuse, TexCoord).a < 0.1){
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vec4 textureColor = texture(material.diffuse, TexCoord);
|
|
||||||
|
|
||||||
//grab light intensity
|
//grab light intensity
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
|
||||||
|
//colors for different times of day
|
||||||
|
vec3 color1 = vec3(0,0,0);
|
||||||
|
vec3 color2= vec3(0.68,0.93,0.93);
|
||||||
|
|
||||||
|
//calculate color
|
||||||
|
float timeOfDay = standardUniforms.timeOfDay;
|
||||||
|
vec3 skyColor = mix(
|
||||||
|
color1,
|
||||||
|
color2,
|
||||||
|
abs((0.5 - timeOfDay)) * 2
|
||||||
|
);
|
||||||
|
|
||||||
//calculate final color
|
//calculate final color
|
||||||
vec3 finalColor = textureColor.rgb * lightIntensity;
|
vec3 finalColor = skyColor;//norm.rgb;
|
||||||
FragColor = vec4(finalColor, textureColor.a);
|
FragColor = vec4(finalColor, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float calcLightIntensityAmbient(){
|
|
||||||
//calculate average of ambient light
|
|
||||||
float avg = (directLight.color.x + directLight.color.y + directLight.color.z)/3.0;
|
|
||||||
return avg;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
float calcLightIntensityTotal(vec3 normal){
|
|
||||||
//ambient intensity
|
|
||||||
float ambientLightIntensity = calcLightIntensityAmbient();
|
|
||||||
|
|
||||||
//sum
|
|
||||||
float total = ambientLightIntensity;
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
@ -18,9 +18,6 @@ uniform mat4 model;
|
|||||||
//output buffers
|
//output buffers
|
||||||
out vec3 Normal;
|
out vec3 Normal;
|
||||||
out vec3 FragPos;
|
out vec3 FragPos;
|
||||||
out vec3 ViewFragPos;
|
|
||||||
out vec2 TexCoord;
|
|
||||||
out vec4 FragPosLightSpace;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -30,16 +27,18 @@ void main() {
|
|||||||
vec4 FinalVertex = vec4(aPos, 1.0);
|
vec4 FinalVertex = vec4(aPos, 1.0);
|
||||||
vec4 FinalNormal = vec4(aNormal, 1.0);
|
vec4 FinalNormal = vec4(aNormal, 1.0);
|
||||||
|
|
||||||
|
//time-of-day normal rotation
|
||||||
|
float angle = 3.14 * standardUniforms.timeOfDay;
|
||||||
|
mat4 rotationAboutZ = mat4(
|
||||||
|
vec4( cos(angle), -sin(angle), 0.0, 0.0 ),
|
||||||
|
vec4( sin(angle), cos(angle), 0.0, 0.0 ),
|
||||||
|
vec4( 0.0, 0.0, 1.0, 0.0 ),
|
||||||
|
vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
||||||
|
|
||||||
|
|
||||||
//push frag, normal, and texture positions to fragment shader
|
//push frag, normal, and texture positions to fragment shader
|
||||||
FragPos = vec3(model * FinalVertex);
|
FragPos = vec3(model * FinalVertex);
|
||||||
ViewFragPos = vec3(standardUniforms.view * model * FinalVertex);
|
Normal = mat3(transpose(inverse(model))) * mat3(rotationAboutZ) * aNormal;
|
||||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
|
||||||
TexCoord = aTex;
|
|
||||||
|
|
||||||
|
|
||||||
//shadow map stuff
|
|
||||||
FragPosLightSpace = standardUniforms.lightSpaceMatrix * vec4(FragPos, 1.0);
|
|
||||||
|
|
||||||
|
|
||||||
//set final position with opengl space
|
//set final position with opengl space
|
||||||
|
|||||||
18
assets/Shaders/lib/math.fs
Normal file
18
assets/Shaders/lib/math.fs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Standard math functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eases in a value at a given power
|
||||||
|
*/
|
||||||
|
float easeInPow(float value, int power){
|
||||||
|
return pow(value,power);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eases in a value at a given power
|
||||||
|
*/
|
||||||
|
float easeOutPow(float value, int power){
|
||||||
|
return 1.0f - pow(value,power);
|
||||||
|
}
|
||||||
@ -32,6 +32,10 @@ struct StandardUniforms {
|
|||||||
* The current engine time
|
* The current engine time
|
||||||
*/
|
*/
|
||||||
float time;
|
float time;
|
||||||
|
/**
|
||||||
|
* The time of day of the engine (range 0->1)
|
||||||
|
*/
|
||||||
|
float timeOfDay;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2082,6 +2082,7 @@ Bounding sphere work
|
|||||||
Don't allocate contact joints for geom-geom
|
Don't allocate contact joints for geom-geom
|
||||||
Remove potential collision engine footgun
|
Remove potential collision engine footgun
|
||||||
Synchronized time-of-day between server and client
|
Synchronized time-of-day between server and client
|
||||||
|
Skybox reflects time of day
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -60,5 +60,13 @@ public class ClientTemporalService extends SignalServiceImpl {
|
|||||||
this.latestServerData = serverData;
|
this.latestServerData = serverData;
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time of day of the service
|
||||||
|
* @return The time of day of the service
|
||||||
|
*/
|
||||||
|
public float getTime(){
|
||||||
|
return (float)((double)clientTemporalData.getTime() / (double)MacroTemporalData.TIME_PER_DAY) % 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public class MacroTemporalData {
|
|||||||
/**
|
/**
|
||||||
* Amount of time per day
|
* Amount of time per day
|
||||||
*/
|
*/
|
||||||
public static final long TIME_PER_DAY = 60 * 60 * 30;
|
public static final long TIME_PER_DAY = 60 * 60 * 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The noon remainder amount
|
* The noon remainder amount
|
||||||
|
|||||||
@ -108,4 +108,10 @@ public class AssetDataStrings {
|
|||||||
*/
|
*/
|
||||||
public static final String MODEL_WAYPOINT = "Models/engine/waypoint.glb";
|
public static final String MODEL_WAYPOINT = "Models/engine/waypoint.glb";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Skybox
|
||||||
|
*/
|
||||||
|
public static final String SHADER_SKYBOX_VERT = "Shaders/entities/skysphere/skysphere.vs";
|
||||||
|
public static final String SHADER_SKYBOX_FRAG = "Shaders/entities/skysphere/skysphere.fs";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import electrosphere.controls.ControlHandler;
|
|||||||
import electrosphere.controls.cursor.CursorState;
|
import electrosphere.controls.cursor.CursorState;
|
||||||
import electrosphere.engine.EngineState;
|
import electrosphere.engine.EngineState;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.engine.assetmanager.AssetDataStrings;
|
||||||
import electrosphere.engine.signal.Signal.SignalType;
|
import electrosphere.engine.signal.Signal.SignalType;
|
||||||
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
|
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
|
||||||
import electrosphere.entity.DrawableUtils;
|
import electrosphere.entity.DrawableUtils;
|
||||||
@ -30,6 +31,7 @@ import electrosphere.net.NetUtils;
|
|||||||
import electrosphere.net.client.ClientNetworking;
|
import electrosphere.net.client.ClientNetworking;
|
||||||
import electrosphere.net.parser.net.message.CharacterMessage;
|
import electrosphere.net.parser.net.message.CharacterMessage;
|
||||||
import electrosphere.net.parser.net.message.LoreMessage;
|
import electrosphere.net.parser.net.message.LoreMessage;
|
||||||
|
import electrosphere.renderer.meshgen.GeometryMeshGen;
|
||||||
|
|
||||||
public class ClientLoading {
|
public class ClientLoading {
|
||||||
|
|
||||||
@ -49,6 +51,21 @@ public class ClientLoading {
|
|||||||
*/
|
*/
|
||||||
private static final int MAX_DRAW_CELL_WAIT = 1000;
|
private static final int MAX_DRAW_CELL_WAIT = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slices in skysphere
|
||||||
|
*/
|
||||||
|
private static final int SKYSPHERE_SLICES = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stack in skysphere
|
||||||
|
*/
|
||||||
|
private static final int SKYSPHERE_STACKS = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale of skysphere
|
||||||
|
*/
|
||||||
|
private static final float SKYSPHERE_SCALE = 5000.0f;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the race data from the server
|
* Loads the race data from the server
|
||||||
@ -257,15 +274,19 @@ public class ClientLoading {
|
|||||||
* Skybox
|
* Skybox
|
||||||
*/
|
*/
|
||||||
Entity skybox = EntityCreationUtils.createClientSpatialEntity();
|
Entity skybox = EntityCreationUtils.createClientSpatialEntity();
|
||||||
EntityCreationUtils.makeEntityDrawable(skybox, "Models/environment/skyboxSphere.fbx");
|
DrawableUtils.makeEntityDrawable(skybox, () -> {
|
||||||
|
return GeometryMeshGen.genSphere(SKYSPHERE_SLICES, SKYSPHERE_STACKS);
|
||||||
|
});
|
||||||
DrawableUtils.disableCulling(skybox);
|
DrawableUtils.disableCulling(skybox);
|
||||||
EntityUtils.getRotation(skybox).rotateX((float)(-Math.PI/2.0f));
|
EntityUtils.getScale(skybox).mul(SKYSPHERE_SCALE);
|
||||||
EntityUtils.getScale(skybox).mul(600000.0f);
|
|
||||||
Globals.clientState.clientScene.registerBehaviorTree(() -> {
|
Globals.clientState.clientScene.registerBehaviorTree(() -> {
|
||||||
EntityUtils.getPosition(skybox).set(EntityUtils.getPosition(Globals.clientState.playerEntity));
|
EntityUtils.getPosition(skybox).set(EntityUtils.getPosition(Globals.clientState.playerEntity));
|
||||||
});
|
});
|
||||||
Globals.assetManager.queueOverrideMeshShader("Models/environment/skyboxSphere.fbx", "Sphere", "Shaders/entities/skysphere/skysphere.vs", "Shaders/entities/skysphere/skysphere.fs");
|
Globals.assetManager.queueOverrideMeshShader(EntityUtils.getActor(skybox).getBaseModelPath(), GeometryMeshGen.SPHERE_MESH_NAME, AssetDataStrings.SHADER_SKYBOX_VERT, AssetDataStrings.SHADER_SKYBOX_FRAG);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cursors
|
||||||
|
*/
|
||||||
CursorState.createCursorEntities();
|
CursorState.createCursorEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,11 @@ import electrosphere.renderer.shader.VisualShader;
|
|||||||
* Routines for generating meshes of basic geometry
|
* Routines for generating meshes of basic geometry
|
||||||
*/
|
*/
|
||||||
public class GeometryMeshGen {
|
public class GeometryMeshGen {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of sphere mesh
|
||||||
|
*/
|
||||||
|
public static final String SPHERE_MESH_NAME = "sphere";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meshes a box
|
* Meshes a box
|
||||||
@ -479,8 +484,8 @@ public class GeometryMeshGen {
|
|||||||
* @param stacks The number of stacks of the sphere
|
* @param stacks The number of stacks of the sphere
|
||||||
* @return The model
|
* @return The model
|
||||||
*/
|
*/
|
||||||
public static Mesh createUnitSphere(int slices, int stacks){
|
public static Mesh genSphere(int slices, int stacks){
|
||||||
Mesh sphereMesh = new Mesh("sphere");
|
Mesh sphereMesh = new Mesh(GeometryMeshGen.SPHERE_MESH_NAME);
|
||||||
OpenGLState openGLState = Globals.renderingEngine.getOpenGLState();
|
OpenGLState openGLState = Globals.renderingEngine.getOpenGLState();
|
||||||
sphereMesh.generateVAO(openGLState);
|
sphereMesh.generateVAO(openGLState);
|
||||||
|
|
||||||
@ -515,6 +520,15 @@ public class GeometryMeshGen {
|
|||||||
sphereMesh.bufferTextureCoords(texCoordsFinal, 2);
|
sphereMesh.bufferTextureCoords(texCoordsFinal, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//normals
|
||||||
|
{
|
||||||
|
FloatBuffer normals = data.normals(numPoints * 3);
|
||||||
|
FloatBuffer normalsFinal = BufferUtils.createFloatBuffer(normals.limit()); //reallocating to BufferUtils buffer to help minimize memory errors
|
||||||
|
normalsFinal.put(normals);
|
||||||
|
normalsFinal.flip();
|
||||||
|
sphereMesh.bufferNormals(normalsFinal, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//setup extra structures
|
//setup extra structures
|
||||||
Material mat = Material.createExisting(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT);
|
Material mat = Material.createExisting(AssetDataStrings.TEXTURE_TEAL_TRANSPARENT);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class StandardUniformManager {
|
|||||||
/**
|
/**
|
||||||
* Size of the standard uniform ssbo
|
* Size of the standard uniform ssbo
|
||||||
*/
|
*/
|
||||||
public static final int STANDARD_UNIFORM_SSBO_SIZE = 216;
|
public static final int STANDARD_UNIFORM_SSBO_SIZE = 220;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The standard uniform ssbo
|
* The standard uniform ssbo
|
||||||
@ -36,8 +36,9 @@ public class StandardUniformManager {
|
|||||||
vec4 viewPos; //16 bytes
|
vec4 viewPos; //16 bytes
|
||||||
unsigned int frame; //4 bytes
|
unsigned int frame; //4 bytes
|
||||||
float time; //4 bytes
|
float time; //4 bytes
|
||||||
|
float timeOfDay; //4 bytes
|
||||||
}
|
}
|
||||||
Totals to 216 bytes
|
Totals to 220 bytes
|
||||||
*/
|
*/
|
||||||
private ShaderStorageBuffer standardUniformSSBO;
|
private ShaderStorageBuffer standardUniformSSBO;
|
||||||
|
|
||||||
@ -148,6 +149,9 @@ public class StandardUniformManager {
|
|||||||
//put the engine time
|
//put the engine time
|
||||||
buff.putFloat((float)Globals.engineState.timekeeper.getCurrentRendererTime());
|
buff.putFloat((float)Globals.engineState.timekeeper.getCurrentRendererTime());
|
||||||
|
|
||||||
|
//put time of day
|
||||||
|
buff.putFloat(Globals.clientState.clientTemporalService.getTime());
|
||||||
|
|
||||||
|
|
||||||
buff.flip();
|
buff.flip();
|
||||||
standardUniformSSBO.upload(Globals.renderingEngine.getOpenGLState());
|
standardUniformSSBO.upload(Globals.renderingEngine.getOpenGLState());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user