This commit is contained in:
SirLynix
2022-11-19 17:10:27 +01:00
committed by Jérôme Leclercq
parent 4a10c1f8fe
commit e990a320cc
54 changed files with 618 additions and 154 deletions

View File

@@ -15,8 +15,8 @@ struct VertOut
}
const vertPos = array[vec2[f32]](
vec2[f32](-1.0, 1.0),
vec2[f32](-1.0, -3.0),
vec2[f32](-1.0, 1.0),
vec2[f32]( 3.0, 1.0)
);

View File

@@ -13,7 +13,8 @@ struct Light
parameter1: vec4[f32],
parameter2: vec4[f32],
parameter3: vec4[f32],
hasShadowMapping: u32
hasShadowMapping: u32,
viewProjMatrix: mat4[f32]
}
[export]

View File

@@ -47,6 +47,7 @@ const HasTangent = (VertexTangentLoc >= 0);
const HasUV = (VertexUvLoc >= 0);
const HasNormalMapping = HasNormalTexture && HasNormal && HasTangent && !DepthPass;
const HasSkinning = (VertexJointIndicesLoc >= 0 && VertexJointWeightsLoc >= 0);
const HasLighting = HasNormal && !DepthPass;
[layout(std140)]
struct MaterialSettings
@@ -96,8 +97,8 @@ external
[tag("ViewerData")] viewerData: uniform[ViewerData],
[tag("SkeletalData")] skeletalData: uniform[SkeletalData],
[tag("LightData")] lightData: uniform[LightData],
[tag("ShadowMaps2D")] shadowMaps2D: array[sampler2D[f32], MaxLightCount],
[tag("ShadowMapsCube")] shadowMapsCube: array[samplerCube[f32], MaxLightCount]
[tag("ShadowMaps2D")] shadowMaps2D: array[depth_sampler2D[f32], MaxLightCount],
[tag("ShadowMapsCube")] shadowMapsCube: array[depth_sampler_cube[f32], MaxLightCount]
}
struct VertToFrag
@@ -107,6 +108,7 @@ struct VertToFrag
[location(2), cond(HasColor)] color: vec4[f32],
[location(3), cond(HasNormal)] normal: vec3[f32],
[location(4), cond(HasNormalMapping)] tangent: vec3[f32],
[location(5), cond(HasLighting)] lightProjPos: array[vec4[f32], MaxLightCount],
[builtin(position)] position: vec4[f32],
}
@@ -139,7 +141,7 @@ fn main(input: VertToFrag) -> FragOut
discard;
}
const if (HasNormal && !DepthPass)
const if (HasLighting)
{
let lightAmbient = vec3[f32](0.0, 0.0, 0.0);
let lightDiffuse = vec3[f32](0.0, 0.0, 0.0);
@@ -225,17 +227,41 @@ fn main(input: VertToFrag) -> FragOut
let attenuationFactor = max(1.0 - dist * lightInvRadius, 0.0);
attenuationFactor *= max((curAngle - lightOuterAngle) / innerMinusOuterAngle, 0.0);
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
let lambert = max(dot(normal, -lightToPosNorm), 0.0);
lightDiffuse += attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
let reflection = reflect(lightToPosNorm, normal);
let specFactor = max(dot(reflection, eyeVec), 0.0);
specFactor = pow(specFactor, settings.Shininess);
lightSpecular += attenuationFactor * specFactor * light.color.rgb;
let shadowFactor = 0.0;
if (true) //< TODO: HasShadowMapping
{
let shadowTexSize = 1.0 / 512.0; //< FIXME
let offsetArray = array[vec2[f32], 9](
vec2[f32](-1.0, -1.0),
vec2[f32](-1.0, 0.0),
vec2[f32](-1.0, 1.0),
vec2[f32](0.0, -1.0),
vec2[f32](0.0, 0.0),
vec2[f32](0.0, 1.0),
vec2[f32](1.0, -1.0),
vec2[f32](1.0, 0.0),
vec2[f32](1.0, 1.0)
);
for offset in offsetArray
{
let shadowCoords = input.lightProjPos[i].xyz / input.lightProjPos[i].w;
shadowCoords.xy += offset * shadowTexSize;
shadowFactor += shadowMaps2D[i].SampleDepthComp(shadowCoords.xy, shadowCoords.z).r;
}
shadowFactor /= 9.0;
}
lightAmbient += attenuationFactor * light.color.rgb * lightAmbientFactor * settings.AmbientColor.rgb;
lightDiffuse += shadowFactor * attenuationFactor * lambert * light.color.rgb * lightDiffuseFactor;
lightSpecular += shadowFactor * attenuationFactor * specFactor * light.color.rgb;
}
}
@@ -382,5 +408,11 @@ fn main(input: VertIn) -> VertToFrag
const if (HasNormalMapping)
output.tangent = rotationMatrix * input.tangent;
const if (HasLighting)
{
for i in u32(0) -> lightData.lightCount
output.lightProjPos[i] = lightData.lights[i].viewProjMatrix * worldPosition;
}
return output;
}