{
	"name": "raymarching",
	"node_position": {
		"x": 0,
		"y": 0
	},
	"parameters": {

	},
	"seed_int": 0,
	"shader_model": {
		"code": [
			"vec2 $(name_uv)_d = raymarch_$name($uv);",
			""
		],
		"global": "",
		"inputs": [
			{
				"default": "vec2(0.0, 0.0)",
				"function": true,
				"label": "",
				"longdesc": "The input object, described as 3D signed distance function with color index",
				"name": "sdf",
				"shortdesc": "Input",
				"type": "sdf3dc"
			}
		],
		"instance": [
			"vec2 raymarch_$name(vec2 uv) {",
			"\tvec3 ro = vec3(uv-vec2(0.5), 1.0);",
			"\tvec3 rd = vec3(0.0, 0.0, -1.0);",
			"\tfloat dO = 0.0;",
			"\tfloat c = 0.0;",
			"\tfor (int i=0; i < 100; i++) {",
			"\t\tvec3 p = ro + rd*dO;",
			"\t\tvec2 dS = $sdf(p);",
			"\t\tdO += dS.x;",
			"",
			"\t\tif (dO >= 1.0) {",
			"\t\t\tbreak;",
			"\t\t} else if (abs(dS.x) < 0.0001) {",
			"\t\t\tc = dS.y;",
			"\t\t\tbreak;",
			"\t\t}",
			"\t}",
			"\t",
			"\treturn vec2(dO, c);",
			"}",
			"",
			"vec3 normal_$name(vec3 p) {",
			"\tif (p.z <= 0.0) {",
			"\t\treturn vec3(0.0, 0.0, -1.0);",
			"\t}",
			"",
			"\tfloat d = $sdf(p).x;",
			"\tfloat e = .001;",
			"\t",
			"\tvec3 n = d - vec3(",
			"\t\t$sdf(p-vec3(e, 0.0, 0.0)).x,",
			"\t\t$sdf(p-vec3(0.0, e, 0.0)).x,",
			"\t\t$sdf(p-vec3(0.0, 0.0, e)).x);",
			"\t",
			"\treturn vec3(-1.0, -1.0, -1.0)*normalize(n);",
			"}",
			"",
			""
		],
		"longdesc": "Raymarches a 3D object (described as signed distance function with optional color index) to render a heightmap, a normal map and a color index map.",
		"name": "Render",
		"outputs": [
			{
				"f": "clamp(1.0-$(name_uv)_d.x, 0.0, 1.0)",
				"longdesc": "The generated height map",
				"shortdesc": "HeightMap",
				"type": "f"
			},
			{
				"longdesc": "The generated normal map",
				"rgb": "vec3(0.5)+0.5*normal_$name(vec3($uv-vec2(0.5), 1.0-$(name_uv)_d.x))",
				"shortdesc": "NormalMap",
				"type": "rgb"
			},
			{
				"f": "$(name_uv)_d.y",
				"longdesc": "The generated color index map",
				"shortdesc": "ColorMap",
				"type": "f"
			}
		],
		"parameters": [

		],
		"shortdesc": "Render"
	},
	"type": "shader"
}