more light manager updates
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
dc52e375e3
commit
980d6813c4
@ -530,6 +530,17 @@
|
|||||||
"maxHealth" : 100,
|
"maxHealth" : 100,
|
||||||
"onDamageIFrames" : 30
|
"onDamageIFrames" : 30
|
||||||
},
|
},
|
||||||
|
"pointLight" : {
|
||||||
|
"const": 1.0,
|
||||||
|
"linear": 0.7,
|
||||||
|
"quadratic": 0.35,
|
||||||
|
"radius": 1.0,
|
||||||
|
"color": {
|
||||||
|
"x": 0.3,
|
||||||
|
"y": 0.3,
|
||||||
|
"z": 0.3
|
||||||
|
}
|
||||||
|
},
|
||||||
"idleData": {
|
"idleData": {
|
||||||
"animation": {
|
"animation": {
|
||||||
"nameFirstPerson" : "Idle",
|
"nameFirstPerson" : "Idle",
|
||||||
|
|||||||
@ -414,6 +414,17 @@
|
|||||||
"maxHealth" : 60,
|
"maxHealth" : 60,
|
||||||
"onDamageIFrames" : 30
|
"onDamageIFrames" : 30
|
||||||
},
|
},
|
||||||
|
"pointLight" : {
|
||||||
|
"const": 1.0,
|
||||||
|
"linear": 0.7,
|
||||||
|
"quadratic": 0.35,
|
||||||
|
"radius": 1.0,
|
||||||
|
"color": {
|
||||||
|
"x": 0.3,
|
||||||
|
"y": 0.3,
|
||||||
|
"z": 0.3
|
||||||
|
}
|
||||||
|
},
|
||||||
"idleData": {
|
"idleData": {
|
||||||
"animation": {
|
"animation": {
|
||||||
"nameFirstPerson" : "Idle",
|
"nameFirstPerson" : "Idle",
|
||||||
|
|||||||
@ -27,6 +27,8 @@ public class ClientEntityUtils {
|
|||||||
* @param entity the entity to destroy
|
* @param entity the entity to destroy
|
||||||
*/
|
*/
|
||||||
public static void destroyEntity(Entity entity){
|
public static void destroyEntity(Entity entity){
|
||||||
|
//check for client-specific stuff
|
||||||
|
|
||||||
//deregister all behavior trees
|
//deregister all behavior trees
|
||||||
EntityUtils.cleanUpEntity(entity);
|
EntityUtils.cleanUpEntity(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -259,6 +259,11 @@ public class EntityDataStrings {
|
|||||||
public static final String EQUIP_INVENTORY = "equipInventory";
|
public static final String EQUIP_INVENTORY = "equipInventory";
|
||||||
public static final String TREE_SERVEREQUIPSTATE = "treeServerEquipState";
|
public static final String TREE_SERVEREQUIPSTATE = "treeServerEquipState";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Light state
|
||||||
|
*/
|
||||||
|
public static final String TREE_CLIENTLIGHTSTATE = "treeClientLightState";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Inventory in general
|
Inventory in general
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -0,0 +1,90 @@
|
|||||||
|
package electrosphere.entity.state.light;
|
||||||
|
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityDataStrings;
|
||||||
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.entity.btree.BehaviorTree;
|
||||||
|
import electrosphere.entity.state.equip.ClientEquipState;
|
||||||
|
import electrosphere.game.data.common.light.PointLightDescription;
|
||||||
|
import electrosphere.renderer.light.PointLight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps the point light attached to the entity
|
||||||
|
*/
|
||||||
|
public class ClientPointLightComponent implements BehaviorTree {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parent entity
|
||||||
|
*/
|
||||||
|
Entity parent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The description of the point light
|
||||||
|
*/
|
||||||
|
PointLightDescription description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The point light itself
|
||||||
|
*/
|
||||||
|
PointLight light;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void simulate(float deltaTime) {
|
||||||
|
Vector3d entityPos = EntityUtils.getPosition(parent);
|
||||||
|
light.setPosition(new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor
|
||||||
|
* @param parent
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
|
private ClientPointLightComponent(Entity parent, Object ... params){
|
||||||
|
this.parent = parent;
|
||||||
|
description = (PointLightDescription)params[0];
|
||||||
|
light = Globals.renderingEngine.getLightManager().createPointLight(parent, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Attaches this tree to the entity.
|
||||||
|
* </p>
|
||||||
|
* @param entity The entity to attach to
|
||||||
|
* @param tree The behavior tree to attach
|
||||||
|
* @param params Optional parameters that will be provided to the constructor
|
||||||
|
*/
|
||||||
|
public static ClientPointLightComponent attachTree(Entity parent, Object ... params){
|
||||||
|
ClientPointLightComponent rVal = new ClientPointLightComponent(parent,params);
|
||||||
|
//!!WARNING!! from here below should not be touched
|
||||||
|
//This was generated automatically to properly alert various systems that the btree exists and should be tracked
|
||||||
|
parent.putData(EntityDataStrings.TREE_CLIENTLIGHTSTATE, rVal);
|
||||||
|
Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Detatches this tree from the entity.
|
||||||
|
* </p>
|
||||||
|
* @param entity The entity to detach to
|
||||||
|
* @param tree The behavior tree to detach
|
||||||
|
*/
|
||||||
|
public static void detachTree(Entity entity, BehaviorTree tree){
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Gets the ClientEquipState of the entity
|
||||||
|
* </p>
|
||||||
|
* @param entity the entity
|
||||||
|
* @return The ClientEquipState
|
||||||
|
*/
|
||||||
|
public static ClientEquipState getClientEquipState(Entity entity){
|
||||||
|
return (ClientEquipState)entity.getData(EntityDataStrings.TREE_CLIENTEQUIPSTATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -34,6 +34,7 @@ import electrosphere.entity.state.inventory.ServerInventoryState;
|
|||||||
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
||||||
import electrosphere.entity.state.life.ClientLifeTree;
|
import electrosphere.entity.state.life.ClientLifeTree;
|
||||||
import electrosphere.entity.state.life.ServerLifeTree;
|
import electrosphere.entity.state.life.ServerLifeTree;
|
||||||
|
import electrosphere.entity.state.light.ClientPointLightComponent;
|
||||||
import electrosphere.entity.state.movement.fall.ClientFallTree;
|
import electrosphere.entity.state.movement.fall.ClientFallTree;
|
||||||
import electrosphere.entity.state.movement.fall.ServerFallTree;
|
import electrosphere.entity.state.movement.fall.ServerFallTree;
|
||||||
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
|
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
|
||||||
@ -246,6 +247,16 @@ public class CommonEntityUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Light generation
|
||||||
|
//
|
||||||
|
//
|
||||||
|
if(rawType.getPointLight() != null){
|
||||||
|
ClientPointLightComponent.attachTree(entity, rawType.getPointLight());
|
||||||
|
}
|
||||||
|
|
||||||
if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){
|
if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){
|
||||||
ClientEquipState.attachTree(entity, rawType.getEquipPoints());
|
ClientEquipState.attachTree(entity, rawType.getEquipPoints());
|
||||||
entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints()));
|
entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints()));
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import electrosphere.game.data.collidable.CollidableTemplate;
|
import electrosphere.game.data.collidable.CollidableTemplate;
|
||||||
import electrosphere.game.data.collidable.HitboxData;
|
import electrosphere.game.data.collidable.HitboxData;
|
||||||
|
import electrosphere.game.data.common.light.PointLightDescription;
|
||||||
import electrosphere.game.data.creature.type.HealthSystem;
|
import electrosphere.game.data.creature.type.HealthSystem;
|
||||||
import electrosphere.game.data.creature.type.IdleData;
|
import electrosphere.game.data.creature.type.IdleData;
|
||||||
import electrosphere.game.data.creature.type.LookAtSystem;
|
import electrosphere.game.data.creature.type.LookAtSystem;
|
||||||
@ -131,6 +132,11 @@ public class CommonEntityType {
|
|||||||
*/
|
*/
|
||||||
GraphicsTemplate graphicsTemplate;
|
GraphicsTemplate graphicsTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The point light assigned to the entity
|
||||||
|
*/
|
||||||
|
PointLightDescription pointLight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the id for this creature type
|
* Gets the id for this creature type
|
||||||
* @return The id
|
* @return The id
|
||||||
@ -307,4 +313,12 @@ public class CommonEntityType {
|
|||||||
return ambientAudio;
|
return ambientAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the point light data
|
||||||
|
* @return The point light data
|
||||||
|
*/
|
||||||
|
public PointLightDescription getPointLight(){
|
||||||
|
return pointLight;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,115 @@
|
|||||||
|
package electrosphere.game.data.common.light;
|
||||||
|
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of a point light
|
||||||
|
*/
|
||||||
|
public class PointLightDescription {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constant attenuation factor
|
||||||
|
*/
|
||||||
|
float constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The linear attenuation factor
|
||||||
|
*/
|
||||||
|
float linear;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quadratic attenuation factor
|
||||||
|
*/
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The radius of the light
|
||||||
|
*/
|
||||||
|
float radius;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color of the light
|
||||||
|
*/
|
||||||
|
Vector3f color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the constant attenuation factor
|
||||||
|
* @param constant The constant attenuation factor
|
||||||
|
*/
|
||||||
|
public void setConstant(float constant) {
|
||||||
|
this.constant = constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the linear attenuation factor
|
||||||
|
* @param linear The linear attenuation factor
|
||||||
|
*/
|
||||||
|
public void setLinear(float linear) {
|
||||||
|
this.linear = linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the quadratic attenuation factor
|
||||||
|
* @param quadratic The quadratic attenuation factor
|
||||||
|
*/
|
||||||
|
public void setQuadratic(float quadratic) {
|
||||||
|
this.quadratic = quadratic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the radius of the light
|
||||||
|
* @param radius The radius of the light
|
||||||
|
*/
|
||||||
|
public void setRadius(float radius){
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color of the light
|
||||||
|
* @param color The color of the light
|
||||||
|
*/
|
||||||
|
public void setColor(Vector3f color){
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the constant attenuation factor
|
||||||
|
* @return The constant attenuation factor
|
||||||
|
*/
|
||||||
|
public float getConstant() {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the linear attenuation factor
|
||||||
|
* @return The linear attenuation factor
|
||||||
|
*/
|
||||||
|
public float getLinear() {
|
||||||
|
return linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the quadratic attenuation factor
|
||||||
|
* @return The quadratic attenuation factor
|
||||||
|
*/
|
||||||
|
public float getQuadratic() {
|
||||||
|
return quadratic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the color of the light
|
||||||
|
* @return The color of the light
|
||||||
|
*/
|
||||||
|
public Vector3f getColor(){
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the radius of the light
|
||||||
|
* @return The radius of the light
|
||||||
|
*/
|
||||||
|
public float getRadius(){
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,7 +3,6 @@ package electrosphere.renderer.light;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.joml.Matrix4d;
|
import org.joml.Matrix4d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
@ -13,7 +12,7 @@ import electrosphere.client.entity.camera.CameraEntityUtils;
|
|||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.engine.assetmanager.AssetDataStrings;
|
import electrosphere.engine.assetmanager.AssetDataStrings;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityCreationUtils;
|
import electrosphere.game.data.common.light.PointLightDescription;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.renderer.OpenGLState;
|
import electrosphere.renderer.OpenGLState;
|
||||||
import electrosphere.renderer.RenderPipelineState;
|
import electrosphere.renderer.RenderPipelineState;
|
||||||
@ -175,15 +174,6 @@ public class LightManager {
|
|||||||
rVal.entityPointLightMap = new HashMap<Entity,PointLight>();
|
rVal.entityPointLightMap = new HashMap<Entity,PointLight>();
|
||||||
rVal.pointLightSSBO = new ShaderStorageBuffer(POINT_LIGHT_BUFFER_SIZE, BufferUsage.DYNAMIC, BufferAccess.DRAW);
|
rVal.pointLightSSBO = new ShaderStorageBuffer(POINT_LIGHT_BUFFER_SIZE, BufferUsage.DYNAMIC, BufferAccess.DRAW);
|
||||||
|
|
||||||
//create a shit ton of point lights
|
|
||||||
Random rand = new Random(0);
|
|
||||||
for(int i = 0; i < 500; i++){
|
|
||||||
PointLight newLight = new PointLight(new Vector3f(rand.nextFloat(32),rand.nextFloat(),rand.nextFloat(32)));
|
|
||||||
newLight.setRadius(1);
|
|
||||||
newLight.setColor(new Vector3f(rand.nextFloat(),rand.nextFloat(),rand.nextFloat()).normalize());
|
|
||||||
rVal.entityPointLightMap.put(EntityCreationUtils.createClientSpatialEntity(),newLight);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//create direct light ssbo
|
//create direct light ssbo
|
||||||
rVal.dirLightSSBO = new ShaderStorageBuffer(DIRECT_LIGHT_BUFFER_SIZE, BufferUsage.DYNAMIC, BufferAccess.DRAW);
|
rVal.dirLightSSBO = new ShaderStorageBuffer(DIRECT_LIGHT_BUFFER_SIZE, BufferUsage.DYNAMIC, BufferAccess.DRAW);
|
||||||
@ -334,6 +324,49 @@ public class LightManager {
|
|||||||
return directionalLight;
|
return directionalLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the light manager has a light attached to the provided entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @return true if there is an attached light, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean hasAttachedLight(Entity entity){
|
||||||
|
return this.entityPointLightMap.containsKey(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the point light associated with a given entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @return The point light if it exists, null otherwise
|
||||||
|
*/
|
||||||
|
public PointLight getPointLight(Entity entity){
|
||||||
|
return entityPointLightMap.get(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys the light attached to an entity if one is attached
|
||||||
|
* @param entity The entity
|
||||||
|
*/
|
||||||
|
public void destroyPointLight(Entity entity){
|
||||||
|
if(entityPointLightMap.containsKey(entity)){
|
||||||
|
entityPointLightMap.remove(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point light from a description.
|
||||||
|
* <p>
|
||||||
|
* Note: If there is a light already assigned to the entity, it will be overwritten by the new light
|
||||||
|
* </p>
|
||||||
|
* @param entity The entity to assign the light to
|
||||||
|
* @param description The description
|
||||||
|
* @return The light
|
||||||
|
*/
|
||||||
|
public PointLight createPointLight(Entity entity, PointLightDescription description){
|
||||||
|
PointLight light = new PointLight(description);
|
||||||
|
this.entityPointLightMap.put(entity, light);
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2,6 +2,8 @@ package electrosphere.renderer.light;
|
|||||||
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
import electrosphere.game.data.common.light.PointLightDescription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data about a point light
|
* Data about a point light
|
||||||
*/
|
*/
|
||||||
@ -61,7 +63,7 @@ public class PointLight {
|
|||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointLight(Vector3f position){
|
protected PointLight(Vector3f position){
|
||||||
this.position = position;
|
this.position = position;
|
||||||
radius = 1;
|
radius = 1;
|
||||||
constant = 1.0f;
|
constant = 1.0f;
|
||||||
@ -70,7 +72,7 @@ public class PointLight {
|
|||||||
color = new Vector3f(1.0f);
|
color = new Vector3f(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointLight(Vector3f position, Vector3f color){
|
protected PointLight(Vector3f position, Vector3f color){
|
||||||
this.position = position;
|
this.position = position;
|
||||||
radius = 1;
|
radius = 1;
|
||||||
constant = 1.0f;
|
constant = 1.0f;
|
||||||
@ -78,4 +80,16 @@ public class PointLight {
|
|||||||
quadratic = 1.8f;
|
quadratic = 1.8f;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a point light from a light description
|
||||||
|
* @param description The description
|
||||||
|
*/
|
||||||
|
protected PointLight(PointLightDescription description){
|
||||||
|
this.radius = description.getRadius();
|
||||||
|
this.constant = description.getConstant();
|
||||||
|
this.linear = description.getLinear();
|
||||||
|
this.quadratic = description.getQuadratic();
|
||||||
|
this.color = description.getColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user