major shader lighting rework
This commit is contained in:
parent
2fc8283bd5
commit
51f2627621
@ -31,35 +31,22 @@ void main(){
|
||||
}
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(vec3(viewPos) - FragPos);
|
||||
|
||||
//grab light intensity
|
||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
||||
|
||||
//get color of base texture
|
||||
vec3 textureColor = texture(material.diffuse, TexCoord).rgb;
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), -norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
vec3 lightAmount = vec3(0);
|
||||
uint clusterIndex = findCluster(ViewFragPos, zNear, zFar);
|
||||
uint pointLightCount = clusters[clusterIndex].count;
|
||||
for(int i = 0; i < pointLightCount; i++){
|
||||
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
||||
PointLight pointLight = pointLight[pointLightIndex];
|
||||
lightIntensity = lightIntensity + CalcPointLight(pointLight, norm, FragPos, viewDir);
|
||||
}
|
||||
//error checking on light clusters
|
||||
if(pointLightCount > MAX_LIGHTS_PER_CLUSTER){
|
||||
FragColor = vec4(1.0f,0,0,1.0f);
|
||||
return;
|
||||
}
|
||||
// Calculate the light to apply
|
||||
vec3 light = getTotalLight(
|
||||
material,
|
||||
TexCoord,
|
||||
vec3(viewPos.xyz),
|
||||
FragPosLightSpace,
|
||||
ViewFragPos,
|
||||
FragPos,
|
||||
norm,
|
||||
viewDir
|
||||
);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.4);
|
||||
vec3 finalColor = light;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(finalColor, texture(material.diffuse, TexCoord).a);//texture(ourTexture, TexCoord);//vec4(result, 1.0);
|
||||
FragColor = vec4(finalColor, texture(material.diffuse, TexCoord).a);
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ void main() {
|
||||
cluster.count = 0;
|
||||
|
||||
for (uint i = 0; i < lightCount; ++i){
|
||||
if (testSphereAABB(i, cluster) && cluster.count < 100){
|
||||
if (testSphereAABB(i, cluster) && cluster.count < MAX_LIGHTS_PER_CLUSTER){
|
||||
cluster.lightIndices[cluster.count] = i;
|
||||
cluster.count++;
|
||||
}
|
||||
|
||||
@ -37,36 +37,24 @@ void main(){
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(vec3(viewPos) - FragPos);
|
||||
|
||||
//grab light intensity
|
||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
||||
|
||||
//get color of base texture
|
||||
vec4 textureColor = texture(material.diffuse, TexCoord);
|
||||
vec3 textureRGB = textureColor.rgb;
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
uint clusterIndex = findCluster(ViewFragPos, zNear, zFar);
|
||||
uint pointLightCount = clusters[clusterIndex].count;
|
||||
for(int i = 0; i < pointLightCount; i++){
|
||||
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
||||
PointLight pointLight = pointLight[pointLightIndex];
|
||||
lightIntensity = lightIntensity + CalcPointLight(pointLight, norm, FragPos, viewDir);
|
||||
}
|
||||
//error checking on light clusters
|
||||
if(pointLightCount > MAX_LIGHTS_PER_CLUSTER){
|
||||
accum = vec4(1.0f,0.0f,0.0f,1);
|
||||
reveal = textureColor.a;
|
||||
return;
|
||||
}
|
||||
// Calculate the light to apply
|
||||
vec3 light = getTotalLight(
|
||||
material,
|
||||
TexCoord,
|
||||
vec3(viewPos.xyz),
|
||||
FragPosLightSpace,
|
||||
ViewFragPos,
|
||||
FragPos,
|
||||
norm,
|
||||
viewDir
|
||||
);
|
||||
|
||||
//calculate final color
|
||||
vec3 shadowModifiedColor = textureRGB * lightIntensity * max(shadow, 0.4);
|
||||
vec4 finalColor = vec4(shadowModifiedColor,textureColor.a);
|
||||
vec4 finalColor = vec4(light,textureColor.a);
|
||||
|
||||
//calculate weight function
|
||||
float weight = clamp(pow(min(1.0, finalColor.a * 10.0) + 0.01, 3.0) * 1e8 *
|
||||
|
||||
@ -34,41 +34,32 @@ out vec4 FragColor;
|
||||
|
||||
|
||||
// function prototypes
|
||||
vec4 getColor(vec2 uv, vec3 normal, int samplerIndexVec, Material material);
|
||||
vec2 getColor(vec2 uv, vec3 normal, int samplerIndexVec);
|
||||
|
||||
void main(){
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
//grab light intensity
|
||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
||||
|
||||
//get color of base texture
|
||||
vec4 textureColor = getColor(uv, norm, samplerIndexVec, material);
|
||||
vec2 TexCoord = getColor(uv, norm, samplerIndexVec);
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), -norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
uint clusterIndex = findCluster(ViewFragPos, zNear, zFar);
|
||||
uint pointLightCount = clusters[clusterIndex].count;
|
||||
for(int i = 0; i < pointLightCount; i++){
|
||||
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
||||
PointLight pointLight = pointLight[pointLightIndex];
|
||||
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 the light to apply
|
||||
vec3 light = getTotalLight(
|
||||
material,
|
||||
TexCoord,
|
||||
vec3(viewPos.xyz),
|
||||
FragPosLightSpace,
|
||||
ViewFragPos,
|
||||
FragPos,
|
||||
norm,
|
||||
viewDir
|
||||
);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor.rgb * lightIntensity * max(shadow,0.4);
|
||||
vec3 finalColor = light;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(finalColor, textureColor.a);
|
||||
FragColor = vec4(finalColor, texture(material.diffuse, TexCoord).a);
|
||||
}
|
||||
|
||||
|
||||
@ -76,16 +67,14 @@ void main(){
|
||||
* The function that gets the texture color based on the triplanar texture mapping and the voxel type at each point along the vert.
|
||||
* See the triplanar mapping wiki article for an explanation of math involved.
|
||||
*/
|
||||
vec4 getColor(vec2 uv, vec3 normal, int samplerIndexVec, Material material){
|
||||
vec2 getColor(vec2 uv, vec3 normal, int samplerIndexVec){
|
||||
|
||||
//the uv of the texture clamped within the atlas
|
||||
vec2 actualUv = vec2(
|
||||
(fract(uv.x) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (mod(samplerIndexVec,ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL),
|
||||
(fract(uv.y) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (round(samplerIndexVec / ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL)
|
||||
);
|
||||
//albedo for the X texture
|
||||
vec4 color = texture(material.diffuse, actualUv);
|
||||
|
||||
|
||||
return color;
|
||||
return actualUv;
|
||||
}
|
||||
@ -34,41 +34,32 @@ out vec4 FragColor;
|
||||
|
||||
|
||||
// function prototypes
|
||||
vec4 getColor(vec2 uv, vec3 normal, int blockIndex, Material material);
|
||||
vec2 getColor(vec2 uv, vec3 normal, int samplerIndexVec);
|
||||
|
||||
void main(){
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
//grab light intensity
|
||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
||||
|
||||
//get color of base texture
|
||||
vec4 textureColor = getColor(uv, norm, blockAtlasIndex, material);
|
||||
vec2 TexCoord = getColor(uv, norm, blockAtlasIndex);
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), -norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
uint clusterIndex = findCluster(ViewFragPos, zNear, zFar);
|
||||
uint pointLightCount = clusters[clusterIndex].count;
|
||||
for(int i = 0; i < pointLightCount; i++){
|
||||
uint pointLightIndex = clusters[clusterIndex].lightIndices[i];
|
||||
PointLight pointLight = pointLight[pointLightIndex];
|
||||
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 the light to apply
|
||||
vec3 light = getTotalLight(
|
||||
material,
|
||||
TexCoord,
|
||||
vec3(viewPos.xyz),
|
||||
FragPosLightSpace,
|
||||
ViewFragPos,
|
||||
FragPos,
|
||||
norm,
|
||||
viewDir
|
||||
);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor.rgb * lightIntensity * max(shadow,0.4);
|
||||
vec3 finalColor = light;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(finalColor, textureColor.a);
|
||||
FragColor = vec4(finalColor, texture(material.diffuse, TexCoord).a);
|
||||
}
|
||||
|
||||
|
||||
@ -76,16 +67,14 @@ void main(){
|
||||
* The function that gets the texture color based on the triplanar texture mapping and the voxel type at each point along the vert.
|
||||
* See the triplanar mapping wiki article for an explanation of math involved.
|
||||
*/
|
||||
vec4 getColor(vec2 uv, vec3 normal, int blockIndex, Material material){
|
||||
vec2 getColor(vec2 uv, vec3 normal, int samplerIndexVec){
|
||||
|
||||
//the uv of the texture clamped within the atlas
|
||||
vec2 actualUv = vec2(
|
||||
(fract(uv.x) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (mod(blockIndex,ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL),
|
||||
(fract(uv.y) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (round(blockIndex / ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL)
|
||||
(fract(uv.x) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (mod(samplerIndexVec,ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL),
|
||||
(fract(uv.y) * ATLAS_NORMALIZED_ELEMENT_WIDTH) + (round(samplerIndexVec / ATLAS_EL_PER_ROW) * ATLAS_NORMALIZED_ELEMENT_WIDTH_FULL)
|
||||
);
|
||||
//albedo for the X texture
|
||||
vec4 color = texture(material.diffuse, actualUv);
|
||||
|
||||
|
||||
return color;
|
||||
return actualUv;
|
||||
}
|
||||
@ -3,10 +3,11 @@
|
||||
#include "../../lib/lights.fs"
|
||||
#include "../../lib/material.fs"
|
||||
|
||||
|
||||
#define FLUID_TRANSPARENCY 0.2f
|
||||
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec3 ViewFragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 texPlane1;
|
||||
in vec2 texPlane2;
|
||||
@ -27,20 +28,23 @@ void main(){
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(vec3(viewPos) - FragPos);
|
||||
|
||||
//grab light intensity
|
||||
float lightIntensity = calcLightIntensityTotal(norm);
|
||||
|
||||
//get color of base texture
|
||||
vec3 textureColor = vec3(0.6, 0.92, 0.92);//getColor(texPlane1, texPlane2, texPlane3, norm, material);
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), norm);
|
||||
// Calculate the light to apply
|
||||
vec3 light = getTotalLight(
|
||||
material,
|
||||
vec2(0),
|
||||
vec3(viewPos.xyz),
|
||||
FragPosLightSpace,
|
||||
ViewFragPos,
|
||||
FragPos,
|
||||
norm,
|
||||
viewDir
|
||||
);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.4);
|
||||
vec3 finalColor = light;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(finalColor, 0.2);
|
||||
FragColor = vec4(finalColor, FLUID_TRANSPARENCY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ uniform mat4 lightSpaceMatrix;
|
||||
//output buffers
|
||||
out vec3 Normal;
|
||||
out vec3 FragPos;
|
||||
out vec3 ViewFragPos;
|
||||
out vec2 texPlane1;
|
||||
out vec2 texPlane2;
|
||||
out vec2 texPlane3;
|
||||
@ -39,6 +40,7 @@ void main() {
|
||||
|
||||
//push frag, normal, and texture positions to fragment shader
|
||||
FragPos = vec3(model * FinalVertex);
|
||||
ViewFragPos = vec3(view * model * FinalVertex);
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
|
||||
//reference https://catlikecoding.com/unity/tutorials/advanced-rendering/triplanar-mapping/
|
||||
|
||||
@ -64,7 +64,7 @@ void main(){
|
||||
// vec3 textureColor = vec3(0.17647,0.4,0.09411);//texture(material.diffuse, TexCoord).rgb;
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), norm);
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction.xyz), norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
|
||||
@ -19,6 +19,7 @@ The direct global light
|
||||
struct DirectLight {
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec3 ambientColor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ void main(){
|
||||
vec3 textureColor = getColor(texPlane1, texPlane2, texPlane3, norm, samplerIndexVec, samplerRatioVec, material);
|
||||
|
||||
//shadow
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction), -norm);
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-directLight.direction.xyz), -norm);
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
|
||||
@ -24,9 +24,9 @@
|
||||
* The direct global light
|
||||
*/
|
||||
struct DirectLight {
|
||||
vec3 ambientColor;
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
vec4 ambientColor;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -69,6 +69,11 @@ layout(std430, binding = DIRECT_LIGHT_SSBO_BIND_POINT) restrict buffer dirLightS
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The minimum multiplier that shadow can apply to the fragment (ie how dark can it make the fragment)
|
||||
*/
|
||||
#define SHADOW_MIN_MULTIPLIER 0.4f
|
||||
|
||||
|
||||
|
||||
|
||||
@ -116,39 +121,56 @@ vec3 getTotalLight(Material mat, vec3 norm, vec3 viewDir);
|
||||
*/
|
||||
float calcLightIntensityAmbient(){
|
||||
//calculate average of ambient light
|
||||
float avg = (directLight.ambientColor.x + directLight.ambientColor.y + directLight.ambientColor.z)/3.0;
|
||||
float avg = (directLight.color.x + directLight.color.y + directLight.color.z)/3.0;
|
||||
return avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the ambient light
|
||||
*/
|
||||
vec3 calcAmbientLight(vec3 diffuseVal){
|
||||
return directLight.ambientColor.rgb * diffuseVal;
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* Calculates the direct light applied to this fragment
|
||||
*/
|
||||
float calcLightIntensityDir(vec3 normal){
|
||||
vec3 lightDir = normalize(-directLight.direction);
|
||||
vec3 lightDir = normalize(-directLight.direction.xyz);
|
||||
// diffuse shading
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the direct light
|
||||
*/
|
||||
vec3 calcDiffuseLight(vec3 normal, vec3 diffuseVal){
|
||||
vec3 lightDir = normalize(-directLight.direction.xyz);
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
vec3 fullColor = directLight.color.rgb * (diff * diffuseVal);
|
||||
vec3 colorClamp = vec3(max(fullColor.x,0),max(fullColor.y,0),max(fullColor.z,0));
|
||||
return colorClamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the direct light applied to this fragment
|
||||
*/
|
||||
vec3 calcLightIntensitySpec(
|
||||
DirectLight directLight,
|
||||
vec3 viewPos,
|
||||
vec3 fragPos,
|
||||
vec3 norm,
|
||||
float shininess,
|
||||
float specularVal
|
||||
vec3 calcSpecLight(
|
||||
vec3 viewPos,
|
||||
vec3 fragPos,
|
||||
vec3 norm,
|
||||
float shininess,
|
||||
vec3 specularVal
|
||||
){
|
||||
vec3 viewDir = normalize(viewPos - fragPos);
|
||||
vec3 reflectDir = reflect(-directLight.direction, norm);
|
||||
vec3 reflectDir = reflect(-directLight.direction.xyz, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
|
||||
vec3 specular = directLight.color * (spec * specularVal);
|
||||
|
||||
return specular;
|
||||
vec3 specular = directLight.color.rgb * (spec * specularVal);
|
||||
vec3 specClamp = vec3(max(specular.x,0),max(specular.y,0),max(specular.z,0));
|
||||
return specClamp;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +191,7 @@ float calcLightIntensityTotal(vec3 normal){
|
||||
//
|
||||
vec3 getTotalLightColor(vec3 normal){
|
||||
//get the direct light color adjusted for intensity
|
||||
vec3 diffuseLightColor = directLight.color * calcLightIntensityDir(normal);
|
||||
vec3 diffuseLightColor = directLight.color.rgb * calcLightIntensityDir(normal);
|
||||
|
||||
//sum light colors
|
||||
vec3 totalLightColor = diffuseLightColor;
|
||||
@ -264,39 +286,47 @@ float ShadowCalculation(vec4 fragPosLightSpace, vec3 lightDir, vec3 normal){
|
||||
* Gets the total light to apply to the fragment
|
||||
*/
|
||||
vec3 getTotalLight(
|
||||
Material mat,
|
||||
vec3 viewPos,
|
||||
vec4 fragPosLightSpace,
|
||||
vec3 fragPosView,
|
||||
vec3 fragPos,
|
||||
vec3 norm,
|
||||
vec3 viewDir
|
||||
Material mat,
|
||||
vec2 texCoord,
|
||||
vec3 viewPos,
|
||||
vec4 fragPosLightSpace,
|
||||
vec3 fragPosView,
|
||||
vec3 fragPos,
|
||||
vec3 norm,
|
||||
vec3 viewDir
|
||||
){
|
||||
float specular = 1.0f;
|
||||
vec3 diffuseVal = texture(mat.diffuse, texCoord).rgb;
|
||||
vec3 specularVal = vec3(0);
|
||||
|
||||
//grab light intensity
|
||||
float ambientLightIntensity = calcLightIntensityAmbient();
|
||||
float directLightIntensity = calcLightIntensityDir(norm);
|
||||
vec3 specularLightIntensity = calcLightIntensitySpec(directLight,viewPos,fragPos,norm,mat.shininess,specular);
|
||||
//
|
||||
//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;
|
||||
|
||||
vec3 lightIntensity = vec3(calcLightIntensityTotal(norm));
|
||||
//
|
||||
//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
|
||||
float shadow = ShadowCalculation(fragPosLightSpace, normalize(-directLight.direction), -norm);
|
||||
//
|
||||
//shadow calculations
|
||||
float shadow = ShadowCalculation(fragPosLightSpace, normalize(-directLight.direction.xyz), -norm);
|
||||
float shadowMultiplier = max(shadow,SHADOW_MIN_MULTIPLIER);
|
||||
lightSum = lightSum * shadowMultiplier;
|
||||
|
||||
//
|
||||
//point light calculations
|
||||
vec3 lightAmount = vec3(0);
|
||||
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];
|
||||
lightIntensity = lightIntensity + CalcPointLight(pointLight, norm, fragPos, viewDir);
|
||||
}
|
||||
//error checking on light clusters
|
||||
if(pointLightCount > MAX_LIGHTS_PER_CLUSTER){
|
||||
return vec3(1.0,0.0,0.0);
|
||||
}
|
||||
return lightIntensity;
|
||||
//clamp
|
||||
vec3 lightClamp = vec3(min(lightSum.x,1),min(lightSum.y,1),min(lightSum.z,1));
|
||||
|
||||
return lightClamp;
|
||||
}
|
||||
@ -1,3 +1,3 @@
|
||||
#maven.buildNumber.plugin properties file
|
||||
#Fri May 16 13:50:39 EDT 2025
|
||||
buildNumber=625
|
||||
#Mon May 19 14:18:34 EDT 2025
|
||||
buildNumber=626
|
||||
|
||||
@ -1902,6 +1902,7 @@ Break out shader material into dedicated library file
|
||||
Materials read some properties from assimp data
|
||||
OpenGLState VAO caching
|
||||
Ambient light sent in dedicated variable to shader
|
||||
Major lighting shader organization rework
|
||||
|
||||
|
||||
|
||||
|
||||
@ -383,6 +383,11 @@ public class MenuGeneratorsLevelEditor {
|
||||
fillInDefaultContent(scrollable);
|
||||
}));
|
||||
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
|
||||
Label dirLabel = Label.createLabel("" + directionalLight.getDirection());
|
||||
|
||||
//global light direction
|
||||
scrollable.addChild(Label.createLabel("Global Light Direction"));
|
||||
Div xDiv = Div.createDiv();
|
||||
@ -390,11 +395,11 @@ public class MenuGeneratorsLevelEditor {
|
||||
xDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
xDiv.addChild(Label.createLabel("X: "));
|
||||
xDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f direction = directionalLight.getDirection();
|
||||
direction.x = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setDirection(direction);
|
||||
dirLabel.setText("" + directionalLight.getDirection());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(xDiv);
|
||||
|
||||
@ -403,11 +408,11 @@ public class MenuGeneratorsLevelEditor {
|
||||
yDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
yDiv.addChild(Label.createLabel("Y: "));
|
||||
yDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f direction = directionalLight.getDirection();
|
||||
direction.y = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setDirection(direction);
|
||||
dirLabel.setText("" + directionalLight.getDirection());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(yDiv);
|
||||
|
||||
@ -416,24 +421,29 @@ public class MenuGeneratorsLevelEditor {
|
||||
zDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
zDiv.addChild(Label.createLabel("Z: "));
|
||||
zDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f direction = directionalLight.getDirection();
|
||||
direction.z = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setDirection(direction);
|
||||
dirLabel.setText("" + directionalLight.getDirection());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(zDiv);
|
||||
|
||||
scrollable.addChild(dirLabel);
|
||||
|
||||
|
||||
Label colorLabel = Label.createLabel("" + directionalLight.getColor());
|
||||
|
||||
Div rDiv = Div.createDiv();
|
||||
rDiv.setMaxHeight(50);
|
||||
rDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
rDiv.addChild(Label.createLabel("R: "));
|
||||
rDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f color = directionalLight.getColor();
|
||||
color.x = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setColor(color);
|
||||
colorLabel.setText("" + directionalLight.getColor());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(rDiv);
|
||||
|
||||
@ -442,11 +452,11 @@ public class MenuGeneratorsLevelEditor {
|
||||
gDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
gDiv.addChild(Label.createLabel("G: "));
|
||||
gDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f color = directionalLight.getColor();
|
||||
color.y = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setColor(color);
|
||||
colorLabel.setText("" + directionalLight.getColor());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(gDiv);
|
||||
|
||||
@ -455,13 +465,15 @@ public class MenuGeneratorsLevelEditor {
|
||||
bDiv.setFlexDirection(YogaFlexDirection.Row);
|
||||
bDiv.addChild(Label.createLabel("B: "));
|
||||
bDiv.addChild(Slider.createSlider((ValueChangeEvent event) -> {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
DirectionalLight directionalLight = lightManager.getDirectionalLight();
|
||||
Vector3f color = directionalLight.getColor();
|
||||
color.z = event.getAsFloat() * 2 - 1;
|
||||
directionalLight.setColor(color);
|
||||
colorLabel.setText("" + directionalLight.getColor());
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
}));
|
||||
scrollable.addChild(bDiv);
|
||||
|
||||
scrollable.addChild(colorLabel);
|
||||
|
||||
|
||||
Globals.engineState.signalSystem.post(SignalType.YOGA_APPLY,mainSidePanel);
|
||||
|
||||
@ -83,7 +83,7 @@ public class LightManager {
|
||||
/**
|
||||
* Size of the direct light buffer
|
||||
*/
|
||||
static final int DIRECT_LIGHT_BUFFER_SIZE = 12 + 12 + 12;
|
||||
static final int DIRECT_LIGHT_BUFFER_SIZE = 16 + 16 + 16;
|
||||
|
||||
/**
|
||||
* Bind point for the cluster ssbo
|
||||
@ -140,9 +140,9 @@ public class LightManager {
|
||||
* The direct light ssbo
|
||||
*
|
||||
struct DirectLight {
|
||||
vec3 ambientColor; //12 bytes
|
||||
vec3 direction; //12 bytes
|
||||
vec3 color; //12 bytes
|
||||
vec4 direction; //16 bytes
|
||||
vec4 color; //16 bytes
|
||||
vec4 ambientColor; //16 bytes
|
||||
};
|
||||
*/
|
||||
private ShaderStorageBuffer dirLightSSBO;
|
||||
@ -155,7 +155,7 @@ public class LightManager {
|
||||
/**
|
||||
* Color of the ambient light
|
||||
*/
|
||||
private Vector3f ambientLightColor = new Vector3f(0.8f);
|
||||
private Vector3f ambientLightColor = new Vector3f(0.3f);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -276,23 +276,26 @@ public class LightManager {
|
||||
//push direct light
|
||||
ByteBuffer directLightBuffer = dirLightSSBO.getBuffer();
|
||||
{
|
||||
//
|
||||
//ambient light color
|
||||
directLightBuffer.putFloat(ambientLightColor.x);
|
||||
directLightBuffer.putFloat(ambientLightColor.y);
|
||||
directLightBuffer.putFloat(ambientLightColor.z);
|
||||
|
||||
//
|
||||
//direction
|
||||
directLightBuffer.putFloat(directionalLight.getDirection().x);
|
||||
directLightBuffer.putFloat(directionalLight.getDirection().y);
|
||||
directLightBuffer.putFloat(directionalLight.getDirection().z);
|
||||
directLightBuffer.putFloat(0);
|
||||
|
||||
//
|
||||
//color
|
||||
directLightBuffer.putFloat(directionalLight.getColor().x);
|
||||
directLightBuffer.putFloat(directionalLight.getColor().y);
|
||||
directLightBuffer.putFloat(directionalLight.getColor().z);
|
||||
directLightBuffer.putFloat(0);
|
||||
|
||||
//
|
||||
//ambient light color
|
||||
directLightBuffer.putFloat(ambientLightColor.x);
|
||||
directLightBuffer.putFloat(ambientLightColor.y);
|
||||
directLightBuffer.putFloat(ambientLightColor.z);
|
||||
directLightBuffer.putFloat(0);
|
||||
}
|
||||
directLightBuffer.flip();
|
||||
dirLightSSBO.upload(openGLState);
|
||||
|
||||
@ -30,7 +30,7 @@ public class Material {
|
||||
/**
|
||||
* Default shininess
|
||||
*/
|
||||
public static final double DEFAULT_SHININESS = 0.0f;
|
||||
public static final double DEFAULT_SHININESS = 1.0f;
|
||||
|
||||
/**
|
||||
* The default reflectivity
|
||||
@ -350,9 +350,9 @@ public class Material {
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
//send physical properties
|
||||
openGLState.getActiveShader().setUniform(openGLState, "material.shininess", this.shininess);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "material.shininess", (float)this.shininess);
|
||||
Globals.renderingEngine.checkError();
|
||||
openGLState.getActiveShader().setUniform(openGLState, "material.reflectivity", this.reflectivity);
|
||||
openGLState.getActiveShader().setUniform(openGLState, "material.reflectivity", (float)this.reflectivity);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
|
||||
@ -113,8 +113,15 @@ public class ShaderUtils {
|
||||
Globals.renderingEngine.checkError();
|
||||
uniformMap.put(uniformLocation,(Float)value);
|
||||
|
||||
//
|
||||
//double
|
||||
} else if(value instanceof Double){
|
||||
GL40.glUniform1d(uniformLocation, (Double)value);
|
||||
Globals.renderingEngine.checkError();
|
||||
uniformMap.put(uniformLocation,(Double)value);
|
||||
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
|
||||
throw new UnsupportedOperationException("Tried to set uniform with unsupported type! " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user