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
|
/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
shader_type spatial;
render_mode unshaded;
uniform sampler2D screen_texture : hint_screen_texture, repeat_enable, filter_nearest;
varying vec3 world_camera;
varying vec3 world_position;
uniform float type : hint_range(-1.0, 1.0);
uniform float size : hint_range(0.0, 2.0);
void vertex() {
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
INV_VIEW_MATRIX[0],
INV_VIEW_MATRIX[1],
INV_VIEW_MATRIX[2],
MODEL_MATRIX[3]
);
world_position = VERTEX;
world_camera = (inverse(MODELVIEW_MATRIX) * vec4(0, 0, 0, 1)).xyz;
}
void fragment() {
vec3 ray = world_camera / size;
vec3 rv = normalize(world_position - world_camera);
vec3 em = vec3(0.);
bool hit = false;
for (int i = 0; i < 100; i++) {
float st = length(ray) * 0.1;
ray += normalize(rv) * st;
if (length(ray) < 1.) { hit = true; break; }
rv += -normalize(ray) * -type / exp(dot(ray,ray)) * st;
em += st * smoothstep(1.5,1.2,length(ray)) * 0.2;
}
vec4 k = PROJECTION_MATRIX * vec4(rv*1000.0, 1.0);
k /= k.w;
vec2 k2 = (k.xy + 1.) / 2.;
vec3 col = hit ? vec3(type*0.5+0.5) : texture(screen_texture, k2).rgb;
col += vec3(0.3,0.0,1.0) * max(em - 0.1,0.);
ALBEDO = col;
}
|