hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/geodesic.slang
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/geodesic.slang')
-rw-r--r--assets/shaders/geodesic.slang59
1 files changed, 52 insertions, 7 deletions
diff --git a/assets/shaders/geodesic.slang b/assets/shaders/geodesic.slang
index 111c9b8..3229aee 100644
--- a/assets/shaders/geodesic.slang
+++ b/assets/shaders/geodesic.slang
@@ -19,8 +19,17 @@ struct Camera
float tanHalfFov;
float aspect;
bool moving;
- int _pad4;
+ int outputChannel;
+ int rawOutput;
};
+
+float3 Falsecolor(float t)
+{
+ t = clamp(t, 0.0, 1.0);
+ return clamp(float3(1.5 - abs(4.0 * t - 3.0),
+ 1.5 - abs(4.0 * t - 2.0),
+ 1.5 - abs(4.0 * t - 1.0)), 0.0, 1.0);
+}
ConstantBuffer<Camera> cam;
struct Disk
@@ -134,8 +143,9 @@ float3 Blackbody(float T)
return c;
}
-float3 DiskEmission(float3 P, float3 rayDir)
+float3 DiskEmission(float3 P, float3 rayDir, out float outG, out float outTemit)
{
+ outG = 0.0; outTemit = 0.0;
float rc = length(float2(P.x, P.z));
float rin = max(disk.disk_r1, R_ISCO);
float rout = disk.disk_r2;
@@ -154,6 +164,7 @@ float3 DiskEmission(float3 P, float3 rayDir)
float3 nhat = -normalize(rayDir);
float g = sqrt(max(1.0 - 1.5 * SagA_rs / rc, 0.0)) / max(1.0 - dot(beta, nhat), 1e-3);
+ outG = g; outTemit = Temit;
float Tobs = g * Temit;
float3 colour = Blackbody(Tobs);
@@ -285,8 +296,9 @@ float3 ACESFilm(float3 x)
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
-float3 TracePixel(float2 texCoord)
+float3 TracePixel(float2 texCoord, out float outG, out float outTemit, out bool outHitDisk)
{
+ outG = 0.0; outTemit = 0.0; outHitDisk = false;
float u = (2.0 * texCoord.x - 1.0) * cam.aspect * cam.tanHalfFov;
float v = (1.0 - 2.0 * texCoord.y) * cam.tanHalfFov;
float3 dir = normalize(u * cam.camRight - v * cam.camUp + cam.camForward);
@@ -331,8 +343,9 @@ float3 TracePixel(float2 texCoord)
float rc = length(float2(hitP.x, hitP.z));
if (rc >= max(disk.disk_r1, R_ISCO) && rc <= disk.disk_r2)
{
- diskColor = DiskEmission(hitP, newPos - prevPos);
- hitDisk = true;
+ diskColor = DiskEmission(hitP, newPos - prevPos, outG, outTemit);
+ hitDisk = true;
+ outHitDisk = true;
break;
}
}
@@ -375,8 +388,40 @@ float3 TracePixel(float2 texCoord)
[shader("fragment")]
float4 fragmentMain(VSOutput input) : SV_Target
{
+ if (cam.outputChannel != 0)
+ {
+ float g, Temit; bool hitDisk;
+ TracePixel(input.texCoord, g, Temit, hitDisk);
+
+ float value; float valid = 1.0;
+ if (cam.outputChannel == 3)
+ {
+ float uu = (2.0 * input.texCoord.x - 1.0) * cam.aspect * cam.tanHalfFov;
+ float vv = (1.0 - 2.0 * input.texCoord.y) * cam.tanHalfFov;
+ float3 dir = normalize(uu * cam.camRight - vv * cam.camUp + cam.camForward);
+ value = length(cross(cam.camPos, dir)) / SagA_rs;
+ }
+ else
+ {
+ valid = hitDisk ? 1.0 : 0.0;
+ value = (cam.outputChannel == 1) ? g : Temit;
+ }
+
+ if (cam.rawOutput != 0)
+ return float4(value, value, value, valid);
+
+ if (valid < 0.5) return float4(0.0, 0.0, 0.0, 1.0);
+ float norm = (cam.outputChannel == 1) ? value / 1.5
+ : (cam.outputChannel == 2) ? value / 15000.0
+ : value / 30.0;
+ return float4(Falsecolor(norm), 1.0);
+ }
+
+ float _g, _t; bool _hd;
+ if (cam.rawOutput != 0)
+ return float4(TracePixel(input.texCoord, _g, _t, _hd), 1.0);
if (cam.moving)
- return float4(ACESFilm(TracePixel(input.texCoord)), 1.0);
+ return float4(ACESFilm(TracePixel(input.texCoord, _g, _t, _hd)), 1.0);
float2 dUV = float2(ddx(input.texCoord.x), ddy(input.texCoord.y));
float2 offs[4] = {
@@ -385,7 +430,7 @@ float4 fragmentMain(VSOutput input) : SV_Target
};
float3 sum = float3(0.0);
for (int i = 0; i < 4; ++i)
- sum += TracePixel(input.texCoord + offs[i] * dUV);
+ sum += TracePixel(input.texCoord + offs[i] * dUV, _g, _t, _hd);
return float4(ACESFilm(sum * 0.25), 1.0);
}