-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
276 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
varying vec2 v_texCoords; | ||
void main() { | ||
vec4 mainColor = texture2D(u_mainTexture, v_texCoords); | ||
vec4 vignetteColor = texture2D(u_vignetteTexture, v_texCoords); | ||
vec4 blurColor = texture2D(u_blurTexture, v_texCoords); | ||
gl_FragColor = mix(mainColor, blurColor, u_blurMix) * vignetteColor; | ||
vec4 mainColor = texture2D(u_mainTexture, v_texCoords); | ||
vec4 vignetteColor = texture2D(u_vignetteTexture, v_texCoords); | ||
vec4 blurColor = texture2D(u_blurTexture, v_texCoords); | ||
vec4 lightScatteringColor = texture2D(u_lightScatteringTexture, v_texCoords); | ||
gl_FragColor = (mix(mainColor, blurColor, u_blurMix) + lightScatteringColor ) * vignetteColor; | ||
// gl_FragColor = mix(mainColor, lightScatteringColor, 0.8f); | ||
} |
41 changes: 41 additions & 0 deletions
41
core/assets/graphics/postprocessing/fix-light-scattering.frag.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
varying vec2 v_texCoords; | ||
|
||
vec4 getSampleColor(vec2 coords) { | ||
vec4 rawColor = texture2D(u_mainTexture, coords); | ||
|
||
if (rawColor.r >= 0.01f && rawColor.g == 0.0f && rawColor.b == 0.0f) { | ||
return vec4(0.0f, 0.0f, 0.0f, 1.0f); | ||
} else { | ||
return rawColor; | ||
} | ||
} | ||
|
||
void main() { | ||
vec4 finalColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); | ||
|
||
if (u_lightDirDotViewDir < 0.0f) { | ||
float lightDirDotViewDir = abs(u_lightDirDotViewDir); | ||
vec2 texCoord = v_texCoords.st; | ||
vec2 deltaTexCoord = (1.0 / float(u_numSamples)) * u_density * vec2(texCoord.xy - u_lightPositonOnScreen.xy); | ||
float dist = length(deltaTexCoord.xy); | ||
|
||
float threshold = 0.01f; | ||
if (dist > threshold) { | ||
deltaTexCoord.xy /= dist / threshold; | ||
} | ||
|
||
float illuminationDecay = 1.0f; | ||
for(int i=0; i < int(u_numSamples); i++) { | ||
texCoord -= deltaTexCoord; | ||
vec4 sampleColor = getSampleColor(texCoord); | ||
sampleColor *= illuminationDecay * u_weight; | ||
finalColor += sampleColor; | ||
illuminationDecay *= u_decay; | ||
} | ||
|
||
finalColor *= u_exposure * lightDirDotViewDir; | ||
} | ||
|
||
gl_FragColor = finalColor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
core/src/macbury/forge/shaders/uniforms/UniformLightPositionOnScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package macbury.forge.shaders.uniforms; | ||
|
||
import com.badlogic.gdx.graphics.Camera; | ||
import com.badlogic.gdx.graphics.g3d.utils.RenderContext; | ||
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | ||
import com.badlogic.gdx.math.Vector2; | ||
import com.badlogic.gdx.math.Vector3; | ||
import macbury.forge.ForgE; | ||
import macbury.forge.graphics.skybox.DayNightSkybox; | ||
import macbury.forge.level.env.LevelEnv; | ||
import macbury.forge.shaders.utils.BaseUniform; | ||
|
||
/** | ||
* Created by macbury on 31.08.15. | ||
*/ | ||
public class UniformLightPositionOnScreen extends BaseUniform { | ||
private static final String UNIFORM_POS_ON_SCREEN = "u_lightPositonOnScreen"; | ||
private static final String UNIFORM_DOT_DIR_VIEW_NAME = "u_lightDirDotViewDir"; | ||
|
||
private static final float OFF_SCREEN_RENDER_RATIO = 2.0F; | ||
private final static Vector3 tempVec = new Vector3(); | ||
@Override | ||
public void defineUniforms() { | ||
define(UNIFORM_POS_ON_SCREEN, Vector2.class); | ||
define(UNIFORM_DOT_DIR_VIEW_NAME, Float.class); | ||
} | ||
|
||
@Override | ||
public void bind(ShaderProgram shader, LevelEnv env, RenderContext context, Camera camera) { | ||
if (ForgE.time.isDay()) { | ||
shader.setUniformf( | ||
UNIFORM_DOT_DIR_VIEW_NAME, | ||
tempVec.set(env.mainLight.direction).dot(env.mainCamera.direction) | ||
); | ||
} else { | ||
shader.setUniformf( UNIFORM_DOT_DIR_VIEW_NAME, 1 ); | ||
} | ||
|
||
|
||
if (DayNightSkybox.class.isInstance(env.skybox)) { | ||
DayNightSkybox dayNightSkybox = (DayNightSkybox)env.skybox; | ||
dayNightSkybox.getLightPosition(tempVec); | ||
env.mainCamera.project(tempVec); | ||
|
||
/*tempVec.x /= env.mainCamera.far; | ||
tempVec.y /= env.mainCamera.far; | ||
tempVec.x = (tempVec.x + 1.0f) / 2.0f; | ||
tempVec.y = (tempVec.y + 1.0f) / 2.0f; | ||
//tempVec.z /= camera.far; | ||
*/ | ||
shader.setUniformf( | ||
UNIFORM_POS_ON_SCREEN, | ||
tempVec.x / env.mainCamera.viewportWidth, | ||
tempVec.y / env.mainCamera.viewportHeight | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
|
||
} | ||
} |
Oops, something went wrong.