shadows still broken
This commit is contained in:
parent
c69e4e9c9e
commit
772e1e770c
@ -109,6 +109,19 @@
|
||||
"primaryBone" : "Head",
|
||||
"minValue" : 0.8,
|
||||
"maxValue" : 1.2
|
||||
},
|
||||
{
|
||||
"attributeId" : "hair",
|
||||
"type" : "remesh",
|
||||
"variants" : [
|
||||
{
|
||||
"id" : "hairshort1",
|
||||
"model" : "Models/hairshort1meshed.fbx",
|
||||
"meshes" : [
|
||||
"Hair"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"movementSystems" : [
|
||||
|
||||
@ -60,9 +60,10 @@ uniform sampler2D shadowMap;
|
||||
|
||||
|
||||
// function prototypes
|
||||
vec3 CalcDirLight(vec3 normal, vec3 viewDir);
|
||||
vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||
vec3 CalcSpotLight(vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||
// vec3 CalcDirLight(vec3 normal, vec3 viewDir);
|
||||
// vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||
// vec3 CalcSpotLight(vec3 normal, vec3 fragPos, vec3 viewDir);
|
||||
float calcLightIntensityTotal(vec3 normal);
|
||||
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal);
|
||||
|
||||
void main(){
|
||||
@ -74,63 +75,89 @@ void main(){
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
|
||||
//grab light intensity
|
||||
float lightIntensity = calcLightIntensityTotal(norm);
|
||||
|
||||
vec3 result = CalcDirLight(norm, viewDir);
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||
result += CalcPointLight(i, norm, FragPos, viewDir);
|
||||
}
|
||||
//for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||
// result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
//}
|
||||
//result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
|
||||
//get color of base texture
|
||||
vec3 textureColor = texture(material.diffuse, TexCoord).rgb;
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-dLDirection), norm);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.9);
|
||||
// vec3 lightAmount = CalcDirLight(norm, viewDir);
|
||||
// for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||
// lightAmount += CalcPointLight(i, norm, FragPos, viewDir);
|
||||
// }
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(result, texture(material.diffuse, TexCoord).a);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
|
||||
FragColor = vec4(finalColor, texture(material.diffuse, TexCoord).a);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
|
||||
}
|
||||
|
||||
// calculates the color when using a directional light.
|
||||
vec3 CalcDirLight(vec3 normal, vec3 viewDir){
|
||||
vec3 lightDir = normalize(-dLDirection);
|
||||
// diffuse shading
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
// specular shading
|
||||
// vec3 reflectDir = reflect(-lightDir, normal);
|
||||
// float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
// combine results
|
||||
vec3 texColor = texture(material.diffuse, TexCoord).rgb;
|
||||
vec3 diffuse = dLDiffuse * diff;
|
||||
//vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord).rgb);
|
||||
|
||||
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, lightDir, normal);
|
||||
|
||||
return ( dLAmbient + (1.0-shadow) * diffuse ) * texColor;// + specular);
|
||||
}
|
||||
|
||||
|
||||
// calculates the color when using a point light.
|
||||
// vec3 CalcPointLight(vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||
// vec3 lightDir = normalize(light.position - fragPos);
|
||||
// vec3 CalcDirLight(vec3 normal, vec3 viewDir){
|
||||
// vec3 lightDir = normalize(-dLDirection);
|
||||
// // diffuse shading
|
||||
// float diff = max(dot(normal, lightDir), 0.0);
|
||||
// // specular shading
|
||||
// vec3 reflectDir = reflect(-lightDir, normal);
|
||||
// float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
// // attenuation
|
||||
// float distance = length(light.position - fragPos);
|
||||
// float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
// // vec3 reflectDir = reflect(-lightDir, normal);
|
||||
// // float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
// // combine results
|
||||
// vec3 ambient = light.ambient * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||
// vec3 diffuse = light.diffuse * diff * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||
// vec3 specular = light.specular * spec * vec4(texture(material.specular, TexCoord)).xyz;
|
||||
// ambient *= attenuation;
|
||||
// diffuse *= attenuation;
|
||||
// specular *= attenuation;
|
||||
// return (ambient + diffuse + specular);
|
||||
// vec3 texColor = texture(material.diffuse, TexCoord).rgb;
|
||||
// vec3 diffuse = dLDiffuse * diff;
|
||||
// //vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord).rgb);
|
||||
|
||||
|
||||
// float shadow = ShadowCalculation(FragPosLightSpace, lightDir, normal);
|
||||
|
||||
// return ( dLAmbient + (1.0-shadow) * diffuse ) * texColor;// + specular);
|
||||
// }
|
||||
|
||||
// calculates the color when using a point light.
|
||||
//
|
||||
float calcLightIntensityAmbient(){
|
||||
//calculate average of ambient light
|
||||
float avg = (dLAmbient.x + dLAmbient.y + dLAmbient.z)/3.0;
|
||||
return avg;
|
||||
}
|
||||
|
||||
//
|
||||
float calcLightIntensityDir(vec3 normal){
|
||||
vec3 lightDir = normalize(-dLDirection);
|
||||
// diffuse shading
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
//clamp for cel shading
|
||||
if(diff > 0.1){
|
||||
diff = 0.3;
|
||||
} else {
|
||||
diff = diff * 3.0;
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
//
|
||||
float calcLightIntensityTotal(vec3 normal){
|
||||
//ambient intensity
|
||||
float ambientLightIntensity = calcLightIntensityAmbient();
|
||||
|
||||
//get direct intensity
|
||||
float directLightIntensity = calcLightIntensityDir(normal);
|
||||
|
||||
//sum
|
||||
float total = ambientLightIntensity + directLightIntensity;
|
||||
return total;
|
||||
}
|
||||
|
||||
//
|
||||
vec3 getTotalLightColor(vec3 normal){
|
||||
//get the direct light color adjusted for intensity
|
||||
vec3 diffuseLightColor = dLDiffuse * calcLightIntensityDir(normal);
|
||||
|
||||
//sum light colors
|
||||
vec3 totalLightColor = diffuseLightColor;
|
||||
return totalLightColor;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||
vec3 lightDir = normalize(pLposition[i] - fragPos);
|
||||
// diffuse shading
|
||||
@ -156,6 +183,32 @@ vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||
return finalValue;
|
||||
}
|
||||
|
||||
// // calculates the color when using a point light.
|
||||
// vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir){
|
||||
// vec3 lightDir = normalize(pLposition[i] - fragPos);
|
||||
// // diffuse shading
|
||||
// float diff = max(dot(normal, lightDir), 0.0);
|
||||
// // specular shading
|
||||
// // vec3 reflectDir = reflect(-lightDir, normal);
|
||||
// // float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
// // attenuation
|
||||
// float distance = length(pLposition[i] - fragPos);
|
||||
// float attenuation = 1.0 / (pLconstant[i] + pLlinear[i] * distance + pLquadratic[i] * (distance * distance));
|
||||
// // combine results
|
||||
// vec3 ambient = pLambient[i];// * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||
// vec3 diffuse = pLdiffuse[i] * diff;// * vec4(texture(material.diffuse, TexCoord)).xyz;
|
||||
// // vec3 specular = pLspecular[i] * spec;// * vec4(texture(material.specular, TexCoord)).xyz;
|
||||
// ambient *= attenuation;
|
||||
// diffuse *= attenuation;
|
||||
// // specular *= attenuation;
|
||||
// vec3 specular = vec3(0,0,0);
|
||||
|
||||
// vec3 finalValue = (ambient + diffuse + specular);
|
||||
// finalValue = vec3(max(finalValue.x,0),max(finalValue.y,0),max(finalValue.z,0));
|
||||
|
||||
// return finalValue;
|
||||
// }
|
||||
|
||||
|
||||
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){
|
||||
|
||||
|
||||
@ -157,6 +157,14 @@
|
||||
"/Textures/w1.png",
|
||||
"/Textures/w1.png"
|
||||
],
|
||||
"Ear.R" : [
|
||||
"/Textures/skin1.png",
|
||||
"/Textures/skin1.png"
|
||||
],
|
||||
"Ear.L" : [
|
||||
"/Textures/skin1.png",
|
||||
"/Textures/skin1.png"
|
||||
],
|
||||
"Iris.R" : [
|
||||
"/Textures/b1.png",
|
||||
"/Textures/b1.png"
|
||||
|
||||
@ -6,6 +6,7 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.camera.CameraEntityUtils;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.hitbox.HitboxData;
|
||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||
import electrosphere.game.data.creature.type.CollidableTemplate;
|
||||
@ -569,11 +570,13 @@ public class RenderingEngine {
|
||||
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
|
||||
drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) &&
|
||||
currentEntity.containsKey(EntityDataStrings.DRAW_CAST_SHADOW)
|
||||
// && !currentEntity.containsKey(EntityDataStrings.TERRAIN_IS_TERRAIN)
|
||||
){
|
||||
//fetch actor
|
||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||
//calculate camera-modified vector3f
|
||||
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||
Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
||||
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(cameraCenter);
|
||||
//calculate and apply model transform
|
||||
modelTransformMatrix = modelTransformMatrix.identity();
|
||||
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||
@ -588,6 +591,7 @@ public class RenderingEngine {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//reset texture
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@ -232,6 +232,7 @@ public class Actor {
|
||||
// }
|
||||
// }
|
||||
applyAnimationMasks(model);
|
||||
model.setMeshMask(meshMask);
|
||||
calculateNodeTransforms(model);
|
||||
model.drawForDepthBuffer();
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class LightManager {
|
||||
|
||||
//create directional light
|
||||
directionalLight = new DirectionalLight(new Vector3f(1,-1,0).normalize());
|
||||
directionalLight.setAmbient(new Vector3f(0.1f,0.1f,0.1f));
|
||||
directionalLight.setAmbient(new Vector3f(0.6f,0.6f,0.6f));
|
||||
directionalLight.setDiffuse(new Vector3f(0.3f,0.3f,0.3f));
|
||||
directionalLight.setDirection(sunPosition);
|
||||
directionalLight.setSpecular(new Vector3f(0.0f,0.0f,0.0f));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user