Skip to content

Commit

Permalink
refactor(vignette): use shader to create vignette instead of texture (#…
Browse files Browse the repository at this point in the history
…80)

* adjust vignette value to improve effect
  • Loading branch information
Imitater967 authored Apr 7, 2024
1 parent b84fcfb commit 6f6af53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
14 changes: 10 additions & 4 deletions assets/shaders/post_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ uniform mat4 prevViewProjMatrix;
#endif

#ifdef VIGNETTE
uniform sampler2D texVignette;
uniform vec3 tint = vec3(1.0,1.0,1.0);
uniform float vignetteRadius = 0.8f;
uniform float vignetteFeather = 0.5f;
uniform vec3 vignetteTint = vec3(1.0,0.0,0.0);
#endif

layout(location = 0) out vec4 outColor;
Expand Down Expand Up @@ -120,8 +121,13 @@ void main() {
finalColor.rgb = texture(texColorGradingLut, lutScale * finalColor.rgb + lutOffset).rgb;

#ifdef VIGNETTE
float vig = texture(texVignette, v_uv0.xy).x;
finalColor.rgb *= vec3(vig, vig, vig) + (1 - vig) * tint.rgb;
vec2 newUV = v_uv0.xy * 2 - 1;
float circle = length(newUV);
float mask = 1 - smoothstep(vignetteRadius, vignetteRadius + vignetteFeather, circle);
float invertMask = 1 - mask;
vec3 displayColor = finalColor.rgb * mask;
vec3 vignetteColor = (finalColor.rgb) * vignetteTint * invertMask;
finalColor.rgb = displayColor + vignetteColor;
#endif

outColor.rgba = finalColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ public class FinalPostProcessingNode extends AbstractNode implements PropertyCha
@Range(min = 0.0f, max = 1.0f)
private float filmGrainIntensity = 0.05f;

@SuppressWarnings("FieldCanBeLocal")
@Range(min = 0.0f, max = 1.0f)
private float vignetteFeather = 0.6f;
@SuppressWarnings("FieldCanBeLocal")
@Range(min = 0.0f, max = 1.0f)
private float vignetteRadius = 0.9f;
private Vector3f vignetteTint = new Vector3f(.0f, .0f, .0f);

private FBO lastUpdatedGBuffer;

private StateChange setBlurTexture;
private StateChange setNoiseTexture;
private StateChange setVignetteInputTexture;
private final Mesh renderQuad;

private final Vector3f tint = new Vector3f(.0f, .0f, .0f);


public FinalPostProcessingNode(String nodeUri, Name providingModule, Context context) {
Expand Down Expand Up @@ -128,17 +134,11 @@ public void setDependencies(Context context) {
// TODO: evaluate the possibility to use GPU-based noise algorithms instead of CPU-generated textures.

Check warning on line 134 in src/main/java/org/terasology/corerendering/rendering/dag/nodes/FinalPostProcessingNode.java

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: evaluate the possibility to use GPU-based noise algorithms instead of CPU-generated textures.
setNoiseTexture = new SetInputTexture2D(texId++, TextureUtil.getTextureUriForWhiteNoise(NOISE_TEXTURE_SIZE,
0x1234, 0, 512).toString(), POST_MATERIAL_URN, "texNoise");
setVignetteInputTexture = new SetInputTexture2D(texId++, "engine:vignette", POST_MATERIAL_URN, "texVignette");


if (renderingConfig.getBlurIntensity() != 0) {
addDesiredStateChange(setBlurTexture);
}

if (renderingConfig.isVignette()) {
addDesiredStateChange(setVignetteInputTexture);
}

if (renderingConfig.isFilmGrain()) {
addDesiredStateChange(setNoiseTexture);
}
Expand Down Expand Up @@ -169,7 +169,9 @@ public void process() {
}

if (renderingConfig.isVignette()) {
postMaterial.setFloat3("tint", tint);
postMaterial.setFloat3("vignetteTint", vignetteTint);
postMaterial.setFloat("vignetteRadius", vignetteRadius);
postMaterial.setFloat("vignetteFeather", vignetteFeather);
}

this.renderQuad.render();
Expand All @@ -193,11 +195,6 @@ public void propertyChange(PropertyChangeEvent event) {
}
break;
case RenderingConfig.VIGNETTE:
if (renderingConfig.isVignette()) {
addDesiredStateChange(setVignetteInputTexture);
} else {
removeDesiredStateChange(setVignetteInputTexture);
}
break;
case RenderingConfig.BLUR_INTENSITY:
if (renderingConfig.getBlurIntensity() != 0) {
Expand Down

0 comments on commit 6f6af53

Please sign in to comment.