-
Notifications
You must be signed in to change notification settings - Fork 231
/
Metaball.shader
98 lines (81 loc) · 2.15 KB
/
Metaball.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Shader "Ist/ProceduralModeling/Metaball" {
Properties {
_GridSize("Grid Size", Float) = 0.26
_CubeSize("Cube Size", Float) = 0.22
_Clipping("Clipping", Int) = 2
_Color("Albedo", Color) = (0.75, 0.75, 0.8, 1.0)
_SpecularColor("Specular", Color) = (0.2, 0.2, 0.2, 1.0)
_Smoothness("Smoothness", Range(0, 1)) = 0.7
_EmissionColor("Emission", Color) = (0.0, 0.0, 0.0, 1.0)
_OffsetPosition("OffsetPosition", Vector) = (0, 0, 0, 0)
_Scale("Scale", Vector) = (1, 1, 1, 0)
_CutoutDistance("Cutout Distance", Float) = 0.01
_ZTest("ZTest", Int) = 4
}
CGINCLUDE
struct Metaball
{
float3 position;
float radius;
float softness;
float negative;
float padding[2];
};
int _NumEntities;
StructuredBuffer<Metaball> _Entities;
#define MAX_MARCH_STEPS 24
#include "ProceduralModeling.cginc"
void initialize(inout raymarch_data R)
{
}
float map(float3 pg)
{
float d = dot(_Scale, 1.0);
for (int i = 0; i < _NumEntities; ++i) {
Metaball mb = _Entities[i];
if (mb.negative) {
d = soft_max(d, -sdSphere(pg - mb.position, mb.radius), mb.softness);
}
else {
d = soft_min(d, sdSphere(pg - mb.position, mb.radius), mb.softness);
}
}
d = max(d, sdBox(localize(pg), _Scale*0.5));
return d;
}
void posteffect(inout gbuffer_out O, vs_out I, raymarch_data R)
{
}
#include "Framework.cginc"
ENDCG
SubShader {
Tags{ "RenderType" = "Opaque" "DisableBatching" = "True" "Queue" = "Geometry+10" }
Pass{
Tags{ "LightMode" = "ShadowCaster" }
Cull Front
ColorMask 0
CGPROGRAM
#pragma vertex vert_shadow
#pragma fragment frag_shadow
ENDCG
}
Pass {
Tags { "LightMode" = "Deferred" }
Stencil {
Comp Always
Pass Replace
Ref 128
}
ZTest [_ZTest]
Cull Back
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment frag_gbuffer
#pragma multi_compile ___ UNITY_HDR_ON
#pragma multi_compile ___ ENABLE_DEPTH_OUTPUT
ENDCG
}
}
Fallback Off
}