wrong colour fixed -- Gdx.Color.toIntBits() returns ABGR, GLSL expects RGBA

This commit is contained in:
minjaesong
2019-01-29 03:04:01 +09:00
parent cd1ad9277a
commit 10c188bea7
2 changed files with 16 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ varying vec2 v_texCoords;
// the divisor of 2 input and an output must be the same. I.e. either divide all by 4, or not. // the divisor of 2 input and an output must be the same. I.e. either divide all by 4, or not.
uniform sampler2D shades; uniform sampler2D shades;
uniform sampler2D lights; uniform sampler2D lights;
// WARNING -- Gdx.Color.toIntBits returns ABGR, but GLSL expects RGBA. Use the function Color.toRGBA() in LightmapRenderNew
uniform sampler2D u_texture; uniform sampler2D u_texture;
uniform vec2 outSize; uniform vec2 outSize;
uniform float multiplier = 4.0; // if divided by four, put 4.0 in there uniform float multiplier = 4.0; // if divided by four, put 4.0 in there
@@ -95,6 +96,8 @@ void main() {
gl_FragColor = outColor * multiplier; gl_FragColor = outColor * multiplier;
gl_FragColor = vec4(0,1,0,1); gl_FragColor = vec4(0,1,0,1);
gl_FragColor = vec4(texture2D(lights, v_texCoords)) * multiplier; gl_FragColor = vec4(texture2D(lights, gl_FragCoord.xy / outSize)) * multiplier;
// FIXME (gl_FragCoord / outSize) != v_texCoords
} }

View File

@@ -97,8 +97,8 @@ object LightmapRenderer {
private lateinit var texturedLightCamera: OrthographicCamera private lateinit var texturedLightCamera: OrthographicCamera
private lateinit var texturedLightBatch: SpriteBatch private lateinit var texturedLightBatch: SpriteBatch
private const val LIGHTMAP_UNIT = 1 private const val LIGHTMAP_UNIT = 0
private const val SHADEMAP_UNIT = 0 private const val SHADEMAP_UNIT = 1
init { init {
printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque") printdbg(this, "Overscan open: $overscan_open; opaque: $overscan_opaque")
@@ -403,17 +403,18 @@ object LightmapRenderer {
// Several variables will be altered by this. See its documentation. // Several variables will be altered by this. See its documentation.
getLightsAndShades(wx, wy) getLightsAndShades(wx, wy)
texturedLightSourcePixmap.drawPixel(tx, ty, lightLevelThis.toIntBits()) texturedLightSourcePixmap.drawPixel(tx, ty, lightLevelThis.toRGBA())
texturedShadeSourcePixmap.drawPixel(tx, ty, thisTileOpacity.toIntBits()) texturedShadeSourcePixmap.drawPixel(tx, ty, thisTileOpacity.toRGBA())
if (wy in for_y_start..for_y_end && wx in for_x_start..for_x_end) { /*if (wy in for_y_start..for_y_end && wx in for_x_start..for_x_end) {
texturedLightSourcePixmap.drawPixel(tx, ty, 0x00FFFFFF) texturedLightSourcePixmap.drawPixel(tx, ty, 0x00FFFFFF)
} }
else { else {
texturedLightSourcePixmap.drawPixel(tx, ty, 0xFF000000.toInt()) texturedLightSourcePixmap.drawPixel(tx, ty, 0xFF000000.toInt())
} }*/
} }
} }
@@ -426,9 +427,10 @@ object LightmapRenderer {
texturedLightMap.inAction(texturedLightCamera, null) { texturedLightMap.inAction(texturedLightCamera, null) {
gdxClearAndSetBlend(0f,0f,0f,0f) gdxClearAndSetBlend(0f,0f,0f,0f)
Gdx.gl.glDisable(GL20.GL_BLEND)
texturedLightSources.bind(LIGHTMAP_UNIT)
texturedShadeSources.bind(SHADEMAP_UNIT) texturedShadeSources.bind(SHADEMAP_UNIT)
texturedLightSources.bind(LIGHTMAP_UNIT)
lightCalcShader.begin() lightCalcShader.begin()
lightCalcShader.setUniformMatrix("u_projTrans", texturedLightCamera.combined) lightCalcShader.setUniformMatrix("u_projTrans", texturedLightCamera.combined)
@@ -1079,3 +1081,6 @@ object LightmapRenderer {
return (1f - scale) * startValue + scale * endValue return (1f - scale) * startValue + scale * endValue
} }
} }
fun Color.toRGBA() = (255 * r).toInt() shl 24 or ((255 * g).toInt() shl 16) or ((255 * b).toInt() shl 8) or (255 * a).toInt()