Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(vignette): use shader to create vignette instead of texture #80

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
@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 @@ -125,20 +131,14 @@
addDesiredStateChange(new SetInputTexture3D(texId++, "engine:colorGradingLut1", POST_MATERIAL_URN,
"texColorGradingLut"));

// 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 @@
}

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 @@
}
break;
case RenderingConfig.VIGNETTE:
if (renderingConfig.isVignette()) {
addDesiredStateChange(setVignetteInputTexture);
} else {
removeDesiredStateChange(setVignetteInputTexture);
}
break;
case RenderingConfig.BLUR_INTENSITY:
if (renderingConfig.getBlurIntensity() != 0) {
Expand Down