Shader overwriting
This commit is contained in:
parent
ac8a3a665a
commit
e01e628de5
76
assets/Shaders/skysphere/skysphere.fs
Normal file
76
assets/Shaders/skysphere/skysphere.fs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse;
|
||||||
|
sampler2D specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DirLight {
|
||||||
|
vec3 direction;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PointLight {
|
||||||
|
vec3 position;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpotLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
float cutOff;
|
||||||
|
float outerCutOff;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NR_POINT_LIGHTS 10
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
in vec2 TexCoord;
|
||||||
|
in vec4 FragPosLightSpace;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform DirLight dirLight;
|
||||||
|
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||||
|
uniform SpotLight spotLight;
|
||||||
|
uniform Material material;
|
||||||
|
|
||||||
|
//texture stuff
|
||||||
|
// uniform sampler2D ourTexture;
|
||||||
|
uniform int hasTransparency;
|
||||||
|
// uniform sampler2D specularTexture;
|
||||||
|
|
||||||
|
//light depth map
|
||||||
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
if(hasTransparency == 1){
|
||||||
|
if(texture(material.diffuse, TexCoord).a < 0.1){
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FragColor = texture(material.diffuse, TexCoord);
|
||||||
|
}
|
||||||
48
assets/Shaders/skysphere/skysphere.vs
Normal file
48
assets/Shaders/skysphere/skysphere.vs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//Vertex Shader
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//input buffers
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
layout (location = 4) in vec2 aTex;
|
||||||
|
|
||||||
|
|
||||||
|
//coordinate space transformation matrices
|
||||||
|
uniform mat4 transform;
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//output buffers
|
||||||
|
out vec3 Normal;
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec2 TexCoord;
|
||||||
|
out vec4 FragPosLightSpace;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
//normalize posiiton and normal
|
||||||
|
vec4 FinalVertex = vec4(aPos, 1.0);
|
||||||
|
vec4 FinalNormal = vec4(aNormal, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//push frag, normal, and texture positions to fragment shader
|
||||||
|
FragPos = vec3(model * FinalVertex);
|
||||||
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
|
TexCoord = aTex;
|
||||||
|
|
||||||
|
|
||||||
|
//shadow map stuff
|
||||||
|
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//set final position with opengl space
|
||||||
|
gl_Position = projection * view * model * FinalVertex;
|
||||||
|
}
|
||||||
@ -527,12 +527,14 @@ public class LoadingThread extends Thread {
|
|||||||
Entity skybox = EntityUtils.spawnDrawableEntity("Models/skyboxSphere.fbx");
|
Entity skybox = EntityUtils.spawnDrawableEntity("Models/skyboxSphere.fbx");
|
||||||
EntityUtils.getRotation(skybox).rotateX((float)(-Math.PI/2.0f));
|
EntityUtils.getRotation(skybox).rotateX((float)(-Math.PI/2.0f));
|
||||||
EntityUtils.getScale(skybox).mul(2000.0f);
|
EntityUtils.getScale(skybox).mul(2000.0f);
|
||||||
|
Globals.assetManager.queueOverrideMeshShader("Models/skyboxSphere.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs");
|
||||||
|
|
||||||
//cloud ring pseudo skybox
|
//cloud ring pseudo skybox
|
||||||
Entity cloudRing = EntityUtils.spawnDrawableEntity("Models/cloudRing.fbx");
|
Entity cloudRing = EntityUtils.spawnDrawableEntity("Models/cloudRing.fbx");
|
||||||
EntityUtils.getRotation(cloudRing).rotateX((float)(-Math.PI/2.0f));
|
EntityUtils.getRotation(cloudRing).rotateX((float)(-Math.PI/2.0f));
|
||||||
EntityUtils.getScale(cloudRing).mul(1000.0f);
|
EntityUtils.getScale(cloudRing).mul(1000.0f);
|
||||||
Globals.entityManager.registerBehaviorTree(new ApplyRotationTree(cloudRing,new Quaternionf().rotationZ(0.0001f)));
|
Globals.entityManager.registerBehaviorTree(new ApplyRotationTree(cloudRing,new Quaternionf().rotationZ(0.0001f)));
|
||||||
|
Globals.assetManager.queueOverrideMeshShader("Models/cloudRing.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
package electrosphere.engine.assetmanager;
|
package electrosphere.engine.assetmanager;
|
||||||
|
|
||||||
import electrosphere.audio.AudioBuffer;
|
import electrosphere.audio.AudioBuffer;
|
||||||
|
import electrosphere.renderer.Mesh;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
|
import electrosphere.renderer.ShaderProgram;
|
||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import electrosphere.util.ModelLoader;
|
import electrosphere.util.ModelLoader;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@ -17,14 +20,15 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
*/
|
*/
|
||||||
public class AssetManager {
|
public class AssetManager {
|
||||||
|
|
||||||
ConcurrentHashMap<String,Model> modelsLoadedIntoMemory = new ConcurrentHashMap();
|
Map<String,Model> modelsLoadedIntoMemory = new ConcurrentHashMap<String,Model>();
|
||||||
CopyOnWriteArrayList<String> modelsInQueue = new CopyOnWriteArrayList();
|
List<String> modelsInQueue = new CopyOnWriteArrayList<String>();
|
||||||
|
List<MeshShaderOverride> shaderOverrides = new CopyOnWriteArrayList<MeshShaderOverride>();
|
||||||
|
|
||||||
ConcurrentHashMap<String,Texture> texturesLoadedIntoMemory = new ConcurrentHashMap();
|
Map<String,Texture> texturesLoadedIntoMemory = new ConcurrentHashMap<String,Texture>();
|
||||||
CopyOnWriteArrayList<String> texturesInQueue = new CopyOnWriteArrayList();
|
List<String> texturesInQueue = new CopyOnWriteArrayList<String>();
|
||||||
|
|
||||||
ConcurrentHashMap<String,AudioBuffer> audioLoadedIntoMemory = new ConcurrentHashMap();
|
Map<String,AudioBuffer> audioLoadedIntoMemory = new ConcurrentHashMap<String,AudioBuffer>();
|
||||||
CopyOnWriteArrayList<String> audioInQueue = new CopyOnWriteArrayList();
|
List<String> audioInQueue = new CopyOnWriteArrayList<String>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +52,7 @@ public class AssetManager {
|
|||||||
audioInQueue.remove(currentPath);
|
audioInQueue.remove(currentPath);
|
||||||
audioLoadedIntoMemory.put(currentPath, new AudioBuffer(currentPath));
|
audioLoadedIntoMemory.put(currentPath, new AudioBuffer(currentPath));
|
||||||
}
|
}
|
||||||
|
performMeshOverrides();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,6 +98,30 @@ public class AssetManager {
|
|||||||
modelsLoadedIntoMemory.put(s,m);
|
modelsLoadedIntoMemory.put(s,m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void queueOverrideMeshShader(String modelName, String meshName, String vertPath, String fragPath){
|
||||||
|
MeshShaderOverride override = new MeshShaderOverride(modelName,meshName,vertPath,fragPath);
|
||||||
|
shaderOverrides.add(override);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performMeshOverrides(){
|
||||||
|
List<MeshShaderOverride> toRemove = new LinkedList<MeshShaderOverride>();
|
||||||
|
for(MeshShaderOverride shaderOverride : shaderOverrides){
|
||||||
|
Model model = null;
|
||||||
|
if((model = fetchModel(shaderOverride.modelName)) != null){
|
||||||
|
for(Mesh mesh : model.meshes){
|
||||||
|
if(mesh.nodeID.equals(shaderOverride.getMeshName())){
|
||||||
|
mesh.shader = ShaderProgram.loadSpecificShader(shaderOverride.vertPath, shaderOverride.fragPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toRemove.add(shaderOverride);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MeshShaderOverride shaderOverride : toRemove){
|
||||||
|
shaderOverrides.remove(shaderOverride);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
package electrosphere.engine.assetmanager;
|
||||||
|
|
||||||
|
public class MeshShaderOverride {
|
||||||
|
|
||||||
|
String modelName;
|
||||||
|
String meshName;
|
||||||
|
String vertPath;
|
||||||
|
String fragPath;
|
||||||
|
|
||||||
|
public MeshShaderOverride(String modelName, String meshName, String vertPath, String fragPath){
|
||||||
|
this.modelName = modelName;
|
||||||
|
this.meshName = meshName;
|
||||||
|
this.vertPath = vertPath;
|
||||||
|
this.fragPath = fragPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModelName(){
|
||||||
|
return modelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMeshName(){
|
||||||
|
return meshName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVertPath(){
|
||||||
|
return vertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFragPath(){
|
||||||
|
return fragPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -167,6 +167,8 @@ public class ShaderProgram {
|
|||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ShaderProgram load_default_shader_program(){
|
public static ShaderProgram load_default_shader_program(){
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user