Skip to content

Commit b3d2f51

Browse files
committed
Merge PR #2426 by @emanuele3d - rendering TODOs.
2 parents 21bbdc4 + 7707eb6 commit b3d2f51

15 files changed

+85
-10
lines changed

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ public void applyParameters(Material program) {
4343

4444
program.setFloat("viewingDistance", CoreRegistry.get(Config.class).getRendering().getViewDistance().getChunkDistance().x * 8.0f, true);
4545

46+
// TODO: obtain once in superclass?
4647
WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
4748
BackdropProvider backdropProvider = CoreRegistry.get(BackdropProvider.class);
4849

50+
// TODO: move into BaseMaterial?
4951
if (worldRenderer != null && backdropProvider != null) {
5052
program.setFloat("daylight", backdropProvider.getDaylight(), true);
5153
program.setFloat("swimming", worldRenderer.isHeadUnderWater() ? 1.0f : 0.0f, true);

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersBlock.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ public ShaderParametersBlock() {
3737
public void applyParameters(Material program) {
3838
super.applyParameters(program);
3939

40+
// TODO: move in material or node, take advantage of texture.subscribeToDisposal()
4041
Texture terrainTex = Assets.getTexture("engine:terrain").get();
4142

43+
// TODO: review - unnecessary?
4244
if (terrainTex == null) {
4345
return;
4446
}
4547

48+
// TODO: move texture binding into the appropriate node(s) as state changes.
4649
GL13.glActiveTexture(GL13.GL_TEXTURE0);
4750
glBindTexture(GL11.GL_TEXTURE_2D, terrainTex.getId());
4851

52+
// TODO: move into material
4953
program.setFloat3("colorOffset", 1.0f, 1.0f, 1.0f, true);
5054
program.setBoolean("textured", true, true);
5155
program.setFloat("alpha", 1.0f, true);

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersChunk.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.lwjgl.opengl.GL11;
1919
import org.lwjgl.opengl.GL13;
20+
import org.terasology.config.RenderingConfig;
2021
import org.terasology.utilities.Assets;
2122
import org.terasology.config.Config;
2223
import org.terasology.math.geom.Vector4f;
@@ -76,6 +77,7 @@ public class ShaderParametersChunk extends ShaderParametersBase {
7677
public void applyParameters(Material program) {
7778
super.applyParameters(program);
7879

80+
// TODO: move in material or node, take advantage of texture.subscribeToDisposal()
7981
Optional<Texture> terrain = Assets.getTexture("engine:terrain");
8082
Optional<Texture> terrainNormal = Assets.getTexture("engine:terrainNormal");
8183
Optional<Texture> terrainHeight = Assets.getTexture("engine:terrainHeight");
@@ -91,45 +93,59 @@ public void applyParameters(Material program) {
9193
}
9294

9395
FrameBuffersManager buffersManager = CoreRegistry.get(FrameBuffersManager.class);
96+
RenderingConfig renderingConfig = CoreRegistry.get(Config.class).getRendering();
9497

98+
// TODO move texture binding and setting into nodes
9599
int texId = 0;
100+
// TODO: group these three lines in a method somewhere
96101
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
97102
glBindTexture(GL11.GL_TEXTURE_2D, terrain.get().getId());
98103
program.setInt("textureAtlas", texId++, true);
104+
99105
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
100106
glBindTexture(GL11.GL_TEXTURE_2D, water.get().getId());
101107
program.setInt("textureWater", texId++, true);
108+
102109
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
103110
glBindTexture(GL11.GL_TEXTURE_2D, lava.get().getId());
104111
program.setInt("textureLava", texId++, true);
112+
105113
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
106114
glBindTexture(GL11.GL_TEXTURE_2D, waterNormal.get().getId());
107115
program.setInt("textureWaterNormal", texId++, true);
116+
108117
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
109118
glBindTexture(GL11.GL_TEXTURE_2D, waterNormalAlt.get().getId());
110119
program.setInt("textureWaterNormalAlt", texId++, true);
120+
111121
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
112122
glBindTexture(GL11.GL_TEXTURE_2D, effects.get().getId());
113123
program.setInt("textureEffects", texId++, true);
124+
114125
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
115126
buffersManager.bindFboColorTexture("sceneReflected");
116127
program.setInt("textureWaterReflection", texId++, true);
128+
117129
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
118130
buffersManager.bindFboColorTexture("sceneOpaque");
119131
program.setInt("texSceneOpaque", texId++, true);
120132

121-
if (CoreRegistry.get(Config.class).getRendering().isNormalMapping()) {
133+
// TODO: monitor the renderingConfig for changes rather than check every frame
134+
if (renderingConfig.isNormalMapping()) {
122135
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
123136
glBindTexture(GL11.GL_TEXTURE_2D, terrainNormal.get().getId());
124137
program.setInt("textureAtlasNormal", texId++, true);
125138

126-
if (CoreRegistry.get(Config.class).getRendering().isParallaxMapping()) {
139+
if (renderingConfig.isParallaxMapping()) {
127140
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
128141
glBindTexture(GL11.GL_TEXTURE_2D, terrainHeight.get().getId());
129142
program.setInt("textureAtlasHeight", texId++, true);
143+
144+
program.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
130145
}
131146
}
132147

148+
// TODO: move into Material?
133149
Vector4f lightingSettingsFrag = new Vector4f();
134150
lightingSettingsFrag.z = waterSpecExp;
135151
program.setFloat4("lightingSettingsFrag", lightingSettingsFrag, true);
@@ -145,7 +161,8 @@ public void applyParameters(Material program) {
145161
alternativeWaterSettingsFrag.x = waterTint;
146162
program.setFloat4("alternativeWaterSettingsFrag", alternativeWaterSettingsFrag, true);
147163

148-
if (CoreRegistry.get(Config.class).getRendering().isAnimateWater()) {
164+
// TODO: monitor the renderingConfig for changes rather than check every frame
165+
if (renderingConfig.isAnimateWater()) {
149166
program.setFloat("waveIntensFalloff", waveIntensFalloff, true);
150167
program.setFloat("waveSizeFalloff", waveSizeFalloff, true);
151168
program.setFloat("waveSize", waveSize, true);
@@ -156,10 +173,5 @@ public void applyParameters(Material program) {
156173
program.setFloat("waveOverallScale", waveOverallScale, true);
157174
}
158175

159-
if (CoreRegistry.get(Config.class).getRendering().isParallaxMapping()
160-
&& CoreRegistry.get(Config.class).getRendering().isNormalMapping()) {
161-
program.setFloat4("parallaxProperties", parallaxBias, parallaxScale, 0.0f, 0.0f, true);
162-
}
163176
}
164-
165177
}

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersCombine.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public void applyParameters(Material program) {
4949
super.applyParameters(program);
5050

5151
int texId = 0;
52+
// TODO: obtain these objects once in superclass and add there monitoring functionality as needed?
5253
FrameBuffersManager frameBuffersManager = CoreRegistry.get(FrameBuffersManager.class);
5354
FBO sceneOpaque = frameBuffersManager.getFBO("sceneOpaque");
5455

56+
// TODO: move texture bindings to the appropriate nodes
5557
if (sceneOpaque != null) {
5658
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
5759
sceneOpaque.bindTexture();
@@ -81,10 +83,13 @@ public void applyParameters(Material program) {
8183
RenderingConfig renderingConfig = CoreRegistry.get(Config.class).getRendering();
8284
Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
8385

86+
// TODO: review - unnecessary? Probably from a time when shaders were initialized
87+
// TODO: on application startup rather than renderer startup.
8488
if (renderingConfig == null || activeCamera == null) {
8589
return;
8690
}
8791

92+
// TODO: monitor the property subscribing to it
8893
if (renderingConfig.isLocalReflections()) {
8994
if (sceneReflectiveRefractive != null) {
9095
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
@@ -96,12 +101,14 @@ public void applyParameters(Material program) {
96101
program.setMatrix4("projMatrix", activeCamera.getProjectionMatrix(), true);
97102
}
98103

104+
// TODO: monitor the property subscribing to it
99105
if (renderingConfig.isSsao()) {
100106
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
101107
frameBuffersManager.bindFboColorTexture("ssaoBlurred");
102108
program.setInt("texSsao", texId++, true);
103109
}
104110

111+
// TODO: monitor the property subscribing to it
105112
if (renderingConfig.isOutline()) {
106113
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
107114
frameBuffersManager.bindFboColorTexture("outline");
@@ -111,11 +118,13 @@ public void applyParameters(Material program) {
111118
program.setFloat("outlineThickness", outlineThickness, true);
112119
}
113120

121+
// TODO: monitor the property subscribing to it
114122
if (renderingConfig.isVolumetricFog()) {
115123
program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
116124
//TODO: Other parameters and volumetric fog test case is needed
117125
}
118126

127+
// TODO: monitor the property subscribing to it
119128
if (renderingConfig.isInscattering()) {
120129
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
121130
frameBuffersManager.bindFboColorTexture("sceneSkyBand1");

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersDebug.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void applyParameters(Material program) {
3939

4040
FrameBuffersManager buffersManager = CoreRegistry.get(FrameBuffersManager.class);
4141

42+
// TODO: review - might have to go into a debug node
4243
switch (config.getRendering().getDebug().getStage()) {
4344
case SHADOW_MAP:
4445
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersDefault.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ShaderParametersDefault extends ShaderParametersBase {
3131
public void applyParameters(Material program) {
3232
super.applyParameters(program);
3333

34+
// TODO: verify this is still relevant
3435
GL13.glActiveTexture(GL13.GL_TEXTURE0);
3536
glBindTexture(GL11.GL_TEXTURE_2D, 0);
3637
}

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersHdr.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public void applyParameters(Material program) {
4040
FrameBuffersManager buffersManager = CoreRegistry.get(FrameBuffersManager.class);
4141
PostProcessor postProcessor = CoreRegistry.get(PostProcessor.class);
4242

43+
// TODO: move into a node
4344
GL13.glActiveTexture(GL13.GL_TEXTURE0);
4445
buffersManager.bindFboColorTexture("scenePrePost");
4546

47+
// TODO: move into a material?
4648
program.setInt("texScene", 0, true);
4749
// TODO: move to DownSampleSceneAndUpdateExposure
4850
program.setFloat("exposure", postProcessor.getExposure() * exposureBias, true);

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersLightGeometryPass.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ public class ShaderParametersLightGeometryPass extends ShaderParametersBase {
4040
public void applyParameters(Material program) {
4141
super.applyParameters(program);
4242

43+
// TODO: obtain once in the superclass and monitor from there?
4344
FrameBuffersManager buffersManager = CoreRegistry.get(FrameBuffersManager.class);
4445
FBO sceneOpaque = buffersManager.getFBO("sceneOpaque");
4546

4647
int texId = 0;
4748
if (sceneOpaque != null) {
49+
// TODO: move content of this block into the node
4850
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
4951
sceneOpaque.bindDepthTexture();
5052
program.setInt("texSceneOpaqueDepth", texId++, true);
@@ -58,7 +60,9 @@ public void applyParameters(Material program) {
5860
program.setInt("texSceneOpaqueLightBuffer", texId++, true);
5961
}
6062

63+
// TODO: monitor property by subscribing to it
6164
if (CoreRegistry.get(Config.class).getRendering().isDynamicShadows()) {
65+
// TODO: move into node
6266
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
6367
buffersManager.bindFboDepthTexture("sceneShadowMap");
6468
program.setInt("texSceneShadowMap", texId++, true);
@@ -67,6 +71,7 @@ public void applyParameters(Material program) {
6771
Camera activeCamera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
6872

6973
if (lightCamera != null && activeCamera != null) {
74+
// TODO: move into material?
7075
program.setMatrix4("lightViewProjMatrix", lightCamera.getViewProjectionMatrix(), true);
7176
program.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true);
7277

@@ -76,6 +81,7 @@ public void applyParameters(Material program) {
7681
}
7782

7883
if (CoreRegistry.get(Config.class).getRendering().isCloudShadows()) {
84+
// TODO: move into node - make sure to obtain texture only once and subscribe to it
7985
Texture clouds = Assets.getTexture("engine:perlinNoiseTileable").get();
8086

8187
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersLightShaft.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ public class ShaderParametersLightShaft extends ShaderParametersBase {
4646
public void applyParameters(Material program) {
4747
super.applyParameters(program);
4848

49+
// TODO: obtain once in superclass and monitor from there?
4950
FrameBuffersManager buffersManager = CoreRegistry.get(FrameBuffersManager.class);
5051
FBO scene = buffersManager.getFBO("sceneOpaque");
5152

5253
int texId = 0;
5354

55+
// TODO: - move into node
56+
// TODO: - many null checks are happening in these shader parameter classes. I feel they are unnecessary
57+
// TODO: as those objects should never be null. If they are I'd be happy receiving an NPE and debugging as needed.
5458
if (scene != null) {
5559
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
5660
scene.bindTexture();
@@ -60,6 +64,7 @@ public void applyParameters(Material program) {
6064
program.setInt("texDepth", texId++, true);
6165
}
6266

67+
// TODO: move into Material?
6368
program.setFloat("density", density, true);
6469
program.setFloat("exposure", exposure, true);
6570
program.setFloat("weight", weight, true);
@@ -68,7 +73,9 @@ public void applyParameters(Material program) {
6873
WorldRenderer worldRenderer = CoreRegistry.get(WorldRenderer.class);
6974
BackdropProvider backdropProvider = CoreRegistry.get(BackdropProvider.class);
7075

76+
// TODO: eliminate null check?
7177
if (worldRenderer != null) {
78+
// TODO: move into Material?
7279
Vector3f sunDirection = backdropProvider.getSunDirection(true);
7380

7481
Camera activeCamera = worldRenderer.getActiveCamera();

engine/src/main/java/org/terasology/rendering/shader/ShaderParametersOcDistortion.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public class ShaderParametersOcDistortion extends ShaderParametersBase {
3030
public void applyParameters(Material program) {
3131
super.applyParameters(program);
3232

33+
// TODO: move into node
3334
int texId = 0;
35+
// TODO: convert the next three lines in a public method somewhere.
36+
// TODO: In the BaseMaterial class perhaps? Or an even more generic utility class?
3437
GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
3538
CoreRegistry.get(FrameBuffersManager.class).bindFboColorTexture("sceneFinal");
3639
program.setInt("texSceneFinal", texId++, true);

0 commit comments

Comments
 (0)