Fix light classes with git repo
This commit is contained in:
parent
f43e6f5d50
commit
f004a588a4
@ -115,7 +115,7 @@ public class Main {
|
|||||||
Globals.initGlobals();
|
Globals.initGlobals();
|
||||||
|
|
||||||
//debug: create terrain/world viewer
|
//debug: create terrain/world viewer
|
||||||
TerrainViewer.runViewer();
|
// TerrainViewer.runViewer();
|
||||||
|
|
||||||
//create the drawing context
|
//create the drawing context
|
||||||
Globals.renderingEngine = new RenderingEngine();
|
Globals.renderingEngine = new RenderingEngine();
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/java/electrosphere/renderer/light/LightBuffer.java
Normal file
23
src/main/java/electrosphere/renderer/light/LightBuffer.java
Normal file
@ -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, <my_data>, GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class LightManager {
|
||||||
|
|
||||||
|
}
|
||||||
106
src/main/java/electrosphere/renderer/light/PointLight.java
Normal file
106
src/main/java/electrosphere/renderer/light/PointLight.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
143
src/main/java/electrosphere/renderer/light/SpotLight.java
Normal file
143
src/main/java/electrosphere/renderer/light/SpotLight.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user