terrain uses new lighting flow
This commit is contained in:
parent
51f2627621
commit
0c15941efa
@ -11,6 +11,12 @@
|
|||||||
#define ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL 0.03125 //used to properly shift from texture to texture in the atlas
|
#define ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL 0.03125 //used to properly shift from texture to texture in the atlas
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transparency of the terrain
|
||||||
|
*/
|
||||||
|
#define TERRAIN_TRANSPARENCY 1.0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
in vec3 FragPos;
|
in vec3 FragPos;
|
||||||
@ -43,36 +49,27 @@ vec3 getColor(vec2 texPlane1, vec2 texPlane2, vec2 texPlane3, vec3 normal, vec3
|
|||||||
void main(){
|
void main(){
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
vec3 viewDir = normalize(vec3(viewPos) - FragPos);
|
vec3 viewDir = normalize(vec3(viewPos) - FragPos);
|
||||||
|
|
||||||
//grab light intensity
|
|
||||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
|
||||||
|
|
||||||
//get color of base texture
|
//get color of base texture
|
||||||
vec3 textureColor = getColor(texPlane1, texPlane2, texPlane3, norm, samplerIndexVec, samplerRatioVec, material);
|
vec3 albedo = getColor(texPlane1, texPlane2, texPlane3, norm, samplerIndexVec, samplerRatioVec, material);
|
||||||
|
|
||||||
//shadow
|
// Calculate the light to apply
|
||||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction.xyz), -norm);
|
vec3 light = getTotalLight(
|
||||||
|
material,
|
||||||
//
|
albedo,
|
||||||
//point light calculations
|
vec3(viewPos.xyz),
|
||||||
uint clusterIndex = findCluster(ViewFragPos, zNear, zFar);
|
FragPosLightSpace,
|
||||||
uint pointLightCount = clusters[clusterIndex].count;
|
ViewFragPos,
|
||||||
for(int i = 0; i < pointLightCount; i++){
|
FragPos,
|
||||||
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
norm,
|
||||||
PointLight pointLight = pointLight[pointLightIndex];
|
viewDir
|
||||||
lightIntensity = lightIntensity + CalcPointLight(pointLight, norm, FragPos, viewDir);
|
);
|
||||||
}
|
|
||||||
//error checking on light clusters
|
|
||||||
if(pointLightCount > MAX_LIGHTS_PER_CLUSTER){
|
|
||||||
FragColor = vec4(1.0f,0.0f,0.0f,1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//calculate final color
|
//calculate final color
|
||||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.4);
|
vec3 finalColor = light;
|
||||||
|
|
||||||
//this final calculation is for transparency
|
//this final calculation is for transparency
|
||||||
FragColor = vec4(finalColor, 1);
|
FragColor = vec4(finalColor, TERRAIN_TRANSPARENCY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -328,5 +328,54 @@ vec3 getTotalLight(
|
|||||||
//clamp
|
//clamp
|
||||||
vec3 lightClamp = vec3(min(lightSum.x,1),min(lightSum.y,1),min(lightSum.z,1));
|
vec3 lightClamp = vec3(min(lightSum.x,1),min(lightSum.y,1),min(lightSum.z,1));
|
||||||
|
|
||||||
|
return lightClamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total light to apply to the fragment
|
||||||
|
*/
|
||||||
|
vec3 getTotalLight(
|
||||||
|
Material mat,
|
||||||
|
vec3 albedo,
|
||||||
|
vec3 viewPos,
|
||||||
|
vec4 fragPosLightSpace,
|
||||||
|
vec3 fragPosView,
|
||||||
|
vec3 fragPos,
|
||||||
|
vec3 norm,
|
||||||
|
vec3 viewDir
|
||||||
|
){
|
||||||
|
vec3 diffuseVal = albedo;
|
||||||
|
vec3 specularVal = vec3(0);
|
||||||
|
|
||||||
|
//
|
||||||
|
//Global light calculations
|
||||||
|
vec3 ambientLight = calcAmbientLight(diffuseVal);
|
||||||
|
vec3 diffuseLight = calcDiffuseLight(norm, diffuseVal);
|
||||||
|
vec3 specLight = calcSpecLight(viewPos,fragPos,norm,mat.shininess,specularVal);
|
||||||
|
vec3 lightSum = ambientLight + diffuseLight + specLight;
|
||||||
|
|
||||||
|
//
|
||||||
|
//point light calculations
|
||||||
|
uint clusterIndex = findCluster(fragPosView, zNear, zFar);
|
||||||
|
uint pointLightCount = clusters[clusterIndex].count;
|
||||||
|
for(int i = 0; i < pointLightCount; i++){
|
||||||
|
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
||||||
|
PointLight pointLight = pointLight[pointLightIndex];
|
||||||
|
lightSum = lightSum + CalcPointLight(pointLight, norm, fragPos, viewDir);
|
||||||
|
}
|
||||||
|
//error checking on light clusters
|
||||||
|
if(pointLightCount > MAX_LIGHTS_PER_CLUSTER){
|
||||||
|
return vec3(1.0,0.0,0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//shadow calculations
|
||||||
|
float shadow = ShadowCalculation(fragPosLightSpace, normalize(-directLight.direction.xyz), -norm);
|
||||||
|
float shadowMultiplier = max(shadow,SHADOW_MIN_MULTIPLIER);
|
||||||
|
lightSum = lightSum * shadowMultiplier;
|
||||||
|
|
||||||
|
//clamp
|
||||||
|
vec3 lightClamp = vec3(min(lightSum.x,1),min(lightSum.y,1),min(lightSum.z,1));
|
||||||
|
|
||||||
return lightClamp;
|
return lightClamp;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user