From 597d3c14fb2c6ac303978b06ea389406106f3e28 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Mon, 7 Oct 2024 21:28:04 +0800 Subject: [PATCH] fix(shader): problems from #78 * Fix outline lose when render bg color * Fix incorrect alpha calculation --- assets/shaders/OutlineFragment.glsl | 9 +++++---- core/src/cn/harryh/arkpets/ArkChar.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/shaders/OutlineFragment.glsl b/assets/shaders/OutlineFragment.glsl index 9f48f1a7..7ddcebdb 100644 --- a/assets/shaders/OutlineFragment.glsl +++ b/assets/shaders/OutlineFragment.glsl @@ -10,8 +10,8 @@ varying vec2 v_texCoords; // From VS uniform sampler2D u_texture; // From TCPB uniform vec3 u_outlineColor; // Required uniform float u_outlineWidth; // Required -uniform ivec2 u_textureSize; -uniform float u_alpha; +uniform ivec2 u_textureSize; // Required +uniform float u_alpha; // Required const float c_alphaLv0 = 0.1; const float c_alphaLv1 = 0.5; @@ -78,6 +78,7 @@ void main() { // No effect apply on other areas gl_FragColor = texColor; } - // Alpha - gl_FragColor.a -= (1 - u_alpha); + + // Ultimate alpha control + gl_FragColor.a *= u_alpha; } diff --git a/core/src/cn/harryh/arkpets/ArkChar.java b/core/src/cn/harryh/arkpets/ArkChar.java index 83ef944f..ccba5d77 100644 --- a/core/src/cn/harryh/arkpets/ArkChar.java +++ b/core/src/cn/harryh/arkpets/ArkChar.java @@ -227,7 +227,6 @@ protected void renderToBatch() { batch.setShader(shader1); ScreenUtils.clear(0, 0, 0, 0, true); batch.begin(); - batch.draw(bgTexture, 0, 0); renderer.draw(batch, skeleton); batch.end(); batch.setShader(null); @@ -242,6 +241,7 @@ protected void renderToBatch() { batch.setShader(shader2); ScreenUtils.clear(0, 0, 0, 0, true); batch.begin(); + batch.draw(bgTexture, 0, 0); batch.draw(passedTexture, 0, 0, 0, 0, camera.getWidth(), camera.getHeight(), 1, 1, 0,