partly broken and half working shadows
parent
dd892ba6e1
commit
395144e6ee
|
@ -75,7 +75,7 @@ public class Example {
|
||||||
|
|
||||||
|
|
||||||
TexturedModel dragonMdl = ModelLoader.loadModel("dragon.obj", "stallTexture.png");
|
TexturedModel dragonMdl = ModelLoader.loadModel("dragon.obj", "stallTexture.png");
|
||||||
dragonMdl.getTexture().setReflectivity(4f);
|
dragonMdl.getTexture().setReflectivity(4f);
|
||||||
dragonMdl.getTexture().setShineDamper(2f);
|
dragonMdl.getTexture().setShineDamper(2f);
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ public class Example {
|
||||||
float colour = 0;
|
float colour = 0;
|
||||||
terrains.add(terrain);
|
terrains.add(terrain);
|
||||||
|
|
||||||
GuiTexture shadowMap = new GuiTexture(masterRenderer.getShadowMapTexture(), new Vector2f(0.5f,0.5f), new Vector2f(0.5f,0.5f));
|
// GuiTexture shadowMap = new GuiTexture(masterRenderer.getShadowMapTexture(), new Vector2f(0.5f,0.5f), new Vector2f(0.5f,0.5f));
|
||||||
guis.add(shadowMap);
|
// guis.add(shadowMap);
|
||||||
|
|
||||||
ParticleTexture particleTexture = new ParticleTexture(Loader.loadTexture("particles/smoke.png"), 8);
|
ParticleTexture particleTexture = new ParticleTexture(Loader.loadTexture("particles/smoke.png"), 8);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL13;
|
||||||
|
|
||||||
import io.github.hydos.ginger.engine.elements.Entity;
|
import io.github.hydos.ginger.engine.elements.Entity;
|
||||||
import io.github.hydos.ginger.engine.elements.Light;
|
import io.github.hydos.ginger.engine.elements.Light;
|
||||||
|
@ -80,7 +81,13 @@ public class MasterRenderer {
|
||||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void prepare() {
|
||||||
|
GL13.glActiveTexture(GL13.GL_TEXTURE5);
|
||||||
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, shadowMapRenderer.getShadowMap());
|
||||||
|
}
|
||||||
|
|
||||||
public void renderScene(List<Entity> entities, List<Entity> normalEntities, List<Terrain> terrains, List<Light> lights, ThirdPersonCamera camera, Vector4f clipPlane) {
|
public void renderScene(List<Entity> entities, List<Entity> normalEntities, List<Terrain> terrains, List<Light> lights, ThirdPersonCamera camera, Vector4f clipPlane) {
|
||||||
|
prepare();
|
||||||
renderEntities(entities, camera, lights);
|
renderEntities(entities, camera, lights);
|
||||||
renderNormalEntities(normalEntities, lights, camera, clipPlane);
|
renderNormalEntities(normalEntities, lights, camera, clipPlane);
|
||||||
renderTerrains(terrains, lights, camera);
|
renderTerrains(terrains, lights, camera);
|
||||||
|
@ -105,7 +112,7 @@ public class MasterRenderer {
|
||||||
terrainShader.loadSkyColour(Window.getColour());
|
terrainShader.loadSkyColour(Window.getColour());
|
||||||
terrainShader.loadLights(lights);
|
terrainShader.loadLights(lights);
|
||||||
terrainShader.loadViewMatrix(camera);
|
terrainShader.loadViewMatrix(camera);
|
||||||
terrainRenderer.render(terrains);
|
terrainRenderer.render(terrains, shadowMapRenderer.getToShadowMapSpaceMatrix());
|
||||||
terrainShader.stop();
|
terrainShader.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ public class TerrainRenderer {
|
||||||
shader.stop();
|
shader.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(List<Terrain> terrains) {
|
public void render(List<Terrain> terrains, Matrix4f toShadowSpace) {
|
||||||
|
shader.loadToShadowMapSpace(toShadowSpace);
|
||||||
for(Terrain t : terrains) {
|
for(Terrain t : terrains) {
|
||||||
prepareTerrain(t);
|
prepareTerrain(t);
|
||||||
loadModelMatrix(t);
|
loadModelMatrix(t);
|
||||||
|
|
|
@ -34,7 +34,10 @@ public class TerrainShader extends ShaderProgram{
|
||||||
private int location_bTexture;
|
private int location_bTexture;
|
||||||
|
|
||||||
private int location_blendMap;
|
private int location_blendMap;
|
||||||
|
|
||||||
|
private int location_toShadowMapSpace;
|
||||||
|
|
||||||
|
private int location_shadowMap;
|
||||||
|
|
||||||
public TerrainShader() {
|
public TerrainShader() {
|
||||||
super("terrainVertexShader.glsl", "terrainFragmentShader.glsl");
|
super("terrainVertexShader.glsl", "terrainFragmentShader.glsl");
|
||||||
|
@ -61,6 +64,8 @@ public class TerrainShader extends ShaderProgram{
|
||||||
location_gTexture = super.getUniformLocation("gTexture");
|
location_gTexture = super.getUniformLocation("gTexture");
|
||||||
location_bTexture = super.getUniformLocation("bTexture");
|
location_bTexture = super.getUniformLocation("bTexture");
|
||||||
location_blendMap = super.getUniformLocation("blendMap");
|
location_blendMap = super.getUniformLocation("blendMap");
|
||||||
|
location_toShadowMapSpace = super.getUniformLocation("toShadowMapSpace");
|
||||||
|
location_shadowMap = super.getUniformLocation("shadowMap");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,12 +111,17 @@ public class TerrainShader extends ShaderProgram{
|
||||||
super.loadVector(location_skyColour, colour);
|
super.loadVector(location_skyColour, colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadToShadowMapSpace(Matrix4f matrix) {
|
||||||
|
super.loadMatrix(location_toShadowMapSpace, matrix);
|
||||||
|
}
|
||||||
|
|
||||||
public void connectTextureUnits() {
|
public void connectTextureUnits() {
|
||||||
super.loadInt(location_backgroundTexture, 0);
|
super.loadInt(location_backgroundTexture, 0);
|
||||||
super.loadInt(location_rTexture, 1);
|
super.loadInt(location_rTexture, 1);
|
||||||
super.loadInt(location_gTexture, 2);
|
super.loadInt(location_gTexture, 2);
|
||||||
super.loadInt(location_bTexture, 3);
|
super.loadInt(location_bTexture, 3);
|
||||||
super.loadInt(location_blendMap, 4);
|
super.loadInt(location_blendMap, 4);
|
||||||
|
super.loadInt(location_shadowMap, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import io.github.hydos.ginger.engine.renderEngine.models.TexturedModel;
|
||||||
*/
|
*/
|
||||||
public class ShadowMapMasterRenderer {
|
public class ShadowMapMasterRenderer {
|
||||||
|
|
||||||
private static final int SHADOW_MAP_SIZE = 2048;
|
private static final int SHADOW_MAP_SIZE = 4096;
|
||||||
|
|
||||||
private ShadowFrameBuffer shadowFbo;
|
private ShadowFrameBuffer shadowFbo;
|
||||||
private ShadowShader shader;
|
private ShadowShader shader;
|
||||||
|
|
|
@ -5,6 +5,7 @@ in vec3 surfaceNormal;
|
||||||
in vec3 toLightVector[5];
|
in vec3 toLightVector[5];
|
||||||
in vec3 toCameraVector;
|
in vec3 toCameraVector;
|
||||||
in float visibility;
|
in float visibility;
|
||||||
|
in vec4 shadowCoords;
|
||||||
|
|
||||||
out vec4 out_Color;
|
out vec4 out_Color;
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ uniform sampler2D rTexture;
|
||||||
uniform sampler2D gTexture;
|
uniform sampler2D gTexture;
|
||||||
uniform sampler2D bTexture;
|
uniform sampler2D bTexture;
|
||||||
uniform sampler2D blendMap;
|
uniform sampler2D blendMap;
|
||||||
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
uniform vec3 attenuation[5];
|
uniform vec3 attenuation[5];
|
||||||
uniform vec3 lightColour[5];
|
uniform vec3 lightColour[5];
|
||||||
const float shineDamper = 0;
|
const float shineDamper = 0;
|
||||||
|
@ -21,6 +24,12 @@ uniform vec3 skyColour;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
|
float objectNearestLight = texture(shadowMap, shadowCoords.xy).r;
|
||||||
|
float lightFactor = 1.0;
|
||||||
|
if(shadowCoords.z > objectNearestLight){
|
||||||
|
lightFactor = 1.0 - 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
vec4 blendMapColour = texture(blendMap, pass_textureCoords);
|
vec4 blendMapColour = texture(blendMap, pass_textureCoords);
|
||||||
|
|
||||||
vec3 unitVectorToCamera = normalize(toCameraVector);
|
vec3 unitVectorToCamera = normalize(toCameraVector);
|
||||||
|
@ -55,7 +64,7 @@ void main(void){
|
||||||
totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i] / attFactor;
|
totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i] / attFactor;
|
||||||
|
|
||||||
}
|
}
|
||||||
totalDiffuse = max(totalDiffuse, 0.2);
|
totalDiffuse = max(totalDiffuse, 0.2) * lightFactor;
|
||||||
|
|
||||||
out_Color = vec4(totalDiffuse, 1.0) * totalColour + vec4(totalSpecular, 1.0);
|
out_Color = vec4(totalDiffuse, 1.0) * totalColour + vec4(totalSpecular, 1.0);
|
||||||
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#version 400 core
|
#version 150
|
||||||
|
|
||||||
in vec3 position;
|
in vec3 position;
|
||||||
in vec2 textureCoords;
|
in vec2 textureCoords;
|
||||||
in vec3 normal;
|
in vec3 normal;
|
||||||
|
@ -9,18 +8,23 @@ out vec3 surfaceNormal;
|
||||||
out vec3 toLightVector[5];
|
out vec3 toLightVector[5];
|
||||||
out vec3 toCameraVector;
|
out vec3 toCameraVector;
|
||||||
out float visibility;
|
out float visibility;
|
||||||
|
out vec4 shadowCoords;
|
||||||
|
|
||||||
uniform mat4 transformationMatrix;
|
uniform mat4 transformationMatrix;
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
uniform vec3 lightPosition[5];
|
uniform vec3 lightPosition[5];
|
||||||
|
|
||||||
|
uniform mat4 toShadowMapSpace;
|
||||||
|
|
||||||
const float density = 0.01;
|
const float density = 0.01;
|
||||||
const float gradient = 1;
|
const float gradient = 1;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
||||||
|
shadowCoords = toShadowMapSpace * worldPosition;
|
||||||
|
|
||||||
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
||||||
|
|
||||||
gl_Position = projectionMatrix * positionRelativeToCam;
|
gl_Position = projectionMatrix * positionRelativeToCam;
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,6 +5,7 @@ in vec3 surfaceNormal;
|
||||||
in vec3 toLightVector[5];
|
in vec3 toLightVector[5];
|
||||||
in vec3 toCameraVector;
|
in vec3 toCameraVector;
|
||||||
in float visibility;
|
in float visibility;
|
||||||
|
in vec4 shadowCoords;
|
||||||
|
|
||||||
out vec4 out_Color;
|
out vec4 out_Color;
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ uniform sampler2D rTexture;
|
||||||
uniform sampler2D gTexture;
|
uniform sampler2D gTexture;
|
||||||
uniform sampler2D bTexture;
|
uniform sampler2D bTexture;
|
||||||
uniform sampler2D blendMap;
|
uniform sampler2D blendMap;
|
||||||
|
uniform sampler2D shadowMap;
|
||||||
|
|
||||||
uniform vec3 attenuation[5];
|
uniform vec3 attenuation[5];
|
||||||
uniform vec3 lightColour[5];
|
uniform vec3 lightColour[5];
|
||||||
const float shineDamper = 0;
|
const float shineDamper = 0;
|
||||||
|
@ -21,6 +24,12 @@ uniform vec3 skyColour;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
|
float objectNearestLight = texture(shadowMap, shadowCoords.xy).r;
|
||||||
|
float lightFactor = 1.0;
|
||||||
|
if(shadowCoords.z > objectNearestLight){
|
||||||
|
lightFactor = 1.0 - 0.4;
|
||||||
|
}
|
||||||
|
|
||||||
vec4 blendMapColour = texture(blendMap, pass_textureCoords);
|
vec4 blendMapColour = texture(blendMap, pass_textureCoords);
|
||||||
|
|
||||||
vec3 unitVectorToCamera = normalize(toCameraVector);
|
vec3 unitVectorToCamera = normalize(toCameraVector);
|
||||||
|
@ -55,7 +64,7 @@ void main(void){
|
||||||
totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i] / attFactor;
|
totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i] / attFactor;
|
||||||
|
|
||||||
}
|
}
|
||||||
totalDiffuse = max(totalDiffuse, 0.2);
|
totalDiffuse = max(totalDiffuse, 0.2) * lightFactor;
|
||||||
|
|
||||||
out_Color = vec4(totalDiffuse, 1.0) * totalColour + vec4(totalSpecular, 1.0);
|
out_Color = vec4(totalDiffuse, 1.0) * totalColour + vec4(totalSpecular, 1.0);
|
||||||
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#version 400 core
|
#version 150
|
||||||
|
|
||||||
in vec3 position;
|
in vec3 position;
|
||||||
in vec2 textureCoords;
|
in vec2 textureCoords;
|
||||||
in vec3 normal;
|
in vec3 normal;
|
||||||
|
@ -9,18 +8,23 @@ out vec3 surfaceNormal;
|
||||||
out vec3 toLightVector[5];
|
out vec3 toLightVector[5];
|
||||||
out vec3 toCameraVector;
|
out vec3 toCameraVector;
|
||||||
out float visibility;
|
out float visibility;
|
||||||
|
out vec4 shadowCoords;
|
||||||
|
|
||||||
uniform mat4 transformationMatrix;
|
uniform mat4 transformationMatrix;
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
uniform vec3 lightPosition[5];
|
uniform vec3 lightPosition[5];
|
||||||
|
|
||||||
|
uniform mat4 toShadowMapSpace;
|
||||||
|
|
||||||
const float density = 0.01;
|
const float density = 0.01;
|
||||||
const float gradient = 1;
|
const float gradient = 1;
|
||||||
|
|
||||||
void main(void){
|
void main(void){
|
||||||
|
|
||||||
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
||||||
|
shadowCoords = toShadowMapSpace * worldPosition;
|
||||||
|
|
||||||
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
||||||
|
|
||||||
gl_Position = projectionMatrix * positionRelativeToCam;
|
gl_Position = projectionMatrix * positionRelativeToCam;
|
||||||
|
|
Loading…
Reference in New Issue