ADD: Docs and shader optim

This commit is contained in:
2025-12-25 22:09:02 +09:00
parent 0172996e12
commit d6216b20fc
16 changed files with 1178 additions and 60 deletions

View File

@@ -20,9 +20,9 @@ vec3 getCameraWorldPosition()
return -rot * T; // C = -R * T
}
vec3 projectToScreen(vec3 worldPos)
vec3 projectToScreenFromView(vec3 viewPos)
{
vec4 clip = sceneData.viewproj * vec4(worldPos, 1.0);
vec4 clip = sceneData.proj * vec4(viewPos, 1.0);
if (clip.w <= 0.0)
return vec3(0.0, 0.0, -1.0);
@@ -64,6 +64,8 @@ void main()
vec3 camPos = getCameraWorldPosition();
vec3 V = normalize(camPos - worldPos);
vec3 R = reflect(-V, N);
vec3 viewPos = (sceneData.view * vec4(worldPos, 1.0)).xyz;
vec3 viewDir = normalize((sceneData.view * vec4(R, 0.0)).xyz);
float gloss = 1.0 - roughness;
float F0 = mix(0.04, 1.0, metallic);
@@ -87,9 +89,9 @@ void main()
float t = STEP_LENGTH;
for (int i = 0; i < maxSteps && t <= MAX_DISTANCE; ++i, t += STEP_LENGTH)
{
vec3 samplePos = worldPos + R * t;
vec3 sampleViewPos = viewPos + viewDir * t;
vec3 proj = projectToScreen(samplePos);
vec3 proj = projectToScreenFromView(sampleViewPos);
if (proj.z < 0.0)
{
break;
@@ -102,10 +104,9 @@ void main()
continue;
}
vec3 viewSample = (sceneData.view * vec4(samplePos, 1.0)).xyz;
vec3 viewScene = (sceneData.view * vec4(scenePosSample.xyz, 1.0)).xyz;
float depthRay = -viewSample.z;
float depthRay = -sampleViewPos.z;
float depthScene = -viewScene.z;
float depthDiff = depthRay - depthScene;