diff --git a/assets/Models/flame1.fbx b/assets/Models/flame1.fbx new file mode 100644 index 00000000..b901d198 Binary files /dev/null and b/assets/Models/flame1.fbx differ diff --git a/assets/Shaders/flame2/flame.fs b/assets/Shaders/flame2/flame.fs index 382b4725..b03d0a8d 100644 --- a/assets/Shaders/flame2/flame.fs +++ b/assets/Shaders/flame2/flame.fs @@ -43,6 +43,7 @@ in vec3 FragPos; in vec3 Normal; in vec2 TexCoord; in vec4 projCoord; +in vec4 modelCoord; //uniforms uniform float time; @@ -52,77 +53,62 @@ layout (location = 5) uniform sampler2D volumeDepthFrontface; layout (location = 6) uniform sampler2D volumeDepthBackface; //function declarations +vec4 openSimplex2_Conventional(vec3 X); vec4 openSimplex2_ImproveXY(vec3 X); float flameTex(float x, float y); +float getNoise(float scale, float timeScale); /* Main method */ void main(){ - float timeS = time * 0.003; + float timeS = time * 0.01; // Normalized pixel coordinates (from 0 to 1) - // vec2 uv = vec2(TexCoord.x,TexCoord.y); - vec3 projCoordNorm = projCoord.xyz / projCoord.w / 2.0 + 0.5; - - // vec2 finalProd = vec2((projCoord.x + 1.0)/2.0, (projCoord.y + 1.0)/2.0); + //make vec2 vec2 finalProd = projCoordNorm.xy; - - // float closeDepth = texture(volumeDepthFrontface, projCoordNorm.xy).r; - // float farDepth = texture(volumeDepthBackface, projCoordNorm.xy).r; - + //grab depth values float closeDepth = texture(volumeDepthFrontface, finalProd.xy).r; float farDepth = texture(volumeDepthBackface, finalProd.xy).r; - - // float closeDepth = texture(volumeDepthFrontface, uv).r; - // float farDepth = texture(volumeDepthBackface, uv).r; + //distance between the two + float volume = abs(farDepth - closeDepth); - float dist = farDepth - closeDepth; + //based on distance of model coords from center + float dist = length(modelCoord.xyz); - float red = 0; - float green = 0; - float blue = 0; - // if(projCoordNorm.x > -0.4 && projCoordNorm.x < 0.6 && projCoordNorm.y > -0.4 && projCoordNorm.y < 0.1){ - // dist = 0.1; - // green = 1; - // blue = closeDepth; + //noise + // float noiseInX = modelCoord.x * 7.0; + // float noiseInZ = FragPos.y * 7.0 - timeS; + // float noiseInY = modelCoord.y * 7.0; + // float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x; + float noise = (getNoise(7.0,1.5 * timeS) + getNoise(10.0,1.5 * (timeS + 0.1)) + getNoise(14.0,1.5 * (timeS + 0.2)) + getNoise(20.0,3.0 * timeS)) / 4.0; + // float noise = getNoise(10.0,1.5); + // float noise = getNoise(14.0,2.0); + + float vertical = -modelCoord.z; + + float amountOfFire = volume * 50.0 + vertical * 2.0 + noise * 0.1;// + dist * 0.1; //should be a function of volume + noise + dist from center + + // if(amountOfFire < 0.1){ + // discard; // } - // if(closeDepth != 1){ - // blue = 1; - // } - // val = dist; + amountOfFire = amountOfFire * 2.0; - // red = projCoordNorm.x; - // green = projCoordNorm.y; - // blue = 0; - - // if(mod(TexCoord.x,0.01) < 0.005){ - // red = 1; - // } - // if(mod(TexCoord.y,0.01) < 0.005){ - // green = 1; - // } - - // if(dist != 0){ - // red = 1; - // green = 1; - // blue = 1; - // } - - red = dist; - green = dist; - blue = dist; + float red = amountOfFire * 2.0; + float green = amountOfFire * 0.8; + float blue = amountOfFire * 0.2; + float alpha = amountOfFire * 3.0; vec4 color = vec4( red, green, blue, - 1.0 + alpha ); // if(val < 0.3){ @@ -133,28 +119,16 @@ void main(){ fragColor = color; } -// -//custom flame function -/// -float flameTex(float x, float y){ - //flip y - float t = 1.0 - y; - //calculate vertical component - float verticalFlameValue = pow(log(t+1.0),1.4) - step(0.5,t) * (pow((2.0 * (t - 0.5)),3.0) / pow(log(2.0),1.4)); - //calculate dist along horizontal from vertical component - float dist = abs(x-0.5); - //want to fade to nothing at dist >= vertical flame value - //use exponent to get there - //clamp range with min - float v = max(2.0 * (verticalFlameValue - dist),0.0); - //apply exponent to get value - float rVal = pow(v,1.4); - return rVal; +float getNoise(float scale, float time){ + float noiseInX = modelCoord.x * scale; + float noiseInZ = FragPos.y * scale - time; + float noiseInY = modelCoord.y * scale; + float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x; + return noise; } - //////////////// K.jpg's Re-oriented 4-Point BCC Noise (OpenSimplex2) //////////////// ////////////////////// Output: vec4(dF/dx, dF/dy, dF/dz, value) ////////////////////// diff --git a/assets/Shaders/flame2/flame.vs b/assets/Shaders/flame2/flame.vs index 36deec99..1bf83e85 100644 --- a/assets/Shaders/flame2/flame.vs +++ b/assets/Shaders/flame2/flame.vs @@ -22,6 +22,7 @@ out vec3 FragPos; out vec3 Normal; out vec2 TexCoord; out vec4 projCoord; +out vec4 modelCoord; @@ -36,7 +37,7 @@ void main() { 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; diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index 8be62372..eae18e11 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -678,23 +678,27 @@ public class LoadingThread extends Thread { Entity hair = ItemUtils.spawnBasicItem("hairshort1"); EntityUtils.getPosition(hair).set(new Vector3f(2,0.1f,1)); - //center flame - Entity fire = ParticleUtils.spawnStaticBillboardParticle(); - EntityUtils.getPosition(fire).set(new Vector3f(1,0.2f,1)); - EntityUtils.getScale(fire).set(0.6f); - Actor fireActor = EntityUtils.getActor(fire); - fireActor.maskShader("particleBillboard", "Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs"); - Globals.assetManager.addShaderToQueue("Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs"); + // //center flame + // Entity fire = ParticleUtils.spawnStaticBillboardParticle(); + // EntityUtils.getPosition(fire).set(new Vector3f(1,0.2f,1)); + // EntityUtils.getScale(fire).set(0.6f); + // Actor fireActor = EntityUtils.getActor(fire); + // fireActor.maskShader("particleBillboard", "Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs"); + // Globals.assetManager.addShaderToQueue("Shaders/flame1/flame.vs", "Shaders/flame1/flame.fs"); - //campfire + // //campfire Entity campfire = EntityUtils.spawnDrawableEntity("Models/campfire1.fbx"); EntityUtils.getPosition(campfire).set(1,0,1); EntityUtils.getRotation(campfire).rotationX(-(float)Math.PI/2.0f); - Entity cube = EntityUtils.spawnDrawableEntity("Models/unitcube.fbx"); + //flame + Entity cube = EntityUtils.spawnDrawableEntity("Models/flame1.fbx"); //shader mask - EntityUtils.getActor(cube).maskShader("Cube", "Shaders/flame2/flame.vs", "Shaders/flame2/flame.fs"); + EntityUtils.getActor(cube).maskShader("Sphere", "Shaders/flame2/flame.vs", "Shaders/flame2/flame.fs"); Globals.assetManager.addShaderToQueue("Shaders/flame2/flame.vs", "Shaders/flame2/flame.fs"); + EntityUtils.getScale(cube).set(0.8f); + EntityUtils.getPosition(cube).set(1,0.08f,1); + EntityUtils.getRotation(cube).rotationX(-(float)Math.PI/2.0f); //texture mask List textureList = new LinkedList(); textureList.add(Globals.renderingEngine.getVolumeFrontfaceTexture()); @@ -702,7 +706,7 @@ public class LoadingThread extends Thread { List uniformList = new LinkedList(); uniformList.add("volumeDepthFrontface"); uniformList.add("volumeDepthBackface"); - ActorTextureMask textureMask = new ActorTextureMask("Cube",textureList,uniformList); + ActorTextureMask textureMask = new ActorTextureMask("Sphere",textureList,uniformList); EntityUtils.getActor(cube).addTextureMask(textureMask); //set draw volumetric cube.putData(EntityDataStrings.DRAW_VOLUMETRIC, true);