improved cloud draw perf

This commit is contained in:
minjaesong
2023-08-22 17:43:53 +09:00
parent a21f986f30
commit 52938a4b60
11 changed files with 38 additions and 49 deletions

View File

@@ -310,15 +310,6 @@ internal object WeatherMixer : RNGConsumer {
WeatherObjectCloud(cloud.spriteSheet.get(sheetX, sheetY), flip).also {
it.scale = cloudScale
it.darkness.set(currentWeather.cloudGamma)
it.darkness.x *= it.scale
val varX = 1f + r1.absoluteValue * currentWeather.cloudGammaVariance.x
val varY = 1f + r2.absoluteValue * currentWeather.cloudGammaVariance.y
it.darkness.x *= if (r1 < 0) 1f / varX else varX
it.darkness.y *= if (r2 < 0) 1f / varY else varY
it.posX = posX
it.posY = posY
it.posZ = rZ
@@ -369,13 +360,13 @@ internal object WeatherMixer : RNGConsumer {
}
private fun drawClouds(batch: SpriteBatch) {
batch.shader = shaderClouds
clouds.forEach {
batch.inUse { _ ->
batch.color = globalLightNow.toGdxColor().also { col ->
col.a = it.alpha
} // TODO add cloud-only colour strip on the CLUT
batch.shader.setUniformf("gamma", it.darkness)
batch.inUse { _ ->
batch.shader = shaderClouds
batch.shader.setUniformf("gamma", currentWeather.cloudGamma)
batch.shader.setUniformf("shadeCol", 0.06f, 0.07f, 0.08f, 1f) // TODO temporary value
clouds.forEach {
batch.color = Color(globalLightNow.r, globalLightNow.g, globalLightNow.b, it.alpha)
it.render(batch, 0f, 0f)
}
}

View File

@@ -13,19 +13,6 @@ import kotlin.math.sign
*/
class WeatherObjectCloud(private val texture: TextureRegion, private val flipW: Boolean) : WeatherObject(), Comparable<WeatherObjectCloud> {
/**
* To actually utilise this value, your render code must begin the spritebatch per-object, like so:
* ```
* batch.shader = cloudShader
* for (it in clouds) {
* batch.begin()
* batch.shader.setUniformf("gamma", it.darkness)
* batch.draw(it, ...)
* batch.end()
* }
*/
var darkness: Vector2 = Vector2(0.5f, 2.0f) // the "gamma" value fed into the clouds shader
override fun update() {
throw UnsupportedOperationException()
}

View File

@@ -1,4 +1,4 @@
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -16,5 +16,6 @@ const vec2 boolean = vec2(0.0, 1.0);
void main(void) {
vec4 colorTex0 = texture(u_texture, v_texCoords); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture(tex1, v_texCoords); // lightmap (A) pre-mixed
fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + (colorTex0 * boolean.xxxy);
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + (colorTex0 * boolean.xxxy);
fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, colorTex0 * boolean.xxxy);
}

View File

@@ -1,4 +1,4 @@
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -150,7 +150,10 @@ void main(void) {
); // c = c0..c1
fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + boolean.xxxy;
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + boolean.xxxy;
fragColor = fma(max(colorTex0, colorTex1), boolean.yyyx, boolean.xxxy);
// fragColor = colorTex1;
// fragColor = randomness * boolean.yyyx + boolean.xxxy;
// fragColor = (randomness.rrrr + (colorTex1 * vec4(2.0, -2.0, 2.0, 1.0))) * boolean.yyyx + boolean.xxxy;

View File

@@ -1,4 +1,4 @@
#version 150
#version 400
#ifdef GL_ES
#define LOWP lowp
@@ -7,7 +7,7 @@ precision mediump float;
#define LOWP
#endif
in LOWP vec4 v_color;
in LOWP vec4 v_color; // lightCol.rgb + cloud's alpha
in vec2 v_texCoords;
uniform sampler2D u_texture;
out vec4 fragColor;
@@ -16,10 +16,15 @@ const vec2 boolean = vec2(0.0, 1.0);
uniform vec2 gamma = vec2(10, 2.0); // vec2(gamma for RGB, gamma for A)
uniform LOWP vec4 shadeCol;
void main() {
// r: bw diffuse map, g: normal, b: normal, a: bw diffuse alpha
vec4 inCol = texture(u_texture, v_texCoords);
vec4 rawCol = pow(inCol, gamma.xxxy);
vec4 outCol = pow(inCol, gamma.xxxy);
// do gradient mapping here
vec4 outCol = fma(mix(shadeCol, v_color, rawCol.r), boolean.yyyx, rawCol * boolean.xxxy);
fragColor = outCol * v_color;
fragColor = outCol * fma(v_color, boolean.xxxy, boolean.yyyx);
}

View File

@@ -1,4 +1,4 @@
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -41,7 +41,8 @@ vec4 getDitherredDot(vec4 inColor) {
void main(void) {
float scale = v_texCoords.y * (1.0 - parallax_size) + (parallax_size / 2.0) + (parallax * parallax_size / 2.0);
float parallaxAdder = 0.5 * (parallax + 1.0) * parallax_size;
float scale = fma(v_texCoords.y, 1.0 - parallax_size, parallaxAdder);
float zoomSamplePoint = (1.0 - zoomInv) / 2.0;// will never quite exceed 0.5

View File

@@ -1,4 +1,4 @@
#version 150
#version 400
in vec4 v_color;
in vec2 v_texCoords;
uniform sampler2D u_texture;
@@ -11,5 +11,6 @@ void main(void) {
vec4 incolour = texture(u_texture, v_texCoords);
float lum = dot(incolour * desaturate, boolean.yyyx) * 0.5 + 0.5;
fragColor = v_color * (vec4(lum) * boolean.yyyx + incolour * boolean.xxxy);
// fragColor = v_color * (vec4(lum) * boolean.yyyx + incolour * boolean.xxxy);
fragColor = v_color * fma(vec4(lum), boolean.yyyx, incolour * boolean.xxxy);
}

View File

@@ -3,7 +3,7 @@
* http://momentsingraphics.de/BlueNoise.html
*/
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -79,7 +79,7 @@ void main(void) {
// Dither the output
vec4 graded = ycocg_to_rgb * newColour;
vec4 selvec = getDitherredDot(graded);
vec4 outcol = selvec * boolean.yyyx + boolean.xxxy; // use quantised RGB but not the A
vec4 outcol = fma(selvec, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
fragColor = outcol;
// ivec4 bytes = ivec4(255.0 * outcol);

View File

@@ -3,7 +3,7 @@
* http://momentsingraphics.de/BlueNoise.html
*/
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -60,5 +60,5 @@ void main(void) {
// Dither the output
vec4 graded = ycocg_to_rgb * newColour;
fragColor = graded * boolean.yyyx + boolean.xxxy; // use quantised RGB but not the A
fragColor = fma(graded, boolean.yyyx, boolean.xxxy); // use quantised RGB but not the A
}

View File

@@ -2,7 +2,7 @@
*/
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -107,7 +107,7 @@ void main() {
vec4 finalBreakage = drawBreakage * texture(tilesAtlas, finalUVCoordForBreakage); // drawBreakeage = 0 to not draw, = 1 to draw
vec4 finalColor =mix(finalTile, finalBreakage, finalBreakage.a) * bc.xxxy + (finalTile * bc.yyyx);
vec4 finalColor = fma(mix(finalTile, finalBreakage, finalBreakage.a), bc.xxxy, finalTile * bc.yyyx);
fragColor = mix(colourFilter, colourFilter * finalColor, mulBlendIntensity);

View File

@@ -2,7 +2,7 @@
*/
#version 150
#version 400
#ifdef GL_ES
precision mediump float;
#endif
@@ -121,5 +121,5 @@ void main() {
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
float bayerThreshold = float(bayer[int(entry.y) * int(bayerSize) + int(entry.x)]) / bayerDivider;
fragColor = undithered * bc.xxxy + vec4((undithered.a > bayerThreshold) ? 1.0 : 0.0) * bc.yyyx;
fragColor = fma(undithered, bc.xxxy, vec4((undithered.a > bayerThreshold) ? 1.0 : 0.0) * bc.yyyx);
}