nice try, but it crashes the gpu AND I get <1 fps :(

This commit is contained in:
minjaesong
2019-01-29 17:35:56 +09:00
parent 882cd86dd4
commit 7f7c31d27f
4 changed files with 30 additions and 23 deletions

View File

@@ -61,12 +61,18 @@ vec2[TRAVERSE_SIZE] traceRay(int arraySize, vec2 from, vec2 to) {
void main() {
// this code will produce y-flipped image. It's your job to flip it again (e.g. using y-flipped fullscreen quad)
// Nice try, but it kills GPU :(
// reason: looks like traceRayCount() returns value greater than TRAVERSE_SIZE.
// even if I make traceRayCount() to return constant 3, I get less than 1 fps on GTX 970.
vec4 outColor = vec4(0.0,0.0,0.0,0.0);
// 1. pick a light source
for (int y = 0; y < int(outSize.y); y++) {
for (int x = 0; x < int(outSize.x); x++) {
vec2 from = vec2(x, y);
vec2 from = vec2(x + 0.5, y + 0.5); // +0.5 is used because gl_FragCoord does
vec2 to = gl_FragCoord.xy;
vec2 delta = to - from;
int traceCount = traceRayCount(delta);
@@ -94,10 +100,9 @@ void main() {
}
gl_FragColor = outColor * multiplier;
gl_FragColor = vec4(0,1,0,1);
//gl_FragColor = vec4(0,1,0,1);
gl_FragColor = vec4(texture2D(lights, gl_FragCoord.xy / outSize)) * multiplier;
//gl_FragColor = sampleFrom(lights, gl_FragCoord.xy) * multiplier;
// FIXME (gl_FragCoord / outSize) != v_texCoords
}

View File

@@ -496,7 +496,7 @@ public class AppLoader implements ApplicationListener {
logoBatch.setProjectionMatrix(camera.combined);
}
private void updateFullscreenQuad(int WIDTH, int HEIGHT) {
private void updateFullscreenQuad(int WIDTH, int HEIGHT) { // NOT y-flipped quads!
fullscreenQuad.setVertices(new float[]{
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
WIDTH, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
@@ -650,16 +650,19 @@ public class AppLoader implements ApplicationListener {
* Return config from config set. If the config does not exist, default value will be returned.
* @param key
* *
* @return Config from config set or default config if it does not exist.
* *
* @throws NullPointerException if the specified config simply does not exist.
* @return Config from config set or default config if it does not exist. If the default value is undefined, will return false.
*/
public static boolean getConfigBoolean(String key) {
Object cfg = getConfigMaster(key);
if (cfg instanceof JsonPrimitive)
return ((JsonPrimitive) cfg).getAsBoolean();
else
return ((boolean) cfg);
try {
Object cfg = getConfigMaster(key);
if (cfg instanceof JsonPrimitive)
return ((JsonPrimitive) cfg).getAsBoolean();
else
return ((boolean) cfg);
}
catch (NullPointerException keyNotFound) {
return false;
}
}
public static int[] getConfigIntArray(String key) {

View File

@@ -24,7 +24,6 @@ object DefaultConfig {
jsonObject.addProperty("notificationshowuptime", 6500)
jsonObject.addProperty("multithread", true) // experimental!
jsonObject.addProperty("multithreadedlight", false) // experimental!
jsonObject.addProperty("gpulightcalc", true) // experimental!

View File

@@ -105,10 +105,6 @@ object LightmapRenderer {
if (SHADER_LIGHTING) {
lightCalcShader = AppLoader.loadShader("assets/4096.vert", "assets/raytracelight.frag")
lightCalcShader.setUniformf("outSize", LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat())
lightCalcShader.setUniformi("shades", SHADEMAP_UNIT)
lightCalcShader.setUniformi("lights", LIGHTMAP_UNIT)
lightCalcShader.setUniformi("u_texture", 0)
texturedLightMap = FrameBuffer(Pixmap.Format.RGBA8888, LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT, false)
//texturedLightMap = Texture(LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT, Pixmap.Format.RGBA8888)
@@ -133,11 +129,11 @@ object LightmapRenderer {
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
texturedLightQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
LIGHTMAP_WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, LIGHTMAP_HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f))
texturedLightQuad.setVertices(floatArrayOf( // y-flipped quads!
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 0f,
LIGHTMAP_WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 1f,
0f, LIGHTMAP_HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 1f))
texturedLightQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
texturedLightCamera = OrthographicCamera(LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat())
@@ -433,7 +429,11 @@ object LightmapRenderer {
texturedLightSources.bind(LIGHTMAP_UNIT)
lightCalcShader.begin()
// it seems that every time shader ends, uniforms reset themselves.
lightCalcShader.setUniformMatrix("u_projTrans", texturedLightCamera.combined)
lightCalcShader.setUniformf("outSize", LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat())
lightCalcShader.setUniformi("shades", SHADEMAP_UNIT)
lightCalcShader.setUniformi("lights", LIGHTMAP_UNIT)
texturedLightQuad.render(lightCalcShader, GL20.GL_TRIANGLES)
lightCalcShader.end()
}