[ShaderToy] Copied a shader, but it doesn't work in Magic
Posted: Thu May 21, 2020 1:34 pm
Hello!
I'm having a problem as stated in the title.
This is the shader: https://www.shadertoy.com/view/tsjfWW.
When I copy it to a file and run it, there simply is a completely black output. The module still has the "speed" parameter working, so there aren't any compile errors afaik.
The shader *is* quite a bit chonky though. Might that be a problem? (It does take ShaderToy 3 seconds to compile...)
EDIT:
I changed the code to measure ray trace depth (the shader is a raytracer), and somehow the geometry is there! It's something about lightScene that works in ShaderToy, but not in Magic...
Here's the relevant code (for the structs, reference the full shader):
EDIT:
- Did a little link switcheroo, so I can continue experimenting with raytracing
I'm having a problem as stated in the title.
This is the shader: https://www.shadertoy.com/view/tsjfWW.
When I copy it to a file and run it, there simply is a completely black output. The module still has the "speed" parameter working, so there aren't any compile errors afaik.
The shader *is* quite a bit chonky though. Might that be a problem? (It does take ShaderToy 3 seconds to compile...)
EDIT:
I changed the code to measure ray trace depth (the shader is a raytracer), and somehow the geometry is there! It's something about lightScene that works in ShaderToy, but not in Magic...
Here's the relevant code (for the structs, reference the full shader):
Code: Select all
vec3 lightScene(Scene scene, SurfaceInteraction si, Ray r) {
vec3 color = vec3(0.);
vec3 p = r.o + r.d * si.d;
Material mat = si.shape.mat;
float reflected = mat.albedo / PI;
for(int i = 0; i < scene.lightCount; i++) {
Light l = scene.lights[i];
Ray ra;
ra.o = p + (si.n * scene.shadow_bias);
switch(l.tag) {
case 1:
ra.d = normalize(l.point.p - ra.o);
if(!intersectScene(scene, ra).isHit && si.isHit && dot(r.d, si.n) < 0.0) {
color += dot(normalize(l.point.p - p), si.n) * (l.brightness / (4. * PI * dot(l.point.p - p, l.point.p - p))) * l.color * reflected * mat.color;
}
break;
case 2:
ra.d = normalize(l.point.p - ra.o);
if(!intersectScene(scene, ra).isHit && si.isHit && dot(r.d, si.n) < 0.0) {
color += dot(normalize(l.point.p - p), si.n) * l.brightness * l.color * reflected * mat.color;
}
break;
case 3:
ra.d = -l.dir.d;
if(!intersectScene(scene, ra).isHit && si.isHit && dot(r.d, si.n) < 0.0) {
color += dot(-l.dir.d, si.n) * l.brightness * l.color * reflected * mat.color;
}
case 0:
default:
break;
}
}
return color;
}
- Did a little link switcheroo, so I can continue experimenting with raytracing