83 lines
1.9 KiB
Plaintext
83 lines
1.9 KiB
Plaintext
struct GlobalUniforms {
|
|
float4x4 matrixWStoVS;
|
|
float4x4 matrixVStoCS;
|
|
float2x3 matrixSSPXtoCS;
|
|
|
|
uint pointLightCount;
|
|
uint directionalLightCount;
|
|
float3 ambientLight;
|
|
}
|
|
|
|
struct PointLight {
|
|
float3 positionWS;
|
|
float3 color;
|
|
|
|
IncomingLight getIncoming(float4x4 matrixWStoVS, float3 positionVS) {
|
|
IncomingLight light;
|
|
|
|
let lightPositionVS = mul(matrixWStoVS, float4(positionWS, 1.0)).xyz;
|
|
let lightDirectionVS = normalize(lightPositionVS - positionVS);
|
|
let lightDistance = distance(positionVS, lightPositionVS);
|
|
let lightAttenuation = 1.0 / (lightDistance * lightDistance);
|
|
let incomingRadiance = color * lightAttenuation;
|
|
|
|
light.radiance = incomingRadiance;
|
|
light.directionVS = lightDirectionVS;
|
|
return light;
|
|
}
|
|
}
|
|
|
|
struct DirectionalLight {
|
|
float3 directionWS;
|
|
float3 color;
|
|
|
|
IncomingLight getIncoming(float4x4 matrixWStoVS) {
|
|
IncomingLight light;
|
|
|
|
light.radiance = color;
|
|
light.directionVS = normalize(mul(matrixWStoVS, float4(-directionWS, 0.0)).xyz);
|
|
return light;
|
|
}
|
|
}
|
|
|
|
struct Material {
|
|
float3 baseColor;
|
|
float3 emissive;
|
|
float ior;
|
|
float metallic;
|
|
float normalScale;
|
|
float occlusionTextureStrength;
|
|
float roughness;
|
|
|
|
uint16_t baseColorTexture;
|
|
uint16_t emissiveTexture;
|
|
uint16_t normalTexture;
|
|
uint16_t occlusionRoughnessMetallicTexture;
|
|
}
|
|
|
|
struct ObjectUniforms {
|
|
float4x4 matrixOStoWS;
|
|
float4x4 matrixOStoWSNormal;
|
|
|
|
uint16_t material;
|
|
}
|
|
|
|
struct Surface {
|
|
float3 baseColor;
|
|
float alpha;
|
|
float metallic;
|
|
float3 f0;
|
|
|
|
__init(float3 baseColor, float alpha, float metallic, float3 f0) {
|
|
this.baseColor = baseColor;
|
|
this.alpha = alpha;
|
|
this.metallic = metallic;
|
|
this.f0 = f0;
|
|
}
|
|
}
|
|
|
|
struct IncomingLight {
|
|
float3 radiance;
|
|
float3 directionVS;
|
|
}
|