partially fix first person attachment to viewmodel
	
		
			
	
		
	
	
		
	
		
			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
							
								
									6d3a8f159b
								
							
						
					
					
						commit
						1578eb3780
					
				| @ -467,6 +467,10 @@ Small bugfix with blocking | |||||||
| Refactor math to be client/server agnostic in attach utils | Refactor math to be client/server agnostic in attach utils | ||||||
| Attach utils fixes for first person handling | Attach utils fixes for first person handling | ||||||
| 
 | 
 | ||||||
|  | (07/28/2024) | ||||||
|  | Tear out first person rendering pipeline | ||||||
|  | Partially fix first person attachment to viewmodel | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # TODO | # TODO | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -249,7 +249,7 @@ public class ControlHandler { | |||||||
|     boolean shouldRecaptureScreen = false; |     boolean shouldRecaptureScreen = false; | ||||||
| 
 | 
 | ||||||
|     //controls whether the camera is first or third person |     //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 |     //The list of window strings that would block main game controls | ||||||
|     static String[] controlBlockingWindows = new String[]{ |     static String[] controlBlockingWindows = new String[]{ | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
| import electrosphere.server.datacell.ServerDataCell; | import electrosphere.server.datacell.ServerDataCell; | ||||||
| @ -203,7 +204,7 @@ public class AttachUtils { | |||||||
| 
 | 
 | ||||||
|             Vector3d facingAngle; |             Vector3d facingAngle; | ||||||
|             if(parent == Globals.firstPersonEntity){ |             if(parent == Globals.firstPersonEntity){ | ||||||
|                 facingAngle = CreatureUtils.getFacingVector(Globals.playerEntity); |                 facingAngle = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)).mul(1,0,1).normalize(); | ||||||
|             } else { |             } else { | ||||||
|                 facingAngle = CreatureUtils.getFacingVector(parent); |                 facingAngle = CreatureUtils.getFacingVector(parent); | ||||||
|             } |             } | ||||||
| @ -309,9 +310,9 @@ public class AttachUtils { | |||||||
|     ){ |     ){ | ||||||
|         //transform bone space |         //transform bone space | ||||||
|         Vector3d position = new Vector3d(bonePosition); |         Vector3d position = new Vector3d(bonePosition); | ||||||
|  |         position = position.add(offsetVector); | ||||||
|         position = position.mul(parentScale); |         position = position.mul(parentScale); | ||||||
|         position = position.rotate(new Quaterniond(parentRotation.x,parentRotation.y,parentRotation.z,parentRotation.w)); |         position = position.rotate(new Quaterniond(parentRotation.x,parentRotation.y,parentRotation.z,parentRotation.w)); | ||||||
|         position = position.add(offsetVector); |  | ||||||
|         //transform worldspace |         //transform worldspace | ||||||
|         position.add(parentPosition); |         position.add(parentPosition); | ||||||
|         //set |         //set | ||||||
| @ -589,6 +590,15 @@ public class AttachUtils { | |||||||
|         return (Entity)e.getData(EntityDataStrings.ATTACH_PARENT); |         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 |      * Gets the rotation offset of a given entity | ||||||
|      * @param e The entity |      * @param e The entity | ||||||
|  | |||||||
| @ -427,8 +427,7 @@ public class RenderingEngine { | |||||||
|         // |         // | ||||||
|         //Init pipelines |         //Init pipelines | ||||||
|         // |         // | ||||||
|         firstPersonItemsPipeline.init(Globals.renderingEngine.getOpenGLState()); |         mainContentPipeline.setFirstPersonPipeline(firstPersonItemsPipeline); | ||||||
|         compositePipeline.setFirstPersonPipeline(firstPersonItemsPipeline); |  | ||||||
|          |          | ||||||
|         // |         // | ||||||
|         // Projection and View matrix creation |         // Projection and View matrix creation | ||||||
|  | |||||||
| @ -9,9 +9,6 @@ import electrosphere.renderer.RenderingEngine; | |||||||
| 
 | 
 | ||||||
| public class CompositePipeline implements RenderPipeline { | public class CompositePipeline implements RenderPipeline { | ||||||
| 
 | 
 | ||||||
|     //the pipeline for the first person render items |  | ||||||
|     FirstPersonItemsPipeline firstPersonItemsPipeline; |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { |     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { | ||||||
|         Globals.profiler.beginCpuSample("CompositePipeline.render"); |         Globals.profiler.beginCpuSample("CompositePipeline.render"); | ||||||
| @ -63,31 +60,6 @@ public class CompositePipeline implements RenderPipeline { | |||||||
|         openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.transparencyAccumulatorTexture.getTexturePointer()); |         openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.transparencyAccumulatorTexture.getTexturePointer()); | ||||||
|         openGLState.glActiveTexture(GL40.GL_TEXTURE1); |         openGLState.glActiveTexture(GL40.GL_TEXTURE1); | ||||||
|         openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.transparencyRevealageTexture.getTexturePointer()); |         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); |         GL40.glDrawArrays(GL40.GL_TRIANGLES, 0, 6); | ||||||
| 
 | 
 | ||||||
| @ -106,12 +78,4 @@ public class CompositePipeline implements RenderPipeline { | |||||||
|         Globals.profiler.endCpuSample(); |         Globals.profiler.endCpuSample(); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     /** |  | ||||||
|      * Get the first person pipeline |  | ||||||
|      * @param firstPersonItemsPipeline the first person pipeline |  | ||||||
|      */ |  | ||||||
|     public void setFirstPersonPipeline(FirstPersonItemsPipeline firstPersonItemsPipeline){ |  | ||||||
|         this.firstPersonItemsPipeline = firstPersonItemsPipeline; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,7 +1,5 @@ | |||||||
| package electrosphere.renderer.pipelines; | package electrosphere.renderer.pipelines; | ||||||
| 
 | 
 | ||||||
| import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER; |  | ||||||
| 
 |  | ||||||
| import org.joml.Matrix4d; | import org.joml.Matrix4d; | ||||||
| import org.joml.Quaterniond; | import org.joml.Quaterniond; | ||||||
| import org.joml.Quaternionf; | import org.joml.Quaternionf; | ||||||
| @ -14,41 +12,29 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.client.firstPerson.FirstPersonTree; | 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.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.renderer.OpenGLState; | import electrosphere.renderer.OpenGLState; | ||||||
| import electrosphere.renderer.RenderPipelineState; | import electrosphere.renderer.RenderPipelineState; | ||||||
| import electrosphere.renderer.actor.Actor; | 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) |  * Renders content that should only be rendered in first person (ie the view model/hands/whatever) | ||||||
|  */ |  */ | ||||||
| public class FirstPersonItemsPipeline implements RenderPipeline { | public class FirstPersonItemsPipeline implements RenderPipeline { | ||||||
| 
 | 
 | ||||||
|     //framebuffer to store what is rendered in this pass |  | ||||||
|     Framebuffer firstPersonFramebuffer; |  | ||||||
| 
 |  | ||||||
|     //internal model matrix |     //internal model matrix | ||||||
|     Matrix4d modelTransformMatrix = new Matrix4d(); |     Matrix4d modelTransformMatrix = new Matrix4d(); | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Initializes the pipeline |  | ||||||
|      */ |  | ||||||
|     public void init(OpenGLState openGLState){ |  | ||||||
|         this.firstPersonFramebuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { |     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { | ||||||
| 
 | 
 | ||||||
|  |         if(Globals.firstPersonEntity != null && !Globals.controlHandler.cameraIsThirdPerson()){ | ||||||
|             //update logic |             //update logic | ||||||
|         if(Globals.firstPersonEntity != null){ |  | ||||||
|             updateFirstPersonModelPosition(Globals.firstPersonEntity); |             updateFirstPersonModelPosition(Globals.firstPersonEntity); | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|             //setup opengl state |             //setup opengl state | ||||||
|         this.firstPersonFramebuffer.bind(openGLState); |  | ||||||
|             renderPipelineState.setUseBones(true); |             renderPipelineState.setUseBones(true); | ||||||
|             renderPipelineState.setUseLight(false); |             renderPipelineState.setUseLight(false); | ||||||
|             renderPipelineState.setUseMaterial(true); |             renderPipelineState.setUseMaterial(true); | ||||||
| @ -61,17 +47,11 @@ public class FirstPersonItemsPipeline implements RenderPipeline { | |||||||
|             openGLState.glDepthFunc(GL40.GL_LESS); |             openGLState.glDepthFunc(GL40.GL_LESS); | ||||||
|             GL40.glDepthMask(true); |             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 |             //render | ||||||
|         if( | 
 | ||||||
|             !Globals.controlHandler.cameraIsThirdPerson() && |             // | ||||||
|             Globals.firstPersonEntity != null |             //Draw viewmodel | ||||||
|             ){ |             { | ||||||
|                 Vector3d position = EntityUtils.getPosition(Globals.firstPersonEntity); |                 Vector3d position = EntityUtils.getPosition(Globals.firstPersonEntity); | ||||||
|                 Actor actor = EntityUtils.getActor(Globals.firstPersonEntity); |                 Actor actor = EntityUtils.getActor(Globals.firstPersonEntity); | ||||||
|                 //calculate camera-modified vector3f |                 //calculate camera-modified vector3f | ||||||
| @ -82,21 +62,31 @@ public class FirstPersonItemsPipeline implements RenderPipeline { | |||||||
|                 modelTransformMatrix.rotate(EntityUtils.getRotation(Globals.firstPersonEntity)); |                 modelTransformMatrix.rotate(EntityUtils.getRotation(Globals.firstPersonEntity)); | ||||||
|                 modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(Globals.firstPersonEntity))); |                 modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(Globals.firstPersonEntity))); | ||||||
|                 actor.applySpatialData(modelTransformMatrix,position); |                 actor.applySpatialData(modelTransformMatrix,position); | ||||||
| 
 |  | ||||||
|                 //draw |                 //draw | ||||||
|                 actor.draw(renderPipelineState, openGLState); |                 actor.draw(renderPipelineState, openGLState); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         //finish up |             //draw children of viewmodel | ||||||
|         openGLState.glBindFramebuffer(GL_FRAMEBUFFER,0); |             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); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * 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 |         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); |         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); |         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(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
| } | } | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.types.attach.AttachUtils; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.renderer.OpenGLState; | import electrosphere.renderer.OpenGLState; | ||||||
| import electrosphere.renderer.RenderPipelineState; | import electrosphere.renderer.RenderPipelineState; | ||||||
| @ -27,6 +28,9 @@ import electrosphere.renderer.buffer.ShaderAttribute; | |||||||
|  */ |  */ | ||||||
| public class MainContentPipeline implements RenderPipeline { | public class MainContentPipeline implements RenderPipeline { | ||||||
| 
 | 
 | ||||||
|  |     //First person drawing routine | ||||||
|  |     FirstPersonItemsPipeline firstPersonSubPipeline; | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { |     public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { | ||||||
|         Globals.profiler.beginCpuSample("MainContentPipeline.render"); |         Globals.profiler.beginCpuSample("MainContentPipeline.render"); | ||||||
| @ -114,6 +118,7 @@ public class MainContentPipeline implements RenderPipeline { | |||||||
|         } |         } | ||||||
|         //draw all instanced models |         //draw all instanced models | ||||||
|         Globals.clientInstanceManager.draw(renderPipelineState,openGLState); |         Globals.clientInstanceManager.draw(renderPipelineState,openGLState); | ||||||
|  |         this.firstPersonSubPipeline.render(openGLState, renderPipelineState); | ||||||
| 
 | 
 | ||||||
|         // |         // | ||||||
|         //      Pass Two: Transparency Accumulator + Revealage |         //      Pass Two: Transparency Accumulator + Revealage | ||||||
| @ -255,8 +260,24 @@ public class MainContentPipeline implements RenderPipeline { | |||||||
|         ( |         ( | ||||||
|             !Globals.controlHandler.cameraIsThirdPerson() && |             !Globals.controlHandler.cameraIsThirdPerson() && | ||||||
|             entity == Globals.playerEntity |             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; | ||||||
|  |     } | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user