-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.glsl
185 lines (157 loc) · 5.78 KB
/
main.glsl
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
HELP:
+ 2 действия за проход:
+ сначало рисуем на matrix
+ чтобы отобразить конечный результат, русуем на конечной текстуре
w[x][y].on = true -- in shader: red color
w[x][y].le = 0 -- light energy emit; 0...; in shader: blue color
+ тут не получиться
*/
/*
zlib License
Copyright (c) 2015 Savoshchanka Anton Aleksandrovich
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
https://github.com/AntonioModer/radiosity2D
*/
//extern Image matrix;
//extern Image light, obstacles;
//int iEmits = 1, iEmitsPast = 0;
number textureSize = 1024.0-1.0;
/*
HELP:
+ тут не получиться отдавать энергию соседней ячейке напрямую
TODO:
-+ можно попробовать наоборот: принимать свет с соседних ячеек
*/
number takele(number fromColorB, number toColorB, number lowPow) {
if (fromColorB == toColorB) { return toColorB; }
if ( !(toColorB < fromColorB) ) { return toColorB; }
toColorB = fromColorB - lowPow;
return toColorB;
}
// for help
//number toNormalizedCoord(number notNormalizedTexCoord, number texSize) {
//return notNormalizedTexCoord/texSize;
//}
vec4 emit(Image matrix, vec2 cellNormCoord, number lowPow) {
vec4 cellColor = Texel(matrix, cellNormCoord);
if ( !(cellColor.r > 0.0) ) { return cellColor; }
if (cellColor.b > 0.0) { return cellColor; }
/*
compute
Top-down view
O O O
O x O
O O O
последовательность:
1 2 3
8 x 4
7 6 5
x - light emited cell
O - give light energy to this cell
*/
vec4 cccColor; // current compute cell
vec2 cccNormCoord;
vec2 cellMatrixCoord = vec2(textureSize*cellNormCoord.x, textureSize*cellNormCoord.y);
/**/
// 1
if ( (cellMatrixCoord.x-1.0 > -1.0) && (cellMatrixCoord.y-1.0 > -1.0) ) {
cccNormCoord = vec2((cellMatrixCoord.x-1.0)/textureSize, (cellMatrixCoord.y-1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x-1][cell.y-1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*15);
} else {
}
}
// 2
if (cellMatrixCoord.y-1.0 > -1.0) {
cccNormCoord = vec2(cellNormCoord.x, (cellMatrixCoord.y-1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x][cell.y-1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*5);
} else {
cellColor.b = 0;
}
}
/*
// 3
if ( (cellMatrixCoord.x+1.0 < textureSize) && (cellMatrixCoord.y-1.0 > -1.0) ) {
cccNormCoord = vec2((cellMatrixCoord.x+1.0)/textureSize, (cellMatrixCoord.y-1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x+1][cell.y-1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*1.4142);
} else {
}
}
*/
// 4
if (cellMatrixCoord.x+1.0 < textureSize) {
cccNormCoord = vec2((cellMatrixCoord.x+1.0)/textureSize, cellNormCoord.y);
cccColor = Texel(matrix, cccNormCoord); // [cell.x+1][cell.y]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow);
} else {
cellColor.b = 0;
}
}
/*
// 5
if ( (cellMatrixCoord.x+1.0 < textureSize) && (cellMatrixCoord.y+1.0 < textureSize) ) {
cccNormCoord = vec2((cellMatrixCoord.x+1.0)/textureSize, (cellMatrixCoord.y+1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x+1][cell.y+1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*1.4142);
} else {
}
}
*/
// 6
if (cellMatrixCoord.y+1 < textureSize) {
cccNormCoord = vec2(cellNormCoord.x, (cellMatrixCoord.y+1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x][cell.y+1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*5);
} else {
cellColor.b = 0;
}
}
/**/
// 7
if ( (cellMatrixCoord.x-1.0 > -1) && (cellMatrixCoord.y+1 < textureSize) ) {
cccNormCoord = vec2((cellMatrixCoord.x-1.0)/textureSize, (cellMatrixCoord.y+1.0)/textureSize);
cccColor = Texel(matrix, cccNormCoord); // [cell.x-1][cell.y+1]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*15);
} else {
}
}
// 8
if (cellMatrixCoord.x-1 > -1) {
cccNormCoord = vec2((cellMatrixCoord.x-1.0)/textureSize, cellNormCoord.y);
cccColor = Texel(matrix, cccNormCoord); // [cell.x-1][cell.y]
if (cccColor.r > 0.0) { // ccc.on
cellColor.b = takele(cccColor.b, cellColor.b, lowPow*10);
} else {
cellColor.b = 0;
}
}
/**/
return cellColor;
}
vec4 effect(vec4 color, Image texture, vec2 texCoord, vec2 screenCoord) {
vec4 pixel = Texel(texture, texCoord); // This is the current pixel color
pixel = emit(texture, texCoord, 0.00099);
return pixel;
}