Added i/o type for 3D textures (takes xyz+color index as input)

This commit is contained in:
RodZill4 2020-02-07 22:07:59 +01:00
parent 62e6d57b1e
commit 70a8ea6a48
2 changed files with 46 additions and 0 deletions

View File

@ -70,6 +70,15 @@
{ "type":"sdf3d", "expr":"($(value)).x" } { "type":"sdf3d", "expr":"($(value)).x" }
], ],
"color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 } "color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 }
},
{
"name":"tex3d",
"label":"TEX3D",
"type":"vec3",
"paramdefs":"vec4 p",
"params":"p",
"slot_type":3,
"color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 }
}, },
{ {
"name":"any", "name":"any",

View File

@ -0,0 +1,37 @@
float calcdist(vec3 p) {
return length(p)-0.4;
}
vec3 calcColor(vec4 uv) {
$(code)
return $(value);
}
float raymarch(vec3 ro, vec3 rd) {
float d=0.0;
for (int i = 0; i < 50; i++) {
vec3 p = ro + rd*d;
float dstep = calcdist(p);
d += dstep;
if (dstep < 0.0001) break;
}
return d;
}
vec3 normal(vec3 p) {
float d = calcdist(p);
float e = .0001;
vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));
return normalize(n);
}
void fragment() {
vec2 uv = UV-vec2(0.5);
vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));
vec3 n = normal(p);
vec3 l = vec3(5.0, 5.0, 10.0);
vec3 ld = normalize(l-p);
float o = step(p.z, 0.001);
float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);
float light = 0.3+0.7*dot(n, ld)*shadow;
COLOR = vec4(calcColor(vec4(p, 0.0))*light, 1.0);
}