|
@@ -1,10 +1,7 @@
|
|
package eu.tankernn.gameEngine.renderEngine;
|
|
package eu.tankernn.gameEngine.renderEngine;
|
|
|
|
|
|
import static eu.tankernn.gameEngine.settings.Settings.BLUE;
|
|
import static eu.tankernn.gameEngine.settings.Settings.BLUE;
|
|
-import static eu.tankernn.gameEngine.settings.Settings.FAR_PLANE;
|
|
|
|
-import static eu.tankernn.gameEngine.settings.Settings.FOV;
|
|
|
|
import static eu.tankernn.gameEngine.settings.Settings.GREEN;
|
|
import static eu.tankernn.gameEngine.settings.Settings.GREEN;
|
|
-import static eu.tankernn.gameEngine.settings.Settings.NEAR_PLANE;
|
|
|
|
import static eu.tankernn.gameEngine.settings.Settings.RED;
|
|
import static eu.tankernn.gameEngine.settings.Settings.RED;
|
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
|
@@ -14,10 +11,8 @@ import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
-import org.lwjgl.opengl.Display;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.opengl.GL13;
|
|
import org.lwjgl.opengl.GL13;
|
|
-import org.lwjgl.util.vector.Matrix4f;
|
|
|
|
import org.lwjgl.util.vector.Vector4f;
|
|
import org.lwjgl.util.vector.Vector4f;
|
|
|
|
|
|
import eu.tankernn.gameEngine.entities.Camera;
|
|
import eu.tankernn.gameEngine.entities.Camera;
|
|
@@ -25,11 +20,14 @@ import eu.tankernn.gameEngine.entities.Entity;
|
|
import eu.tankernn.gameEngine.entities.Light;
|
|
import eu.tankernn.gameEngine.entities.Light;
|
|
import eu.tankernn.gameEngine.models.TexturedModel;
|
|
import eu.tankernn.gameEngine.models.TexturedModel;
|
|
import eu.tankernn.gameEngine.normalMapping.renderer.NormalMappingRenderer;
|
|
import eu.tankernn.gameEngine.normalMapping.renderer.NormalMappingRenderer;
|
|
-import eu.tankernn.gameEngine.shaders.StaticShader;
|
|
|
|
-import eu.tankernn.gameEngine.shaders.TerrainShader;
|
|
|
|
|
|
+import eu.tankernn.gameEngine.renderEngine.entities.EntityRenderer;
|
|
|
|
+import eu.tankernn.gameEngine.renderEngine.terrain.TerrainRenderer;
|
|
import eu.tankernn.gameEngine.shadows.ShadowMapMasterRenderer;
|
|
import eu.tankernn.gameEngine.shadows.ShadowMapMasterRenderer;
|
|
|
|
+import eu.tankernn.gameEngine.skybox.Skybox;
|
|
import eu.tankernn.gameEngine.skybox.SkyboxRenderer;
|
|
import eu.tankernn.gameEngine.skybox.SkyboxRenderer;
|
|
import eu.tankernn.gameEngine.terrains.Terrain;
|
|
import eu.tankernn.gameEngine.terrains.Terrain;
|
|
|
|
+import eu.tankernn.gameEngine.textures.Texture;
|
|
|
|
+import eu.tankernn.gameEngine.util.ICamera;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Handles most of the rendering in the game.
|
|
* Handles most of the rendering in the game.
|
|
@@ -37,8 +35,7 @@ import eu.tankernn.gameEngine.terrains.Terrain;
|
|
* @author Frans
|
|
* @author Frans
|
|
*/
|
|
*/
|
|
public class MasterRenderer {
|
|
public class MasterRenderer {
|
|
- private StaticShader staticShader = new StaticShader();
|
|
|
|
- private TerrainShader terrainShader = new TerrainShader();
|
|
|
|
|
|
+ private static final Vector4f NO_CLIP = new Vector4f(0, 0, 0, 1);
|
|
|
|
|
|
private EntityRenderer entityRenderer;
|
|
private EntityRenderer entityRenderer;
|
|
private TerrainRenderer terrainRenderer;
|
|
private TerrainRenderer terrainRenderer;
|
|
@@ -46,28 +43,27 @@ public class MasterRenderer {
|
|
private NormalMappingRenderer normalMapRenderer;
|
|
private NormalMappingRenderer normalMapRenderer;
|
|
private ShadowMapMasterRenderer shadowMapRenderer;
|
|
private ShadowMapMasterRenderer shadowMapRenderer;
|
|
|
|
|
|
- private Matrix4f projectionMatrix;
|
|
|
|
-
|
|
|
|
private Map<TexturedModel, List<Entity>> entities = new HashMap<TexturedModel, List<Entity>>();
|
|
private Map<TexturedModel, List<Entity>> entities = new HashMap<TexturedModel, List<Entity>>();
|
|
private Map<TexturedModel, List<Entity>> normalMapEntities = new HashMap<TexturedModel, List<Entity>>();
|
|
private Map<TexturedModel, List<Entity>> normalMapEntities = new HashMap<TexturedModel, List<Entity>>();
|
|
private List<Terrain> terrains = new ArrayList<Terrain>();
|
|
private List<Terrain> terrains = new ArrayList<Terrain>();
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets up most other renderers for rendering.
|
|
* Sets up most other renderers for rendering.
|
|
*
|
|
*
|
|
- * @param loader The main <code>Loader</code>, used by some other renderers
|
|
|
|
- * @param camera The main <code>Camera</code>
|
|
|
|
|
|
+ * @param loader
|
|
|
|
+ * The main <code>Loader</code>, used by some other renderers
|
|
|
|
+ * @param camera
|
|
|
|
+ * The main <code>Camera</code>
|
|
*/
|
|
*/
|
|
- public MasterRenderer(Loader loader, Camera camera, String[] dayTextureFiles, String[] nightTextureFiles) {
|
|
|
|
|
|
+ public MasterRenderer(Loader loader, Camera camera, Skybox skybox) {
|
|
enableCulling();
|
|
enableCulling();
|
|
- createProjectionMatrix();
|
|
|
|
- terrainRenderer = new TerrainRenderer(terrainShader, projectionMatrix);
|
|
|
|
- normalMapRenderer = new NormalMappingRenderer(projectionMatrix);
|
|
|
|
|
|
+ terrainRenderer = new TerrainRenderer(camera.getProjectionMatrix());
|
|
|
|
+ normalMapRenderer = new NormalMappingRenderer(camera.getProjectionMatrix());
|
|
shadowMapRenderer = new ShadowMapMasterRenderer(camera);
|
|
shadowMapRenderer = new ShadowMapMasterRenderer(camera);
|
|
- skyboxRenderer = new SkyboxRenderer(loader, projectionMatrix, dayTextureFiles, nightTextureFiles);
|
|
|
|
- entityRenderer = new EntityRenderer(staticShader, projectionMatrix, skyboxRenderer.getCubeMap());
|
|
|
|
|
|
+ skyboxRenderer = new SkyboxRenderer(loader, camera.getProjectionMatrix(), skybox);
|
|
|
|
+ entityRenderer = new EntityRenderer(camera.getProjectionMatrix());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Enables culling of faces facing away from the camera.
|
|
* Enables culling of faces facing away from the camera.
|
|
*/
|
|
*/
|
|
@@ -75,7 +71,7 @@ public class MasterRenderer {
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
GL11.glCullFace(GL11.GL_BACK);
|
|
GL11.glCullFace(GL11.GL_BACK);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Disables culling of faces facing away from the camera. Used when
|
|
* Disables culling of faces facing away from the camera. Used when
|
|
* rendering flat objects.
|
|
* rendering flat objects.
|
|
@@ -83,63 +79,62 @@ public class MasterRenderer {
|
|
public static void disableCulling() {
|
|
public static void disableCulling() {
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Renders a scene.
|
|
* Renders a scene.
|
|
*
|
|
*
|
|
- * @param scene The <code>Scene</code> to render.
|
|
|
|
- * @param clipPlane The clip plane.
|
|
|
|
|
|
+ * @param scene
|
|
|
|
+ * The <code>Scene</code> to render.
|
|
|
|
+ * @param clipPlane
|
|
|
|
+ * The clip plane.
|
|
*/
|
|
*/
|
|
public void renderScene(Scene scene, Vector4f clipPlane) {
|
|
public void renderScene(Scene scene, Vector4f clipPlane) {
|
|
scene.getTerrainPack().prepareRenderTerrains(this);
|
|
scene.getTerrainPack().prepareRenderTerrains(this);
|
|
- for (Entity e: scene.getEntities()) {
|
|
|
|
|
|
+ for (Entity e : scene.getEntities()) {
|
|
processEntity(e);
|
|
processEntity(e);
|
|
}
|
|
}
|
|
- for (Entity e: scene.getNormalEntities()) {
|
|
|
|
|
|
+ for (Entity e : scene.getNormalEntities()) {
|
|
processNormalMappedEntity(e);
|
|
processNormalMappedEntity(e);
|
|
}
|
|
}
|
|
- render(scene.getLights(), scene.getCamera(), clipPlane);
|
|
|
|
|
|
+ render(scene.getLights(), scene.getCamera(), clipPlane, scene.getEnvironmentMap());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void renderLowQualityScene(Scene scene, ICamera camera) {
|
|
|
|
+ prepare();
|
|
|
|
+ entityRenderer.render(entities, shadowMapRenderer.getToShadowMapSpaceMatrix(), camera, NO_CLIP, scene.getLights(), scene.getEnvironmentMap());
|
|
|
|
+ normalMapRenderer.render(normalMapEntities, NO_CLIP, scene.getLights(), camera);
|
|
|
|
+ terrainRenderer.render(terrains, shadowMapRenderer.getToShadowMapSpaceMatrix(), camera, NO_CLIP, scene.getLights());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Renders the current scene to the current buffer.
|
|
* Renders the current scene to the current buffer.
|
|
*
|
|
*
|
|
- * @param lights List of lights in the scene.
|
|
|
|
- * @param camera The main camera.
|
|
|
|
- * @param clipPlane The clip plane.
|
|
|
|
|
|
+ * @param lights
|
|
|
|
+ * List of lights in the scene.
|
|
|
|
+ * @param camera
|
|
|
|
+ * The main camera.
|
|
|
|
+ * @param clipPlane
|
|
|
|
+ * The clip plane.
|
|
*/
|
|
*/
|
|
- public void render(List<Light> lights, Camera camera, Vector4f clipPlane) {
|
|
|
|
|
|
+ public void render(List<Light> lights, ICamera camera, Vector4f clipPlane, Texture environmentMap) {
|
|
prepare();
|
|
prepare();
|
|
- staticShader.start();
|
|
|
|
- staticShader.loadClipPlane(clipPlane);
|
|
|
|
- staticShader.loadSkyColor(RED, GREEN, BLUE);
|
|
|
|
- staticShader.loadLights(lights);
|
|
|
|
- staticShader.loadViewMatrix(camera);
|
|
|
|
- entityRenderer.render(entities, shadowMapRenderer.getToShadowMapSpaceMatrix(), camera);
|
|
|
|
- staticShader.stop();
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ entityRenderer.render(entities, shadowMapRenderer.getToShadowMapSpaceMatrix(), camera, clipPlane, lights, environmentMap);
|
|
normalMapRenderer.render(normalMapEntities, clipPlane, lights, camera);
|
|
normalMapRenderer.render(normalMapEntities, clipPlane, lights, camera);
|
|
-
|
|
|
|
- terrainShader.start();
|
|
|
|
- terrainShader.loadClipPlane(clipPlane);
|
|
|
|
- terrainShader.loadSkyColor(RED, GREEN, BLUE);
|
|
|
|
- terrainShader.loadShadowMapSize(ShadowMapMasterRenderer.SHADOW_MAP_SIZE);
|
|
|
|
- terrainShader.loadLights(lights);
|
|
|
|
- terrainShader.loadViewMatrix(camera);
|
|
|
|
- terrainRenderer.render(terrains, shadowMapRenderer.getToShadowMapSpaceMatrix());
|
|
|
|
- terrainShader.stop();
|
|
|
|
-
|
|
|
|
|
|
+ terrainRenderer.render(terrains, shadowMapRenderer.getToShadowMapSpaceMatrix(), camera, clipPlane, lights);
|
|
skyboxRenderer.render(camera, RED, GREEN, BLUE);
|
|
skyboxRenderer.render(camera, RED, GREEN, BLUE);
|
|
-
|
|
|
|
|
|
+
|
|
entities.clear();
|
|
entities.clear();
|
|
terrains.clear();
|
|
terrains.clear();
|
|
normalMapEntities.clear();
|
|
normalMapEntities.clear();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Adds an entity to the list of entities.
|
|
* Adds an entity to the list of entities.
|
|
*
|
|
*
|
|
- * @param entity Entity to add to the list
|
|
|
|
|
|
+ * @param entity
|
|
|
|
+ * Entity to add to the list
|
|
*/
|
|
*/
|
|
public void processEntity(Entity entity) {
|
|
public void processEntity(Entity entity) {
|
|
TexturedModel entityModel = entity.getModel();
|
|
TexturedModel entityModel = entity.getModel();
|
|
@@ -152,11 +147,12 @@ public class MasterRenderer {
|
|
entities.put(entityModel, newBatch);
|
|
entities.put(entityModel, newBatch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Same as {@link #processEntity(Entity)}, but for normal-mapped entities.
|
|
* Same as {@link #processEntity(Entity)}, but for normal-mapped entities.
|
|
*
|
|
*
|
|
- * @param entity Entity to add to the list
|
|
|
|
|
|
+ * @param entity
|
|
|
|
+ * Entity to add to the list
|
|
*/
|
|
*/
|
|
public void processNormalMappedEntity(Entity entity) {
|
|
public void processNormalMappedEntity(Entity entity) {
|
|
TexturedModel entityModel = entity.getModel();
|
|
TexturedModel entityModel = entity.getModel();
|
|
@@ -169,24 +165,25 @@ public class MasterRenderer {
|
|
normalMapEntities.put(entityModel, newBatch);
|
|
normalMapEntities.put(entityModel, newBatch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Adds specified terrain to the terrain list.
|
|
* Adds specified terrain to the terrain list.
|
|
*
|
|
*
|
|
- * @param terrain Terrain object to add to list
|
|
|
|
|
|
+ * @param terrain
|
|
|
|
+ * Terrain object to add to list
|
|
*/
|
|
*/
|
|
public void processTerrain(Terrain terrain) {
|
|
public void processTerrain(Terrain terrain) {
|
|
terrains.add(terrain);
|
|
terrains.add(terrain);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void renderShadowMap(List<Entity> entityList, Light sun) {
|
|
public void renderShadowMap(List<Entity> entityList, Light sun) {
|
|
- for (Entity e: entityList) {
|
|
|
|
|
|
+ for (Entity e : entityList) {
|
|
processEntity(e);
|
|
processEntity(e);
|
|
}
|
|
}
|
|
shadowMapRenderer.render(entities, sun);
|
|
shadowMapRenderer.render(entities, sun);
|
|
entities.clear();
|
|
entities.clear();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Gets the shadow map texture from the <code>shadowMapRenderer</code>.
|
|
* Gets the shadow map texture from the <code>shadowMapRenderer</code>.
|
|
*
|
|
*
|
|
@@ -195,48 +192,27 @@ public class MasterRenderer {
|
|
public int getShadowMapTexture() {
|
|
public int getShadowMapTexture() {
|
|
return shadowMapRenderer.getShadowMap();
|
|
return shadowMapRenderer.getShadowMap();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Runs the cleanup method for the other renderers.
|
|
* Runs the cleanup method for the other renderers.
|
|
*/
|
|
*/
|
|
public void cleanUp() {
|
|
public void cleanUp() {
|
|
- staticShader.cleanUp();
|
|
|
|
- terrainShader.cleanUp();
|
|
|
|
|
|
+ entityRenderer.cleanUp();
|
|
|
|
+ terrainRenderer.cleanUp();
|
|
normalMapRenderer.cleanUp();
|
|
normalMapRenderer.cleanUp();
|
|
shadowMapRenderer.cleanUp();
|
|
shadowMapRenderer.cleanUp();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Prepares the current buffer for rendering.
|
|
* Prepares the current buffer for rendering.
|
|
*/
|
|
*/
|
|
public void prepare() {
|
|
public void prepare() {
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST | GL11.GL_DEPTH_BUFFER_BIT);
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST | GL11.GL_DEPTH_BUFFER_BIT);
|
|
GL11.glClearColor(RED, GREEN, BLUE, 1);
|
|
GL11.glClearColor(RED, GREEN, BLUE, 1);
|
|
- GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
|
|
|
|
|
|
+ GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the
|
|
|
|
+ // framebuffer
|
|
GL13.glActiveTexture(GL13.GL_TEXTURE5);
|
|
GL13.glActiveTexture(GL13.GL_TEXTURE5);
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, getShadowMapTexture());
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, getShadowMapTexture());
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void createProjectionMatrix() {
|
|
|
|
- float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();
|
|
|
|
- float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))));
|
|
|
|
- float x_scale = y_scale / aspectRatio;
|
|
|
|
- float frustum_length = FAR_PLANE - NEAR_PLANE;
|
|
|
|
-
|
|
|
|
- projectionMatrix = new Matrix4f();
|
|
|
|
- projectionMatrix.m00 = x_scale;
|
|
|
|
- projectionMatrix.m11 = y_scale;
|
|
|
|
- projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
|
|
|
|
- projectionMatrix.m23 = -1;
|
|
|
|
- projectionMatrix.m32 = -((2 * FAR_PLANE * NEAR_PLANE) / frustum_length);
|
|
|
|
- projectionMatrix.m33 = 0;
|
|
|
|
- }
|
|
|
|
- /**
|
|
|
|
- * Gets the current projection matrix.
|
|
|
|
- * @return The current projection matrix
|
|
|
|
- */
|
|
|
|
- public Matrix4f getProjectionMatrix() {
|
|
|
|
- return projectionMatrix;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|