Merge pull request 'shadows still broken' (#119) from animeShader into master

Reviewed-on: https://git.austinwhoover.com/gitadmin/Renderer/pulls/119
This commit is contained in:
gitadmin 2022-05-15 22:14:15 +00:00
commit 6d731db5b2
6 changed files with 129 additions and 50 deletions

View File

@ -109,6 +109,19 @@
"primaryBone" : "Head", "primaryBone" : "Head",
"minValue" : 0.8, "minValue" : 0.8,
"maxValue" : 1.2 "maxValue" : 1.2
},
{
"attributeId" : "hair",
"type" : "remesh",
"variants" : [
{
"id" : "hairshort1",
"model" : "Models/hairshort1meshed.fbx",
"meshes" : [
"Hair"
]
}
]
} }
], ],
"movementSystems" : [ "movementSystems" : [

View File

@ -60,9 +60,10 @@ uniform sampler2D shadowMap;
// function prototypes // function prototypes
vec3 CalcDirLight(vec3 normal, vec3 viewDir); // vec3 CalcDirLight(vec3 normal, vec3 viewDir);
vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir); // vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir);
vec3 CalcSpotLight(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); float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal);
void main(){ void main(){
@ -74,63 +75,89 @@ void main(){
vec3 norm = normalize(Normal); vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPos - FragPos); vec3 viewDir = normalize(viewPos - FragPos);
//grab light intensity
float lightIntensity = calcLightIntensityTotal(norm);
vec3 result = CalcDirLight(norm, viewDir); //get color of base texture
for(int i = 0; i < NR_POINT_LIGHTS; i++){ vec3 textureColor = texture(material.diffuse, TexCoord).rgb;
result += CalcPointLight(i, norm, FragPos, viewDir);
} //shadow
//for(int i = 0; i < NR_POINT_LIGHTS; i++){ float shadow = ShadowCalculation(FragPosLightSpace, normalize(-dLDirection), norm);
// result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
//} //calculate final color
//result += CalcSpotLight(spotLight, norm, FragPos, viewDir); 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 //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. // calculates the color when using a directional light.
vec3 CalcDirLight(vec3 normal, vec3 viewDir){ // vec3 CalcDirLight(vec3 normal, vec3 viewDir){
vec3 lightDir = normalize(-dLDirection); // 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);
// // diffuse shading // // diffuse shading
// float diff = max(dot(normal, lightDir), 0.0); // float diff = max(dot(normal, lightDir), 0.0);
// // specular shading // // specular shading
// vec3 reflectDir = reflect(-lightDir, normal); // // vec3 reflectDir = reflect(-lightDir, normal);
// float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); // // 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));
// // combine results // // combine results
// vec3 ambient = light.ambient * vec4(texture(material.diffuse, TexCoord)).xyz; // vec3 texColor = texture(material.diffuse, TexCoord).rgb;
// vec3 diffuse = light.diffuse * diff * vec4(texture(material.diffuse, TexCoord)).xyz; // vec3 diffuse = dLDiffuse * diff;
// vec3 specular = light.specular * spec * vec4(texture(material.specular, TexCoord)).xyz; // //vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoord).rgb);
// ambient *= attenuation;
// diffuse *= attenuation;
// specular *= attenuation; // float shadow = ShadowCalculation(FragPosLightSpace, lightDir, normal);
// return (ambient + diffuse + specular);
// 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 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir){
vec3 lightDir = normalize(pLposition[i] - fragPos); vec3 lightDir = normalize(pLposition[i] - fragPos);
// diffuse shading // diffuse shading
@ -156,6 +183,32 @@ vec3 CalcPointLight(int i, vec3 normal, vec3 fragPos, vec3 viewDir){
return finalValue; 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){ float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){

View File

@ -157,6 +157,14 @@
"/Textures/w1.png", "/Textures/w1.png",
"/Textures/w1.png" "/Textures/w1.png"
], ],
"Ear.R" : [
"/Textures/skin1.png",
"/Textures/skin1.png"
],
"Ear.L" : [
"/Textures/skin1.png",
"/Textures/skin1.png"
],
"Iris.R" : [ "Iris.R" : [
"/Textures/b1.png", "/Textures/b1.png",
"/Textures/b1.png" "/Textures/b1.png"

View File

@ -6,6 +6,7 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.creature.type.CollidableTemplate; import electrosphere.game.data.creature.type.CollidableTemplate;
@ -569,11 +570,13 @@ public class RenderingEngine {
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && (boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) && drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) &&
currentEntity.containsKey(EntityDataStrings.DRAW_CAST_SHADOW) currentEntity.containsKey(EntityDataStrings.DRAW_CAST_SHADOW)
// && !currentEntity.containsKey(EntityDataStrings.TERRAIN_IS_TERRAIN)
){ ){
//fetch actor //fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3f //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 //calculate and apply model transform
modelTransformMatrix = modelTransformMatrix.identity(); modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.translate(cameraModifiedPosition);
@ -588,6 +591,7 @@ public class RenderingEngine {
} }
} }
//reset texture //reset texture
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View File

@ -232,6 +232,7 @@ public class Actor {
// } // }
// } // }
applyAnimationMasks(model); applyAnimationMasks(model);
model.setMeshMask(meshMask);
calculateNodeTransforms(model); calculateNodeTransforms(model);
model.drawForDepthBuffer(); model.drawForDepthBuffer();
} }

View File

@ -48,7 +48,7 @@ public class LightManager {
//create directional light //create directional light
directionalLight = new DirectionalLight(new Vector3f(1,-1,0).normalize()); 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.setDiffuse(new Vector3f(0.3f,0.3f,0.3f));
directionalLight.setDirection(sunPosition); directionalLight.setDirection(sunPosition);
directionalLight.setSpecular(new Vector3f(0.0f,0.0f,0.0f)); directionalLight.setSpecular(new Vector3f(0.0f,0.0f,0.0f));