diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index 85a75f2f..0cd96b05 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -115,7 +115,7 @@ public class Main { Globals.initGlobals(); //debug: create terrain/world viewer - TerrainViewer.runViewer(); +// TerrainViewer.runViewer(); //create the drawing context Globals.renderingEngine = new RenderingEngine(); diff --git a/src/main/java/electrosphere/renderer/light/DirectionalLight.java b/src/main/java/electrosphere/renderer/light/DirectionalLight.java new file mode 100644 index 00000000..0618730c --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/DirectionalLight.java @@ -0,0 +1,69 @@ +package electrosphere.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class DirectionalLight { + Vector3f direction; + + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setDirection(Vector3f direction) { + this.direction = direction; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getDirection() { + return direction; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + public DirectionalLight(Vector3f direction){ + this.direction = direction; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.4f, 0.4f, 0.4f); + specular = new Vector3f(0.5f, 0.5f, 0.5f); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public DirectionalLight(Vector3f direction, Vector3f color){ + this.direction = direction; + ambient = new Vector3f( color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f( color.x * 0.4f, color.y * 0.4f, color.z * 0.4f); + specular = new Vector3f(color.x * 0.5f, color.y * 0.5f, color.z * 0.5f); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +} \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/LightBuffer.java b/src/main/java/electrosphere/renderer/light/LightBuffer.java new file mode 100644 index 00000000..66c17063 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightBuffer.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package electrosphere.renderer.light; + +import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL31.GL_UNIFORM_BUFFER; + +/** + * + * @author amaterasu + */ +public class LightBuffer { + int light_uniform_buffer_address; + + public LightBuffer(){ + light_uniform_buffer_address = glGenBuffers(); + glBindBuffer(GL_UNIFORM_BUFFER,light_uniform_buffer_address); + //glBufferData(GL_UNIFORM_BUFFER, , GL_STATIC_DRAW); + } +} \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/LightEntityUtils.java b/src/main/java/electrosphere/renderer/light/LightEntityUtils.java new file mode 100644 index 00000000..f9255f3d --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightEntityUtils.java @@ -0,0 +1,42 @@ +package electrosphere.renderer.light; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.main.Globals; +import org.joml.Vector3d; +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class LightEntityUtils { + + public static Entity createDirectionalLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular){ + Entity rVal = new Entity(); + Globals.entityManager.registerEntity(rVal); + Globals.entityManager.registerLightEntity(rVal); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular); + return rVal; + } + + public static Entity createPointLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular, float constant, float linear, float quadratic){ + Entity rVal = new Entity(); + Globals.entityManager.registerEntity(rVal); + Globals.entityManager.registerLightEntity(rVal); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT); + rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z)); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_CONSTANT, constant); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_LINEAR, linear); + rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_QUADRATIC, quadratic); + return rVal; + } + +} \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/LightManager.java b/src/main/java/electrosphere/renderer/light/LightManager.java new file mode 100644 index 00000000..7d829967 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/LightManager.java @@ -0,0 +1,9 @@ +package electrosphere.renderer.light; + +/** + * + * @author amaterasu + */ +public class LightManager { + +} \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/PointLight.java b/src/main/java/electrosphere/renderer/light/PointLight.java new file mode 100644 index 00000000..f57aed52 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/PointLight.java @@ -0,0 +1,106 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package electrosphere.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class PointLight { + Vector3f position; + float constant; + float linear; + float quadratic; + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setPosition(Vector3f position) { + this.position = position; + } + + public void setConstant(float constant) { + this.constant = constant; + } + + public void setLinear(float linear) { + this.linear = linear; + } + + public void setQuadratic(float quadratic) { + this.quadratic = quadratic; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getPosition() { + return position; + } + + public float getConstant() { + return constant; + } + + public float getLinear() { + return linear; + } + + public float getQuadratic() { + return quadratic; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + public PointLight(Vector3f position){ + this.position = position; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.8f, 0.8f, 0.8f); + specular = new Vector3f(1.0f, 1.0f, 1.0f); + this.position.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public PointLight(Vector3f position, Vector3f color){ + this.position = position; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f(color.x * 0.8f, color.y * 0.8f, color.z * 0.8f); + specular = new Vector3f(color.x, color.y, color.z); + this.position.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +} \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/SpotLight.java b/src/main/java/electrosphere/renderer/light/SpotLight.java new file mode 100644 index 00000000..2458ece3 --- /dev/null +++ b/src/main/java/electrosphere/renderer/light/SpotLight.java @@ -0,0 +1,143 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package electrosphere.renderer.light; + +import org.joml.Vector3f; + +/** + * + * @author amaterasu + */ +public class SpotLight { + Vector3f position; + Vector3f direction; + float cutOff; + float outerCutOff; + + float constant; + float linear; + float quadratic; + + Vector3f ambient; + Vector3f diffuse; + Vector3f specular; + + public void setPosition(Vector3f position) { + this.position = position; + } + + public void setDirection(Vector3f direction) { + this.direction = direction; + } + + public void setCutOff(float cutOff) { + this.cutOff = cutOff; + } + + public void setOuterCutOff(float outerCutOff) { + this.outerCutOff = outerCutOff; + } + + public void setConstant(float constant) { + this.constant = constant; + } + + public void setLinear(float linear) { + this.linear = linear; + } + + public void setQuadratic(float quadratic) { + this.quadratic = quadratic; + } + + public void setAmbient(Vector3f ambient) { + this.ambient = ambient; + } + + public void setDiffuse(Vector3f diffuse) { + this.diffuse = diffuse; + } + + public void setSpecular(Vector3f specular) { + this.specular = specular; + } + + public Vector3f getPosition() { + return position; + } + + public Vector3f getDirection() { + return direction; + } + + public float getCutOff() { + return cutOff; + } + + public float getOuterCutOff() { + return outerCutOff; + } + + public float getConstant() { + return constant; + } + + public float getLinear() { + return linear; + } + + public float getQuadratic() { + return quadratic; + } + + public Vector3f getAmbient() { + return ambient; + } + + public Vector3f getDiffuse() { + return diffuse; + } + + public Vector3f getSpecular() { + return specular; + } + + + + public SpotLight(Vector3f position, Vector3f direction){ + this.position = position; + this.direction = direction; + cutOff = (float)Math.toRadians(12.5f); + outerCutOff = (float)Math.toRadians(15.0f); + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(0.05f, 0.05f, 0.05f); + diffuse = new Vector3f(0.8f, 0.8f, 0.8f); + specular = new Vector3f(1.0f, 1.0f, 1.0f); + this.position.normalize(); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } + + public SpotLight(Vector3f position, Vector3f direction, Vector3f color){ + this.position = position; + this.direction = direction; + constant = 1.0f; + linear = 0.01f; + quadratic = 0.01f; + ambient = new Vector3f(color.x * 0.05f, color.y * 0.05f, color.z * 0.05f); + diffuse = new Vector3f(color.x * 0.8f, color.y * 0.8f, color.z * 0.8f); + specular = new Vector3f(color.x, color.y, color.z); + this.position.normalize(); + this.direction.normalize(); + ambient.normalize(); + diffuse.normalize(); + specular.normalize(); + } +} \ No newline at end of file