mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
nice try, but it crashes the gpu AND I get <1 fps :(
This commit is contained in:
@@ -61,12 +61,18 @@ vec2[TRAVERSE_SIZE] traceRay(int arraySize, vec2 from, vec2 to) {
|
|||||||
|
|
||||||
void main() {
|
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);
|
vec4 outColor = vec4(0.0,0.0,0.0,0.0);
|
||||||
|
|
||||||
// 1. pick a light source
|
// 1. pick a light source
|
||||||
for (int y = 0; y < int(outSize.y); y++) {
|
for (int y = 0; y < int(outSize.y); y++) {
|
||||||
for (int x = 0; x < int(outSize.x); x++) {
|
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 to = gl_FragCoord.xy;
|
||||||
vec2 delta = to - from;
|
vec2 delta = to - from;
|
||||||
int traceCount = traceRayCount(delta);
|
int traceCount = traceRayCount(delta);
|
||||||
@@ -94,10 +100,9 @@ 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, gl_FragCoord.xy / outSize)) * multiplier;
|
//gl_FragColor = sampleFrom(lights, gl_FragCoord.xy) * multiplier;
|
||||||
|
|
||||||
// FIXME (gl_FragCoord / outSize) != v_texCoords
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
logoBatch.setProjectionMatrix(camera.combined);
|
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[]{
|
fullscreenQuad.setVertices(new float[]{
|
||||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
||||||
WIDTH, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 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.
|
* Return config from config set. If the config does not exist, default value will be returned.
|
||||||
* @param key
|
* @param key
|
||||||
* *
|
* *
|
||||||
* @return Config from config set or default config if it 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.
|
||||||
* *
|
|
||||||
* @throws NullPointerException if the specified config simply does not exist.
|
|
||||||
*/
|
*/
|
||||||
public static boolean getConfigBoolean(String key) {
|
public static boolean getConfigBoolean(String key) {
|
||||||
Object cfg = getConfigMaster(key);
|
try {
|
||||||
if (cfg instanceof JsonPrimitive)
|
Object cfg = getConfigMaster(key);
|
||||||
return ((JsonPrimitive) cfg).getAsBoolean();
|
if (cfg instanceof JsonPrimitive)
|
||||||
else
|
return ((JsonPrimitive) cfg).getAsBoolean();
|
||||||
return ((boolean) cfg);
|
else
|
||||||
|
return ((boolean) cfg);
|
||||||
|
}
|
||||||
|
catch (NullPointerException keyNotFound) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getConfigIntArray(String key) {
|
public static int[] getConfigIntArray(String key) {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ object DefaultConfig {
|
|||||||
jsonObject.addProperty("notificationshowuptime", 6500)
|
jsonObject.addProperty("notificationshowuptime", 6500)
|
||||||
jsonObject.addProperty("multithread", true) // experimental!
|
jsonObject.addProperty("multithread", true) // experimental!
|
||||||
jsonObject.addProperty("multithreadedlight", false) // experimental!
|
jsonObject.addProperty("multithreadedlight", false) // experimental!
|
||||||
jsonObject.addProperty("gpulightcalc", true) // experimental!
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,10 +105,6 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
if (SHADER_LIGHTING) {
|
if (SHADER_LIGHTING) {
|
||||||
lightCalcShader = AppLoader.loadShader("assets/4096.vert", "assets/raytracelight.frag")
|
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 = FrameBuffer(Pixmap.Format.RGBA8888, LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT, false)
|
||||||
//texturedLightMap = Texture(LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT, Pixmap.Format.RGBA8888)
|
//texturedLightMap = Texture(LIGHTMAP_WIDTH, LIGHTMAP_HEIGHT, Pixmap.Format.RGBA8888)
|
||||||
@@ -133,11 +129,11 @@ object LightmapRenderer {
|
|||||||
VertexAttribute.ColorUnpacked(),
|
VertexAttribute.ColorUnpacked(),
|
||||||
VertexAttribute.TexCoords(0)
|
VertexAttribute.TexCoords(0)
|
||||||
)
|
)
|
||||||
texturedLightQuad.setVertices(floatArrayOf(
|
texturedLightQuad.setVertices(floatArrayOf( // y-flipped quads!
|
||||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 0f,
|
||||||
LIGHTMAP_WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
|
LIGHTMAP_WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
|
||||||
LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat(), 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, 0f))
|
0f, LIGHTMAP_HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 1f))
|
||||||
texturedLightQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
texturedLightQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
|
||||||
|
|
||||||
texturedLightCamera = OrthographicCamera(LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat())
|
texturedLightCamera = OrthographicCamera(LIGHTMAP_WIDTH.toFloat(), LIGHTMAP_HEIGHT.toFloat())
|
||||||
@@ -433,7 +429,11 @@ object LightmapRenderer {
|
|||||||
texturedLightSources.bind(LIGHTMAP_UNIT)
|
texturedLightSources.bind(LIGHTMAP_UNIT)
|
||||||
|
|
||||||
lightCalcShader.begin()
|
lightCalcShader.begin()
|
||||||
|
// it seems that every time shader ends, uniforms reset themselves.
|
||||||
lightCalcShader.setUniformMatrix("u_projTrans", texturedLightCamera.combined)
|
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)
|
texturedLightQuad.render(lightCalcShader, GL20.GL_TRIANGLES)
|
||||||
lightCalcShader.end()
|
lightCalcShader.end()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user