Fix shadow maps
This commit is contained in:
parent
ad04661533
commit
dc1c05546e
@ -13,7 +13,7 @@
|
|||||||
"graphicsPerformanceDrawShadows" : true,
|
"graphicsPerformanceDrawShadows" : true,
|
||||||
|
|
||||||
"graphicsDebugDrawCollisionSpheres" : false,
|
"graphicsDebugDrawCollisionSpheres" : false,
|
||||||
"graphicsDebugDrawPhysicsObjects" : true,
|
"graphicsDebugDrawPhysicsObjects" : false,
|
||||||
"graphicsDebugDrawMovementVectors" : false,
|
"graphicsDebugDrawMovementVectors" : false,
|
||||||
"graphicsDebugDrawNavmesh" : false
|
"graphicsDebugDrawNavmesh" : false
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class EntityDataStrings {
|
|||||||
public static final String DATA_STRING_MODEL_PATH = "modelPath";
|
public static final String DATA_STRING_MODEL_PATH = "modelPath";
|
||||||
public static final String DATA_STRING_ACTOR = "actor";
|
public static final String DATA_STRING_ACTOR = "actor";
|
||||||
public static final String DATA_STRING_DRAW = "drawFlag";
|
public static final String DATA_STRING_DRAW = "drawFlag";
|
||||||
|
public static final String DRAW_CAST_SHADOW = "castShadow";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -147,6 +147,7 @@ public class CreatureUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
|
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,1));
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,1));
|
||||||
|
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,6 +91,7 @@ public class ItemUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
|
||||||
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
||||||
rVal.putData(EntityDataStrings.ITEM_TYPE, name);
|
rVal.putData(EntityDataStrings.ITEM_TYPE, name);
|
||||||
// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
|
// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
|
||||||
|
|||||||
@ -38,16 +38,16 @@ public class DrawCell {
|
|||||||
|
|
||||||
CollisionObject physicsObject;
|
CollisionObject physicsObject;
|
||||||
|
|
||||||
static Texture groundTextureOne;
|
static Texture groundTextureOne = new Texture("/Textures/Ground/GrassTileable.png");
|
||||||
static Texture groundTextureTwo;
|
static Texture groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
static Texture groundTextureThree;
|
static Texture groundTextureThree = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
static Texture groundTextureFour;
|
static Texture groundTextureFour = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
groundTextureOne = new Texture("/Textures/Ground/GrassTileable.png");
|
// groundTextureOne = new Texture("/Textures/Ground/GrassTileable.png");
|
||||||
groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png");
|
// groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
groundTextureThree = new Texture("/Textures/Ground/Dirt1.png");
|
// groundTextureThree = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
groundTextureFour = new Texture("/Textures/Ground/Dirt1.png");
|
// groundTextureFour = new Texture("/Textures/Ground/Dirt1.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +103,7 @@ public class DrawCell {
|
|||||||
String terrainModelPath = Globals.assetManager.registerModel(terrainModel);
|
String terrainModelPath = Globals.assetManager.registerModel(terrainModel);
|
||||||
modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath);
|
modelEntity = EntityUtils.spawnDrawableEntity(terrainModelPath);
|
||||||
modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true);
|
modelEntity.putData(EntityDataStrings.TERRAIN_IS_TERRAIN, true);
|
||||||
|
modelEntity.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
|
||||||
LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio);
|
LoggerInterface.loggerRenderer.INFO("New cell @ " + cellX * dynamicInterpolationRatio + "," + cellY * dynamicInterpolationRatio);
|
||||||
EntityUtils.getPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.0f, cellY * dynamicInterpolationRatio));
|
EntityUtils.getPosition(modelEntity).set(new Vector3f(cellX * dynamicInterpolationRatio, 0.0f, cellY * dynamicInterpolationRatio));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -772,11 +772,7 @@ public class Mesh {
|
|||||||
|
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(vertexArrayObject);
|
||||||
|
|
||||||
if(useShadowMap){
|
|
||||||
glActiveTexture(GL_TEXTURE3);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, Globals.shadowMapTextureLoc);
|
|
||||||
glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "shadowMap"), 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(useTextureList){
|
if(useTextureList){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -798,6 +794,12 @@ public class Mesh {
|
|||||||
// glActiveTexture(GL_TEXTURE0);
|
// glActiveTexture(GL_TEXTURE0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(useShadowMap){
|
||||||
|
glActiveTexture(GL_TEXTURE3);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, Globals.shadowMapTextureLoc);
|
||||||
|
glUniform1i(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "shadowMap"), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(setBones){
|
if(setBones){
|
||||||
//
|
//
|
||||||
@ -820,6 +822,8 @@ public class Mesh {
|
|||||||
} else {
|
} else {
|
||||||
glUniform1i(Globals.renderingEngine.getActiveShader().shaderVertexHasBonesLoc, 0);
|
glUniform1i(Globals.renderingEngine.getActiveShader().shaderVertexHasBonesLoc, 0);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
glUniform1i(Globals.renderingEngine.getActiveShader().shaderVertexHasBonesLoc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -342,10 +342,13 @@ public class RenderingEngine {
|
|||||||
|
|
||||||
lightDepthBuffer.bind();
|
lightDepthBuffer.bind();
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D, woodTexture);
|
||||||
|
// renderScene(simpleDepthShader);
|
||||||
|
|
||||||
float eyeX = -20.0f;
|
float eyeX = -10.0f;
|
||||||
float eyeY = 40.0f;
|
float eyeY = 20.0f;
|
||||||
float eyeZ = -10.0f;
|
float eyeZ = -5.0f;
|
||||||
float nearPlane = 0.001f;
|
float nearPlane = 0.001f;
|
||||||
float farPlane = (float)Math.sqrt(eyeX * eyeX + eyeY * eyeY + eyeZ * eyeZ) + 20.0f;
|
float farPlane = (float)Math.sqrt(eyeX * eyeX + eyeY * eyeY + eyeZ * eyeZ) + 20.0f;
|
||||||
//set matrices for light render
|
//set matrices for light render
|
||||||
@ -368,19 +371,26 @@ public class RenderingEngine {
|
|||||||
modelTransformMatrix = new Matrix4f();
|
modelTransformMatrix = new Matrix4f();
|
||||||
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
||||||
Vector3d position = EntityUtils.getPosition(currentEntity);
|
Vector3d position = EntityUtils.getPosition(currentEntity);
|
||||||
if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z))){
|
if(
|
||||||
|
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
|
||||||
|
drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) &&
|
||||||
|
currentEntity.getDataKeys().contains(EntityDataStrings.DRAW_CAST_SHADOW)
|
||||||
|
){
|
||||||
//fetch actor
|
//fetch actor
|
||||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||||
//calculate camera-modified vector3f
|
//calculate camera-modified vector3f
|
||||||
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
//calculate and apply model transform
|
//calculate and apply model transform
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix = modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(cameraModifiedPosition);
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
||||||
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
||||||
currentActor.applyModelMatrix(modelTransformMatrix);
|
currentActor.applyModelMatrix(modelTransformMatrix);
|
||||||
//draw
|
//draw
|
||||||
currentActor.drawForDepthBuffer();
|
// if(!currentEntity.getDataKeys().contains(EntityDataStrings.TERRAIN_IS_TERRAIN) && !currentEntity.getDataKeys().contains(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE)){
|
||||||
|
currentActor.drawForDepthBuffer();
|
||||||
|
System.out.println(currentActor.modelPath);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,8 +645,9 @@ public class RenderingEngine {
|
|||||||
// GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
// GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
Globals.renderingEngine.setActiveShader(screenTextureShaders);
|
Globals.renderingEngine.setActiveShader(screenTextureShaders);
|
||||||
glBindVertexArray(screenTextureVAO);
|
glBindVertexArray(screenTextureVAO);
|
||||||
|
//aaa
|
||||||
glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexturePointer());
|
glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexturePointer());
|
||||||
// glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexture());
|
// glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexturePointer());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL15.*;
|
import static org.lwjgl.opengl.GL15.*;
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package electrosphere.renderer.light;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class LightManager {
|
public class LightManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,8 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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;
|
package electrosphere.renderer.light;
|
||||||
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user