Migrate GLSL to Slang, text shader

This commit is contained in:
2026-09-12 23:48:30 +02:00
parent 8d5a2db342
commit f7576a941d
30 changed files with 868 additions and 632 deletions

View File

@@ -1,6 +0,0 @@
layout(set = 0, binding = 0, scalar) uniform GlobalUniforms {
mat4 matrixWStoVS;
mat4 matrixVStoCS;
mat3x2 matrixSSPXtoCS;
vec3 ambientLight;
} _Global;

View File

@@ -1,14 +0,0 @@
struct Box {
vec4 backgroundColor;
vec4 borderColor;
vec2 positionSSPX;
vec2 sizePX;
float borderWidthPX;
float borderRadiusPX;
};
#include "global_uniforms.glsl"
layout(set = 0, binding = 1, scalar) readonly buffer Boxes {
Box _Boxes[];
};

View File

@@ -1,17 +0,0 @@
struct Image {
vec4 tint;
vec2 positionSSPX;
vec2 sizePX;
vec2 uvMin;
vec2 uvMax;
uint16_t textureId;
};
#include "global_uniforms.glsl"
layout(set = 0, binding = 1, scalar) readonly buffer Images {
Image _Images[];
};
layout(set = 0, binding = 2) uniform sampler _Sampler;
layout(set = 0, binding = 3) uniform texture2D _Textures[];

View File

@@ -1,58 +0,0 @@
// --- SET 0 --- GLOBAL --------------------------------------------------------
struct PointLight {
vec3 positionWS;
vec3 color;
};
struct DirectionalLight {
vec3 directionWS;
vec3 color;
};
struct Material {
vec3 baseColor;
vec3 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 {
mat4 matrixOStoWS;
mat4 matrixOStoWSNormal;
uint16_t material;
};
#include "global_uniforms.glsl"
layout(set = 0, binding = 1, scalar) readonly buffer PointLights {
uint count;
PointLight lights[];
} _PointLights;
layout(set = 0, binding = 2, scalar) readonly buffer DirectionalLights {
uint count;
DirectionalLight lights[];
} _DirectionalLights;
layout(set = 0, binding = 3, scalar) readonly buffer Materials {
Material _Materials[];
};
layout(set = 0, binding = 4) uniform sampler _Sampler;
layout(set = 0, binding = 5) uniform texture2D _Textures[];
// --- SET 1 --- PER BATCH -----------------------------------------------------
layout(set = 1, binding = 0, scalar) readonly buffer ObjectsUniforms {
ObjectUniforms _Object[];
};

View File

@@ -0,0 +1,77 @@
import "structs";
static const float INV_PI = 0.31830987;
static const float HALF_INV_PI = 0.15915494;
static const float3 F90 = float3(1.0);
float4 texture2DAA(Texture2D texture, SamplerState sampler, float2 texCoord) {
uint width, height;
texture.GetDimensions(width, height);
let size = float2(width, height);
var texCoordPX = texCoord * size;
let seam = floor(texCoordPX + 0.5);
texCoordPX = (texCoordPX - seam) / fwidth(texCoordPX) + seam;
texCoordPX = clamp(texCoordPX, seam - 0.5, seam + 0.5);
texCoord = texCoordPX / size;
return texture.Sample(sampler, texCoord);
}
float3 fresnelSchlick(float dotVH, float3 f0) {
return lerp(f0, F90, pow(1.0 - dotVH, 5.0));
}
float visibilityGGX(float dotNL, float dotNV, float alpha) {
let alphaSquared = alpha * alpha;
let vGGX = dotNL * sqrt(dotNV * dotNV * (1.0 - alphaSquared) + alphaSquared);
let lGGX = dotNV * sqrt(dotNL * dotNL * (1.0 - alphaSquared) + alphaSquared);
let GGX = vGGX + lGGX;
return select(GGX > 0.0, 0.5 / GGX, 0.0);
}
float distributionGGX(float dotNH, float alpha) {
let alphaSquared = alpha * alpha;
let tmp = dotNH * dotNH * (alphaSquared - 1.0) + 1.0;
return alphaSquared * INV_PI / (tmp * tmp);
}
float3 lightOutgoingRadiance(
float3 viewDirectionVS, float3 normalVS, float dotNV,
Surface surf, IncomingLight light,
) {
let halfVectorVS = normalize(light.directionVS + viewDirectionVS);
let dotVH = saturate(dot(viewDirectionVS, halfVectorVS));
let dotNH = saturate(dot(normalVS, halfVectorVS));
let dotNL = saturate(dot(normalVS, light.directionVS));
let fresnel = fresnelSchlick(dotVH, surf.f0);
let visibility = visibilityGGX(dotNL, dotNV, surf.alpha);
let distribution = distributionGGX(dotNH, surf.alpha);
let scatteredFactor = (1.0 - fresnel) * (1.0 - surf.metallic) * surf.baseColor * INV_PI;
let reflectedFactor = fresnel * visibility * distribution;
return (scatteredFactor + reflectedFactor) * light.radiance * dotNL;
}
float3 toneMapAcesNarkowicz(float3 color) {
static const float A = 2.51;
static const float B = 0.03;
static const float C = 2.43;
static const float D = 0.59;
static const float E = 0.14;
return saturate((color * (A * color + B)) / (color * (C * color + D) + E));
}
float3 linearToSrgbColor(float3 color) {
return pow(color, 1.0 / 2.2);
}
float boxSDF(float2 p, float2 center, float2 halfExtents, float borderRadius) {
let q = abs(p - center) - halfExtents + borderRadius;
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - borderRadius;
}

View File

@@ -0,0 +1,82 @@
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;
}

View File

@@ -1,8 +0,0 @@
vec3 toneMapAcesNarkowicz(vec3 color) {
const float A = 2.51;
const float B = 0.03;
const float C = 2.43;
const float D = 0.59;
const float E = 0.14;
return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0);
}