Skip to content

Commit 002e2eb

Browse files
committed
Shader refactor
1 parent bdb84d7 commit 002e2eb

File tree

5 files changed

+56
-50
lines changed

5 files changed

+56
-50
lines changed

Assets/Demoscene/TheGlow/TheGlow.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ GameObject:
784784
- component: {fileID: 1015702061}
785785
- component: {fileID: 1015702060}
786786
m_Layer: 0
787-
m_Name: Point light (1)
787+
m_Name: Point light
788788
m_TagString: Untagged
789789
m_Icon: {fileID: 0}
790790
m_NavMeshLayer: 0

Assets/Demoscene/TheGlow/TheGlowTimeline.playable

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MonoBehaviour:
99
m_Enabled: 1
1010
m_EditorHideFlags: 0
1111
m_Script: {fileID: 337831424, guid: 6a10b2909283487f913b00d94cd3faf5, type: 3}
12-
m_Name: DemoTimeline
12+
m_Name: TheGlowTimeline
1313
m_EditorClassIdentifier:
1414
m_NextId: 0
1515
m_Tracks:

Assets/Demoscene/TheGlow/TheGlowWorld.asset

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ MonoBehaviour:
99
m_Enabled: 1
1010
m_EditorHideFlags: 0
1111
m_Script: {fileID: 11500000, guid: 160e2c6c162f4a5489a4784f095d4158, type: 3}
12-
m_Name: World
12+
m_Name: TheGlowWorld
1313
m_EditorClassIdentifier:
14-
shaderName: World
14+
shaderName: TheGlowWorld
1515
shaderReference: {fileID: 4800000, guid: 87a584a97f34fd4438ddd726e04938ed, type: 3}
1616
shaderTemplate: 2. Direct GBuffer
1717
variables:
1818
- key: Name
19-
value: World
19+
value: TheGlowWorld
2020
- key: Culling
2121
value: Back
2222
- key: RaymarchingShaderDirectory
@@ -44,43 +44,44 @@ MonoBehaviour:
4444
4545
_FloorSpecular("Floor Specular", Color) = (1.0, 1.0, 1.0, 1.0)
4646
47-
//[Header(Additional Parameters)]
47+
_SlideEmission("Slide Emission", Vector) = (2.0, 2.0, 5.0, 1.0)
4848
49-
//_Grid("Grid", 2D) = "" {}'
49+
_InnerEmission("Inner Emission", Vector) = (3.0, 1.0, 1.0, 1.0)'
5050
folded: 0
5151
- key: DistanceFunction
52-
value: "#define PI2 (2.0 * PI)\n#define EPS (0.01)\n\nfloat2x2 rotate(in float
53-
a)\n{\n float s = sin(a), c = cos(a);\n return float2x2(c, s, -s, c);\n}\n\n//
54-
https://www.shadertoy.com/view/Mlf3Wj\nfloat2 foldRotate(in float2 p, in float
55-
s)\n{\n float a = PI / s - atan2(p.x, p.y);\n float n = PI2 / s;\n a
56-
= floor(a / n) * n;\n p = mul(rotate(a), p);\n return p;\n}\n\nfloat HoleBox(float3
57-
pos, float3 outer, float3 inner)\n{\n return max(sdBox(pos, outer), -sdBox(pos,
58-
inner));\n}\n\nfloat dOuterPillar(float3 pos)\n{\n float3 p = pos;\n p.xz
59-
= Repeat(p.xz, float2(3, 3));\n p.xz = foldRotate(p.xz, 12.0 * sin(_Time.x));\n
60-
\ p.y = Repeat(p.y, 0.5);\n return HoleBox(p, float3(0.3 + 0.1 * sin(36.0
61-
* _Time.x + 2.0 * Rand(float2(floor(pos.y * 2), 0))), 0.2, 0.3), float3(0.5,
62-
0.15, 0.25));\n}\n\nfloat dInnerPillar(float3 pos)\n{\n float3 p = pos;\n
63-
\ p.xz = Repeat(p.xz, float2(3, 3));\n p.xz = foldRotate(p.xz, 12.0 * cos(12.0
64-
* _Time.x));\n p.y = Repeat(p.y, 0.2);\n return Box(p, float3(0.3 * abs(sin(36.0
65-
* _Time.x)), 0.2, 0.15));\n}\n\nfloat dFloor(float3 pos)\n{\n float3 p =
66-
pos;\n p.xz = Repeat(p.xz, 0.5);\n p.y += 1 + 0.1 * sin(36.0 * _Time.x
67-
+ 2.0 * Rand(floor(2.0 * pos.xz)));\n return sdBox(p, float3(0.2, 0.2, 0.2));\n}\n\ninline
68-
float DistanceFunction(float3 pos)\n{\n float d = dFloor(pos);\n d = min(dOuterPillar(pos),
69-
d);\n d = min(dInnerPillar(pos), d);\n return d;\n}"
52+
value: "#define PI2 (2.0 * PI)\n\nfloat2x2 opRotate(in float a)\n{\n float
53+
s = sin(a), c = cos(a);\n return float2x2(c, s, -s, c);\n}\n\n// https://www.shadertoy.com/view/Mlf3Wj\nfloat2
54+
opFoldRotate(in float2 p, in float s)\n{\n float a = PI / s - atan2(p.x,
55+
p.y);\n float n = PI2 / s;\n a = floor(a / n) * n;\n p = mul(opRotate(a),
56+
p);\n return p;\n}\n\nfloat sdHoleBox(float3 pos, float3 outer, float3 inner)\n{\n
57+
\ return max(sdBox(pos, outer), -sdBox(pos, inner));\n}\n\nfloat dOuterPillar(float3
58+
pos)\n{\n float3 p = pos;\n p.xz = Repeat(p.xz, float2(3, 3));\n p.xz
59+
= opFoldRotate(p.xz, 12.0 * sin(_Time.x));\n p.y = Repeat(p.y, 0.5);\n return
60+
sdHoleBox(p, float3(0.3 + 0.1 * sin(36.0 * _Time.x + 2.0 * Rand(float2(floor(pos.y
61+
* 2), 0))), 0.2, 0.3), float3(0.5, 0.15, 0.25));\n}\n\nfloat dInnerPillar(float3
62+
pos)\n{\n float3 p = pos;\n p.xz = Repeat(p.xz, float2(3, 3));\n p.xz
63+
= opFoldRotate(p.xz, 12.0 * cos(12.0 * _Time.x));\n p.y = Repeat(p.y, 0.2);\n
64+
\ return Box(p, float3(0.3 * abs(sin(36.0 * _Time.x)), 0.2, 0.15));\n}\n\nfloat
65+
dFloor(float3 pos)\n{\n float3 p = pos;\n p.xz = Repeat(p.xz, 0.5);\n
66+
\ p.y += 1 + 0.1 * sin(36.0 * _Time.x + 2.0 * Rand(floor(2.0 * pos.xz)));\n
67+
\ return sdBox(p, float3(0.2, 0.2, 0.2));\n}\n\ninline float DistanceFunction(float3
68+
pos)\n{\n float d = dFloor(pos);\n d = min(dOuterPillar(pos), d);\n d
69+
= min(dInnerPillar(pos), d);\n return d;\n}"
7070
folded: 0
7171
- key: PostEffect
72-
value: "//sampler2D _Grid;\n//float4 _Grid_ST;\nfloat4 _FloorDiffuse;\nfloat4
73-
_FloorSpecular;\n\ninline void PostEffect(RaymarchInfo ray, inout PostEffectOutput
74-
o)\n{\n o.emission = half4(2.0, 2.0, 5.0, 1.0) * abs(sin(PI * 12.0 * _Time.x))
75-
* step(frac(ray.endPos.y - 4.0 * _Time.x), 0.02);\n \n if (abs(dInnerPillar(ray.endPos))
76-
< ray.minDistance)\n {\n o.emission = half4(3.0, 1.0, 1.0, 1.0) *
77-
abs(sin(PI * 24.0 * _Time.x));\n }\n \n if (abs(dFloor(ray.endPos)) <
78-
ray.minDistance)\n {\n o.diffuse = _FloorDiffuse;\n o.specular
79-
=_FloorSpecular;\n }\n}"
72+
value: "float4 _FloorDiffuse;\nfloat4 _FloorSpecular;\nfloat4 _SlideEmission;\nfloat4
73+
_InnerEmission;\n\ninline void PostEffect(RaymarchInfo ray, inout PostEffectOutput
74+
o)\n{\n float a = frac(4.0 * ray.endPos.y - 2.0 * _Time.x - 0.5);\n float
75+
width = 0.02;\n o.emission = _SlideEmission * abs(sin(PI * 12.0 * _Time.x))
76+
* step(a, width) * ((a + 0.5 * width) / width);\n \n if (abs(dInnerPillar(ray.endPos))
77+
< ray.minDistance)\n {\n o.emission = _InnerEmission * abs(sin(PI
78+
* 24.0 * _Time.x));\n }\n \n if (abs(dFloor(ray.endPos)) < ray.minDistance)\n
79+
\ {\n o.diffuse = _FloorDiffuse;\n o.specular =_FloorSpecular;\n
80+
\ }\n}"
8081
folded: 0
81-
basicFolded: 0
82-
conditionsFolded: 0
83-
variablesFolded: 0
84-
materialsFolded: 1
82+
basicFolded: 1
83+
conditionsFolded: 1
84+
variablesFolded: 1
85+
materialsFolded: 0
8586
distanceFunction:
8687
postEffect:

Assets/Demoscene/TheGlow/TheGlowWorld.mat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Material:
66
m_ObjectHideFlags: 0
77
m_PrefabParentObject: {fileID: 0}
88
m_PrefabInternal: {fileID: 0}
9-
m_Name: World
9+
m_Name: TheGlowWorld
1010
m_Shader: {fileID: 4800000, guid: 87a584a97f34fd4438ddd726e04938ed, type: 3}
1111
m_ShaderKeywords:
1212
m_LightmapFlags: 4
@@ -30,7 +30,9 @@ Material:
3030
- _ShadowMinDistance: 0.01
3131
m_Colors:
3232
- _Diffuse: {r: 1, g: 1, b: 1, a: 1}
33-
- _Emission: {r: 1, g: 1, b: 1, a: 1}
33+
- _Emission: {r: 1, g: 0.591, b: 1, a: 1}
3434
- _FloorDiffuse: {r: 1, g: 1, b: 1, a: 1}
3535
- _FloorSpecular: {r: 0.75, g: 0.96896553, b: 1, a: 1}
36+
- _InnerEmission: {r: 3, g: 1, b: 1, a: 1}
37+
- _SlideEmission: {r: 2, g: 2, b: 5, a: 1}
3638
- _Specular: {r: 1, g: 0, b: 0, a: 0.634}

Assets/Demoscene/TheGlow/TheGlowWorld.shader

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Properties
1818
// @block Properties
1919
_FloorDiffuse("Floor Diffuse", Color) = (1.0, 1.0, 1.0, 1.0)
2020
_FloorSpecular("Floor Specular", Color) = (1.0, 1.0, 1.0, 1.0)
21+
_SlideEmission("Slide Emission", Vector) = (2.0, 2.0, 5.0, 1.0)
22+
_InnerEmission("Inner Emission", Vector) = (3.0, 1.0, 1.0, 1.0)
23+
// @endblock
2124
}
2225

2326
SubShader
@@ -45,23 +48,23 @@ CGINCLUDE
4548
// @block DistanceFunction
4649
#define PI2 (2.0 * PI)
4750

48-
float2x2 rotate(in float a)
51+
float2x2 opRotate(in float a)
4952
{
5053
float s = sin(a), c = cos(a);
5154
return float2x2(c, s, -s, c);
5255
}
5356

5457
// https://www.shadertoy.com/view/Mlf3Wj
55-
float2 foldRotate(in float2 p, in float s)
58+
float2 opFoldRotate(in float2 p, in float s)
5659
{
5760
float a = PI / s - atan2(p.x, p.y);
5861
float n = PI2 / s;
5962
a = floor(a / n) * n;
60-
p = mul(rotate(a), p);
63+
p = mul(opRotate(a), p);
6164
return p;
6265
}
6366

64-
float HoleBox(float3 pos, float3 outer, float3 inner)
67+
float sdHoleBox(float3 pos, float3 outer, float3 inner)
6568
{
6669
return max(sdBox(pos, outer), -sdBox(pos, inner));
6770
}
@@ -70,16 +73,16 @@ float dOuterPillar(float3 pos)
7073
{
7174
float3 p = pos;
7275
p.xz = Repeat(p.xz, float2(3, 3));
73-
p.xz = foldRotate(p.xz, 12.0 * sin(_Time.x));
76+
p.xz = opFoldRotate(p.xz, 12.0 * sin(_Time.x));
7477
p.y = Repeat(p.y, 0.5);
75-
return HoleBox(p, float3(0.3 + 0.1 * sin(36.0 * _Time.x + 2.0 * Rand(float2(floor(pos.y * 2), 0))), 0.2, 0.3), float3(0.5, 0.15, 0.25));
78+
return sdHoleBox(p, float3(0.3 + 0.1 * sin(36.0 * _Time.x + 2.0 * Rand(float2(floor(pos.y * 2), 0))), 0.2, 0.3), float3(0.5, 0.15, 0.25));
7679
}
7780

7881
float dInnerPillar(float3 pos)
7982
{
8083
float3 p = pos;
8184
p.xz = Repeat(p.xz, float2(3, 3));
82-
p.xz = foldRotate(p.xz, 12.0 * cos(12.0 * _Time.x));
85+
p.xz = opFoldRotate(p.xz, 12.0 * cos(12.0 * _Time.x));
8386
p.y = Repeat(p.y, 0.2);
8487
return Box(p, float3(0.3 * abs(sin(36.0 * _Time.x)), 0.2, 0.15));
8588
}
@@ -102,20 +105,20 @@ inline float DistanceFunction(float3 pos)
102105
// @endblock
103106

104107
// @block PostEffect
105-
//sampler2D _Grid;
106-
//float4 _Grid_ST;
107108
float4 _FloorDiffuse;
108109
float4 _FloorSpecular;
110+
float4 _SlideEmission;
111+
float4 _InnerEmission;
109112

110113
inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)
111114
{
112115
float a = frac(4.0 * ray.endPos.y - 2.0 * _Time.x - 0.5);
113116
float width = 0.02;
114-
o.emission = half4(2.0, 2.0, 5.0, 1.0) * abs(sin(PI * 12.0 * _Time.x)) * step(a, width) * ((a + 0.5 * width) / width);
117+
o.emission = _SlideEmission * abs(sin(PI * 12.0 * _Time.x)) * step(a, width) * ((a + 0.5 * width) / width);
115118

116119
if (abs(dInnerPillar(ray.endPos)) < ray.minDistance)
117120
{
118-
o.emission = half4(3.0, 1.0, 1.0, 1.0) * abs(sin(PI * 24.0 * _Time.x));
121+
o.emission = _InnerEmission * abs(sin(PI * 24.0 * _Time.x));
119122
}
120123

121124
if (abs(dFloor(ray.endPos)) < ray.minDistance)

0 commit comments

Comments
 (0)