Преглед изворни кода

Uniforms for everything and lower settings

Tankernn пре 8 година
родитељ
комит
1963d5196b

+ 1 - 2
TODO.txt

@@ -1,5 +1,4 @@
-All Masters, Renderers, etc. should be objects, not static
-Reflectivity uniform vars
+Particles and post-processing is broken.
 Multiplayer
 Modular GUIs
  - Make text variables uniform/ change text rendering method

+ 8 - 8
src/main/java/eu/tankernn/gameEngine/MainLoop.java

@@ -22,7 +22,6 @@ import eu.tankernn.gameEngine.font.meshCreator.FontType;
 import eu.tankernn.gameEngine.font.meshCreator.GUIText;
 import eu.tankernn.gameEngine.loader.Loader;
 import eu.tankernn.gameEngine.loader.models.TexturedModel;
-import eu.tankernn.gameEngine.loader.obj.OBJFileLoader;
 import eu.tankernn.gameEngine.loader.textures.ModelTexture;
 import eu.tankernn.gameEngine.loader.textures.TerrainTexturePack;
 import eu.tankernn.gameEngine.loader.textures.Texture;
@@ -86,17 +85,18 @@ public class MainLoop {
 		TerrainPack terrainPack = new TerrainPack(loader, texturePack, blendMap, SEED);
 
 		// Player
-		RawModel playerModel = loader.loadOBJ(new InternalFile("dragon.obj"));
+		RawModel playerModel = loader.loadOBJ(new InternalFile("apple.obj"));
 		TexturedModel texturedMonkeyModel = new TexturedModel(playerModel,
 				new ModelTexture(loader.loadTexture("white.png")));
 
 		ModelTexture texture = texturedMonkeyModel.getModelTexture();
 		texture.setReflectivity(3);
+		texture.setRefractivity(1.0f);
 		texture.setShineDamper(10);
 
 		Entity entity = new Entity(texturedMonkeyModel, new Vector3f(0, 0, 20), new Vector3f(0, 0, 0), 1);
 		entities.add(entity);
-		TexturedModel monkey = new TexturedModel(playerModel, new ModelTexture(loader.loadTexture("white.png")));
+		TexturedModel monkey = new TexturedModel(playerModel, texture);
 		Player player = new Player(monkey, new Vector3f(10, 0, 50), new Vector3f(0, 0, 0), 1, terrainPack);
 		entities.add(player);
 		Camera camera = new PlayerCamera(player, terrainPack);
@@ -104,7 +104,7 @@ public class MainLoop {
 		InternalFile[] dayTextures = InternalFile.fromFilenames("skybox", TEXTURE_FILES, "png"),
 				nightTextures = InternalFile.fromFilenames("skybox", NIGHT_TEXTURE_FILES, "png");
 
-		Skybox skybox = new Skybox(Texture.newCubeMap(dayTextures, 500), Texture.newCubeMap(nightTextures, 500), 500);
+		Skybox skybox = new Skybox(Texture.newCubeMap(dayTextures, 200), Texture.newCubeMap(nightTextures, 200), 200);
 
 		MasterRenderer renderer = new MasterRenderer(loader, camera, skybox);
 		ParticleMaster particleMaster = new ParticleMaster(loader, camera.getProjectionMatrix());
@@ -163,8 +163,8 @@ public class MainLoop {
 		List<GuiTexture> guis = new ArrayList<GuiTexture>();
 		GuiRenderer guiRenderer = new GuiRenderer(loader);
 
-		ParticleTexture particleTexture = new ParticleTexture(loader.loadTexture("particles/cosmic.png"), 4, true);
-		ParticleSystem ps = new ParticleSystem(particleTexture, 50, 10, 0.3f, 4);
+		ParticleTexture particleTexture = new ParticleTexture(loader.loadTexture("particles/fire.png"), 4, false);
+		ParticleSystem ps = new ParticleSystem(particleTexture, 50, 10, 0.3f, 1);
 		particleMaster.addSystem(ps);
 		
 		MultisampleMultitargetFbo multisampleFbo = new MultisampleMultitargetFbo(Display.getWidth(),
@@ -227,12 +227,12 @@ public class MainLoop {
 			EnvironmentMapRenderer.renderEnvironmentMap(scene.getEnvironmentMap(), scene, player.getPosition(),
 					renderer);
 
-			waterMaster.renderBuffers(renderer, scene);
+			//waterMaster.renderBuffers(renderer, scene);
 
 			multisampleFbo.bindFrameBuffer();
 
 			renderer.renderScene(scene, new Vector4f(0, 1, 0, Float.MAX_VALUE));
-			waterMaster.renderWater(camera, lights);
+			//waterMaster.renderWater(camera, lights);
 			particleMaster.renderParticles(camera);
 
 			multisampleFbo.unbindFrameBuffer();

+ 17 - 7
src/main/java/eu/tankernn/gameEngine/loader/textures/ModelTexture.java

@@ -1,12 +1,13 @@
 package eu.tankernn.gameEngine.loader.textures;
 
 public class ModelTexture {
-	private Texture textureID;
+	private Texture colorTexture;
 	private Texture normalMap;
 	private Texture specularMap;
 
-	private float shineDemper = 1;
+	private float shineDamper = 1;
 	private float reflectivity = 0;
+	private float refractivity = 0;
 
 	private boolean hasTransparency = false;
 	private boolean useFakeLighting = false;
@@ -14,12 +15,12 @@ public class ModelTexture {
 
 	private int numberOfRows = 1;
 
-	public ModelTexture(Texture id) {
-		this.textureID = id;
+	public ModelTexture(Texture texture) {
+		this.colorTexture = texture;
 	}
 
 	public Texture getTexture() {
-		return textureID;
+		return colorTexture;
 	}
 
 	public boolean hasTransparency() {
@@ -56,11 +57,11 @@ public class ModelTexture {
 	}
 
 	public float getShineDamper() {
-		return shineDemper;
+		return shineDamper;
 	}
 
 	public ModelTexture setShineDamper(float shineDemper) {
-		this.shineDemper = shineDemper;
+		this.shineDamper = shineDemper;
 		return this;
 	}
 
@@ -86,4 +87,13 @@ public class ModelTexture {
 	public Texture getSpecularMap() {
 		return this.specularMap;
 	}
+
+	public float getRefractivity() {
+		return refractivity;
+	}
+
+	public ModelTexture setRefractivity(float refractivity) {
+		this.refractivity = refractivity;
+		return this;
+	}
 }

+ 1 - 0
src/main/java/eu/tankernn/gameEngine/renderEngine/entities/EntityRenderer.java

@@ -95,6 +95,7 @@ public class EntityRenderer<S extends EntityShader> {
 		shader.useFakeLighting.loadBoolean(texture.isUseFakeLighting());
 		shader.shineDamper.loadFloat(texture.getShineDamper());
 		shader.reflectivity.loadFloat(texture.getReflectivity());
+		shader.refractivity.loadFloat(texture.getRefractivity());
 		model.getModelTexture().getTexture().bindToUnit(0);
 		shader.usesSpecularMap.loadBoolean(texture.hasSpecularMap());
 		if (texture.hasSpecularMap()) {

+ 4 - 3
src/main/java/eu/tankernn/gameEngine/renderEngine/entities/EntityShader.java

@@ -18,9 +18,10 @@ public class EntityShader extends ShaderProgram {
 	protected UniformMatrix transformationMatrix = new UniformMatrix("transformationMatrix");
 	protected UniformMatrix projectionMatrix = new UniformMatrix("projectionMatrix");
 	protected UniformViewMatrix viewMatrix = new UniformViewMatrix("viewMatrix");
-	
+
 	protected UniformFloat shineDamper = new UniformFloat("shineDamper");
 	protected UniformFloat reflectivity = new UniformFloat("reflectivity");
+	protected UniformFloat refractivity = new UniformFloat("refractivity");
 	protected UniformBoolean useFakeLighting = new UniformBoolean("useFakeLighting");
 	protected UniformVec3 skyColor = new UniformVec3("skyColor");
 	protected UniformFloat numberOfRows = new UniformFloat("numberOfRows");
@@ -38,8 +39,8 @@ public class EntityShader extends ShaderProgram {
 		super(VERTEX_FILE, FRAGMENT_FILE, "position", "textureCoords", "normal");
 		super.getLightUniformLocations();
 		super.storeAllUniformLocations(transformationMatrix, projectionMatrix, viewMatrix, shineDamper, reflectivity,
-				useFakeLighting, skyColor, numberOfRows, offset, plane, toShadowMapSpace, shadowMap, specularMap,
-				usesSpecularMap, modelTexture, cameraPosition, enviroMap);
+				refractivity, useFakeLighting, skyColor, numberOfRows, offset, plane, toShadowMapSpace, shadowMap,
+				specularMap, usesSpecularMap, modelTexture, cameraPosition, enviroMap);
 	}
 
 	public EntityShader(String vertexFile, String fragmentFile, String... string) {

+ 6 - 2
src/main/java/eu/tankernn/gameEngine/renderEngine/entities/fragmentShader.glsl

@@ -21,6 +21,7 @@ uniform vec3 lightColor[4]; //4 max light sources
 uniform vec3 attenuation[4];
 uniform float shineDamper;
 uniform float reflectivity;
+uniform float refractivity;
 uniform vec3 skyColor;
 
 //const float levels = 3.0;
@@ -80,7 +81,10 @@ void main(void){
 	
 	vec4 reflectedColor = texture(enviroMap, reflectedVector);
 	vec4 refractedColor = texture(enviroMap, refractedVector);
-	vec4 enviroColor = mix(reflectedColor, refractedColor, 0.5);
+	vec4 enviroColor = reflectedColor;
+	if (refractivity > 0) {
+		enviroColor = mix(reflectedColor, refractedColor, (reflectivity / 10) / refractivity);
+	}
 	
-	out_Color = mix(out_Color, enviroColor, 0.3);
+	out_Color = mix(out_Color, enviroColor, (reflectivity / 10 + refractivity) / 2);
 }

+ 1 - 1
src/main/java/eu/tankernn/gameEngine/renderEngine/shadows/ShadowMapMasterRenderer.java

@@ -25,7 +25,7 @@ import eu.tankernn.gameEngine.loader.textures.Texture;
  */
 public class ShadowMapMasterRenderer {
 
-	public static final int SHADOW_MAP_SIZE = 1024 * 4;
+	public static final int SHADOW_MAP_SIZE = 1024 * 2;
 
 	private ShadowFrameBuffer shadowFbo;
 	private ShadowShader shader;

+ 9 - 0
src/main/java/eu/tankernn/gameEngine/renderEngine/water/WaterRenderer.java

@@ -14,11 +14,15 @@ import eu.tankernn.gameEngine.loader.Loader;
 import eu.tankernn.gameEngine.loader.textures.Texture;
 import eu.tankernn.gameEngine.renderEngine.DisplayManager;
 import eu.tankernn.gameEngine.renderEngine.RawModel;
+import eu.tankernn.gameEngine.settings.Settings;
 import eu.tankernn.gameEngine.util.Maths;
 
 public class WaterRenderer {
 	
 	private static final float WAVE_SPEED = 0.03f;
+	private static final float WAVE_STRENGTH = 0.04f;
+	private static final float SHINE_DAMPER = 20.0f;
+	private static final float REFLECTIVITY = 0.5f;
 	
 	private RawModel quad;
 	private WaterShader shader;
@@ -61,6 +65,11 @@ public class WaterRenderer {
 		moveFactor %= 1;
 		shader.moveFactor.loadFloat(moveFactor);
 		shader.loadLights(lights);
+		shader.nearPlane.loadFloat(Settings.NEAR_PLANE);
+		shader.farPlane.loadFloat(Settings.FAR_PLANE);
+		shader.waveStrength.loadFloat(WAVE_STRENGTH);
+		shader.shineDamper.loadFloat(SHINE_DAMPER);
+		shader.reflectivity.loadFloat(REFLECTIVITY);
 		quad.bind(0);
 		buffers.getReflectionTexture().bindToUnit(0);
 		buffers.getRefractionTexture().bindToUnit(1);

+ 6 - 1
src/main/java/eu/tankernn/gameEngine/renderEngine/water/WaterShader.java

@@ -22,12 +22,17 @@ public class WaterShader extends ShaderProgram {
 	protected UniformVec3 cameraPosition = new UniformVec3("cameraPosition");
 	protected UniformSampler normalMap = new UniformSampler("normalMap");
 	protected UniformSampler depthMap = new UniformSampler("depthMap");
+	protected UniformFloat nearPlane = new UniformFloat("nearPlane");
+	protected UniformFloat farPlane = new UniformFloat("farPlane");
+	protected UniformFloat shineDamper = new UniformFloat("shineDamper");
+	protected UniformFloat reflectivity = new UniformFloat("reflectivity");
+	protected UniformFloat waveStrength = new UniformFloat("waveStrength");
 
 	public WaterShader() {
 		super(VERTEX_FILE, FRAGMENT_FILE, "position");
 		super.getLightUniformLocations();
 		super.storeAllUniformLocations(modelMatrix, viewMatrix, projectionMatrix, reflectionTexture, refractionTexture,
-				dudvMap, moveFactor, cameraPosition, normalMap, depthMap);
+				dudvMap, moveFactor, cameraPosition, normalMap, depthMap, nearPlane, farPlane, shineDamper, reflectivity, waveStrength);
 	}
 
 	public void connectTextureUnits() {

+ 5 - 5
src/main/java/eu/tankernn/gameEngine/renderEngine/water/waterFragment.glsl

@@ -17,11 +17,11 @@ uniform vec3 lightColor[4]; //4 max light sources
 uniform vec3 attenuation[4];
 uniform float moveFactor;
 
-const float waveStrength = 0.04;
-const float shineDamper = 20.0;
-const float reflectivity = 0.5;
-const float nearPlane = 0.1;
-const float farPlane = 1000.0;
+uniform float waveStrength;
+uniform float shineDamper;
+uniform float reflectivity;
+uniform float nearPlane;
+uniform float farPlane;
 
 void main(void) {
 	

+ 2 - 2
src/main/java/eu/tankernn/gameEngine/settings/Settings.java

@@ -4,7 +4,7 @@ public class Settings {
 	//Display settings
 	public static final float FOV = 70;
 	public static final float NEAR_PLANE = 0.1f;
-	public static final float FAR_PLANE = 1000;
+	public static final float FAR_PLANE = 500;
 	
 	//Sky color
 	public static final float RED = 0.7f;
@@ -14,5 +14,5 @@ public class Settings {
 	public static final float TERRAIN_SIZE = 800;
 	
 	public static final float ANISOTROPIC_FILTERING_AMOUNT = 4f;
-	public static final int MULTISAMPLING = 2;
+	public static final int MULTISAMPLING = 0;
 }

+ 0 - 3
src/main/java/eu/tankernn/gameEngine/terrains/TerrainPack.java

@@ -15,7 +15,6 @@ import java.util.concurrent.Future;
 
 import org.apache.commons.lang3.tuple.Pair;
 
-import eu.tankernn.gameEngine.MainLoop;
 import eu.tankernn.gameEngine.loader.Loader;
 import eu.tankernn.gameEngine.loader.textures.TerrainTexturePack;
 import eu.tankernn.gameEngine.loader.textures.Texture;
@@ -91,8 +90,6 @@ public class TerrainPack {
 
 		waitingData.values().removeIf(f -> {
 			if (f.isDone()) {
-				if (MainLoop.DEBUG)
-					System.out.println("Adding terrain");
 				try {
 					TerrainModelData data = f.get();
 					terrains.put(Pair.of(data.getGridX(), data.getGridZ()),