work on fully shader volumetric
This commit is contained in:
		
							parent
							
								
									40ce8dd161
								
							
						
					
					
						commit
						aa6bfe796d
					
				
							
								
								
									
										103
									
								
								assets/Shaders/clouds1/clouds1.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								assets/Shaders/clouds1/clouds1.fs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,103 @@ | |||||||
|  | //version | ||||||
|  | #version 330 core | ||||||
|  | 
 | ||||||
|  | //macros | ||||||
|  | #extension GL_ARB_explicit_uniform_location : enable | ||||||
|  | 
 | ||||||
|  | //output | ||||||
|  | out vec4 fragColor; | ||||||
|  | 
 | ||||||
|  | //input | ||||||
|  | in vec3 FragPos; | ||||||
|  | in vec3 Normal; | ||||||
|  | in vec2 TexCoord; | ||||||
|  | in vec4 projCoord; | ||||||
|  | in vec4 modelCoord; | ||||||
|  | 
 | ||||||
|  | //uniforms | ||||||
|  | uniform float time; | ||||||
|  | uniform mat4 model; | ||||||
|  | uniform vec3 viewPos; | ||||||
|  | 
 | ||||||
|  | const float CONTACT_TEST_MARGIN = -0.001; | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  | Main method | ||||||
|  | */ | ||||||
|  | void main(){ | ||||||
|  |      | ||||||
|  |     float timeS = time * 0.01; | ||||||
|  |      | ||||||
|  |     // Normalized pixel coordinates (from 0 to 1) | ||||||
|  |     vec3 projCoordNorm = projCoord.xyz / projCoord.w / 2.0 + 0.5; | ||||||
|  |     //make vec2 | ||||||
|  |     vec2 finalProd = projCoordNorm.xy; | ||||||
|  | 
 | ||||||
|  |     //get vector that describes the movement through the cube | ||||||
|  |     vec3 viewDir = normalize(viewPos - FragPos); | ||||||
|  |     //need to transform to model space | ||||||
|  |     //get inverse of model transform | ||||||
|  |     mat4 inverseModel = inverse(model); | ||||||
|  |     //apply to view dir | ||||||
|  |     vec4 modelViewDir = normalize(inverseModel * vec4(viewDir,1.0)); | ||||||
|  | 
 | ||||||
|  |     //where the vector first hits the cube | ||||||
|  |     vec4 contactPoint = modelCoord; | ||||||
|  | 
 | ||||||
|  |      | ||||||
|  |     float red = 1.0; | ||||||
|  |     float green = 1.0; | ||||||
|  |     float blue = 1.0; | ||||||
|  | 
 | ||||||
|  |     red = modelViewDir.x; | ||||||
|  |     green = modelViewDir.y; | ||||||
|  |     blue = modelViewDir.z; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     //need to calculate exit point | ||||||
|  |     //if we hit one of the X edges | ||||||
|  |     vec4 backPoint = vec4(1.0); | ||||||
|  |     if(abs(contactPoint.x)-1.0>CONTACT_TEST_MARGIN){ | ||||||
|  |         red = 1.0; | ||||||
|  |         //discard if backface | ||||||
|  |         if(sign(contactPoint.x)!=sign(modelViewDir.x)){ | ||||||
|  |             discard; | ||||||
|  |         } | ||||||
|  |         //calculate distance to nearest face | ||||||
|  |         float distX = 2.0; | ||||||
|  |         //this is some really weird logic that I believe works to calculate distance to nearest face | ||||||
|  |         float distY = abs(sign(modelViewDir.y) - contactPoint.y); | ||||||
|  |         float distZ = abs(sign(modelViewDir.z) - contactPoint.z); | ||||||
|  |         //calculate number of times to add viewDir to get dist | ||||||
|  |         float scaleX = distX / modelViewDir.x; | ||||||
|  |         float scaleY = distY / modelViewDir.y; | ||||||
|  |         float scaleZ = distZ / modelViewDir.z; | ||||||
|  |         //this is the smallest distance of all of them | ||||||
|  |         float minScale = min(scaleX,min(scaleY,scaleZ)); | ||||||
|  |         backPoint = contactPoint + (modelViewDir * minScale); | ||||||
|  |         float dist = length(abs(vec3(contactPoint) - vec3(backPoint)))/1.0; | ||||||
|  |         red = green = blue = dist; | ||||||
|  |     } else if(abs(contactPoint.y)-1.0>CONTACT_TEST_MARGIN){ | ||||||
|  |         green = 1.0; | ||||||
|  |         //discard if backface | ||||||
|  |         if(sign(contactPoint.y)!=sign(modelViewDir.y)){ | ||||||
|  |             discard; | ||||||
|  |         } | ||||||
|  |     } else if(abs(contactPoint.z)-1.0>CONTACT_TEST_MARGIN){ | ||||||
|  |         blue = 1.0; | ||||||
|  |         //discard if backface | ||||||
|  |         if(sign(contactPoint.z)!=sign(modelViewDir.z)){ | ||||||
|  |             discard; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     vec4 color = vec4( | ||||||
|  |         red, | ||||||
|  |         green, | ||||||
|  |         blue, | ||||||
|  |         0.3 | ||||||
|  |         ); | ||||||
|  |          | ||||||
|  |     fragColor = color; | ||||||
|  | } | ||||||
							
								
								
									
										44
									
								
								assets/Shaders/clouds1/clouds1.vs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								assets/Shaders/clouds1/clouds1.vs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | //Vertex Shader | ||||||
|  | #version 330 core | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //input buffers | ||||||
|  | layout (location = 0) in vec3 aPos; | ||||||
|  | layout (location = 1) in vec3 aNormal; | ||||||
|  | layout (location = 4) in vec2 aTex; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //coordinate space transformation matrices | ||||||
|  | uniform mat4 model; | ||||||
|  | uniform mat4 view; | ||||||
|  | uniform mat4 projection; | ||||||
|  | uniform float time; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //output buffers | ||||||
|  | out vec3 FragPos; | ||||||
|  | out vec3 Normal; | ||||||
|  | out vec2 TexCoord; | ||||||
|  | out vec4 projCoord; | ||||||
|  | out vec4 modelCoord; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void main() { | ||||||
|  |     //normalize posiiton and normal | ||||||
|  |     vec4 FinalVertex = vec4(aPos, 1.0); | ||||||
|  |     vec4 FinalNormal = vec4(aNormal, 1.0); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     //push frag, normal, and texture positions to fragment shader | ||||||
|  |     FragPos = vec3(model * FinalVertex); | ||||||
|  |     Normal = mat3(transpose(inverse(model))) * aNormal; | ||||||
|  |     TexCoord = aTex; | ||||||
|  |     projCoord = projection * view * model * FinalVertex; | ||||||
|  |     modelCoord = FinalVertex; | ||||||
|  |      | ||||||
|  |     //set final position with opengl space | ||||||
|  |     gl_Position = projection * view * model * FinalVertex; | ||||||
|  | } | ||||||
| @ -46,6 +46,7 @@ import electrosphere.net.client.ClientNetworking; | |||||||
| import electrosphere.net.server.Server; | import electrosphere.net.server.Server; | ||||||
| import electrosphere.renderer.Mesh; | import electrosphere.renderer.Mesh; | ||||||
| import electrosphere.renderer.Model; | import electrosphere.renderer.Model; | ||||||
|  | import electrosphere.renderer.ModelUtils; | ||||||
| import electrosphere.renderer.RenderUtils; | import electrosphere.renderer.RenderUtils; | ||||||
| import electrosphere.renderer.RenderingEngine; | import electrosphere.renderer.RenderingEngine; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
| @ -683,6 +684,16 @@ public class LoadingThread extends Thread { | |||||||
|         Entity sword = ItemUtils.spawnBasicItem("Katana"); |         Entity sword = ItemUtils.spawnBasicItem("Katana"); | ||||||
|         EntityUtils.getPosition(sword).set(new Vector3f(1,0.4f,2)); |         EntityUtils.getPosition(sword).set(new Vector3f(1,0.4f,2)); | ||||||
|         EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0))); |         EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0))); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         //work on ez volumetrics shader | ||||||
|  |         Entity myCube = EntityUtils.spawnDrawableEntity("Models/unitcube.fbx"); | ||||||
|  |         EntityUtils.getActor(myCube).maskShader("Cube", "Shaders/clouds1/clouds1.vs", "Shaders/clouds1/clouds1.fs"); | ||||||
|  |         Globals.assetManager.addShaderToQueue("Shaders/clouds1/clouds1.vs", "Shaders/clouds1/clouds1.fs"); | ||||||
|  |         myCube.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); | ||||||
|  |         EntityUtils.getPosition(myCube).set(3,1,3); | ||||||
|  | 
 | ||||||
|         // Globals.entityManager.registerBehaviorTree(new BehaviorTree() { |         // Globals.entityManager.registerBehaviorTree(new BehaviorTree() { | ||||||
|         //     int i = 0; |         //     int i = 0; | ||||||
|         //     public void simulate(){ |         //     public void simulate(){ | ||||||
|  | |||||||
| @ -1789,4 +1789,5 @@ public class RenderUtils { | |||||||
| 
 | 
 | ||||||
|      |      | ||||||
| 
 | 
 | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user