partially fix first person attachment to viewmodel
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-07-28 12:07:44 -04:00
parent 6d3a8f159b
commit 1578eb3780
7 changed files with 100 additions and 107 deletions

View File

@ -467,6 +467,10 @@ Small bugfix with blocking
Refactor math to be client/server agnostic in attach utils
Attach utils fixes for first person handling
(07/28/2024)
Tear out first person rendering pipeline
Partially fix first person attachment to viewmodel
# TODO

View File

@ -249,7 +249,7 @@ public class ControlHandler {
boolean shouldRecaptureScreen = false;
//controls whether the camera is first or third person
boolean cameraIsThirdPerson = true;
boolean cameraIsThirdPerson = false;
//The list of window strings that would block main game controls
static String[] controlBlockingWindows = new String[]{

View File

@ -5,6 +5,7 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.renderer.actor.Actor;
import electrosphere.server.datacell.ServerDataCell;
@ -203,7 +204,7 @@ public class AttachUtils {
Vector3d facingAngle;
if(parent == Globals.firstPersonEntity){
facingAngle = CreatureUtils.getFacingVector(Globals.playerEntity);
facingAngle = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)).mul(1,0,1).normalize();
} else {
facingAngle = CreatureUtils.getFacingVector(parent);
}
@ -309,9 +310,9 @@ public class AttachUtils {
){
//transform bone space
Vector3d position = new Vector3d(bonePosition);
position = position.add(offsetVector);
position = position.mul(parentScale);
position = position.rotate(new Quaterniond(parentRotation.x,parentRotation.y,parentRotation.z,parentRotation.w));
position = position.add(offsetVector);
//transform worldspace
position.add(parentPosition);
//set
@ -589,6 +590,15 @@ public class AttachUtils {
return (Entity)e.getData(EntityDataStrings.ATTACH_PARENT);
}
/**
* Checks if the entity has a parent
* @param e The entity
* @return true if has a parent, false otherwise
*/
public static boolean hasParent(Entity e){
return e.containsKey(EntityDataStrings.ATTACH_PARENT);
}
/**
* Gets the rotation offset of a given entity
* @param e The entity

View File

@ -427,8 +427,7 @@ public class RenderingEngine {
//
//Init pipelines
//
firstPersonItemsPipeline.init(Globals.renderingEngine.getOpenGLState());
compositePipeline.setFirstPersonPipeline(firstPersonItemsPipeline);
mainContentPipeline.setFirstPersonPipeline(firstPersonItemsPipeline);
//
// Projection and View matrix creation

View File

@ -9,9 +9,6 @@ import electrosphere.renderer.RenderingEngine;
public class CompositePipeline implements RenderPipeline {
//the pipeline for the first person render items
FirstPersonItemsPipeline firstPersonItemsPipeline;
@Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
Globals.profiler.beginCpuSample("CompositePipeline.render");
@ -63,31 +60,6 @@ public class CompositePipeline implements RenderPipeline {
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.transparencyAccumulatorTexture.getTexturePointer());
openGLState.glActiveTexture(GL40.GL_TEXTURE1);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.transparencyRevealageTexture.getTexturePointer());
openGLState.glActiveTexture(GL40.GL_TEXTURE2);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, firstPersonItemsPipeline.getFramebuffer().getTexturePointer());
GL40.glDrawArrays(GL40.GL_TRIANGLES, 0, 6);
//
//Draw the first person texture on top of the other textures
//
openGLState.setActiveShader(renderPipelineState, RenderingEngine.screenTextureShaders);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
openGLState.glActiveTexture(GL40.GL_TEXTURE1);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
openGLState.glActiveTexture(GL40.GL_TEXTURE2);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
openGLState.glActiveTexture(GL40.GL_TEXTURE3);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, firstPersonItemsPipeline.getFramebuffer().getTexturePointer());
openGLState.glActiveTexture(GL40.GL_TEXTURE1);
GL40.glDrawArrays(GL40.GL_TRIANGLES, 0, 6);
@ -106,12 +78,4 @@ public class CompositePipeline implements RenderPipeline {
Globals.profiler.endCpuSample();
}
/**
* Get the first person pipeline
* @param firstPersonItemsPipeline the first person pipeline
*/
public void setFirstPersonPipeline(FirstPersonItemsPipeline firstPersonItemsPipeline){
this.firstPersonItemsPipeline = firstPersonItemsPipeline;
}
}

View File

@ -1,7 +1,5 @@
package electrosphere.renderer.pipelines;
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
import org.joml.Matrix4d;
import org.joml.Quaterniond;
import org.joml.Quaternionf;
@ -14,89 +12,81 @@ import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.client.firstPerson.FirstPersonTree;
import electrosphere.entity.state.equip.ClientEquipState;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
/**
* Renders content that should only be rendered in first person (ie the view model/hands/whatever)
*/
public class FirstPersonItemsPipeline implements RenderPipeline {
//framebuffer to store what is rendered in this pass
Framebuffer firstPersonFramebuffer;
//internal model matrix
Matrix4d modelTransformMatrix = new Matrix4d();
/**
* Initializes the pipeline
*/
public void init(OpenGLState openGLState){
this.firstPersonFramebuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
}
@Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
//update logic
if(Globals.firstPersonEntity != null){
if(Globals.firstPersonEntity != null && !Globals.controlHandler.cameraIsThirdPerson()){
//update logic
updateFirstPersonModelPosition(Globals.firstPersonEntity);
//setup opengl state
renderPipelineState.setUseBones(true);
renderPipelineState.setUseLight(false);
renderPipelineState.setUseMaterial(true);
renderPipelineState.setUseMeshShader(true);
renderPipelineState.setUseShadowMap(false);
renderPipelineState.setBufferStandardUniforms(true);
renderPipelineState.setFrustumCheck(false);
openGLState.glDepthTest(true);
openGLState.glDepthFunc(GL40.GL_LESS);
GL40.glDepthMask(true);
//render
//
//Draw viewmodel
{
Vector3d position = EntityUtils.getPosition(Globals.firstPersonEntity);
Actor actor = EntityUtils.getActor(Globals.firstPersonEntity);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(Globals.firstPersonEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(Globals.firstPersonEntity)));
actor.applySpatialData(modelTransformMatrix,position);
//draw
actor.draw(renderPipelineState, openGLState);
}
//draw children of viewmodel
if(AttachUtils.hasChildren(Globals.firstPersonEntity)){
for(Entity child : AttachUtils.getChildrenList(Globals.firstPersonEntity)){
Vector3d position = EntityUtils.getPosition(child);
Actor actor = EntityUtils.getActor(child);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(child));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(child)));
actor.applySpatialData(modelTransformMatrix,position);
//draw
actor.draw(renderPipelineState, openGLState);
}
}
}
//setup opengl state
this.firstPersonFramebuffer.bind(openGLState);
renderPipelineState.setUseBones(true);
renderPipelineState.setUseLight(false);
renderPipelineState.setUseMaterial(true);
renderPipelineState.setUseMeshShader(true);
renderPipelineState.setUseShadowMap(false);
renderPipelineState.setBufferStandardUniforms(true);
renderPipelineState.setFrustumCheck(false);
openGLState.glDepthTest(true);
openGLState.glDepthFunc(GL40.GL_LESS);
GL40.glDepthMask(true);
//clear
GL40.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL40.glClear(GL40.GL_COLOR_BUFFER_BIT);
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
//render
if(
!Globals.controlHandler.cameraIsThirdPerson() &&
Globals.firstPersonEntity != null
){
Vector3d position = EntityUtils.getPosition(Globals.firstPersonEntity);
Actor actor = EntityUtils.getActor(Globals.firstPersonEntity);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(Globals.firstPersonEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(Globals.firstPersonEntity)));
actor.applySpatialData(modelTransformMatrix,position);
//draw
actor.draw(renderPipelineState, openGLState);
}
//finish up
openGLState.glBindFramebuffer(GL_FRAMEBUFFER,0);
}
/**
* Gets the framebuffer of the pipeline
* @return the framebuffer
*/
public Framebuffer getFramebuffer(){
return this.firstPersonFramebuffer;
}
/**
@ -116,6 +106,11 @@ public class FirstPersonItemsPipeline implements RenderPipeline {
Vector4d behindCameraOffsetRaw = rotationMat.transform(new Vector4d(0,tree.getCameraViewDirOffsetY(),tree.getCameraViewDirOffsetZ(),1)); //pushes the model behind the camera
Vector3d behindCameraOffset = new Vector3d(behindCameraOffsetRaw.x,behindCameraOffsetRaw.y,behindCameraOffsetRaw.z);
EntityUtils.getPosition(Globals.firstPersonEntity).set(playerPos).add(0.0f,tree.getHeightFromOrigin(),0.0f).add(behindCameraOffset);
if(ClientEquipState.hasEquipState(Globals.playerEntity)){
ClientEquipState clientEquipState = ClientEquipState.getClientEquipState(Globals.playerEntity);
clientEquipState.evaluatePlayerAttachments();
}
}
}

View File

@ -13,6 +13,7 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
@ -27,6 +28,9 @@ import electrosphere.renderer.buffer.ShaderAttribute;
*/
public class MainContentPipeline implements RenderPipeline {
//First person drawing routine
FirstPersonItemsPipeline firstPersonSubPipeline;
@Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
Globals.profiler.beginCpuSample("MainContentPipeline.render");
@ -114,6 +118,7 @@ public class MainContentPipeline implements RenderPipeline {
}
//draw all instanced models
Globals.clientInstanceManager.draw(renderPipelineState,openGLState);
this.firstPersonSubPipeline.render(openGLState, renderPipelineState);
//
// Pass Two: Transparency Accumulator + Revealage
@ -255,8 +260,24 @@ public class MainContentPipeline implements RenderPipeline {
(
!Globals.controlHandler.cameraIsThirdPerson() &&
entity == Globals.playerEntity
) ||
//don't draw items if they're attached to viewmodel
(
!Globals.controlHandler.cameraIsThirdPerson() &&
AttachUtils.hasParent(entity) &&
Globals.firstPersonEntity != null &&
AttachUtils.getParent(entity) == Globals.firstPersonEntity
)
;
}
/**
* Get the first person pipeline
* @param firstPersonItemsPipeline the first person pipeline
*/
public void setFirstPersonPipeline(FirstPersonItemsPipeline firstPersonItemsPipeline){
this.firstPersonSubPipeline = firstPersonItemsPipeline;
}
}