Remove cel clamp in default shader
This commit is contained in:
parent
dc7f8dda0a
commit
9ccea0a9b5
@ -127,11 +127,11 @@ float calcLightIntensityDir(vec3 normal){
|
|||||||
// diffuse shading
|
// diffuse shading
|
||||||
float diff = max(dot(normal, lightDir), 0.0);
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
//clamp for cel shading
|
//clamp for cel shading
|
||||||
if(diff > 0.1){
|
// if(diff > 0.1){
|
||||||
diff = 0.3;
|
// diff = 0.3;
|
||||||
} else {
|
// } else {
|
||||||
diff = diff * 3.0;
|
// diff = diff * 3.0;
|
||||||
}
|
// }
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
248
assets/Shaders/anime/celShading.fs
Normal file
248
assets/Shaders/anime/celShading.fs
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
#define NR_POINT_LIGHTS 10
|
||||||
|
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
|
||||||
|
layout (std140) uniform Lights {
|
||||||
|
// this is how many because we have to align
|
||||||
|
// bytes it SHOULD in multiples of 16, this
|
||||||
|
// take it where it ACTUALLY is
|
||||||
|
//
|
||||||
|
//refer: https://learnopengl.com/Advanced-OpenGL/Advanced-GLSL
|
||||||
|
//
|
||||||
|
// base alignment aligned offset
|
||||||
|
//direct light
|
||||||
|
vec3 dLDirection; // 16 0
|
||||||
|
vec3 dLAmbient; // 16 16
|
||||||
|
vec3 dLDiffuse; // 16 32
|
||||||
|
vec3 dLSpecular; // 16 48
|
||||||
|
|
||||||
|
//point light
|
||||||
|
vec3 pLposition[NR_POINT_LIGHTS]; // 16*10 64
|
||||||
|
float pLconstant[NR_POINT_LIGHTS]; // 16*10 224
|
||||||
|
float pLlinear[NR_POINT_LIGHTS]; // 16*10 384
|
||||||
|
float pLquadratic[NR_POINT_LIGHTS]; // 16*10 544
|
||||||
|
vec3 pLambient[NR_POINT_LIGHTS]; // 16*10 704
|
||||||
|
vec3 pLdiffuse[NR_POINT_LIGHTS]; // 16*10 864
|
||||||
|
vec3 pLspecular[NR_POINT_LIGHTS]; // 16*10 1024
|
||||||
|
|
||||||
|
//for a total size of 1184
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse;
|
||||||
|
sampler2D specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
in vec2 TexCoord;
|
||||||
|
in vec4 FragPosLightSpace;
|
||||||
|
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
// uniform DirLight dirLight;
|
||||||
|
// uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||||
|
// uniform SpotLight spotLight;
|
||||||
|
uniform Material material;
|
||||||
|
|
||||||
|
//texture stuff
|
||||||
|
// uniform sampler2D ourTexture;
|
||||||
|
uniform int hasTransparency;
|
||||||
|
// uniform sampler2D specularTexture;
|
||||||
|
|
||||||
|
//light depth map
|
||||||
|
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);
|
||||||
|
float calcLightIntensityTotal(vec3 normal);
|
||||||
|
float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal);
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
if(hasTransparency == 1){
|
||||||
|
if(texture(material.diffuse, TexCoord).a < 0.1){
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
|
||||||
|
//grab light intensity
|
||||||
|
float lightIntensity = calcLightIntensityTotal(norm);
|
||||||
|
|
||||||
|
//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.4);
|
||||||
|
// 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(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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
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
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// // 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){
|
||||||
|
|
||||||
|
// perform perspective divide
|
||||||
|
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||||
|
|
||||||
|
//transform to NDC
|
||||||
|
projCoords = projCoords * 0.5 + 0.5;
|
||||||
|
|
||||||
|
//get closest depth from light's POV
|
||||||
|
float closestDepth = texture(shadowMap, projCoords.xy).r;
|
||||||
|
|
||||||
|
//get depth of current fragment
|
||||||
|
float currentDepth = projCoords.z;
|
||||||
|
|
||||||
|
//calculate bias
|
||||||
|
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||||
|
|
||||||
|
//calculate shadow value
|
||||||
|
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||||
|
|
||||||
|
if(projCoords.z > 1.0){
|
||||||
|
shadow = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//calculate dot product, if it is >0 we know they're parallel-ish therefore should disregard the shadow mapping
|
||||||
|
//ie the fragment is already facing away from the light source
|
||||||
|
float dotprod = dot(normalize(lightDir),normalize(normal));
|
||||||
|
|
||||||
|
if(dotprod > 0.0){
|
||||||
|
shadow = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow = currentDepth;
|
||||||
|
|
||||||
|
return shadow;
|
||||||
|
}
|
||||||
71
assets/Shaders/anime/celShading.vs
Normal file
71
assets/Shaders/anime/celShading.vs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
//Vertex Shader
|
||||||
|
#version 330 core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//input buffers
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
layout (location = 2) in vec4 aWeights;
|
||||||
|
layout (location = 3) in vec4 aIndex;
|
||||||
|
layout (location = 4) in vec2 aTex;
|
||||||
|
|
||||||
|
|
||||||
|
//coordinate space transformation matrices
|
||||||
|
uniform mat4 transform;
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
|
||||||
|
//bone related variables
|
||||||
|
const int MAX_WEIGHTS = 4;
|
||||||
|
const int MAX_BONES = 100;
|
||||||
|
uniform mat4 bones[MAX_BONES];
|
||||||
|
uniform int hasBones;
|
||||||
|
uniform int numBones;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//output buffers
|
||||||
|
out vec3 Normal;
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec2 TexCoord;
|
||||||
|
out vec4 FragPosLightSpace;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//calculate bone transform
|
||||||
|
mat4 BoneTransform = (bones[int(aIndex[0])] * aWeights[0]);
|
||||||
|
BoneTransform = BoneTransform + (bones[int(aIndex[1])] * aWeights[1]);
|
||||||
|
BoneTransform = BoneTransform + (bones[int(aIndex[2])] * aWeights[2]);
|
||||||
|
BoneTransform = BoneTransform + (bones[int(aIndex[3])] * aWeights[3]);
|
||||||
|
|
||||||
|
|
||||||
|
//apply bone transform to position vectors
|
||||||
|
vec4 FinalVertex = BoneTransform * vec4(aPos, 1.0);
|
||||||
|
vec4 FinalNormal = BoneTransform * vec4(aNormal, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//make sure the W component is 1.0
|
||||||
|
FinalVertex = vec4(FinalVertex.xyz, 1.0);
|
||||||
|
FinalNormal = vec4(FinalNormal.xyz, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//push frag, normal, and texture positions to fragment shader
|
||||||
|
FragPos = vec3(model * FinalVertex);
|
||||||
|
Normal = mat3(transpose(inverse(model))) * FinalNormal.xyz;
|
||||||
|
TexCoord = aTex;
|
||||||
|
|
||||||
|
//shadow map stuff
|
||||||
|
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
//set final position with opengl space
|
||||||
|
gl_Position = projection * view * model * FinalVertex;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user