From c538641ec8c10e00251ea9d284649608885aed9f Mon Sep 17 00:00:00 2001 From: asrael Date: Tue, 10 Feb 2026 11:10:37 -0600 Subject: [PATCH] glow rendering fixes to bring stars back --- demo/mod/colormap.fnl | 1031 --------------------------------- demo/mod/entities.fnl | 23 +- demo/mod/first_person3d.fnl | 27 +- demo/mod/palette.fnl | 263 --------- demo/mod/sky.fnl | 490 ++++++++++++---- demo/res/palettes/palette.ase | Bin 0 -> 944 bytes pxl8.sh | 1 + pxl8d/src/procgen.rs | 7 + src/bsp/pxl8_bsp.c | 26 + src/bsp/pxl8_bsp.h | 1 + src/gfx/pxl8_colormap.c | 55 ++ src/gfx/pxl8_colormap.h | 16 +- src/gfx/pxl8_gfx.c | 105 +++- src/gfx/pxl8_glows.c | 4 +- src/gfx/pxl8_glows.h | 2 +- src/gfx/pxl8_palette.c | 2 +- src/gfx/pxl8_render.c | 80 +-- src/gfx/pxl8_render.h | 1 + src/gfx/pxl8_render_types.h | 26 +- src/gfx/pxl8_shader.h | 1 + src/gfx/shaders/cpu/lit.c | 37 ++ src/lua/pxl8.lua | 14 + src/lua/pxl8/effects.lua | 37 ++ src/lua/pxl8/world.lua | 4 + src/math/pxl8_math.h | 1 + src/script/pxl8_script_ffi.h | 10 + 26 files changed, 773 insertions(+), 1491 deletions(-) delete mode 100644 demo/mod/colormap.fnl delete mode 100644 demo/mod/palette.fnl create mode 100644 demo/res/palettes/palette.ase diff --git a/demo/mod/colormap.fnl b/demo/mod/colormap.fnl deleted file mode 100644 index 937abb9..0000000 --- a/demo/mod/colormap.fnl +++ /dev/null @@ -1,1031 +0,0 @@ -(require :pxl8) -(local ffi (require :ffi)) - -(local data (ffi.new "u8[16384]" [ - 254 254 48 48 48 253 253 253 253 144 106 106 106 252 252 252 - 253 253 48 48 48 48 48 48 48 48 48 48 48 254 254 254 - 253 253 253 253 253 253 253 128 128 48 48 48 48 48 48 254 - 253 105 253 253 105 105 105 105 105 105 105 105 48 48 48 48 - 105 105 105 105 128 105 48 48 48 49 49 48 48 254 254 254 - 253 253 253 253 253 253 253 48 48 48 48 48 48 48 254 254 - 253 48 48 48 48 48 254 254 105 105 106 252 252 106 106 10 - 10 9 9 9 8 8 8 8 128 128 128 147 148 148 254 49 - 253 253 253 253 253 253 48 48 48 48 48 48 48 254 254 254 - 106 106 253 253 253 253 253 253 253 253 48 48 48 48 48 254 - 105 105 105 105 253 48 48 48 48 48 48 254 254 254 254 254 - 106 10 9 9 9 9 253 253 253 253 128 128 128 128 254 254 - 106 106 144 253 253 253 253 253 253 48 48 48 48 48 254 49 - 145 145 145 145 145 145 253 252 252 252 252 247 247 52 247 52 - 52 52 52 52 248 248 248 248 248 105 160 160 160 104 254 129 - 105 105 253 128 128 128 129 106 105 105 105 252 106 106 105 160 - 84 84 82 151 150 254 254 254 128 146 253 253 253 253 106 106 - 80 81 81 81 81 81 51 82 82 83 83 83 83 83 83 83 - 254 254 254 254 130 130 130 131 131 131 131 151 152 152 152 83 - 254 104 255 80 105 48 104 104 53 53 53 104 54 54 51 96 - 161 161 162 162 162 162 162 163 163 164 164 96 96 83 83 84 - 49 49 49 80 80 80 80 80 81 81 81 82 83 83 83 96 - 80 81 162 163 82 83 83 83 160 105 105 253 144 253 253 253 - 146 147 148 149 150 150 150 150 151 151 152 152 152 84 84 84 - 254 255 255 255 255 162 162 162 162 81 163 83 83 83 84 84 - 253 48 48 48 254 49 254 254 254 49 50 50 151 151 152 84 - 49 255 255 161 162 162 162 162 163 163 164 83 83 83 84 84 - 128 8 128 128 129 254 130 130 130 130 131 131 132 132 133 133 - 253 48 48 49 49 49 49 49 49 50 51 51 82 83 83 16 - 214 214 214 214 214 49 254 106 106 106 52 52 52 52 52 53 - 58 53 53 53 53 104 249 161 162 162 162 163 164 164 164 164 - 80 129 129 36 131 152 83 253 48 104 80 105 105 105 104 104 - 186 186 185 184 184 184 183 182 182 182 182 181 180 180 180 179 - 183 184 184 184 184 184 184 185 185 185 185 185 185 185 185 185 - 183 183 183 184 184 184 184 184 185 185 185 185 185 185 185 185 - 35 132 132 133 130 131 132 133 130 80 132 132 133 133 135 136 - 164 164 164 164 164 134 135 135 135 185 185 185 185 185 185 185 - 35 132 132 35 184 184 184 184 184 184 184 185 185 185 185 186 - 133 134 135 135 185 185 186 185 131 131 129 180 180 180 180 181 - 182 182 182 183 184 183 184 184 184 184 185 185 185 185 186 186 - 132 132 132 133 133 134 184 184 185 185 185 185 185 185 185 186 - 34 34 34 34 35 35 35 183 184 184 184 184 185 185 185 185 - 132 132 132 133 133 134 135 135 184 185 185 185 185 186 186 185 - 182 182 182 182 182 182 183 183 184 184 184 184 185 185 185 186 - 34 34 34 35 35 35 35 35 184 185 184 185 185 185 185 244 - 37 153 151 152 36 35 183 8 128 128 128 254 254 254 80 255 - 255 162 163 163 163 164 164 164 164 164 165 134 135 135 185 186 - 132 133 183 184 184 185 135 130 131 132 133 128 130 130 132 128 - 239 239 169 168 168 167 167 166 165 133 133 132 131 130 130 129 - 167 237 168 168 168 168 168 238 238 238 238 238 238 238 239 239 - 166 167 167 167 167 167 168 168 168 168 169 169 169 169 169 238 - 165 166 167 167 164 165 166 70 250 68 69 70 237 71 238 238 - 69 69 69 70 70 70 237 237 71 71 238 238 238 238 238 239 - 166 166 167 167 167 167 168 168 168 168 238 238 238 238 238 238 - 237 237 237 71 238 238 238 238 165 164 163 162 130 131 131 132 - 133 134 135 135 136 136 136 136 137 137 137 170 170 239 239 239 - 166 166 166 237 237 237 237 168 168 238 238 238 238 239 239 239 - 164 165 165 165 165 166 166 166 167 167 168 168 169 238 238 238 - 69 69 69 70 70 237 237 237 71 238 238 238 238 239 239 170 - 133 133 134 134 134 135 135 135 135 136 136 168 169 169 239 239 - 164 165 165 165 166 166 167 167 168 168 168 238 238 238 238 239 - 17 19 17 97 97 166 166 104 255 80 54 54 59 59 250 250 - 66 66 234 69 69 69 69 69 236 70 70 237 71 71 238 73 - 70 165 166 135 168 238 238 163 165 70 237 255 163 164 165 160 - 71 71 237 70 70 236 69 68 250 250 162 162 162 161 160 160 - 236 236 236 70 70 70 70 70 70 70 71 71 71 71 71 71 - 165 165 69 69 236 236 70 70 70 70 70 71 71 71 71 71 - 67 68 69 69 66 234 234 234 232 233 233 234 234 236 70 70 - 234 234 234 234 236 236 236 70 70 70 70 71 71 71 71 71 - 68 68 69 69 69 236 236 236 70 70 70 71 71 71 71 71 - 236 236 70 70 70 71 71 71 67 66 65 64 160 161 162 162 - 163 164 165 166 166 167 168 168 168 237 71 71 72 72 71 71 - 68 235 68 69 69 69 236 236 70 70 70 71 71 71 72 72 - 250 250 250 250 250 68 68 69 69 236 70 70 70 71 71 71 - 68 234 69 236 236 236 70 70 70 70 70 70 71 71 72 73 - 163 163 164 164 164 165 165 166 236 70 70 70 70 71 71 71 - 250 250 250 250 250 250 69 69 70 70 70 71 71 71 71 72 - 60 60 60 60 60 60 165 53 53 53 58 58 228 228 229 229 - 230 230 230 230 233 234 234 234 234 234 236 236 70 71 71 71 - 68 67 164 166 237 71 71 65 233 234 69 64 249 250 165 160 - 67 67 66 249 249 58 58 58 53 57 57 52 52 52 52 52 - 229 229 229 229 230 230 230 230 233 233 233 233 233 233 233 233 - 58 58 58 58 58 249 249 249 249 249 249 249 66 66 66 233 - 227 227 231 228 227 227 228 229 226 227 228 228 229 229 230 230 - 228 228 229 229 229 229 229 230 230 230 230 230 230 233 233 233 - 58 58 58 58 249 231 231 232 232 232 232 233 233 233 233 233 - 229 229 229 230 230 230 233 230 227 227 56 248 52 248 248 248 - 53 53 58 58 249 59 59 59 59 59 250 250 250 250 67 67 - 58 231 231 231 231 231 231 232 230 230 233 233 233 233 233 234 - 57 57 58 58 58 58 58 58 58 58 249 249 249 66 66 233 - 231 228 229 229 229 229 229 230 230 230 230 230 233 233 233 233 - 248 248 53 53 53 64 249 249 249 249 249 249 66 66 66 67 - 57 57 57 58 58 58 58 58 58 58 249 249 249 66 233 67 - 58 58 58 58 58 58 58 52 56 56 225 225 225 226 226 226 - 226 226 226 227 228 228 228 228 229 229 229 229 230 230 230 230 - 231 231 64 249 250 250 233 56 227 228 229 56 56 57 53 53 - 58 57 57 57 56 56 56 56 56 56 56 221 221 219 219 219 - 56 56 56 56 56 57 57 57 57 57 57 57 57 57 57 57 - 56 56 56 56 56 56 56 56 57 57 57 57 57 57 57 57 - 56 225 225 225 222 224 225 225 222 224 224 225 225 56 57 227 - 225 225 225 225 226 226 226 227 227 227 227 227 227 227 227 227 - 56 56 56 56 56 56 56 56 57 56 57 57 57 57 57 57 - 56 56 56 56 57 57 57 57 225 223 222 219 219 219 219 56 - 52 56 56 56 56 56 57 57 57 57 57 57 57 57 57 57 - 56 56 56 56 56 56 56 56 57 57 57 57 57 57 57 57 - 222 223 223 225 225 225 225 56 56 56 57 57 57 57 57 57 - 225 225 225 225 225 225 226 226 227 227 227 57 57 57 57 57 - 52 52 52 52 52 56 56 56 56 56 57 57 57 57 57 57 - 222 222 223 225 225 225 56 56 56 56 56 57 57 57 57 57 - 222 222 222 223 223 225 223 219 219 220 220 220 221 221 221 222 - 224 224 224 224 224 224 225 225 226 226 226 227 227 227 227 227 - 225 56 56 57 57 57 57 222 224 225 225 219 221 222 56 58 - 144 106 106 106 106 252 252 252 252 217 217 217 217 217 217 216 - 247 247 247 247 247 247 247 247 247 247 52 52 52 52 52 144 - 252 252 252 252 252 252 252 252 106 106 106 106 106 106 144 106 - 252 247 247 247 217 218 247 52 218 218 218 247 247 247 247 247 - 247 247 247 247 247 247 247 247 247 247 247 247 247 247 52 52 - 252 247 247 247 247 247 247 247 247 247 247 52 247 247 247 52 - 247 247 247 247 247 247 52 52 247 217 217 217 216 216 216 217 - 251 252 252 252 252 252 252 106 106 106 144 144 144 144 144 52 - 252 247 247 247 247 247 247 247 247 247 247 247 247 52 144 52 - 217 217 218 252 252 252 252 252 252 252 106 106 106 106 106 247 - 247 247 247 247 247 247 247 247 247 247 247 247 247 52 52 144 - 251 251 251 251 252 252 252 252 252 252 252 106 106 144 144 144 - 217 217 217 218 252 252 247 247 247 247 247 247 247 247 52 52 - 218 218 218 218 218 247 252 216 216 217 217 218 218 218 218 218 - 218 218 218 219 219 247 247 247 247 247 247 247 247 247 247 247 - 247 252 252 252 106 144 144 217 217 247 247 216 217 217 252 160 - 198 197 196 195 195 195 194 194 194 193 193 193 192 192 192 192 - 195 195 195 195 195 195 195 195 196 196 196 196 196 197 197 197 - 194 194 194 194 195 195 195 195 195 195 195 195 196 196 197 196 - 194 194 194 195 193 194 194 195 194 194 194 194 195 195 195 196 - 195 196 196 195 195 196 196 196 196 196 196 196 196 197 197 197 - 194 194 194 195 195 195 195 195 195 195 195 196 196 196 197 197 - 195 195 195 195 196 196 197 197 193 193 192 192 192 192 192 193 - 193 193 194 194 194 195 195 195 195 196 196 196 197 197 197 198 - 194 194 194 195 195 195 195 195 195 195 196 196 197 197 197 198 - 193 193 194 194 194 194 194 194 195 195 195 195 195 196 196 197 - 194 195 195 195 195 195 195 196 196 196 196 196 197 197 197 198 - 193 193 193 193 194 194 194 194 195 195 195 195 196 196 197 197 - 193 194 194 194 194 194 194 194 195 195 195 196 196 196 197 198 - 194 211 212 194 194 194 194 12 12 192 192 192 193 194 194 144 - 144 145 145 146 146 146 145 146 147 147 214 214 214 196 197 199 - 146 146 9 8 195 196 197 192 194 194 195 192 192 193 144 129 - 203 203 202 201 201 201 201 201 213 213 213 213 213 213 213 213 - 201 201 201 201 201 201 201 201 202 202 202 202 202 203 203 203 - 201 201 201 201 201 201 201 202 202 202 202 202 202 202 203 203 - 213 201 201 201 213 213 201 201 213 213 213 201 201 201 202 203 - 201 201 201 201 202 202 202 202 202 202 202 202 202 203 203 203 - 201 201 201 201 201 201 201 202 202 202 202 202 202 202 202 203 - 201 201 202 202 202 202 203 203 201 213 213 213 213 213 213 213 - 213 201 201 201 201 201 201 201 201 201 202 202 202 203 203 203 - 201 201 201 201 201 201 201 201 202 202 202 202 202 202 203 203 - 213 213 213 213 201 201 201 201 201 201 201 202 202 202 203 203 - 201 201 201 201 201 201 202 202 202 202 202 202 202 203 203 203 - 201 201 201 201 201 201 201 201 201 201 201 202 202 202 203 203 - 213 213 213 213 213 213 201 201 201 201 202 202 201 201 202 203 - 210 210 210 211 210 211 201 212 213 213 213 213 213 213 213 213 - 213 213 213 213 213 201 201 201 202 202 202 202 202 202 202 202 - 201 201 200 3 201 203 203 213 201 201 201 213 213 201 200 49 - 207 207 206 101 156 42 155 41 40 153 153 152 152 151 150 149 - 23 205 205 205 205 205 206 206 206 206 206 206 207 207 207 207 - 41 41 3 3 3 42 156 156 156 101 101 206 206 206 206 207 - 154 20 21 21 16 18 21 61 96 97 61 21 21 205 206 245 - 87 168 168 169 169 169 169 239 170 171 63 63 207 207 207 207 - 20 21 21 21 23 23 23 205 205 206 206 206 206 206 207 207 - 23 62 206 206 206 206 207 207 98 84 152 151 150 36 37 37 - 38 39 41 3 43 43 93 44 2 31 45 102 102 102 207 207 - 99 99 90 90 22 62 62 62 246 246 245 245 207 207 207 207 - 153 202 202 202 203 203 20 204 204 204 205 205 206 206 207 207 - 20 87 90 169 169 62 62 246 246 245 245 207 207 207 207 102 - 38 184 4 4 39 41 3 3 3 43 44 44 157 157 63 207 - 152 202 202 202 203 203 204 204 205 205 205 206 206 206 207 207 - 203 203 203 203 203 203 204 197 199 199 198 200 54 59 60 60 - 60 60 60 60 61 61 61 72 168 238 238 239 239 245 63 63 - 168 167 136 244 101 206 206 83 17 19 62 150 152 153 98 48 - 202 201 201 152 200 150 150 149 148 147 147 146 145 145 144 144 - 200 200 200 200 200 201 201 201 201 201 201 201 201 201 201 202 - 199 150 150 150 150 150 200 200 200 200 200 201 201 201 201 201 - 197 197 197 200 214 214 214 214 48 53 214 214 200 200 201 201 - 49 50 50 50 51 51 51 83 16 16 16 201 201 201 201 202 - 199 198 198 198 200 200 200 200 200 200 200 201 201 201 201 202 - 151 151 200 201 201 201 201 202 149 147 146 145 144 145 146 146 - 147 148 149 150 36 36 36 36 152 152 152 153 153 153 202 202 - 149 149 150 150 150 151 151 151 152 151 152 201 201 201 201 202 - 196 196 196 197 197 197 197 198 198 200 200 200 201 201 201 202 - 49 49 50 50 50 51 51 152 152 152 201 201 201 202 202 202 - 8 8 7 7 7 33 33 6 150 151 151 152 152 153 153 153 - 195 196 196 197 197 197 198 198 200 200 201 201 201 201 201 202 - 212 212 213 213 214 197 197 192 144 144 194 194 53 53 53 53 - 53 53 53 58 54 54 54 55 54 51 51 51 83 16 16 16 - 50 130 129 35 200 201 16 146 48 49 50 144 146 147 148 48 - 153 152 152 151 150 150 149 148 147 147 146 145 145 144 10 10 - 199 199 198 198 200 200 200 200 152 152 152 152 152 152 152 152 - 148 149 199 149 149 150 150 150 150 151 151 151 151 152 152 152 - 148 199 199 149 146 147 197 199 48 48 149 149 199 198 200 152 - 149 49 49 80 50 50 50 82 152 152 152 152 152 152 152 153 - 149 149 149 199 150 150 150 150 150 151 151 151 152 152 152 152 - 150 150 151 200 152 152 152 152 148 146 145 144 144 145 145 8 - 8 8 7 7 33 6 6 6 6 6 36 37 152 152 153 153 - 148 148 149 149 150 150 150 150 151 151 151 152 152 152 153 153 - 146 195 196 196 148 148 148 149 199 199 150 151 151 152 152 152 - 149 49 49 49 150 50 151 151 151 151 152 152 152 152 153 5 - 8 8 8 8 32 32 7 7 7 150 151 151 151 152 37 153 - 146 195 196 196 196 196 199 199 198 198 200 200 200 201 201 201 - 213 213 213 214 196 148 199 10 144 144 144 145 145 52 52 53 - 53 53 53 53 54 54 54 54 80 50 50 50 151 152 152 152 - 254 129 129 34 6 152 152 146 48 254 150 144 145 146 148 48 - 189 189 188 187 187 187 186 4 4 38 5 37 35 35 33 33 - 3 43 43 43 43 44 2 2 2 2 94 189 188 189 189 189 - 186 186 186 186 186 244 187 187 187 187 188 188 188 188 189 94 - 39 41 244 3 38 40 41 91 84 85 86 89 91 26 29 94 - 136 136 136 137 137 170 246 246 246 138 94 94 45 189 189 189 - 41 3 3 3 3 3 43 43 43 43 188 188 188 188 189 189 - 43 25 93 93 29 94 94 103 39 38 37 35 34 34 34 184 - 184 185 185 186 186 187 187 187 187 124 188 188 188 189 189 189 - 39 39 41 42 42 42 43 43 43 2 188 188 188 189 189 189 - 38 38 4 4 39 39 3 3 3 3 43 2 188 188 188 189 - 39 136 91 137 92 24 27 138 138 29 188 188 189 189 189 189 - 184 184 184 184 185 185 185 186 186 187 187 187 188 188 188 189 - 5 38 4 4 39 41 3 3 43 43 44 2 2 94 95 158 - 203 203 202 203 154 155 155 7 7 150 150 150 151 51 96 96 - 97 97 97 98 167 167 168 168 169 169 170 170 246 139 45 139 - 136 134 244 186 124 125 95 37 38 136 137 34 5 4 135 128 - 185 184 184 184 183 183 182 181 181 180 180 180 8 112 112 112 - 35 35 35 35 183 184 184 184 184 184 184 184 184 184 184 184 - 182 182 182 182 182 183 183 183 183 183 184 184 184 184 184 185 - 33 34 34 35 7 33 34 35 7 7 33 34 35 5 184 185 - 34 35 35 35 37 37 5 5 5 184 185 185 185 185 184 185 - 33 34 34 34 35 35 183 183 184 184 184 184 184 184 184 185 - 35 35 5 184 184 185 185 185 33 32 8 9 112 179 179 180 - 181 181 182 182 182 183 183 183 183 184 184 184 184 184 185 185 - 33 33 34 34 35 35 183 183 184 184 184 184 184 184 185 185 - 32 32 32 33 33 33 33 34 34 183 184 184 184 184 184 185 - 33 34 35 35 35 37 5 5 5 184 184 184 184 185 185 185 - 180 180 181 181 181 182 182 182 182 183 183 183 184 184 184 185 - 32 32 33 33 33 34 6 34 35 35 5 184 184 184 185 185 - 6 6 33 33 33 34 34 10 9 9 9 145 146 147 148 147 - 49 49 49 80 131 131 132 132 132 132 37 37 5 184 185 185 - 131 130 34 182 184 184 185 8 32 34 35 9 8 32 130 128 - 183 182 182 181 181 181 180 179 179 178 178 178 177 111 110 110 - 181 181 181 181 182 182 182 182 182 182 182 182 182 182 182 182 - 180 180 180 180 180 181 181 181 181 181 181 182 182 182 182 182 - 180 180 180 181 112 8 8 33 9 8 8 8 32 182 182 183 - 32 32 32 32 33 182 182 182 182 182 182 182 182 182 182 182 - 180 181 180 181 181 181 181 181 181 182 182 182 182 182 182 183 - 181 181 181 182 182 182 182 183 113 112 112 111 110 177 177 178 - 178 179 179 180 180 181 181 181 181 182 182 182 182 182 182 183 - 180 180 180 180 181 181 181 181 182 181 182 182 182 182 183 183 - 112 113 113 180 180 180 180 180 180 181 181 181 182 182 182 182 - 180 181 181 181 181 181 181 182 182 182 182 182 182 182 183 183 - 178 178 178 179 179 179 180 180 180 181 181 181 182 182 182 183 - 112 112 113 113 113 181 181 181 181 181 181 182 182 182 182 183 - 114 114 114 113 113 113 114 110 110 110 10 10 10 144 144 145 - 253 253 128 128 128 128 7 7 32 33 33 182 182 182 182 183 - 32 8 179 181 181 182 183 10 8 7 33 110 111 113 32 128 - 141 1 103 94 29 93 43 3 39 4 38 5 5 35 35 6 - 93 28 28 28 28 94 139 139 139 139 139 140 140 140 140 140 - 3 3 3 43 43 93 44 29 29 94 94 94 45 103 140 103 - 41 42 24 24 85 88 22 62 16 98 20 21 62 171 171 172 - 169 169 169 170 170 171 171 171 172 172 172 172 172 140 140 140 - 42 92 92 25 27 138 138 138 28 94 139 139 139 140 140 140 - 246 171 171 171 139 103 140 140 136 135 133 37 35 5 5 184 - 185 185 186 187 187 124 125 125 125 125 189 126 46 46 47 47 - 137 137 137 137 137 138 138 138 139 139 139 139 140 140 47 141 - 39 39 39 41 41 42 42 92 25 93 27 29 139 103 158 140 - 137 169 169 170 170 170 171 171 171 139 172 140 140 140 140 47 - 185 185 185 186 186 186 187 187 187 188 94 94 94 103 46 47 - 39 40 154 41 41 42 24 25 28 30 30 157 103 103 158 159 - 155 204 204 203 204 23 100 150 150 151 151 51 55 60 60 60 - 97 97 61 61 237 72 238 238 238 239 239 171 171 172 172 172 - 169 167 137 244 188 45 173 84 86 87 246 36 37 40 87 128 - 76 239 170 169 169 90 88 86 85 84 83 82 50 80 130 254 - 168 168 168 168 169 238 238 238 239 239 239 239 239 239 239 239 - 86 88 88 168 168 168 168 169 169 169 169 169 170 170 170 239 - 97 61 61 61 96 165 61 237 96 60 60 61 61 238 238 74 - 167 237 237 237 237 72 238 238 238 238 238 239 239 239 239 75 - 167 167 167 168 168 168 168 168 169 169 238 239 239 239 239 75 - 168 238 238 238 238 239 239 75 166 164 163 81 131 131 132 132 - 153 153 40 41 42 42 42 24 24 26 246 246 171 171 171 76 - 166 166 167 167 168 168 168 238 238 238 238 239 239 75 75 75 - 84 84 84 17 98 98 98 19 168 168 169 169 169 170 239 75 - 166 237 237 237 237 71 72 238 238 238 238 239 239 239 75 76 - 133 133 134 134 135 135 136 136 136 169 169 169 170 170 170 75 - 83 16 16 16 17 19 61 61 61 62 62 62 239 239 239 76 - 203 203 203 203 17 19 19 254 254 49 54 54 59 59 59 59 - 250 60 68 69 236 236 70 70 70 71 71 72 73 73 74 74 - 237 166 167 136 169 170 74 163 165 166 168 80 132 84 166 160 - 167 167 165 165 164 164 132 131 130 255 255 255 160 48 105 105 - 164 165 165 165 165 165 165 165 166 166 166 166 166 166 167 167 - 163 163 163 163 164 164 164 165 165 165 165 166 166 166 166 166 - 162 250 250 250 161 249 250 250 64 249 249 250 250 164 165 70 - 163 250 250 250 250 164 165 165 69 166 166 166 166 166 70 70 - 163 250 250 250 250 250 164 165 165 165 165 166 166 166 166 237 - 164 164 68 165 165 166 166 70 162 161 104 160 48 48 254 254 - 254 80 131 82 133 133 133 134 134 135 135 166 167 167 167 167 - 163 163 250 250 250 250 250 165 165 165 166 166 166 167 167 168 - 254 80 80 80 81 81 163 132 164 164 165 165 165 166 166 167 - 163 250 250 250 250 250 68 165 69 166 166 166 166 167 167 167 - 255 130 130 131 131 131 163 132 164 133 165 165 165 166 167 167 - 254 49 80 50 50 51 55 55 96 96 61 97 166 166 167 61 - 150 200 55 55 55 51 51 105 105 105 53 53 53 58 58 58 - 58 58 249 249 66 66 66 66 66 235 68 69 69 236 70 70 - 163 162 132 133 134 166 166 160 64 250 164 105 255 255 162 160 - 139 28 27 92 42 41 39 39 38 37 37 36 34 33 7 129 - 87 168 90 169 90 91 169 24 246 26 26 246 246 246 246 138 - 39 39 39 39 41 41 41 155 42 92 92 25 93 27 28 138 - 134 85 88 88 83 84 98 61 51 96 97 98 87 22 170 170 - 167 167 167 167 168 169 169 169 169 170 170 170 246 246 246 171 - 85 88 88 88 87 90 90 90 91 23 100 24 26 246 246 246 - 90 90 90 91 137 138 246 246 84 133 82 150 149 150 36 37 - 37 38 38 39 244 244 244 43 244 43 93 93 29 29 94 139 - 85 86 86 88 87 90 90 90 169 137 137 246 246 138 30 139 - 37 153 153 153 40 40 40 40 41 41 41 42 92 93 28 138 - 85 86 88 87 168 90 169 169 169 169 170 246 246 246 171 139 - 5 5 184 38 38 4 4 39 244 244 244 92 43 93 28 94 - 37 153 153 153 40 40 154 154 41 23 24 24 26 246 246 245 - 202 203 203 202 202 202 154 148 148 148 149 54 54 55 55 55 - 55 60 60 60 166 70 70 237 237 167 168 169 169 170 170 171 - 167 133 135 39 43 93 170 82 83 98 88 254 151 152 166 160 - 3 3 41 39 4 38 5 37 6 6 33 7 7 8 8 8 - 153 153 40 40 40 154 154 154 154 154 41 41 155 3 3 3 - 5 5 5 5 5 38 4 39 154 154 154 154 41 41 155 155 - 151 152 153 153 150 151 83 16 49 51 51 83 84 18 99 90 - 83 84 84 84 85 85 86 86 89 99 99 22 91 155 155 155 - 152 153 153 153 153 153 40 40 154 154 154 154 41 155 155 155 - 153 85 40 154 154 41 41 155 152 150 149 148 8 7 32 32 - 33 6 35 5 4 4 4 4 4 4 3 3 3 3 3 24 - 152 152 84 84 153 85 40 40 154 154 41 41 155 155 42 156 - 150 151 151 151 152 152 152 5 153 153 39 154 154 41 155 155 - 152 152 84 84 85 85 86 40 154 41 41 155 155 155 42 3 - 34 34 35 35 35 5 5 5 4 4 4 39 41 3 3 155 - 150 150 151 151 152 152 153 153 153 39 154 154 154 155 155 156 - 200 200 201 201 201 201 201 146 146 195 195 214 214 54 54 54 - 54 54 54 55 55 60 96 97 97 97 98 86 87 99 41 91 - 133 132 133 38 4 3 22 149 151 152 153 146 199 150 82 48 - 151 151 150 149 148 148 147 146 146 145 145 144 144 10 11 11 - 148 148 149 149 149 149 150 150 150 150 150 150 150 150 150 151 - 147 147 147 147 148 148 148 148 149 149 199 150 150 150 150 151 - 146 147 147 147 145 146 48 48 145 146 48 48 148 149 150 150 - 48 48 48 254 254 49 49 49 150 150 150 150 150 151 151 151 - 147 147 147 148 148 148 148 148 149 149 149 150 150 150 151 151 - 148 149 149 149 149 150 150 151 146 145 144 10 10 10 10 9 - 9 9 8 8 7 7 7 7 33 33 6 6 6 151 151 151 - 146 147 148 148 148 148 149 149 149 149 150 150 150 151 151 151 - 145 145 146 146 146 146 147 147 148 148 148 149 149 150 150 151 - 147 48 48 48 254 49 49 149 150 150 150 150 151 151 151 151 - 9 9 9 8 8 8 8 7 7 7 7 7 150 150 151 151 - 145 145 146 146 146 147 147 148 148 149 149 150 150 150 151 200 - 195 212 196 195 195 196 146 11 192 192 192 144 144 52 52 52 - 52 52 52 53 53 53 48 48 49 49 49 49 150 150 151 131 - 128 128 128 32 7 6 150 144 146 48 148 106 144 145 146 48 - 43 42 155 41 39 4 5 5 36 6 33 33 7 7 8 8 - 40 40 154 154 154 154 41 41 155 155 155 155 155 42 42 43 - 5 5 5 38 38 4 39 39 154 154 41 41 155 155 155 42 - 152 153 153 153 151 152 152 17 50 51 83 153 17 154 41 22 - 84 84 85 85 98 86 88 87 90 21 22 22 42 42 156 156 - 153 153 153 153 40 40 40 154 154 154 41 155 155 155 155 156 - 40 154 154 154 41 155 155 156 152 151 149 7 7 7 32 33 - 6 35 5 5 4 4 185 185 244 3 3 3 3 43 43 156 - 152 153 153 153 153 40 154 154 154 41 41 155 155 42 43 156 - 6 36 152 152 152 152 153 153 153 40 40 154 154 155 155 42 - 84 84 85 85 85 86 88 89 99 41 41 155 42 156 156 43 - 34 34 35 35 5 5 5 5 4 4 4 39 41 155 42 156 - 150 151 151 152 152 153 153 153 154 154 154 155 155 155 42 156 - 202 202 201 201 201 201 153 146 146 147 148 148 49 54 54 54 - 59 54 55 96 96 96 97 97 166 98 98 87 90 22 91 91 - 134 133 134 38 4 3 91 150 83 152 153 148 149 151 83 128 - 140 140 139 94 27 92 42 155 41 39 38 38 37 36 36 34 - 26 170 170 246 246 171 171 171 171 171 139 172 172 172 140 140 - 42 3 3 92 43 25 27 138 138 138 139 139 139 172 172 172 - 89 22 91 62 16 61 168 62 61 61 61 168 62 62 171 171 - 168 72 238 238 74 74 75 75 76 76 76 172 172 172 172 172 - 91 91 137 137 170 170 170 170 246 246 171 139 139 172 172 173 - 26 170 170 170 139 172 172 173 136 135 133 132 36 37 5 38 - 4 4 244 244 187 188 188 188 188 125 95 158 46 140 173 173 - 136 169 169 169 169 170 170 170 170 171 171 139 172 140 140 173 - 134 86 88 89 99 22 91 23 100 24 246 246 171 139 172 172 - 136 169 169 169 170 170 170 170 171 171 171 172 172 140 173 140 - 185 185 185 185 244 244 244 3 43 93 29 94 139 172 172 173 - 153 40 154 41 41 91 92 24 246 246 245 245 63 172 172 173 - 23 204 204 204 204 21 100 149 149 150 50 55 60 60 60 60 - 60 61 61 166 237 71 237 72 238 73 74 75 75 76 172 77 - 169 167 136 137 94 139 77 133 167 168 169 131 132 135 167 160 - 89 88 86 84 84 83 82 50 80 49 254 254 48 48 146 253 - 83 164 165 165 165 165 166 166 166 166 135 135 167 167 167 167 - 131 132 132 132 132 133 133 133 133 84 134 134 85 135 86 167 - 80 82 132 133 129 80 81 164 104 54 54 81 96 165 134 166 - 163 250 250 250 164 165 165 165 166 166 166 135 135 135 135 167 - 132 132 132 164 164 164 164 165 165 165 165 166 135 135 167 167 - 133 133 165 165 135 135 167 167 162 255 129 128 8 8 8 7 - 7 33 34 35 37 5 5 5 38 38 39 40 40 88 88 167 - 131 163 163 163 164 164 164 164 165 165 135 135 167 167 88 87 - 254 49 49 50 50 50 82 82 82 83 84 84 85 85 86 167 - 131 163 132 164 164 164 165 165 165 134 135 135 135 167 167 136 - 7 33 33 34 34 34 35 37 37 133 133 84 85 86 167 167 - 254 49 80 50 50 82 82 82 83 84 84 84 85 86 88 99 - 200 200 200 200 151 151 82 253 253 253 48 53 53 53 58 58 - 58 249 249 249 249 250 250 250 250 250 165 165 166 166 167 167 - 163 162 132 132 134 135 166 255 161 163 133 253 128 255 162 160 - 137 137 136 136 135 135 134 133 132 131 131 130 149 148 147 128 - 135 135 86 135 88 88 89 136 136 136 136 136 136 137 137 137 - 133 133 134 134 134 134 135 135 135 88 136 136 136 91 137 137 - 133 84 133 135 131 132 133 85 81 55 96 96 98 86 136 136 - 165 165 165 166 166 167 167 87 136 136 136 136 137 137 137 137 - 133 134 134 134 135 135 135 135 88 88 88 136 136 137 137 137 - 135 135 135 135 136 136 137 137 132 132 131 129 8 7 33 34 - 34 35 5 4 185 185 185 185 244 244 3 3 3 92 25 138 - 133 133 134 134 134 135 135 135 88 136 136 136 137 137 137 26 - 151 151 152 152 152 152 153 153 153 40 40 88 89 136 137 137 - 133 84 134 135 135 135 135 88 136 136 136 136 137 137 137 138 - 35 35 35 35 35 5 38 38 39 135 135 136 136 136 137 137 - 131 151 151 152 152 153 153 153 18 19 99 99 41 91 92 24 - 201 201 201 201 16 153 153 8 253 147 48 49 54 54 54 54 - 54 59 250 250 164 165 165 165 166 166 167 167 168 168 137 169 - 165 133 134 134 244 244 136 131 82 84 85 128 150 132 83 160 - 126 126 125 125 124 124 187 187 186 186 185 184 183 183 34 34 - 2 31 2 2 125 125 125 126 126 126 126 126 126 126 127 190 - 187 187 187 187 187 124 124 124 125 125 125 125 125 126 126 126 - 3 43 43 2 39 155 42 101 154 20 41 42 44 157 125 127 - 43 93 28 30 157 45 45 95 95 158 46 126 126 126 127 127 - 187 187 187 188 188 188 188 188 188 125 126 126 126 126 127 127 - 2 157 45 95 126 126 127 127 3 4 38 5 183 184 184 184 - 120 120 119 119 123 123 124 124 124 125 125 125 126 126 126 127 - 122 187 187 187 187 188 188 188 189 189 126 126 126 126 127 127 - 4 39 3 244 244 244 187 187 187 124 125 125 125 125 126 126 - 3 43 43 44 2 94 94 94 95 126 126 126 126 127 127 127 - 185 185 185 121 121 121 122 122 124 124 125 125 125 125 126 127 - 4 39 41 3 3 3 43 2 188 188 125 126 126 126 127 127 - 156 156 155 155 155 156 43 33 6 6 200 201 201 202 202 202 - 17 19 20 21 21 23 24 246 246 171 139 103 158 126 127 127 - 93 244 244 122 125 125 126 5 41 92 93 35 5 4 136 128 - 119 119 119 119 118 117 117 116 115 115 115 114 114 114 114 113 - 185 185 185 186 186 121 121 121 121 119 119 119 119 119 119 119 - 116 116 117 117 117 117 118 118 118 118 119 119 119 119 119 119 - 183 184 184 185 35 5 5 4 6 37 5 5 4 185 186 187 - 5 4 4 4 185 186 186 186 186 186 186 122 122 123 119 123 - 184 184 184 185 185 185 185 185 120 120 120 119 119 119 119 119 - 185 185 185 186 120 119 119 123 183 182 33 114 114 114 114 115 - 115 115 116 116 117 117 117 118 118 118 119 119 119 119 119 123 - 184 184 184 184 185 185 185 185 185 121 121 121 119 119 119 119 - 115 115 115 183 183 116 116 117 117 117 118 118 119 119 119 119 - 184 184 184 185 185 185 186 186 186 121 121 121 121 119 119 119 - 115 115 115 116 116 116 116 116 117 117 118 119 119 119 119 123 - 115 115 115 115 116 116 117 117 117 118 119 119 119 119 119 119 - 117 116 117 116 116 116 116 113 113 8 196 196 197 197 198 198 - 151 151 152 37 5 38 4 4 4 4 185 186 186 122 122 123 - 184 183 184 117 119 119 122 33 35 5 185 32 114 182 134 128 - 183 182 182 114 114 113 113 113 113 112 111 111 111 111 110 110 - 32 32 32 32 32 32 32 33 182 182 182 182 182 182 182 115 - 113 113 113 113 113 113 114 114 114 114 182 182 182 182 182 182 - 8 8 8 8 9 8 8 7 9 9 8 8 7 32 33 182 - 8 8 32 32 32 32 32 32 33 33 33 182 182 182 182 183 - 8 8 8 8 32 32 32 32 32 32 32 182 182 182 182 182 - 32 32 32 32 32 182 182 183 8 9 112 111 110 110 111 111 - 111 113 113 113 114 114 114 114 114 115 115 115 115 115 115 183 - 8 8 8 8 32 32 32 32 32 32 182 182 182 182 183 183 - 112 113 113 113 113 113 113 113 113 114 114 114 114 182 182 183 - 8 8 32 32 32 32 32 32 32 33 182 182 182 182 183 183 - 112 112 113 113 113 113 113 113 114 114 114 114 114 115 182 115 - 112 112 112 113 113 113 113 113 114 114 32 32 182 182 182 183 - 113 113 113 113 113 113 113 109 109 11 11 10 144 144 144 144 - 145 145 145 146 8 8 8 7 7 7 33 33 33 33 182 182 - 8 8 8 180 114 182 182 10 9 8 32 110 111 9 8 128 - 9 9 9 10 11 11 11 12 12 12 12 13 13 14 14 14 - 11 10 10 10 10 10 10 10 10 10 10 9 9 9 9 9 - 11 11 11 11 11 11 11 10 10 10 10 10 10 10 9 9 - 107 252 252 106 251 252 252 106 251 252 252 252 106 106 10 9 - 252 252 106 106 106 106 144 144 10 10 10 9 9 9 9 9 - 11 11 11 11 106 106 106 106 10 10 10 10 10 9 9 9 - 106 106 106 10 10 10 9 253 107 107 251 13 14 14 108 108 - 109 109 109 110 110 110 110 111 111 111 10 9 10 9 9 9 - 107 252 252 252 106 106 106 106 10 10 10 9 9 9 9 9 - 107 107 107 107 107 107 11 11 11 11 10 10 10 10 9 9 - 252 252 252 106 106 106 106 10 10 10 10 10 9 9 253 9 - 12 109 109 109 109 109 110 110 110 10 10 10 10 10 9 9 - 107 107 107 107 107 11 11 11 10 10 10 10 10 9 9 145 - 11 192 11 11 11 11 11 15 15 14 251 251 251 251 251 251 - 252 252 252 252 252 252 106 106 106 106 106 253 106 144 9 9 - 252 106 11 10 10 10 9 251 107 252 11 14 13 251 252 128 - 137 91 136 86 134 134 133 132 132 131 130 254 129 128 128 128 - 84 84 85 85 98 86 88 88 88 87 87 90 90 90 90 91 - 153 153 153 153 153 153 85 85 135 86 88 89 136 136 136 90 - 82 83 84 84 80 82 96 96 80 51 96 96 165 166 88 168 - 164 165 165 165 165 166 167 167 167 167 168 168 168 90 90 169 - 84 84 84 84 84 84 85 98 86 86 88 88 89 90 90 90 - 84 85 98 86 88 87 168 168 82 80 254 129 128 129 7 7 - 6 36 37 38 38 39 39 39 39 39 41 136 90 91 137 169 - 82 83 84 84 165 84 85 85 86 86 88 87 90 91 91 137 - 150 151 151 151 132 152 133 153 133 153 85 40 88 89 136 90 - 164 164 165 165 165 165 166 167 167 88 87 90 90 90 91 137 - 36 36 36 36 36 37 38 38 38 38 40 41 89 136 90 91 - 149 150 151 151 152 153 153 84 85 18 86 88 88 90 90 23 - 201 201 201 201 201 201 153 146 146 48 48 53 53 58 58 59 - 54 54 250 250 250 250 165 165 165 166 166 166 167 167 168 167 - 164 163 133 134 39 136 168 49 81 96 97 48 254 80 163 160 - 63 245 246 23 23 21 20 86 85 153 152 152 151 150 149 149 - 21 21 62 62 62 62 62 62 62 62 62 246 246 245 245 245 - 154 154 99 99 99 21 22 23 23 23 62 62 246 246 246 246 - 17 17 61 61 16 16 61 61 60 60 61 61 61 169 62 239 - 167 237 237 237 238 238 238 238 239 239 239 239 239 246 171 245 - 19 19 20 20 21 21 62 62 62 62 62 62 246 246 246 171 - 168 62 62 62 62 62 245 171 98 83 82 50 150 151 152 37 - 5 38 39 41 155 3 43 43 43 93 27 101 245 245 245 245 - 86 86 167 168 168 168 168 169 62 62 62 62 246 246 245 63 - 153 153 153 18 18 18 19 20 99 21 22 23 62 246 246 239 - 61 61 61 61 168 168 62 62 62 62 62 246 246 245 245 63 - 5 38 38 4 4 39 41 41 91 91 100 24 246 246 245 245 - 152 84 16 17 18 19 19 20 21 62 62 62 62 246 245 245 - 203 203 203 203 202 17 20 148 148 49 54 54 59 59 59 59 - 60 60 60 60 166 70 70 237 237 71 238 238 238 239 239 239 - 166 166 135 136 25 246 239 51 97 61 61 49 82 84 97 48 - 1 63 157 101 25 92 155 41 39 38 38 5 37 36 34 33 - 23 23 62 62 246 246 246 246 245 245 245 245 63 63 63 63 - 41 3 3 3 42 43 156 25 26 26 101 157 157 157 103 63 - 19 99 21 23 16 19 19 62 97 97 61 87 62 62 246 171 - 168 168 168 169 169 239 239 239 239 171 171 171 63 63 63 63 - 99 90 22 22 23 23 24 246 246 246 246 246 245 63 63 63 - 62 62 246 246 246 245 139 63 89 84 133 151 36 36 37 5 - 38 4 39 3 3 43 2 2 2 2 31 94 103 158 140 172 - 89 90 90 90 91 23 24 246 246 246 246 245 245 172 172 172 - 153 40 40 154 154 41 41 22 91 23 24 26 246 245 63 63 - 87 168 168 169 169 169 170 170 170 246 171 245 245 172 172 140 - 4 185 185 185 185 244 244 244 3 43 93 44 29 94 103 103 - 5 153 40 154 41 21 22 22 23 24 246 246 245 245 63 63 - 20 203 203 203 203 203 155 149 149 150 150 55 55 55 60 60 - 60 60 60 97 61 237 237 72 238 238 238 239 239 171 172 171 - 168 166 136 136 138 246 171 83 98 87 23 150 132 85 98 48 - 246 26 100 91 41 154 40 153 153 37 36 6 33 7 7 148 - 154 20 99 99 90 22 22 23 91 92 92 24 24 26 26 26 - 39 39 39 39 40 40 41 41 99 90 22 91 23 23 24 24 - 153 85 85 86 151 16 16 17 55 60 97 97 61 20 23 62 - 85 166 166 167 167 168 168 168 169 23 23 23 24 26 26 26 - 153 85 85 86 86 88 88 99 99 22 91 91 92 24 26 246 - 19 20 99 22 91 24 26 246 84 132 131 254 148 33 34 6 - 35 5 5 4 4 4 4 244 244 3 43 43 43 43 101 246 - 153 85 85 86 86 86 88 99 22 91 91 100 24 26 246 246 - 151 152 152 153 153 153 153 40 40 86 88 90 91 91 24 137 - 135 135 135 135 88 87 90 90 22 23 23 23 26 246 246 101 - 36 35 37 5 5 38 38 4 4 39 3 3 42 92 26 101 - 36 152 152 153 153 153 40 86 20 99 90 22 23 24 26 246 - 202 202 202 202 201 201 40 147 147 148 49 54 54 59 54 59 - 59 59 60 60 60 60 165 70 237 237 237 168 168 169 170 169 - 166 165 135 135 136 92 62 50 83 16 19 254 150 82 97 48 - 88 86 85 153 152 152 151 150 149 148 148 148 146 146 146 145 - 152 83 83 83 84 84 84 85 85 134 85 85 40 86 86 86 - 151 151 151 151 151 152 152 83 84 84 84 84 85 85 85 86 - 150 50 50 83 48 50 50 51 49 54 54 51 51 83 16 85 - 131 132 132 164 83 84 84 84 97 17 85 85 85 86 40 86 - 151 82 82 82 82 83 83 83 133 84 84 85 85 85 86 86 - 83 83 84 153 153 85 85 86 50 254 254 147 146 8 8 7 - 7 33 34 6 5 5 5 5 38 38 38 39 40 40 154 99 - 150 50 82 82 82 83 83 152 84 84 85 85 85 86 86 20 - 148 149 149 150 150 50 50 151 82 83 152 84 153 153 86 86 - 131 131 132 132 132 133 84 84 84 84 85 85 86 86 88 41 - 7 32 33 33 34 35 35 35 37 37 37 38 153 85 86 19 - 148 149 149 150 150 151 151 151 83 83 84 84 85 86 86 20 - 197 198 200 200 200 200 151 144 144 253 48 53 53 53 53 53 - 58 58 58 54 249 250 250 250 250 164 165 165 165 85 135 135 - 163 162 131 132 133 134 86 48 49 50 82 253 48 254 80 48 - 172 245 246 246 92 91 22 154 40 153 153 152 151 151 150 149 - 90 23 62 62 62 170 246 246 246 246 171 171 171 63 63 63 - 41 41 91 91 91 91 91 100 24 246 246 246 246 245 139 245 - 86 20 21 21 16 17 61 61 96 96 61 61 168 62 170 171 - 167 167 168 169 169 238 239 239 239 239 171 171 171 171 63 63 - 88 99 21 22 22 23 23 24 24 246 246 246 246 245 245 171 - 169 169 169 170 246 171 171 171 86 84 133 131 36 36 37 5 - 38 4 39 3 3 43 43 2 2 2 29 94 139 172 172 172 - 88 87 90 90 90 169 169 169 170 170 246 171 171 171 172 172 - 153 153 85 86 86 20 99 99 22 22 100 26 246 246 245 171 - 167 168 168 168 169 169 169 62 170 170 171 171 171 171 172 172 - 5 5 4 4 4 244 244 244 3 43 25 138 246 245 63 63 - 153 153 18 18 20 20 21 21 23 23 246 246 246 245 63 63 - 203 203 203 203 203 20 21 148 149 149 50 55 55 55 55 60 - 60 60 60 237 70 70 237 71 71 72 238 238 239 171 171 239 - 168 166 136 136 138 138 171 83 97 167 169 150 152 85 98 48 - 77 76 76 239 170 169 169 168 88 86 84 84 83 82 131 80 - 169 238 239 239 239 239 75 239 75 75 76 76 76 76 76 76 - 169 169 169 169 169 169 169 170 239 239 239 239 75 76 76 76 - 167 168 238 238 97 166 237 73 165 60 166 72 73 238 75 75 - 71 71 71 72 73 73 73 74 74 75 75 75 75 76 76 76 - 168 168 238 238 238 238 239 239 239 239 239 75 75 76 76 76 - 238 238 238 239 75 75 76 76 167 166 165 82 132 132 133 38 - 40 40 41 92 25 138 138 246 246 245 171 172 77 77 77 77 - 168 168 168 238 238 238 238 238 239 239 75 75 76 76 76 77 - 17 17 98 61 61 168 168 168 169 62 239 239 239 75 76 76 - 168 237 71 72 73 73 74 74 75 75 75 75 76 76 76 76 - 135 135 135 136 136 136 137 137 169 170 170 171 171 171 76 76 - 97 17 98 61 61 168 62 62 62 62 239 239 76 76 76 77 - 21 203 204 204 61 61 21 49 80 80 54 55 60 60 60 60 - 250 69 68 70 70 70 70 71 71 72 73 74 74 75 75 75 - 237 167 168 137 171 171 75 165 166 237 238 81 83 166 167 160 - 71 237 237 166 166 165 164 164 163 162 162 161 104 160 160 160 - 165 165 165 166 166 166 166 166 237 237 237 237 237 237 237 237 - 164 164 164 164 165 165 165 69 236 70 70 70 70 237 237 237 - 250 250 68 68 162 250 250 67 249 65 66 67 69 236 70 70 - 235 235 234 234 234 69 69 236 70 70 70 70 70 237 237 237 - 164 250 164 68 165 165 165 69 166 166 70 70 70 237 237 71 - 69 69 69 70 70 70 237 237 250 162 161 160 160 104 255 255 - 131 132 132 133 165 166 166 166 167 167 167 168 168 237 237 71 - 250 250 164 164 164 165 69 165 166 166 70 237 237 237 71 71 - 162 250 250 250 250 250 250 250 164 165 166 166 166 237 237 70 - 66 67 235 68 68 69 69 236 236 70 70 70 237 71 71 71 - 162 162 163 163 163 164 164 164 165 165 166 166 166 237 237 237 - 162 249 250 250 250 250 250 250 165 166 70 237 237 237 237 72 - 55 16 55 60 55 60 250 248 160 53 53 53 58 58 58 58 - 229 230 230 233 233 233 234 235 234 234 69 69 236 70 70 71 - 235 66 164 165 167 168 237 64 65 66 69 160 104 162 250 160 - 169 169 168 167 166 166 165 83 83 82 80 80 80 49 48 48 - 97 166 166 166 167 167 167 167 168 168 168 168 168 169 169 168 - 84 84 84 97 97 166 166 166 61 61 167 167 168 168 168 168 - 96 96 165 97 81 96 96 165 250 250 250 165 166 237 167 237 - 68 69 69 69 236 70 70 237 237 237 237 168 238 238 238 238 - 97 97 97 97 166 166 166 166 167 167 167 168 168 168 169 238 - 166 166 167 167 167 168 168 238 164 163 80 254 48 254 130 131 - 131 132 133 134 135 135 88 136 89 136 90 90 169 169 169 238 - 96 165 165 165 166 166 166 166 167 167 168 168 168 169 169 169 - 81 81 82 164 164 164 165 165 165 166 166 167 167 168 168 168 - 165 68 69 69 236 70 70 237 237 237 168 168 168 169 169 169 - 131 132 132 132 133 133 133 134 85 86 86 167 168 168 169 238 - 81 81 51 96 96 96 97 97 97 61 61 61 168 168 168 62 - 201 202 201 16 60 96 97 253 48 53 53 53 58 58 58 58 - 59 249 250 250 67 68 68 69 69 69 70 70 237 237 238 71 - 165 164 133 135 88 168 238 80 250 250 166 160 80 163 164 160 - 60 60 60 55 54 54 54 54 53 53 53 53 53 52 105 52 - 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 - 54 49 54 54 54 54 54 55 55 55 55 55 55 55 55 60 - 58 59 59 59 53 58 58 59 57 57 58 58 59 59 59 60 - 58 58 59 59 59 59 59 59 59 59 60 60 60 60 60 60 - 54 59 54 54 59 59 59 59 59 59 55 60 60 60 60 60 - 59 59 59 59 55 60 60 60 53 53 53 52 52 52 48 48 - 48 48 49 49 50 50 51 51 51 55 55 96 60 60 60 60 - 53 59 59 59 59 59 59 59 59 59 55 60 60 60 60 60 - 53 53 53 53 53 53 54 54 54 54 55 55 55 60 60 60 - 58 59 59 59 59 59 59 59 59 55 55 60 60 60 60 60 - 48 48 48 49 49 49 49 54 54 55 55 55 55 55 60 60 - 53 53 53 53 54 54 54 54 59 59 59 55 60 60 60 60 - 214 213 213 214 58 58 54 52 52 52 52 56 56 56 57 57 - 57 57 57 58 58 58 58 59 59 59 59 59 59 60 60 60 - 249 249 162 162 55 55 60 53 58 58 54 52 52 53 53 53 - 55 55 54 54 49 49 48 48 48 48 253 253 105 106 106 106 - 54 54 54 54 54 54 54 54 55 55 55 55 55 55 55 55 - 48 48 48 49 49 49 49 49 54 54 54 54 54 55 55 55 - 53 53 53 53 52 53 53 58 52 57 53 53 58 54 54 55 - 53 58 58 58 58 59 59 59 54 54 55 55 55 55 55 55 - 53 53 54 54 54 54 54 54 54 54 54 54 55 55 55 55 - 54 54 54 54 54 54 55 55 53 52 52 105 144 144 253 145 - 146 146 48 148 49 149 49 150 150 150 50 51 55 55 55 55 - 53 53 53 54 54 54 54 54 54 54 54 55 55 55 55 55 - 48 53 53 53 53 53 53 53 54 54 54 54 54 54 55 55 - 53 53 53 53 54 54 54 54 54 54 54 55 55 55 55 51 - 146 146 146 48 48 48 48 49 49 49 80 54 54 55 55 55 - 52 53 53 53 53 53 53 54 54 54 54 54 54 55 55 55 - 212 212 214 214 53 53 53 106 106 52 52 52 56 56 56 56 - 56 56 57 57 57 58 58 58 58 58 59 59 59 59 55 55 - 249 160 255 130 80 51 55 52 53 53 53 247 52 52 53 160 - 91 91 99 40 153 153 152 152 151 151 149 149 148 148 8 146 - 84 84 85 85 18 18 86 86 99 99 41 41 41 22 91 22 - 152 152 152 153 153 153 153 153 40 40 40 154 41 41 41 22 - 151 152 152 84 50 51 83 97 54 54 51 83 16 17 18 87 - 84 165 165 165 97 98 98 98 19 19 20 99 21 22 22 22 - 152 152 152 153 153 153 85 153 153 40 154 41 41 41 91 22 - 153 85 85 18 86 99 21 22 151 150 149 148 147 148 7 7 - 33 6 5 5 5 4 4 4 4 39 154 41 155 155 42 100 - 152 83 133 84 84 85 85 85 86 40 41 41 41 91 42 23 - 150 151 151 151 151 152 152 152 153 153 40 40 40 41 41 22 - 132 83 84 84 84 84 17 18 18 19 20 99 99 22 91 42 - 34 34 34 34 35 5 5 5 38 38 39 39 41 41 41 91 - 150 150 151 151 152 152 153 153 153 18 18 19 20 99 22 23 - 200 201 201 201 201 152 152 9 146 146 48 48 53 53 54 54 - 59 59 59 59 250 250 250 165 165 166 166 166 167 88 90 90 - 133 132 133 38 4 41 22 254 50 83 84 147 149 150 81 128 - 158 95 2 2 43 3 3 4 4 4 5 5 35 6 33 7 - 92 24 26 26 26 101 44 44 2 31 31 94 45 95 95 95 - 244 244 3 3 3 3 43 43 43 2 2 2 2 2 94 45 - 39 41 155 22 153 85 99 21 84 16 18 21 23 26 246 245 - 136 136 169 169 169 170 170 171 246 246 245 139 139 103 103 103 - 41 3 3 3 3 3 43 43 43 44 2 2 31 31 95 102 - 24 24 26 27 28 30 139 103 39 38 37 36 34 35 35 5 - 5 4 185 186 187 187 187 187 188 188 94 45 95 95 158 158 - 39 41 41 42 42 92 25 25 93 28 29 94 45 95 158 158 - 38 38 39 39 39 41 41 3 3 3 43 2 2 31 45 103 - 41 89 90 91 23 24 246 246 246 101 157 94 45 95 95 126 - 184 184 184 185 185 185 186 186 187 187 187 2 2 31 95 158 - 38 153 40 154 154 155 155 155 156 156 101 30 157 157 45 158 - 204 203 203 203 202 155 155 7 7 199 198 200 55 55 96 96 - 60 60 61 61 61 61 168 168 169 169 170 170 170 139 139 139 - 136 135 136 244 188 31 139 132 85 89 42 6 5 38 135 128 - 3 244 4 4 38 5 35 35 34 33 32 7 8 8 8 8 - 38 38 38 38 4 4 4 4 4 4 4 39 3 3 3 3 - 35 35 37 37 5 5 5 38 38 38 4 4 4 39 39 41 - 6 36 37 153 150 150 83 83 49 50 50 152 153 153 40 136 - 132 133 133 133 134 135 135 135 88 40 40 41 41 41 41 3 - 37 37 5 5 5 5 5 38 4 4 4 4 39 39 3 41 - 38 153 40 40 39 39 41 41 36 7 7 8 8 8 32 32 - 33 34 34 183 184 184 184 184 185 185 4 39 3 3 3 3 - 35 37 37 37 5 5 38 38 38 4 39 39 41 3 3 3 - 33 33 6 6 36 37 5 5 5 5 38 4 4 4 39 41 - 132 132 132 133 84 153 153 40 40 40 39 41 41 41 3 244 - 33 33 33 34 34 35 35 5 5 5 38 4 4 4 3 3 - 7 6 6 36 36 36 37 5 5 38 4 39 39 39 3 155 - 200 201 200 200 200 152 36 9 9 146 146 147 48 48 49 49 - 54 54 54 51 51 82 83 165 165 165 85 135 135 41 41 136 - 132 131 132 35 4 3 41 148 150 151 153 8 7 33 131 128 - 3 39 4 38 5 5 35 35 34 33 32 7 8 8 8 9 - 5 38 38 38 38 4 4 4 4 4 4 39 39 39 41 244 - 35 35 35 5 5 5 5 5 5 4 4 4 4 4 4 39 - 6 36 37 38 149 150 151 83 49 50 151 152 152 153 39 135 - 132 164 133 133 134 134 135 40 40 40 39 39 39 39 244 244 - 35 35 37 5 5 5 38 38 38 38 4 4 4 4 39 39 - 37 38 38 4 4 39 39 41 36 33 7 8 8 8 32 32 - 33 34 34 183 184 184 184 185 185 185 4 4 39 244 244 244 - 35 35 35 37 5 5 5 38 38 4 4 4 4 39 3 3 - 33 33 34 6 6 35 35 37 5 5 5 38 4 4 4 41 - 36 133 133 133 133 38 38 38 39 39 39 39 39 3 3 244 - 182 182 182 182 182 34 35 35 5 5 5 38 4 4 4 244 - 33 33 33 6 6 36 37 37 5 38 4 4 39 39 3 155 - 198 200 201 200 201 200 37 9 9 9 146 146 147 48 49 49 - 49 49 80 50 82 82 132 133 133 165 134 135 135 40 41 136 - 133 131 132 37 4 4 41 254 150 152 37 8 7 33 131 128 - 141 1 102 157 2 93 43 3 3 39 4 38 5 5 35 6 - 26 246 246 245 245 245 63 63 63 172 172 158 140 140 1 47 - 3 3 43 43 43 93 44 30 30 157 103 103 103 158 1 1 - 22 23 23 246 17 21 21 62 17 61 21 169 62 245 63 172 - 169 238 238 239 239 239 75 76 76 77 172 172 173 173 173 173 - 91 100 24 26 26 246 246 245 245 245 63 63 172 140 140 173 - 246 246 245 245 103 172 140 173 90 135 133 37 36 37 5 4 - 4 39 244 43 2 188 188 188 189 189 95 158 1 47 141 141 - 91 91 24 246 246 246 246 246 139 139 139 172 140 1 159 141 - 40 154 41 41 155 155 100 24 25 26 101 157 103 172 1 173 - 91 169 169 170 170 170 171 171 171 172 172 172 140 47 159 159 - 185 185 186 186 186 244 187 187 2 2 2 45 103 158 1 159 - 4 154 41 41 155 100 24 24 246 245 63 63 63 173 173 173 - 204 204 204 204 204 204 156 150 150 150 151 55 60 60 60 60 - 60 61 61 61 168 238 238 238 238 239 239 75 76 77 77 77 - 169 167 137 137 45 158 173 153 19 62 62 151 133 135 168 128 - 63 245 246 26 24 91 41 154 40 153 153 152 151 150 199 149 - 21 23 62 62 62 62 62 62 246 246 246 245 245 245 245 245 - 41 41 41 155 155 91 23 100 24 26 246 246 246 245 245 245 - 18 20 20 21 16 17 61 61 60 60 17 19 20 62 246 171 - 167 168 168 238 238 238 239 62 239 239 246 246 245 245 245 63 - 20 99 90 21 22 23 23 62 62 62 246 246 246 245 245 63 - 22 62 62 62 246 246 245 171 86 84 132 131 150 36 37 5 - 38 4 39 3 3 3 43 43 44 44 44 30 157 139 63 63 - 86 88 99 21 22 23 23 62 62 62 246 246 245 245 63 63 - 153 153 153 40 40 88 99 99 90 22 23 24 246 246 245 63 - 167 168 168 168 168 169 62 62 62 246 246 245 245 245 63 172 - 5 5 38 4 4 39 41 3 3 42 25 26 101 157 245 245 - 152 153 40 154 20 20 20 21 21 62 62 62 246 245 245 207 - 203 203 203 203 203 203 20 148 148 150 54 54 55 59 59 60 - 60 60 60 60 61 61 237 237 72 238 238 238 239 239 171 171 - 167 166 136 136 27 246 63 152 16 61 62 150 82 84 98 48 - 21 20 18 85 153 153 152 152 151 150 149 148 147 147 146 145 - 16 16 16 16 16 16 17 17 18 18 18 19 19 20 20 20 - 151 152 152 152 152 152 153 84 85 85 85 18 18 18 20 20 - 50 51 83 83 49 54 55 96 54 54 54 55 96 16 17 98 - 96 96 96 96 96 97 97 97 97 98 98 19 19 20 20 20 - 151 83 83 83 83 16 16 16 16 16 17 18 19 19 20 20 - 83 16 16 17 18 18 19 20 50 49 254 147 146 147 148 7 - 7 6 36 37 5 5 38 4 4 39 40 154 41 41 99 21 - 151 152 152 83 83 16 16 16 16 17 18 18 19 20 99 21 - 149 149 150 150 151 151 82 152 83 84 16 17 17 18 19 20 - 51 51 96 96 97 97 97 97 17 98 98 19 20 20 21 22 - 33 33 34 6 35 36 37 37 37 153 153 40 40 86 20 99 - 149 150 150 50 50 51 83 83 16 16 16 17 18 19 20 20 - 200 200 201 200 200 200 152 145 146 145 48 53 53 53 58 58 - 58 58 54 54 55 250 250 250 96 96 165 166 166 98 88 88 - 164 163 132 133 38 40 20 48 50 51 97 146 254 49 81 48 - 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 - 10 10 10 10 10 10 10 10 10 10 10 9 9 9 9 9 - 11 11 11 11 11 11 10 10 10 10 10 10 9 10 9 9 - 11 11 11 11 107 107 252 106 252 252 252 252 106 10 10 9 - 106 106 106 106 106 106 106 144 144 9 9 9 9 9 9 9 - 11 11 11 11 10 10 10 10 10 10 10 10 9 9 9 9 - 106 10 10 10 10 10 9 9 107 107 13 13 14 13 13 108 - 12 109 109 110 110 110 10 10 10 9 10 9 9 9 9 9 - 11 11 11 11 11 10 10 10 10 10 10 9 9 9 9 9 - 12 12 12 11 11 11 11 11 11 10 10 10 10 10 9 9 - 252 252 106 106 106 10 10 10 10 10 9 9 9 9 9 9 - 109 109 109 109 11 11 11 11 11 10 10 10 10 10 9 9 - 12 12 12 11 11 11 11 11 10 10 10 10 9 9 9 9 - 11 192 192 11 11 11 11 15 14 14 251 251 251 251 251 107 - 107 252 252 252 252 106 106 106 106 106 106 106 144 9 9 9 - 106 106 11 9 10 10 9 251 107 252 106 13 13 12 252 128 - 35 6 33 7 7 7 8 8 9 9 9 10 10 10 11 11 - 7 148 7 7 7 33 33 33 6 33 33 34 34 6 6 6 - 8 8 8 8 7 7 7 7 7 33 32 33 33 33 6 6 - 8 147 147 148 145 146 146 147 253 146 146 147 148 148 33 36 - 128 48 254 254 254 254 254 150 150 6 6 6 6 6 6 35 - 8 8 8 8 7 7 7 7 32 32 33 33 33 34 34 6 - 148 149 7 33 33 34 6 36 253 253 9 10 10 10 10 9 - 9 9 8 8 32 32 32 32 33 33 33 34 34 34 35 35 - 8 8 8 7 7 7 7 7 33 33 33 34 34 6 35 35 - 9 9 9 8 8 8 8 8 8 7 7 32 32 33 6 6 - 147 48 48 148 148 149 149 149 33 6 6 6 6 6 35 35 - 9 9 9 8 8 8 8 8 7 7 32 33 33 33 6 6 - 9 9 9 8 8 147 148 148 148 149 199 7 6 6 6 37 - 195 196 195 195 195 147 8 11 11 11 10 144 144 144 144 145 - 253 253 253 48 48 48 48 254 254 254 130 130 130 34 36 36 - 128 128 8 32 33 6 36 144 253 147 148 10 10 9 128 128 - 94 2 43 3 3 3 4 4 5 5 35 6 6 33 7 7 - 155 155 155 155 42 43 43 43 43 93 2 2 2 2 2 2 - 4 4 39 39 3 3 3 3 3 3 43 3 43 2 2 44 - 153 154 154 21 152 153 18 20 82 84 16 18 99 91 92 246 - 86 167 87 90 90 90 137 170 26 26 27 138 28 28 29 94 - 39 39 41 41 41 155 3 3 3 3 43 43 93 44 2 30 - 90 21 156 43 43 43 2 157 153 133 36 33 33 33 34 35 - 5 5 4 185 185 186 122 122 187 187 187 2 2 2 2 45 - 39 39 39 41 41 41 3 3 3 43 43 93 2 2 94 94 - 5 5 5 38 4 4 39 39 41 3 3 3 43 93 2 29 - 40 86 88 89 90 90 91 91 24 26 27 28 29 29 94 188 - 183 183 184 184 184 185 185 186 244 244 244 244 43 43 2 31 - 37 5 153 153 40 154 154 154 155 155 156 156 43 44 2 157 - 202 203 202 202 153 154 39 8 8 199 199 214 150 55 55 55 - 55 60 60 97 97 98 167 167 168 168 169 169 170 138 138 138 - 135 133 135 185 3 2 28 36 133 40 22 7 6 5 134 128 - 143 143 143 175 191 191 141 141 141 47 47 46 46 158 95 95 - 142 142 142 142 175 175 175 175 175 175 143 143 143 143 143 143 - 141 141 141 142 141 142 142 142 142 175 175 175 175 143 143 143 - 141 174 174 142 46 141 141 174 173 173 173 79 174 142 175 143 - 141 174 174 174 174 174 142 142 175 175 175 143 175 143 143 143 - 141 141 174 142 142 142 142 142 142 175 175 175 143 143 143 143 - 174 174 142 175 191 175 143 143 141 47 1 158 95 158 46 127 - 127 127 127 191 191 191 191 191 191 191 175 175 143 143 143 143 - 141 174 174 174 174 142 142 142 175 175 143 143 143 143 143 143 - 47 159 159 159 141 141 141 141 142 142 142 175 175 175 143 143 - 141 174 174 174 174 142 142 142 175 175 175 175 143 143 143 143 - 190 190 190 190 190 190 190 191 191 191 191 175 175 143 143 143 - 1 159 159 141 141 141 141 142 142 142 142 175 143 143 143 143 - 159 142 159 159 159 141 141 45 95 95 102 158 173 173 172 173 - 173 173 173 78 79 79 79 79 174 174 174 142 175 175 143 175 - 174 141 174 190 191 143 142 47 159 141 174 103 127 1 78 128 - 143 175 191 191 159 47 1 46 95 95 94 2 2 2 43 43 - 141 141 141 141 141 141 174 174 142 142 142 142 175 175 143 143 - 46 1 47 47 47 47 159 141 141 141 142 142 142 142 175 175 - 158 1 1 141 157 46 140 173 245 63 63 173 173 141 174 142 - 173 173 173 78 79 79 79 79 174 174 142 175 175 175 175 175 - 1 1 1 47 47 141 141 141 141 141 141 142 142 175 175 143 - 141 141 141 141 142 191 175 143 158 45 29 28 43 2 2 188 - 189 189 126 127 127 127 127 127 191 191 191 191 175 143 143 143 - 1 140 140 47 141 141 141 141 141 142 142 142 175 175 143 143 - 45 102 102 158 158 46 1 1 47 159 159 141 142 142 175 175 - 140 140 140 173 173 79 79 174 174 174 142 175 143 175 143 143 - 45 189 189 189 189 47 47 46 47 159 141 142 142 142 175 143 - 45 102 102 158 158 46 1 47 159 159 159 142 142 142 143 143 - 158 1 207 207 207 159 1 43 43 156 101 205 205 206 245 245 - 245 171 76 77 77 77 77 78 78 78 79 79 174 174 142 142 - 173 172 141 189 191 191 142 245 63 173 140 93 2 102 171 128 - 143 191 47 46 95 45 2 43 3 3 39 4 4 5 5 36 - 139 172 172 140 140 140 140 141 47 141 141 141 141 142 191 191 - 2 2 2 31 94 45 95 158 158 1 47 159 159 141 141 174 - 24 246 246 63 20 23 62 75 19 21 62 62 245 63 173 79 - 239 239 75 75 76 77 77 77 78 78 78 79 79 174 142 142 - 246 246 245 245 139 139 172 140 140 1 47 141 141 141 142 142 - 172 172 140 140 173 141 174 174 25 41 39 38 5 5 4 4 - 186 186 187 124 125 125 126 126 126 127 127 127 191 191 143 143 - 27 246 246 171 139 139 172 140 140 47 141 141 142 142 143 143 - 3 155 42 156 43 93 44 30 31 45 158 1 47 159 141 174 - 138 170 171 171 171 172 77 77 173 78 79 174 174 142 175 175 - 186 186 186 187 187 187 188 188 188 189 46 46 47 141 174 143 - 41 155 155 43 43 44 30 157 102 1 1 159 159 159 142 143 - 206 205 205 205 205 205 101 36 36 151 152 16 16 60 61 61 - 61 61 61 73 74 74 75 75 75 75 76 78 78 79 174 79 - 171 136 138 2 127 142 78 86 90 169 171 37 4 155 169 160 - 143 191 47 95 2 2 3 244 4 5 37 6 33 7 8 8 - 26 246 245 245 63 63 172 140 140 1 47 141 141 141 141 142 - 3 3 3 43 43 43 2 31 94 95 158 158 46 47 141 141 - 40 22 23 62 83 17 20 62 55 60 61 61 62 245 172 78 - 168 238 238 238 74 75 76 76 77 77 78 78 79 79 174 142 - 41 91 23 100 26 246 246 245 245 139 140 140 1 141 141 79 - 246 245 245 172 140 140 141 79 135 133 36 33 7 32 33 35 - 183 185 186 122 123 124 124 125 125 126 126 126 127 191 191 175 - 41 136 91 137 246 246 246 139 139 140 140 47 141 142 142 143 - 5 153 153 40 154 41 155 155 43 43 2 45 158 1 159 174 - 136 168 169 169 170 239 171 76 77 77 173 78 79 142 175 191 - 183 183 184 185 185 186 186 187 187 188 188 189 126 127 141 142 - 152 153 153 154 41 155 156 156 101 101 207 207 159 159 159 142 - 202 204 204 203 203 203 204 146 146 147 147 214 54 59 59 59 - 59 60 60 236 70 71 71 72 73 74 75 76 77 78 78 79 - 169 134 137 244 158 159 78 131 165 167 245 148 6 153 166 160 - 143 141 158 2 3 3 4 5 35 33 7 8 9 9 10 11 - 21 23 23 24 246 245 245 63 172 172 46 1 159 141 141 141 - 38 4 4 4 39 3 3 43 44 2 94 45 95 46 47 47 - 37 85 18 20 49 51 16 61 58 59 60 97 61 62 63 77 - 166 70 237 71 72 73 74 75 76 76 77 78 78 79 79 174 - 153 86 86 88 22 22 23 26 246 246 157 103 140 140 141 79 - 90 62 246 245 139 140 141 79 132 131 128 8 10 9 8 32 - 181 182 116 118 119 119 119 123 124 125 126 126 127 191 191 142 - 134 135 135 88 136 169 169 137 170 139 172 140 141 141 142 143 - 149 150 151 152 152 153 153 40 154 155 43 44 31 158 47 79 - 84 166 167 168 168 238 238 239 75 76 77 173 79 174 142 191 - 181 181 182 183 183 184 185 185 186 187 187 188 189 126 159 142 - 148 150 151 152 153 202 202 203 204 205 206 206 207 159 159 159 - 211 210 213 201 201 202 202 11 11 144 144 52 57 57 57 58 - 58 58 229 230 234 234 69 70 70 71 72 74 75 77 78 78 - 166 131 183 185 187 126 173 48 163 165 87 10 147 49 83 160 - 143 47 45 43 3 4 5 6 7 8 9 9 11 12 12 13 - 18 20 21 21 23 62 246 245 245 63 172 140 1 141 141 141 - 35 35 5 5 38 4 39 3 3 43 44 2 94 95 46 173 - 254 82 16 61 53 54 55 60 57 58 59 55 61 61 62 76 - 250 68 69 236 70 71 71 73 75 75 76 77 77 78 78 79 - 151 83 84 84 86 86 89 22 23 24 246 245 103 140 141 79 - 98 61 62 246 245 63 173 78 255 128 106 11 12 110 110 112 - 113 114 115 116 117 118 119 119 123 124 125 125 126 127 191 142 - 131 163 164 165 166 167 168 136 137 170 139 172 140 159 142 143 - 146 147 148 149 150 150 151 153 153 39 41 43 44 102 1 78 - 163 250 68 69 70 237 71 238 238 239 76 172 173 141 142 191 - 179 179 180 181 182 182 183 184 184 186 186 187 188 189 47 142 - 145 196 196 197 200 201 201 202 203 204 205 205 206 207 159 159 - 209 209 210 212 213 200 152 14 13 251 218 219 221 222 225 225 - 226 226 227 228 229 230 233 234 236 236 70 71 73 75 77 76 - 162 161 241 184 186 189 77 105 104 163 165 251 144 48 80 48 - 143 47 2 3 4 5 6 7 8 9 10 11 13 14 15 215 - 84 17 17 19 20 21 23 246 246 246 245 103 140 173 141 141 - 33 33 34 35 35 5 38 39 39 3 43 93 2 94 95 140 - 147 49 50 55 247 53 54 60 56 56 58 59 60 61 62 75 - 249 65 233 234 236 70 71 72 73 74 75 75 76 77 78 78 - 254 50 50 82 84 84 85 88 99 22 24 246 245 172 173 78 - 97 166 61 23 246 245 173 78 160 105 252 251 14 108 109 110 - 111 113 114 115 116 117 118 118 119 119 124 125 126 127 191 175 - 130 130 131 132 133 134 135 135 136 137 246 139 140 47 174 143 - 144 144 145 146 147 148 199 150 151 153 40 41 43 30 158 173 - 161 162 163 164 165 166 237 237 238 239 239 76 173 79 174 191 - 176 177 178 178 179 180 182 183 183 184 185 186 187 188 46 142 - 144 144 194 195 196 197 200 201 202 203 204 205 206 207 159 159 - 209 208 210 211 212 213 198 215 216 216 218 218 220 220 220 222 - 224 224 226 226 228 229 229 230 234 234 236 70 71 75 76 76 - 65 161 241 184 185 188 77 252 248 64 165 216 252 253 48 104 - 143 47 2 3 5 6 7 8 10 11 12 13 14 15 15 215 - 51 96 16 16 17 19 21 23 24 26 246 245 172 140 173 47 - 8 32 32 33 34 35 5 5 4 4 244 3 43 2 95 172 - 253 48 49 54 247 52 53 59 219 225 56 58 59 60 62 75 - 162 64 65 233 234 69 70 237 73 73 74 75 75 76 78 78 - 147 254 49 80 50 83 83 85 86 88 91 24 246 63 173 78 - 96 60 61 61 62 245 172 77 105 252 251 215 15 15 108 108 - 110 111 113 114 115 116 116 117 118 119 123 125 126 127 191 175 - 128 255 255 255 131 132 133 134 88 168 170 246 172 140 141 143 - 11 11 144 144 145 146 147 148 149 151 153 40 155 43 102 173 - 160 104 64 162 163 164 166 237 237 238 239 76 77 79 174 191 - 177 176 176 176 177 179 180 181 182 183 184 185 187 188 46 142 - 11 192 144 144 195 196 197 198 201 202 203 204 205 207 159 159 - 209 208 209 210 211 212 197 215 215 216 217 218 219 220 220 220 - 222 224 224 226 226 228 228 229 230 233 234 236 71 73 76 76 - 65 161 241 184 184 188 77 252 247 53 163 215 14 252 105 160 - 143 46 43 4 35 7 8 10 11 12 14 15 15 15 15 215 - 49 55 55 96 97 17 19 21 22 24 26 246 63 172 140 173 - 9 9 8 8 32 33 34 35 5 38 4 244 3 2 94 103 - 106 48 48 54 217 52 52 58 219 222 225 56 58 60 61 74 - 248 64 232 232 233 234 234 70 71 72 73 74 75 76 77 78 - 253 48 48 48 49 50 82 83 84 85 89 91 26 245 172 77 - 54 60 60 61 62 62 171 77 106 252 216 215 215 15 15 14 - 108 110 111 113 115 115 116 116 117 118 119 123 125 126 191 142 - 106 105 160 160 255 162 132 132 134 167 136 170 139 140 141 175 - 251 107 252 11 144 144 145 147 148 150 152 153 154 43 31 77 - 105 248 64 64 64 250 164 69 70 237 238 239 172 173 174 191 - 109 176 176 176 176 177 178 180 181 182 183 185 186 187 95 141 - 13 252 11 11 144 194 195 214 198 201 202 203 205 206 207 159 - 209 208 209 210 211 212 195 215 215 216 216 218 219 220 220 220 - 220 222 224 224 226 226 227 228 229 230 234 234 70 71 75 75 - 65 161 241 184 184 188 63 216 252 248 104 215 215 251 106 160 - 143 95 3 38 33 7 9 11 12 14 15 15 15 15 15 215 - 49 54 54 55 55 16 17 19 20 23 23 246 245 63 140 173 - 10 10 9 8 8 8 32 34 35 5 4 4 244 43 2 245 - 252 105 253 53 217 52 52 58 219 220 223 56 58 59 61 73 - 248 228 228 229 230 233 234 236 70 71 72 73 74 75 77 78 - 144 253 146 48 48 49 150 50 83 84 86 99 100 246 172 77 - 54 54 60 97 61 62 171 77 252 251 215 215 215 15 15 15 - 14 108 110 113 115 115 115 116 116 117 119 123 125 126 127 174 - 106 247 105 160 160 255 162 162 133 135 136 137 171 140 141 175 - 215 251 251 107 252 10 144 145 146 148 150 152 40 155 2 172 - 247 248 248 160 65 64 66 68 69 237 238 239 171 173 174 143 - 14 108 110 176 176 176 177 178 180 181 182 184 186 187 95 141 - 216 216 251 252 144 144 194 195 197 200 201 203 204 206 207 207 - 208 208 208 209 211 194 144 215 15 215 216 217 219 220 220 220 - 220 221 224 224 224 226 226 227 228 229 230 234 236 71 75 75 - 65 160 241 184 183 187 207 216 247 247 53 215 215 14 252 160 - 143 95 3 5 7 8 10 12 13 15 15 15 15 15 15 215 - 48 54 54 54 55 96 16 17 19 20 23 62 246 245 172 46 - 11 11 10 9 9 8 7 7 33 5 5 4 4 3 43 245 - 252 247 247 53 217 218 52 57 218 219 221 224 57 59 61 73 - 56 227 227 228 229 230 233 234 236 70 71 73 73 75 77 77 - 106 105 105 253 48 48 48 150 50 152 84 86 91 26 139 77 - 53 59 250 163 17 23 246 77 252 216 215 215 215 15 15 15 - 15 14 109 111 113 115 115 115 116 117 118 119 124 126 190 174 - 252 247 247 247 160 160 161 161 163 165 135 136 138 172 141 175 - 215 215 14 251 107 252 252 144 145 195 199 151 153 155 2 172 - 252 247 248 248 64 64 65 66 68 70 237 239 171 173 79 175 - 15 14 14 108 176 176 176 177 178 180 182 183 184 186 94 79 - 216 216 216 251 252 192 192 194 196 197 201 202 203 156 207 207 - 208 208 209 210 218 144 10 15 15 215 216 217 219 220 220 220 - 219 220 221 224 224 224 226 226 240 240 240 233 234 71 74 75 - 65 160 241 184 183 3 157 216 217 247 52 216 215 215 251 160 - 143 94 3 35 8 9 11 13 15 15 15 15 15 15 15 215 - 53 53 53 54 54 55 55 16 17 19 21 23 246 245 63 158 - 12 109 11 10 10 9 8 7 7 35 35 5 4 244 43 245 - 216 247 247 52 217 218 56 56 218 219 220 222 56 58 60 72 - 247 226 226 226 228 229 230 234 69 236 70 71 73 74 76 77 - 252 252 105 105 105 48 48 49 49 50 83 85 99 24 245 77 - 53 58 249 55 16 23 62 77 252 215 215 15 15 15 15 15 - 15 15 108 110 113 114 115 115 116 116 118 119 124 126 127 174 - 252 252 247 247 247 160 160 104 162 164 166 136 170 139 141 175 - 215 216 216 216 251 107 107 11 144 145 148 150 152 39 43 63 - 252 247 248 247 248 64 64 66 67 69 70 238 239 77 79 175 - 15 15 15 14 108 176 176 176 178 179 181 182 184 186 188 141 - 216 216 216 216 217 144 192 144 195 214 198 202 203 205 206 207 - 208 208 209 218 218 218 192 15 215 215 216 217 218 219 220 220 - 220 220 220 224 224 224 224 226 240 240 240 240 233 70 73 74 - 65 161 241 185 182 3 157 216 216 247 52 216 215 215 251 160 - 143 31 4 34 8 10 12 14 15 15 15 15 15 15 15 215 - 52 53 53 53 54 55 55 96 16 17 19 23 246 246 245 103 - 13 108 109 11 11 10 9 8 7 33 34 5 38 244 3 246 - 216 247 247 247 217 218 218 56 218 218 219 220 225 57 60 72 - 247 56 226 226 228 228 229 230 234 69 70 71 71 73 76 76 - 252 251 252 247 105 105 48 48 49 49 82 153 88 23 246 76 - 52 57 58 54 16 19 62 76 251 215 215 15 15 15 15 15 - 15 15 14 110 113 113 114 115 115 116 117 119 123 125 127 174 - 251 247 247 247 247 248 248 160 161 163 165 88 137 139 140 175 - 215 215 216 216 215 14 251 107 11 144 146 149 36 4 156 207 - 252 247 247 248 248 248 64 65 66 68 236 237 239 77 79 175 - 15 15 15 15 14 14 176 176 176 178 180 182 183 185 188 46 - 215 216 216 216 216 217 144 192 194 214 198 200 203 205 206 207 - 208 208 210 219 219 218 217 215 15 215 216 216 218 219 219 220 - 220 220 220 221 224 224 224 225 240 240 240 240 233 236 72 74 - 65 160 241 184 182 244 2 215 216 247 247 215 215 215 215 160 -])) - -data diff --git a/demo/mod/entities.fnl b/demo/mod/entities.fnl index 1a17c01..c4077e2 100644 --- a/demo/mod/entities.fnl +++ b/demo/mod/entities.fnl @@ -10,17 +10,19 @@ (var door-tex nil) (var fireball-mesh nil) -(fn create-door-mesh [] +(fn create-door-mesh [bsp ambient] (let [verts [] indices [] hw (/ DOOR_WIDTH 2) y0 0 y1 DOOR_HEIGHT - x DOOR_X] - (table.insert verts {:x x :y y0 :z (- DOOR_Z hw) :u 0 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light 200}) - (table.insert verts {:x x :y y0 :z (+ DOOR_Z hw) :u 1 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light 200}) - (table.insert verts {:x x :y y1 :z (+ DOOR_Z hw) :u 1 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light 200}) - (table.insert verts {:x x :y y1 :z (- DOOR_Z hw) :u 0 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light 200}) + x DOOR_X + sample (fn [vx vy vz] + (if bsp (bsp:light_at vx vy vz (or ambient 0)) 200))] + (table.insert verts {:x x :y y0 :z (- DOOR_Z hw) :u 0 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y0 (- DOOR_Z hw))}) + (table.insert verts {:x x :y y0 :z (+ DOOR_Z hw) :u 1 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y0 (+ DOOR_Z hw))}) + (table.insert verts {:x x :y y1 :z (+ DOOR_Z hw) :u 1 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y1 (+ DOOR_Z hw))}) + (table.insert verts {:x x :y y1 :z (- DOOR_Z hw) :u 0 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y1 (- DOOR_Z hw))}) (table.insert indices 0) (table.insert indices 1) (table.insert indices 2) @@ -150,13 +152,15 @@ 20) (fn init [textures] - (when (not door-mesh) - (create-door-mesh)) (when (not fireball-mesh) (create-fireball-mesh)) (when (and (not door-tex) textures) (set door-tex (textures.door)))) +(fn setup-lighting [bsp ambient] + (when (and (not door-mesh) bsp) + (create-door-mesh bsp ambient))) + (fn render-door [wireframe floor-y] (when (and door-mesh door-tex) (pxl8.draw_mesh door-mesh {:x 0 :y (or floor-y 0) :z 0 @@ -176,4 +180,5 @@ :get-door-radius get-door-radius :init init :render-door render-door - :render-fireball render-fireball} + :render-fireball render-fireball + :setup-lighting setup-lighting} diff --git a/demo/mod/first_person3d.fnl b/demo/mod/first_person3d.fnl index bc3fa85..857746f 100644 --- a/demo/mod/first_person3d.fnl +++ b/demo/mod/first_person3d.fnl @@ -2,10 +2,8 @@ (local effects (require :pxl8.effects)) (local net (require :pxl8.net)) -(local colormap (require :mod.colormap)) (local entities (require :mod.entities)) (local menu (require :mod.menu)) -(local palette (require :mod.palette)) (local sky (require :mod.sky)) (local textures (require :mod.textures)) @@ -26,14 +24,16 @@ (local player-height 72) (local player-radius 12) (local step-height 24) +(local day-length 1800) (local turn-speed 4.0) (var auto-run-cancel-key nil) (var auto-run? false) (var bob-time 0) (var cam-pitch 0) +(var day-time 0) (var cam-x 416) -(var cam-y 0) +(var cam-y 600) (var cam-yaw 0) (var cam-z 416) (var camera nil) @@ -43,6 +43,7 @@ (var land-squash 0) (var last-dt 0.016) (var light-time 0) +(var glows nil) (var lights nil) (var bsp-materials-setup false) (var network nil) @@ -102,8 +103,7 @@ (fn init [] (pxl8.set_relative_mouse_mode true) - (pxl8.set_palette palette 256) - (pxl8.set_colormap colormap 16384) + (pxl8.load_palette "res/palettes/palette.ase") (for [i 0 7] (let [t (/ i 7) r 0xFF @@ -117,6 +117,8 @@ (when (not camera) (set camera (pxl8.create_camera_3d))) + (when (not glows) + (set glows (pxl8.create_glows))) (when (not lights) (set lights (pxl8.create_lights))) @@ -143,6 +145,7 @@ (world:set_bsp_material 0 floor-mat) (world:set_bsp_material 1 wall-mat) (world:set_bsp_material 3 trim-mat) + (entities.setup-lighting (chunk:bsp) 2) (set bsp-materials-setup true)))))) (fn sample-input [] @@ -194,7 +197,7 @@ (pxl8.info "Exiting through door...") (let [exit-x (+ door-x 50) exit-z door-z - exit-y 200] + exit-y 600] (network:exit_chunk exit-x exit-y exit-z) (set cam-x exit-x) (set cam-z exit-z) @@ -287,6 +290,7 @@ (let [target-phase (* (math.floor (/ bob-time math.pi)) math.pi)] (set bob-time (+ (* bob-time 0.8) (* target-phase 0.2)))))) + (set day-time (% (+ day-time (/ dt day-length)) 1)) (set light-time (+ light-time (* dt 0.5))) (set real-time (+ real-time dt)))))) @@ -345,14 +349,13 @@ (pxl8.begin_frame_3d camera lights { :ambient 2 :dither true - :fog_density 0.0 + :fog_density 0.002 :celestial_dir [0.5 -0.8 0.3] :celestial_intensity 0.3}) - (pxl8.clear_depth) - (sky.update-gradient 1 2 6 6 10 18) + (when (not (menu.is-wireframe)) + (sky.update-gradient 1 2 6 6 10 18)) (sky.render smooth-cam-x eye-y smooth-cam-z (menu.is-wireframe)) - (sky.render-stars smooth-cam-x eye-y smooth-cam-z 1.0 last-dt) (pxl8.clear_depth) (pxl8.set_wireframe (menu.is-wireframe)) @@ -364,6 +367,10 @@ (entities.render-door (menu.is-wireframe) (if voxel-space 128 0)) (pxl8.end_frame_3d) + + (when (not (menu.is-wireframe)) + (sky.render-stars smooth-cam-x eye-y smooth-cam-z day-time 0 last-dt)) + (pxl8.pop_target)) (pxl8.push_target) diff --git a/demo/mod/palette.fnl b/demo/mod/palette.fnl deleted file mode 100644 index f97f744..0000000 --- a/demo/mod/palette.fnl +++ /dev/null @@ -1,263 +0,0 @@ -(require :pxl8) -(local ffi (require :ffi)) - -(local data (ffi.new "u32[256]" [ - 0x080602 - 0x14120E - 0x23211E - 0x31302C - 0x403E3B - 0x4B4946 - 0x595755 - 0x676664 - 0x767573 - 0x858382 - 0x939290 - 0xA2A09F - 0xB0AFAE - 0xBEBDBC - 0xCDCCCC - 0xDADAD9 - 0x594625 - 0x544023 - 0x4F3C24 - 0x4C3A22 - 0x453821 - 0x40321F - 0x3E2F20 - 0x382D1D - 0x33291E - 0x30271F - 0x2F251D - 0x2D231E - 0x28211C - 0x251F1D - 0x23201A - 0x221F1B - 0x646269 - 0x5F5C61 - 0x5C545A - 0x584F55 - 0x5B514F - 0x554A47 - 0x4B413F - 0x423C36 - 0x463D31 - 0x3E352A - 0x362E25 - 0x2D2922 - 0x26221D - 0x1C1916 - 0x151310 - 0x100F0D - 0x8C6F52 - 0x7E6045 - 0x73553B - 0x715134 - 0xBA8346 - 0xA1723B - 0x815C2E - 0x745226 - 0xCC8926 - 0xBB7E22 - 0x9F6B1F - 0x875A1C - 0x6E4918 - 0x553712 - 0x3B250D - 0x24180A - 0xA34331 - 0x9B3728 - 0x923220 - 0x882E18 - 0x842B16 - 0x772312 - 0x69200D - 0x5A1C06 - 0x541C04 - 0x4C1A03 - 0x411701 - 0x371000 - 0x2E0D00 - 0x250B00 - 0x1B0600 - 0x130500 - 0x7D5741 - 0x76503A - 0x6E4C37 - 0x684833 - 0x5D3F2F - 0x553A2C - 0x4F3628 - 0x483024 - 0x4A3126 - 0x483025 - 0x432D22 - 0x3C2C22 - 0x352922 - 0x2C241F - 0x221C1B - 0x1A1916 - 0x6E4626 - 0x5F4025 - 0x523924 - 0x433322 - 0x352B1E - 0x28231A - 0x1A1A14 - 0x1C1815 - 0x96544B - 0xAC7369 - 0xB48C86 - 0xBCA7A4 - 0xB1BCC2 - 0x9DB0B9 - 0x8A9FAA - 0x77929F - 0x738995 - 0x5E7C8B - 0x4A6C7D - 0x345E72 - 0x1F4C64 - 0x19445C - 0x143C51 - 0x10384B - 0x183748 - 0x1A3341 - 0x192F39 - 0x152B34 - 0x13262E - 0x101E23 - 0x0E1519 - 0x0B0E10 - 0x896463 - 0x815C5B - 0x785352 - 0x6F4C4D - 0x664444 - 0x5F3C3D - 0x573738 - 0x523233 - 0x442929 - 0x392324 - 0x2D1D1D - 0x241414 - 0x1A0E0E - 0x100909 - 0x070403 - 0x000000 - 0x98936F - 0x918B68 - 0x887F60 - 0x807759 - 0x797055 - 0x73684D - 0x6B6146 - 0x63593F - 0x5B523A - 0x504834 - 0x423D2D - 0x373226 - 0x2E2B1F - 0x222018 - 0x161511 - 0x0E0F0A - 0x9A554F - 0x904D48 - 0x87453F - 0x7D4037 - 0x743831 - 0x693329 - 0x612C24 - 0x572720 - 0x4F231A - 0x441E16 - 0x391914 - 0x2D150F - 0x22110D - 0x1A0B06 - 0x0D0403 - 0x040202 - 0x7F77C0 - 0x7770B5 - 0x6E68A8 - 0x686099 - 0x60588C - 0x575381 - 0x4E4C72 - 0x454263 - 0x3D3957 - 0x34324A - 0x2C2940 - 0x242135 - 0x1E1928 - 0x16121D - 0x0C0A12 - 0x050306 - 0x88AF7B - 0x81A473 - 0x7B9A67 - 0x728E5D - 0x6D8553 - 0x61794A - 0x5B7144 - 0x61734B - 0x586A3D - 0x4D5E2D - 0x465422 - 0x3F4D17 - 0x36420E - 0x2F3507 - 0x272804 - 0x211F02 - 0x1EF708 - 0x3CE10D - 0x51CC1B - 0x64B621 - 0x6DA12C - 0x69882B - 0x727F3B - 0xE4DDCE - 0xEEE6BA - 0xEAE290 - 0xE9E26D - 0xE5DE43 - 0xE3DB20 - 0xE1CC18 - 0xDFB911 - 0xDCA60B - 0xE8A306 - 0xDF9312 - 0xE17B05 - 0xC86815 - 0xBC5908 - 0xB14805 - 0xA63D07 - 0xB6431E - 0xAA381A - 0x9A2E12 - 0x8C270F - 0x892B17 - 0x762311 - 0x5F1F0D - 0x491B09 - 0x3B1809 - 0xE50F19 - 0x6A34C4 - 0xE00B28 - 0x2B08C8 - 0x322A33 - 0x281C0E - 0x2F1E15 - 0xD48067 - 0xC26B4C - 0x974928 - 0x814123 - 0xD5B3A9 - 0xBE9D93 - 0x9A7B6C - 0x7F5F51 - 0x8E504C -])) - -data diff --git a/demo/mod/sky.fnl b/demo/mod/sky.fnl index eb6d2d0..dd1dcfc 100644 --- a/demo/mod/sky.fnl +++ b/demo/mod/sky.fnl @@ -8,17 +8,60 @@ (local NUM_RANDOM_STARS 300) (local NUM_TINY_STARS 7000) -(local STAR_CYCLE_PERIOD 86400) +(local NUM_BEACON_STARS 8) (local STAR_SEED 0xDEADBEEF) +(local STAR_CYCLE_DAYS 90) +(local TAU (* math.pi 2)) -;; Use existing bright palette colors -;; Silver/white: indices 14-15 (brightest grays) -(local IDX_SILVER 14) -;; Warm/torch: indices 216-218 (bright creams/yellows) -(local IDX_TORCH 216) -;; Blue/magic: indices 176-178 (purples - brightest of the range) -(local IDX_MAGIC 176) +(local GLOW_TORCH pxl8.LIGHT_ORANGE) +(local GLOW_MAGIC pxl8.LIGHT_PURPLE) +(local GLOW_SILVER pxl8.LIGHT_WHITE) +(local GLOW_CRIMSON pxl8.LIGHT_RED) +(local GLOW_DEEP_BLUE pxl8.LIGHT_BLUE) +(local CONSTELLATIONS + [{:stars [[-0.09 0.075 240] [-0.12 0.105 200] [-0.075 0.112 190] + [-0.06 0.045 255] [-0.022 0.022 220] [0.03 0.0 200] + [0.075 -0.018 190] [0.12 -0.009 180] [0.158 0.022 170] + [0.18 0.06 160] [0.15 0.075 150]]} + {:stars [[0.0 0.0 240] [0.04 0.0 220] [0.08 0.01 200] + [0.08 0.05 190] [0.04 0.06 180] [0.0 0.05 200] + [-0.02 0.08 170]]} + {:stars [[-0.03 0.04 230] [0.03 0.04 230] [0.05 0.0 200] + [0.03 -0.04 190] [-0.03 -0.04 190] [-0.05 0.0 200] + [0.0 -0.06 170]]} + {:stars [[-0.06 0.04 255] [-0.03 0.02 220] [0.0 0.0 240] + [0.04 -0.025 200] [0.08 -0.05 180] [0.12 -0.075 160] + [-0.02 -0.03 190] [-0.02 0.04 190]]} + {:stars [[0.0 0.0 250] [-0.015 0.022 200] [-0.03 0.04 180] + [0.015 0.015 190] [0.035 0.03 170] [0.0 -0.022 200] + [-0.022 -0.038 180] [0.022 -0.038 180] + [0.045 0.0 220] [0.07 0.0 200] [0.09 0.008 180]]} + {:stars [[-0.06 0.0 200] [-0.03 0.015 210] [0.0 0.0 230] + [0.03 -0.015 210] [0.06 0.0 200] [0.09 0.015 190] + [0.12 0.0 180]]} + {:stars [[0.0 0.0 250] [0.008 0.03 220] [-0.02 0.05 200] + [0.015 0.055 190] [-0.035 0.07 170] [0.03 0.065 180] + [0.0 -0.02 200] [-0.015 -0.045 180]]} + {:stars [[0.0 0.0 255] [-0.025 0.012 200] [-0.055 0.018 180] + [-0.08 0.012 160] [0.02 0.01 190] [0.045 0.018 180] + [0.07 0.03 160] [0.0 -0.025 190]]} + {:stars [[0.0 0.0 240] [0.03 0.025 220] [0.05 0.05 200] + [-0.02 0.03 200] [-0.05 0.045 180] [0.01 -0.03 210] + [0.04 -0.05 190] [-0.03 -0.06 170]]} + {:stars [[0.0 0.0 230] [0.045 0.01 220] [0.025 0.04 210] + [-0.015 0.035 200] [-0.04 0.005 210] [-0.025 -0.03 200] + [0.02 -0.04 190]]} + {:stars [[0.0 0.0 250] [0.05 0.015 200] [0.035 0.05 190] + [-0.02 0.055 180] [-0.055 0.025 200] [-0.045 -0.025 190] + [-0.01 -0.05 180] [0.04 -0.04 190]]} + {:stars [[0.0 0.0 255] [0.025 0.015 180] [-0.015 0.025 170] + [0.02 -0.025 175] [-0.03 -0.01 165]]}]) + +(var beacon-stars []) +(var celestial-directions nil) +(var celestial-projected nil) +(var constellation-stars []) (var last-gradient-key nil) (var random-stars []) (var sky-mesh nil) @@ -26,8 +69,8 @@ (var star-directions nil) (var star-glows nil) (var star-projected nil) -(var star-time 0) (var tiny-stars []) +(var twinkle-time 0) (fn generate-sky-gradient [zenith-r zenith-g zenith-b horizon-r horizon-g horizon-b] (for [i 0 (- SKY_GRADIENT_COUNT 1)] @@ -105,142 +148,341 @@ (generate-sky-gradient zenith-r zenith-g zenith-b horizon-r horizon-g horizon-b) (set last-gradient-key key)))) -(fn band-factor [dx dy dz bx by bz width] - (let [dist (math.abs (+ (* dx bx) (* dy by) (* dz bz))) - in-band (- 1 (math.min (* dist width) 1))] +(fn galactic-band-factor [dx dy dz] + (let [band-len (math.sqrt (+ (* 0.6 0.6) (* 0.3 0.3) (* 0.742 0.742))) + bx (/ 0.6 band-len) + by (/ 0.3 band-len) + bz (/ 0.742 band-len) + dist (math.abs (+ (* dx bx) (* dy by) (* dz bz))) + in-band (- 1 (math.min (* dist 3) 1))] (* in-band in-band))) -(fn galactic-band-factor [dx dy dz] - (let [;; Main galactic band - crosses zenith - band-len (math.sqrt (+ (* 0.6 0.6) (* 0.3 0.3) (* 0.742 0.742))) - b1 (band-factor dx dy dz (/ 0.6 band-len) (/ 0.3 band-len) (/ 0.742 band-len) 3) - ;; Secondary band - lower angle, different orientation - b2 (band-factor dx dy dz 0.8 0.15 0.58 3.5) - ;; Tertiary band - opposite side - b3 (band-factor dx dy dz -0.7 0.2 0.69 4)] - (math.max b1 b2 b3))) +(fn compute-right [cx cy cz] + (if (> (math.abs cy) 0.99) + (values 1 0 0) + (let [rx (- cz) + rz cx + rlen (math.sqrt (+ (* rx rx) (* rz rz)))] + (values (/ rx rlen) 0 (/ rz rlen))))) -(fn generate-stars [] - (set random-stars []) - (set tiny-stars []) - - ;; Generate random stars - use full upper hemisphere (dy > -0.1) - (for [i 0 (- NUM_RANDOM_STARS 1)] - (let [h1 (pxl8.hash32 (+ STAR_SEED (* i 5))) - h2 (pxl8.hash32 (+ STAR_SEED (* i 5) 1)) - h3 (pxl8.hash32 (+ STAR_SEED (* i 5) 2)) - h4 (pxl8.hash32 (+ STAR_SEED (* i 5) 3)) - theta (* (/ h1 0xFFFFFFFF) math.pi 2) - phi (math.acos (- 1 (* (/ h2 0xFFFFFFFF) 1.0))) - sin-phi (math.sin phi) - cos-phi (math.cos phi) - dx (* sin-phi (math.cos theta)) - dy cos-phi - dz (* sin-phi (math.sin theta)) - brightness-raw (/ (% h3 256) 255) - brightness (math.floor (+ 60 (* brightness-raw brightness-raw 195))) - color-type (% h4 100) - color (if (< color-type 8) (+ IDX_TORCH (% (bit.rshift h4 8) 2)) - (< color-type 16) (+ IDX_MAGIC (% (bit.rshift h4 8) 2)) - (+ IDX_SILVER (% (bit.rshift h4 8) 2)))] - - (when (> dy -0.1) - (table.insert random-stars {:dx dx :dy dy :dz dz - :brightness brightness - :color color})))) - - (let [tiny-seed (+ STAR_SEED 0xCAFEBABE)] - (for [i 0 (- NUM_TINY_STARS 1)] - (let [h1 (pxl8.hash32 (+ tiny-seed (* i 4))) - h2 (pxl8.hash32 (+ tiny-seed (* i 4) 1)) - h3 (pxl8.hash32 (+ tiny-seed (* i 4) 2)) - h4 (pxl8.hash32 (+ tiny-seed (* i 4) 3)) - theta (* (/ h1 0xFFFFFFFF) math.pi 2) - phi (math.acos (- 1 (* (/ h2 0xFFFFFFFF) 1.0))) +(fn generate-constellation-centers [] + (let [centers [] + seed (+ STAR_SEED 0xC0057E11) + num (# CONSTELLATIONS)] + (for [i 0 (- num 1)] + (let [h1 (pxl8.hash32 (+ seed (* i 3))) + h2 (pxl8.hash32 (+ seed (* i 3) 1)) + h1f (/ h1 0xFFFFFFFF) + h2f (/ h2 0xFFFFFFFF) + base-theta (* (/ i num) TAU) + theta-jitter (* (- h1f 0.5) 0.3) + theta-offset (if (= i 0) -0.3 (= i 1) 0.4 (= i 4) 0.5 0) + theta (+ base-theta theta-jitter theta-offset) + phi (if (or (= i 0) (= i 6)) (+ 0.25 (* h2f 0.3)) + (= i 9) (+ 0.5 (* h2f 0.3)) + (or (= i 1) (= i 4) (= i 7) (= i 10)) (+ 0.65 (* h2f 0.4)) + (= i 3) (+ 1.1 (* h2f 0.2)) + (+ 0.85 (* h2f 0.4))) + sin-phi (math.sin phi) + x (* sin-phi (math.cos theta)) + y (math.cos phi) + z (* sin-phi (math.sin theta)) + len (math.sqrt (+ (* x x) (* y y) (* z z)))] + (table.insert centers {:x (/ x len) :y (/ y len) :z (/ z len)}))) + centers)) + +(fn generate-constellation-stars-data [] + (let [centers (generate-constellation-centers) + stars []] + (for [i 0 (- (# CONSTELLATIONS) 1)] + (let [constellation (. CONSTELLATIONS (+ i 1)) + center (. centers (+ i 1)) + (rx ry rz) (compute-right center.x center.y center.z) + ux (- (* center.y rz) (* center.z ry)) + uy (- (* center.z rx) (* center.x rz)) + uz (- (* center.x ry) (* center.y rx)) + ulen (math.sqrt (+ (* ux ux) (* uy uy) (* uz uz))) + ux (/ ux ulen) uy (/ uy ulen) uz (/ uz ulen)] + (each [j star-data (ipairs constellation.stars)] + (let [ox (. star-data 1) + oy (. star-data 2) + brightness (. star-data 3) + dx (+ center.x (* rx ox) (* ux oy)) + dy (+ center.y (* ry ox) (* uy oy)) + dz (+ center.z (* rz ox) (* uz oy)) + dlen (math.sqrt (+ (* dx dx) (* dy dy) (* dz dz))) + star-seed (pxl8.hash32 (+ STAR_SEED (* i 1000) (* (- j 1) 7))) + color-type (% star-seed 6) + glow (if (< color-type 2) GLOW_MAGIC GLOW_SILVER) + is-anchor (and (= (- j 1) 0) (= i 11))] + (table.insert stars {:dx (/ dx dlen) :dy (/ dy dlen) :dz (/ dz dlen) + :brightness brightness + :glow glow + :is-anchor is-anchor}))))) + stars)) + +(fn generate-beacon-stars-data [] + (let [stars [] + seed (+ STAR_SEED 0xBEAC0000)] + (for [i 0 (- NUM_BEACON_STARS 1)] + (let [h1 (pxl8.hash32 (+ seed (* i 4))) + h2 (pxl8.hash32 (+ seed (* i 4) 1)) + h3 (pxl8.hash32 (+ seed (* i 4) 2)) + theta (* (/ h1 0xFFFFFFFF) TAU) + phi (+ 0.3 (* (/ h2 0xFFFFFFFF) 0.9)) + sin-phi (math.sin phi) + x (* sin-phi (math.cos theta)) + y (math.cos phi) + z (* sin-phi (math.sin theta)) + color-type (% h3 8) + glow (if (< color-type 3) GLOW_MAGIC GLOW_SILVER)] + (table.insert stars {:dx x :dy y :dz z :brightness 255 :glow glow}))) + stars)) + +(fn generate-random-stars-data [] + (let [stars []] + (for [i 0 (- NUM_RANDOM_STARS 1)] + (let [h1 (pxl8.hash32 (+ STAR_SEED (* i 5))) + h2 (pxl8.hash32 (+ STAR_SEED (* i 5) 1)) + h3 (pxl8.hash32 (+ STAR_SEED (* i 5) 2)) + h4 (pxl8.hash32 (+ STAR_SEED (* i 5) 3)) + theta (* (/ h1 0xFFFFFFFF) TAU) + phi (math.acos (- 1 (* (/ h2 0xFFFFFFFF) 0.85))) sin-phi (math.sin phi) - cos-phi (math.cos phi) dx (* sin-phi (math.cos theta)) - dy cos-phi + dy (math.cos phi) + dz (* sin-phi (math.sin theta)) + brightness-raw (/ (% h3 256) 255) + brightness (math.floor (+ 60 (* brightness-raw brightness-raw 140))) + color-type (% h4 100) + glow (if (< color-type 8) GLOW_TORCH + (< color-type 16) GLOW_MAGIC + GLOW_SILVER)] + (when (> dy 0.05) + (table.insert stars {:dx dx :dy dy :dz dz + :brightness brightness :glow glow})))) + stars)) + +(fn generate-tiny-stars-data [] + (let [stars [] + seed (+ STAR_SEED 0xCAFEBABE)] + (for [i 0 (- NUM_TINY_STARS 1)] + (let [h1 (pxl8.hash32 (+ seed (* i 4))) + h2 (pxl8.hash32 (+ seed (* i 4) 1)) + h3 (pxl8.hash32 (+ seed (* i 4) 2)) + h4 (pxl8.hash32 (+ seed (* i 4) 3)) + theta (* (/ h1 0xFFFFFFFF) TAU) + phi (math.acos (- 1 (* (/ h2 0xFFFFFFFF) 0.95))) + sin-phi (math.sin phi) + dx (* sin-phi (math.cos theta)) + dy (math.cos phi) dz (* sin-phi (math.sin theta)) band-boost (galactic-band-factor dx dy dz) - base-bright (+ 40 (% h3 50)) - brightness (+ base-bright (math.floor (* band-boost 40))) + base-bright (+ 25 (% h3 40)) + brightness (+ base-bright (math.floor (* band-boost 35))) color-shift (% h4 100) - color (if (< color-shift 3) (+ IDX_TORCH (% (bit.rshift h4 8) 2)) - (< color-shift 12) (+ IDX_MAGIC (% (bit.rshift h4 8) 2)) - (+ IDX_SILVER (% (bit.rshift h4 8) 2)))] - (when (> dy -0.1) - (table.insert tiny-stars {:dx dx :dy dy :dz dz - :brightness brightness - :color color}))))) + glow (if (< color-shift 3) GLOW_TORCH + (< color-shift 15) GLOW_MAGIC + GLOW_SILVER)] + (when (> dy -0.05) + (table.insert stars {:dx dx :dy dy :dz dz + :brightness brightness :glow glow})))) + stars)) - (set star-count (+ (length tiny-stars) (length random-stars))) +(fn pack-star-directions [stars idx] + (var i idx) + (each [_ star (ipairs stars)] + (let [dir (. star-directions i)] + (set dir.x star.dx) + (set dir.y star.dy) + (set dir.z star.dz)) + (set i (+ i 1))) + i) + +(fn generate-stars [] + (set tiny-stars (generate-tiny-stars-data)) + (set random-stars (generate-random-stars-data)) + (set constellation-stars (generate-constellation-stars-data)) + (set beacon-stars (generate-beacon-stars-data)) + + (set star-count (+ (# tiny-stars) (# random-stars) + (# constellation-stars) (# beacon-stars))) (set star-directions (pxl8.create_vec3_array star-count)) (when pxl8.create_glows - (set star-glows (pxl8.create_glows 10000))) + (set star-glows (pxl8.create_glows 16384))) (set star-projected (pxl8.create_vec3_array star-count)) - + (set celestial-directions (pxl8.create_vec3_array 2)) + (set celestial-projected (pxl8.create_vec3_array 2)) (var idx 0) - (each [_ star (ipairs tiny-stars)] - (let [dir (. star-directions idx)] - (set dir.x star.dx) - (set dir.y star.dy) - (set dir.z star.dz)) - (set idx (+ idx 1))) - (each [_ star (ipairs random-stars)] - (let [dir (. star-directions idx)] - (set dir.x star.dx) - (set dir.y star.dy) - (set dir.z star.dz)) - (set idx (+ idx 1)))) + (set idx (pack-star-directions tiny-stars idx)) + (set idx (pack-star-directions random-stars idx)) + (set idx (pack-star-directions constellation-stars idx)) + (set idx (pack-star-directions beacon-stars idx))) -(fn render-stars [cam-x cam-y cam-z intensity dt] - (set star-time (+ star-time (or dt 0))) - (when (and (> intensity 0) (> star-count 0) star-glows) - (let [fade-in (* intensity intensity) - time-factor (/ star-time 60) - star-rotation (/ (* star-time math.pi 2) STAR_CYCLE_PERIOD) +(fn star-brightness [time] + (if (< time 0.18) 1.0 + (< time 0.26) (let [t (/ (- time 0.18) 0.08) + ease (* t t (- 3.0 (* 2.0 t)))] + (- 1.0 ease)) + (< time 0.74) 0.0 + (< time 0.82) (let [t (/ (- time 0.74) 0.08) + ease (* t t (- 3.0 (* 2.0 t)))] + ease) + 1.0)) + +(fn ease-celestial [t] + (let [s (math.sin (* 2 t TAU)) + ease (/ (* 0.9 s) (* 2 TAU))] + (- t ease))) + +(fn sun-direction [time] + (let [eased (ease-celestial time) + angle (* (- eased 0.25) TAU) + y (math.sin angle) + xz (math.cos angle) + sx (* xz 0.7) + sz (* xz 0.7) + len (math.sqrt (+ (* sx sx) (* y y) (* sz sz)))] + (values (/ sx len) (/ y len) (/ sz len)))) + +(fn moon-direction [time] + (let [eased (ease-celestial time) + azimuth (* (- eased 0.75) TAU 0.5) + elev (math.sin (* 25 (/ math.pi 180))) + horiz (math.cos (* 25 (/ math.pi 180))) + sx (* (- (math.cos azimuth)) horiz) + sz (* (math.sin azimuth) horiz)] + (values sx elev sz))) + +(fn render-stars [cam-x cam-y cam-z time days dt] + (set twinkle-time (+ twinkle-time (or dt 0))) + (when (and (> star-count 0) star-glows) + (let [time-val (or time 0) + days-val (or days 0) + star-bright (star-brightness time-val) + fade-in (* star-bright star-bright) + time-factor (/ twinkle-time 60) + star-rotation (/ (* (+ days-val time-val) TAU) STAR_CYCLE_DAYS) t (pxl8.mat4_translate cam-x cam-y cam-z) r (pxl8.mat4_rotate_y star-rotation) s (pxl8.mat4_scale sky-radius sky-radius sky-radius) transform (pxl8.mat4_multiply t (pxl8.mat4_multiply r s)) - tiny-count (length tiny-stars)] + tiny-count (# tiny-stars) + random-count (# random-stars) + constellation-count (# constellation-stars) + beacon-count (# beacon-stars) + random-offset tiny-count + constellation-offset (+ tiny-count random-count) + beacon-offset (+ tiny-count random-count constellation-count)] (star-glows:clear) (pxl8.project_points star-directions star-projected star-count transform) - (for [i 0 (- tiny-count 1)] - (let [screen (. star-projected i)] - (when (> screen.z 0) - (let [star (. tiny-stars (+ i 1)) - int (math.floor (* star.brightness fade-in))] - (when (> int 8) - (let [px (math.floor (+ screen.x 0.5)) - py (math.floor (+ screen.y 0.5))] - (star-glows:add px py 1 int star.color pxl8.GLOW_CIRCLE))))))) + (when (> star-bright 0.02) + (for [i 0 (- tiny-count 1)] + (let [screen (. star-projected i)] + (when (> screen.z 0) + (let [star (. tiny-stars (+ i 1)) + int (math.floor (* star.brightness fade-in))] + (when (> int 8) + (star-glows:add (math.floor (+ screen.x 0.5)) + (math.floor (+ screen.y 0.5)) + 1 int star.glow pxl8.GLOW_CIRCLE)))))) + + (for [i 0 (- constellation-count 1)] + (let [screen (. star-projected (+ constellation-offset i))] + (when (> screen.z 0) + (let [star (. constellation-stars (+ i 1)) + phase (+ (* i 1.618) (* time-val 2.5)) + twinkle (+ 0.85 (* 0.15 (math.sin (* phase 6.28)))) + int (math.floor (* star.brightness fade-in twinkle 1.5)) + sx (math.floor (+ screen.x 0.5)) + sy (math.floor (+ screen.y 0.5))] + (if star.is-anchor + (do + (star-glows:add sx sy 4 (* int 2) star.glow pxl8.GLOW_CIRCLE) + (star-glows:add sx sy 8 (math.floor (/ int 2)) star.glow pxl8.GLOW_CIRCLE)) + (> star.brightness 220) + (do + (star-glows:add sx sy 3 (math.floor (* int 1.5)) star.glow pxl8.GLOW_DIAMOND) + (star-glows:add sx sy 5 (math.floor (/ int 2)) star.glow pxl8.GLOW_CIRCLE)) + (> star.brightness 180) + (do + (star-glows:add sx sy 2 int star.glow pxl8.GLOW_DIAMOND) + (star-glows:add sx sy 4 (math.floor (/ int 3)) star.glow pxl8.GLOW_CIRCLE)) + (do + (star-glows:add sx sy 2 (math.floor (/ (* int 2) 3)) star.glow pxl8.GLOW_DIAMOND) + (star-glows:add sx sy 3 (math.floor (/ int 4)) star.glow pxl8.GLOW_CIRCLE))))))) + + (for [i 0 (- beacon-count 1)] + (let [screen (. star-projected (+ beacon-offset i))] + (when (> screen.z 0) + (let [star (. beacon-stars (+ i 1)) + phase (+ (* i 2.718) (* time-val 1.5)) + twinkle (+ 0.9 (* 0.1 (math.sin (* phase 6.28)))) + int (math.floor (* 400 fade-in twinkle)) + sx (math.floor (+ screen.x 0.5)) + sy (math.floor (+ screen.y 0.5))] + (star-glows:add sx sy 4 int star.glow pxl8.GLOW_CIRCLE) + (star-glows:add sx sy 7 (math.floor (/ int 3)) star.glow pxl8.GLOW_CIRCLE))))) + + (for [i 0 (- random-count 1)] + (let [screen (. star-projected (+ random-offset i))] + (when (> screen.z 0) + (let [star (. random-stars (+ i 1)) + phase (+ (* i 2.137) (* time-factor 3.0)) + twinkle (+ 0.75 (* 0.25 (math.sin (* phase 6.28)))) + int (math.floor (* star.brightness fade-in twinkle)) + sx (math.floor (+ screen.x 0.5)) + sy (math.floor (+ screen.y 0.5))] + (when (> star.brightness 180) + (star-glows:add sx sy 2 (math.floor (* int 1.5)) star.glow pxl8.GLOW_CIRCLE)) + (when (and (<= star.brightness 180) (> star.brightness 120)) + (star-glows:add sx sy 2 int star.glow pxl8.GLOW_CIRCLE))))))) + + (let [(sun-dx sun-dy sun-dz) (sun-direction time-val)] + (when (> sun-dy 0) + (let [dir (. celestial-directions 0)] + (set dir.x sun-dx) + (set dir.y sun-dy) + (set dir.z sun-dz)) + (let [ct (pxl8.mat4_translate cam-x cam-y cam-z) + cs (pxl8.mat4_scale sky-radius sky-radius sky-radius) + cel-transform (pxl8.mat4_multiply ct cs)] + (pxl8.project_points celestial-directions celestial-projected 1 cel-transform) + (let [screen (. celestial-projected 0)] + (when (> screen.z 0) + (let [sx (math.floor (+ screen.x 0.5)) + sy (math.floor (+ screen.y 0.5)) + horizon-factor (- 1 sun-dy) + size-scale (+ 1 (* horizon-factor 0.6)) + r-outer (math.floor (* 50 size-scale)) + r-mid (math.floor (* 38 size-scale)) + r-inner (math.floor (* 26 size-scale))] + (star-glows:add sx sy r-outer 80 GLOW_CRIMSON pxl8.GLOW_CIRCLE 0) + (star-glows:add sx sy r-mid 180 GLOW_CRIMSON pxl8.GLOW_CIRCLE 0) + (star-glows:add sx sy r-inner 255 GLOW_TORCH pxl8.GLOW_CIRCLE 0))))))) + + (when (> star-bright 0.02) + (let [(moon-dx moon-dy moon-dz) (moon-direction time-val)] + (when (> moon-dy 0) + (let [dir (. celestial-directions 1)] + (set dir.x moon-dx) + (set dir.y moon-dy) + (set dir.z moon-dz)) + (let [ct (pxl8.mat4_translate cam-x cam-y cam-z) + cs (pxl8.mat4_scale sky-radius sky-radius sky-radius) + cel-transform (pxl8.mat4_multiply ct cs)] + (pxl8.project_points celestial-directions celestial-projected 2 cel-transform) + (let [screen (. celestial-projected 1)] + (when (> screen.z 0) + (let [sx (math.floor (+ screen.x 0.5)) + sy (math.floor (+ screen.y 0.5))] + (star-glows:add sx sy 6 (math.floor (* 500 fade-in)) GLOW_SILVER pxl8.GLOW_DIAMOND) + (star-glows:add sx sy 10 (math.floor (* 200 fade-in)) GLOW_SILVER pxl8.GLOW_CIRCLE) + (star-glows:add sx sy 16 (math.floor (* 60 fade-in)) GLOW_DEEP_BLUE pxl8.GLOW_CIRCLE)))))))) + - (for [i 0 (- (length random-stars) 1)] - (let [screen (. star-projected (+ tiny-count i))] - (when (> screen.z 0) - (let [star (. random-stars (+ i 1)) - phase (+ (* (+ i 1) 2.137) (* time-factor 3.0)) - twinkle (+ 0.75 (* 0.25 (math.sin (* phase 6.28)))) - int (math.floor (* star.brightness fade-in twinkle)) - sx (math.floor (+ screen.x 0.5)) - sy (math.floor (+ screen.y 0.5))] - (if (> star.brightness 220) - (do - (star-glows:add sx sy 3 (math.floor (* int 1.5)) star.color pxl8.GLOW_DIAMOND) - (star-glows:add sx sy 5 (math.floor (/ int 2)) star.color pxl8.GLOW_CIRCLE)) - (> star.brightness 180) - (do - (star-glows:add sx sy 2 int star.color pxl8.GLOW_DIAMOND) - (star-glows:add sx sy 4 (math.floor (/ int 3)) star.color pxl8.GLOW_CIRCLE)) - (> star.brightness 120) - (do - (star-glows:add sx sy 2 (math.floor (* int 0.67)) star.color pxl8.GLOW_DIAMOND) - (star-glows:add sx sy 3 (math.floor (/ int 4)) star.color pxl8.GLOW_CIRCLE)) - (star-glows:add sx sy 2 (math.floor (* int 0.5)) star.color pxl8.GLOW_CIRCLE)))))) (when (> (star-glows:count) 0) (star-glows:render))))) @@ -255,5 +497,9 @@ :generate-stars generate-stars :reset-gradient reset-gradient :update-gradient update-gradient + :star-brightness star-brightness + :ease-celestial ease-celestial + :sun-direction sun-direction + :moon-direction moon-direction :SKY_GRADIENT_START SKY_GRADIENT_START :SKY_GRADIENT_COUNT SKY_GRADIENT_COUNT} diff --git a/demo/res/palettes/palette.ase b/demo/res/palettes/palette.ase new file mode 100644 index 0000000000000000000000000000000000000000..1e4a8ef65e5a3f47d1293c2cd814d6f5a0c670d2 GIT binary patch literal 944 zcmdnM%)szqDI)_2asV*{LkbWh0Y*kf1_1`JJd!BYm)(^s(2l{MCsGff0F>|vuv@_K*(^J*eR8mutm5~$^6&4WS=k3W4 zs!MP!4z(@}G}+bcwy?;$F-ET>NbO9g+U`1~`PuUAQ8Ia+5~1co)~dWJ5?qU23};(t zOfpvJ(3fb@5i3^_%2eQul3@#xVeye-b`)nc7huriWl-g2kY-~LW@V@icPtCA%JVVL z@Gy?G*AKPQ@i)`(Fi`O_RP!)Ub=Fm~(NQwhRMJtASCWyIk`&8xQ;T;{4YE{mHdZp# zmeWv{l9CdUkr160>b<5Ub4yR#p5;r{9XdE`=eG7$%S-3aE}S|krn}vvw!)|=M=m8! zA|_lo(1+jKRoufx($P-B(p1F6KuAxUUs-`qQi5ARpffeOF*dp)Bq-mg_(tkX-3I`zTB-XsVl1EW)_C^qz5)edldyZCc9gN+ZcM8 zXgFvqm?}wVND9gFaS5?8v-Pa6Y*|uRH!H2QFQ%Y1D5cUfw$M4b*efc_#y?KSBSg{B zSKPvh&%l&jLxV+8p2_k%YrsS9gfo(P+vJNEYUg%nmDF23xqI&2vt6$qPI&ns_vszy z$2Sxno|3q~L-5X0?iY*L?oSqaSj~DOLv&9h$3_pe1lu)DbUJ z5sa7T^_1qcmf(EKFZzH>X_DcQEY=gon#LM3eEM>tR~pg}W&2F`)M#{6zPfqkzPXcU NRp->l2lfT}002a-?EC-# literal 0 HcmV?d00001 diff --git a/pxl8.sh b/pxl8.sh index 605e1eb..db454c4 100755 --- a/pxl8.sh +++ b/pxl8.sh @@ -507,6 +507,7 @@ case "$COMMAND" in src/gfx/pxl8_shader_runtime.c src/gfx/pxl8_font.c src/gfx/pxl8_gfx.c + src/gfx/pxl8_glows.c src/gfx/pxl8_lightmap.c src/gfx/pxl8_lights.c src/gfx/pxl8_mesh.c diff --git a/pxl8d/src/procgen.rs b/pxl8d/src/procgen.rs index a344792..5818198 100644 --- a/pxl8d/src/procgen.rs +++ b/pxl8d/src/procgen.rs @@ -1062,6 +1062,13 @@ pub fn generate_rooms(params: &ProcgenParams) -> Bsp { }) }).collect(); + let mut lights = lights; + lights.push(LightSource { + position: Vec3::new(860.0, light_height, 416.0), + intensity: 1.2, + radius: 120.0, + }); + compute_bsp_vertex_lighting(&mut bsp, &lights); bsp.into() diff --git a/src/bsp/pxl8_bsp.c b/src/bsp/pxl8_bsp.c index b3d2a8e..0a2136d 100644 --- a/src/bsp/pxl8_bsp.c +++ b/src/bsp/pxl8_bsp.c @@ -474,6 +474,32 @@ pxl8_bsp_lightmap pxl8_bsp_lightmap_mapped(u8 width, u8 height, u32 offset) { }; } +u8 pxl8_bsp_light_at(const pxl8_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient) { + if (!bsp || !bsp->vertices || !bsp->vertex_lights) return 255; + + f32 best_dist = FLT_MAX; + u32 best_idx = 0; + + for (u32 i = 0; i < bsp->num_vertices; i++) { + f32 dx = bsp->vertices[i].position.x - x; + f32 dy = bsp->vertices[i].position.y - y; + f32 dz = bsp->vertices[i].position.z - z; + f32 dist = dx * dx + dy * dy + dz * dz; + if (dist < best_dist) { + best_dist = dist; + best_idx = i; + } + } + + if (best_idx >= bsp->num_vertex_lights) return 255; + + u32 packed = bsp->vertex_lights[best_idx]; + u8 direct = (packed >> 24) & 0xFF; + u8 ao = (packed >> 16) & 0xFF; + f32 combined = (f32)direct + ((f32)ambient / 255.0f) * (f32)ao; + return (u8)(combined > 255.0f ? 255.0f : combined); +} + pxl8_bsp_lightmap_sample pxl8_bsp_sample_lightmap(const pxl8_bsp* bsp, u32 face_idx, f32 u, f32 v) { pxl8_bsp_lightmap_sample white = {255, 255, 255}; diff --git a/src/bsp/pxl8_bsp.h b/src/bsp/pxl8_bsp.h index eead2a2..71fd615 100644 --- a/src/bsp/pxl8_bsp.h +++ b/src/bsp/pxl8_bsp.h @@ -143,6 +143,7 @@ pxl8_bsp_lightmap pxl8_bsp_lightmap_uniform(u8 r, u8 g, u8 b); pxl8_result pxl8_bsp_load(const char* path, pxl8_bsp* bsp); void pxl8_bsp_pvs_destroy(pxl8_bsp_pvs* pvs); bool pxl8_bsp_pvs_is_visible(const pxl8_bsp_pvs* pvs, i32 leaf); +u8 pxl8_bsp_light_at(const pxl8_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient); pxl8_bsp_lightmap_sample pxl8_bsp_sample_lightmap(const pxl8_bsp* bsp, u32 face_idx, f32 u, f32 v); #ifdef __cplusplus diff --git a/src/gfx/pxl8_colormap.c b/src/gfx/pxl8_colormap.c index 925fd87..e8c52b8 100644 --- a/src/gfx/pxl8_colormap.c +++ b/src/gfx/pxl8_colormap.c @@ -112,12 +112,67 @@ static void generate_blend_table(pxl8_colormap* cm, const u32* palette) { } } +static void generate_additive_table(pxl8_colormap* cm, const u32* palette, pxl8_light_color light_color) { + pxl8_rgb light = pxl8_light_colors[light_color]; + u32 base_row = PXL8_ADDITIVE_START + (u32)light_color * PXL8_LIGHT_LEVELS; + + for (u32 level = 0; level < PXL8_LIGHT_LEVELS; level++) { + f32 brightness = (f32)level / (f32)(PXL8_LIGHT_LEVELS - 1); + u32 row = base_row + level; + + f32 lr = (f32)light.r / 255.0f; + f32 lg = (f32)light.g / 255.0f; + f32 lb = (f32)light.b / 255.0f; + i32 add_r = (i32)(brightness * lr * 255.0f); + i32 add_g = (i32)(brightness * lg * 255.0f); + i32 add_b = (i32)(brightness * lb * 255.0f); + + for (u32 pal_idx = 0; pal_idx < 256; pal_idx++) { + u8 result_idx; + + if (pal_idx == PXL8_TRANSPARENT) { + result_idx = PXL8_TRANSPARENT; + } else if (pal_idx >= PXL8_FULLBRIGHT_START) { + result_idx = (u8)pal_idx; + } else { + u32 c = palette[pal_idx]; + i32 r = (i32)(c & 0xFF); + i32 g = (i32)((c >> 8) & 0xFF); + i32 b = (i32)((c >> 16) & 0xFF); + + i32 tr = r + add_r; + i32 tg = g + add_g; + i32 tb = b + add_b; + + result_idx = find_closest_color(palette, + (u8)(tr > 255 ? 255 : tr), + (u8)(tg > 255 ? 255 : tg), + (u8)(tb > 255 ? 255 : tb)); + } + + cm->table[row * 256 + pal_idx] = result_idx; + } + } +} + +static void generate_luminance_table(pxl8_colormap* cm, const u32* palette) { + for (u32 i = 0; i < 256; i++) { + u32 c = palette[i]; + u32 r = c & 0xFF; + u32 g = (c >> 8) & 0xFF; + u32 b = (c >> 16) & 0xFF; + cm->luminance[i] = (u8)((77 * r + 150 * g + 29 * b) >> 8); + } +} + void pxl8_colormap_generate(pxl8_colormap* cm, const u32* palette) { if (!cm || !palette) return; for (u32 light = 0; light < PXL8_LIGHT_COLORS; light++) { generate_light_table(cm, palette, (pxl8_light_color)light); + generate_additive_table(cm, palette, (pxl8_light_color)light); } generate_blend_table(cm, palette); + generate_luminance_table(cm, palette); } diff --git a/src/gfx/pxl8_colormap.h b/src/gfx/pxl8_colormap.h index 584e448..05b4aef 100644 --- a/src/gfx/pxl8_colormap.h +++ b/src/gfx/pxl8_colormap.h @@ -11,7 +11,9 @@ extern "C" { #define PXL8_LIGHT_LEVELS 8 #define PXL8_LIGHT_ROWS (PXL8_LIGHT_COLORS * PXL8_LIGHT_LEVELS) #define PXL8_BLEND_ROWS 256 -#define PXL8_COLORMAP_ROWS (PXL8_LIGHT_ROWS + PXL8_BLEND_ROWS) +#define PXL8_ADDITIVE_ROWS (PXL8_LIGHT_COLORS * PXL8_LIGHT_LEVELS) +#define PXL8_ADDITIVE_START (PXL8_LIGHT_ROWS + PXL8_BLEND_ROWS) +#define PXL8_COLORMAP_ROWS (PXL8_LIGHT_ROWS + PXL8_BLEND_ROWS + PXL8_ADDITIVE_ROWS) #define PXL8_COLORMAP_SIZE (256 * PXL8_COLORMAP_ROWS) #define PXL8_FULLBRIGHT_START 240 @@ -47,6 +49,7 @@ static const pxl8_rgb pxl8_light_colors[PXL8_LIGHT_COLORS] = { typedef struct { u8 table[PXL8_COLORMAP_SIZE]; + u8 luminance[256]; } pxl8_colormap; void pxl8_colormap_generate(pxl8_colormap* cm, const u32* palette); @@ -68,6 +71,17 @@ static inline u8 pxl8_colormap_blend(const pxl8_colormap* cm, u8 src, u8 dst) { return cm->table[(blend_row << 8) + dst]; } +static inline u8 pxl8_colormap_additive(const pxl8_colormap* cm, u8 pal_idx, pxl8_light_color light_color, u8 intensity) { + u32 row = PXL8_ADDITIVE_START + ((u32)light_color << 3) + (intensity >> 5); + return cm->table[(row << 8) + pal_idx]; +} + +static inline u8 pxl8_colormap_additive_dithered(const pxl8_colormap* cm, u8 pal_idx, pxl8_light_color light_color, u8 intensity, u32 x, u32 y) { + u8 dithered = pxl8_gfx_dither((f32)intensity + 0.5f, x, y); + u32 row = PXL8_ADDITIVE_START + ((u32)light_color << 3) + (dithered >> 5); + return cm->table[(row << 8) + pal_idx]; +} + #ifdef __cplusplus } #endif diff --git a/src/gfx/pxl8_gfx.c b/src/gfx/pxl8_gfx.c index 3d2b2ed..06b5dd8 100644 --- a/src/gfx/pxl8_gfx.c +++ b/src/gfx/pxl8_gfx.c @@ -9,6 +9,7 @@ #include "pxl8_color.h" #include "pxl8_colormap.h" #include "pxl8_font.h" +#include "pxl8_glows.h" #include "pxl8_hal.h" #include "pxl8_log.h" #include "pxl8_macros.h" @@ -694,6 +695,7 @@ void pxl8_3d_begin_frame(pxl8_gfx* gfx, const pxl8_3d_camera* camera, const pxl8 pxl8_3d_frame frame = pxl8_3d_frame_from_camera(camera, uniforms); frame.bsp = gfx->bsp; + frame.uniforms.camera_pos = frame.camera_pos; frame.uniforms.lights = lights ? pxl8_lights_data(lights) : NULL; frame.uniforms.lights_count = lights ? pxl8_lights_count(lights) : 0; @@ -765,7 +767,7 @@ void pxl8_3d_clear(pxl8_gfx* gfx, u8 color) { void pxl8_3d_clear_depth(pxl8_gfx* gfx) { if (!gfx) return; - pxl8_clear_depth(gfx->renderer, gfx_current_depth(gfx)); + pxl8_cmdbuf_clear_depth(gfx->cmdbuf, gfx_current_depth(gfx)); } void pxl8_3d_draw_line(pxl8_gfx* gfx, pxl8_vec3 v0, pxl8_vec3 v1, u8 color) { @@ -1043,6 +1045,107 @@ bool pxl8_gfx_get_wireframe(const pxl8_gfx* gfx) { return gfx ? gfx->wireframe : false; } +void pxl8_gfx_apply_effect(pxl8_gfx* gfx, pxl8_gfx_effect effect, const void* params, u32 count) { + if (!gfx || !params || count == 0) return; + + if (effect == PXL8_GFX_EFFECT_GLOWS) { + u8* fb = (u8*)pxl8_texture_get_data(gfx->renderer, gfx_current_color(gfx)); + if (!fb || !gfx->colormap) return; + + u16* zb = (u16*)pxl8_texture_get_data(gfx->renderer, gfx_current_depth(gfx)); + i32 w = gfx->framebuffer_width; + i32 h = gfx->framebuffer_height; + const pxl8_glow* glows = (const pxl8_glow*)params; + + for (u32 i = 0; i < count; i++) { + const pxl8_glow* g = &glows[i]; + i32 cx = g->x; + i32 cy = g->y; + i32 r = (i32)g->radius; + if (r <= 0) continue; + + bool depth_test = g->depth > 0 && zb; + f32 base_intensity = (f32)g->intensity / 255.0f; + f32 inv_r = 1.0f / (f32)r; + + i32 x0 = cx - r; + i32 y0 = cy - r; + i32 x1 = cx + r; + i32 y1 = cy + r; + + if (g->shape == PXL8_GLOW_SHAFT) { + i32 sh = (i32)g->height; + if (sh <= 0) sh = 1; + y0 = cy - sh; + y1 = cy + sh; + } + + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= w) x1 = w - 1; + if (y1 >= h) y1 = h - 1; + + for (i32 py = y0; py <= y1; py++) { + i32 dy = py - cy; + for (i32 px = x0; px <= x1; px++) { + i32 idx = py * w + px; + + if (depth_test && zb[idx] < g->depth) continue; + + u8 src = fb[idx]; + if (src == PXL8_TRANSPARENT) continue; + + i32 dx = px - cx; + f32 falloff; + + switch (g->shape) { + case PXL8_GLOW_CIRCLE: { + f32 dist_sq = (f32)(dx * dx + dy * dy); + f32 norm = dist_sq * inv_r * inv_r; + if (norm >= 1.0f) continue; + falloff = 1.0f - norm; + falloff *= falloff; + break; + } + case PXL8_GLOW_DIAMOND: { + f32 manhattan = (f32)(abs(dx) + abs(dy)); + f32 norm = manhattan * inv_r; + if (norm >= 1.0f) continue; + falloff = 1.0f - norm; + falloff *= falloff; + break; + } + case PXL8_GLOW_SHAFT: { + f32 abs_dx = (f32)abs(dx); + if (abs_dx >= (f32)r) continue; + f32 x_falloff = 1.0f - abs_dx * inv_r; + i32 sh = (i32)g->height; + if (sh <= 0) sh = 1; + f32 abs_dy = (f32)abs(dy); + f32 y_falloff = 1.0f - abs_dy / (f32)sh; + falloff = x_falloff * y_falloff; + falloff *= falloff; + break; + } + default: continue; + } + + f32 brightness = falloff * base_intensity; + f32 raw = brightness * 255.0f; + if (raw > 255.0f) raw = 255.0f; + u8 light_u8 = (u8)raw; + if (light_u8 < 4) continue; + + fb[idx] = pxl8_colormap_additive_dithered( + gfx->colormap, src, g->color, + light_u8, (u32)px, (u32)py + ); + } + } + } + } +} + u8 pxl8_gfx_get_ambient(const pxl8_gfx* gfx) { return gfx ? gfx->frame.uniforms.ambient : 0; } diff --git a/src/gfx/pxl8_glows.c b/src/gfx/pxl8_glows.c index 018fea5..a817bc9 100644 --- a/src/gfx/pxl8_glows.c +++ b/src/gfx/pxl8_glows.c @@ -33,7 +33,7 @@ void pxl8_glows_destroy(pxl8_glows* glows) { pxl8_free(glows); } -void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape) { +void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape, u16 depth) { if (!glows || glows->count >= glows->capacity) return; pxl8_glow* g = &glows->data[glows->count++]; @@ -43,7 +43,7 @@ void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u g->intensity = intensity; g->color = color; g->shape = shape; - g->depth = 0xFFFF; + g->depth = depth; g->height = 0; } diff --git a/src/gfx/pxl8_glows.h b/src/gfx/pxl8_glows.h index 5edb1bd..f307a3d 100644 --- a/src/gfx/pxl8_glows.h +++ b/src/gfx/pxl8_glows.h @@ -31,7 +31,7 @@ extern "C" { pxl8_glows* pxl8_glows_create(u32 capacity); void pxl8_glows_destroy(pxl8_glows* glows); -void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape); +void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape, u16 depth); void pxl8_glows_clear(pxl8_glows* glows); u32 pxl8_glows_count(const pxl8_glows* glows); const pxl8_glow* pxl8_glows_data(const pxl8_glows* glows); diff --git a/src/gfx/pxl8_palette.c b/src/gfx/pxl8_palette.c index 6e32aef..632302f 100644 --- a/src/gfx/pxl8_palette.c +++ b/src/gfx/pxl8_palette.c @@ -148,7 +148,7 @@ static void pxl8_palette_sort_colors(pxl8_palette* pal) { pal->color_ramp[0] = 0; - u8 count = pal->color_count; + u16 count = pal->color_count; palette_sort_entry entries[PXL8_PALETTE_SIZE - 1]; for (u32 i = 1; i < count; i++) { u8 r, g, b, a; diff --git a/src/gfx/pxl8_render.c b/src/gfx/pxl8_render.c index 2ecf566..00c3362 100644 --- a/src/gfx/pxl8_render.c +++ b/src/gfx/pxl8_render.c @@ -87,18 +87,15 @@ static u8 blend_indexed( const pxl8_gfx_pipeline_desc* pipeline, u8 src, u8 dst, - const u32* palette, - const u8* colormap + const u32* palette ) { - (void)colormap; if (!pipeline || !pipeline->blend.enabled) return src; if (src == 0) return dst; if (!palette) return src; - f32 src_a = src == 0 ? 0.0f : 1.0f; f32 dst_a = dst == 0 ? 0.0f : 1.0f; - f32 sf = blend_factor_value(pipeline->blend.src, src_a, dst_a); - f32 df = blend_factor_value(pipeline->blend.dst, src_a, dst_a); + f32 sf = blend_factor_value(pipeline->blend.src, 1.0f, dst_a); + f32 df = blend_factor_value(pipeline->blend.dst, 1.0f, dst_a); if (sf == 1.0f && df == 0.0f) return src; if (sf == 0.0f && df == 1.0f) return dst; @@ -111,18 +108,11 @@ static u8 blend_indexed( u8 dg = (palette[dst] >> 8) & 0xFF; u8 db = (palette[dst] >> 16) & 0xFF; - i32 out_r = (i32)(sr * sf + dr * df); - i32 out_g = (i32)(sg * sf + dg * df); - i32 out_b = (i32)(sb * sf + db * df); + u8 out_r = (u8)pxl8_clamp_byte((i32)(sr * sf + dr * df)); + u8 out_g = (u8)pxl8_clamp_byte((i32)(sg * sf + dg * df)); + u8 out_b = (u8)pxl8_clamp_byte((i32)(sb * sf + db * df)); - if (out_r < 0) out_r = 0; - if (out_g < 0) out_g = 0; - if (out_b < 0) out_b = 0; - if (out_r > 255) out_r = 255; - if (out_g > 255) out_g = 255; - if (out_b > 255) out_b = 255; - - return palette_find_closest(palette, (u8)out_r, (u8)out_g, (u8)out_b); + return palette_find_closest(palette, out_r, out_g, out_b); } static inline pxl8_vec4 vec4_lerp(pxl8_vec4 a, pxl8_vec4 b, f32 t) { @@ -192,6 +182,15 @@ static i32 clip_triangle_near( return 6; } +static inline pxl8_vec3 clip_to_screen(pxl8_vec4 clip, f32 vp_x, f32 vp_y, f32 hw, f32 hh) { + f32 inv_w = 1.0f / clip.w; + return (pxl8_vec3){ + vp_x + hw + clip.x * inv_w * hw, + vp_y + hh - clip.y * inv_w * hh, + clip.z * inv_w, + }; +} + static bool setup_tri( tri_setup* setup, const raster_vertex* vo0, const raster_vertex* vo1, const raster_vertex* vo2, @@ -203,18 +202,12 @@ static bool setup_tri( f32 hw = (f32)viewport_w * 0.5f; f32 hh = (f32)viewport_h * 0.5f; + f32 vp_xf = (f32)viewport_x; + f32 vp_yf = (f32)viewport_y; - setup->p0.x = (f32)viewport_x + hw + vo0->clip_pos.x / vo0->clip_pos.w * hw; - setup->p0.y = (f32)viewport_y + hh - vo0->clip_pos.y / vo0->clip_pos.w * hh; - setup->p0.z = vo0->clip_pos.z / vo0->clip_pos.w; - - setup->p1.x = (f32)viewport_x + hw + vo1->clip_pos.x / vo1->clip_pos.w * hw; - setup->p1.y = (f32)viewport_y + hh - vo1->clip_pos.y / vo1->clip_pos.w * hh; - setup->p1.z = vo1->clip_pos.z / vo1->clip_pos.w; - - setup->p2.x = (f32)viewport_x + hw + vo2->clip_pos.x / vo2->clip_pos.w * hw; - setup->p2.y = (f32)viewport_y + hh - vo2->clip_pos.y / vo2->clip_pos.w * hh; - setup->p2.z = vo2->clip_pos.z / vo2->clip_pos.w; + setup->p0 = clip_to_screen(vo0->clip_pos, vp_xf, vp_yf, hw, hh); + setup->p1 = clip_to_screen(vo1->clip_pos, vp_xf, vp_yf, hw, hh); + setup->p2 = clip_to_screen(vo2->clip_pos, vp_xf, vp_yf, hw, hh); f32 cross = (setup->p1.x - setup->p0.x) * (setup->p2.y - setup->p0.y) - (setup->p1.y - setup->p0.y) * (setup->p2.x - setup->p0.x); @@ -303,7 +296,6 @@ static void rasterize_triangle( u8 alpha_ref = pipeline ? pipeline->blend.alpha_ref : 0; bool blend_enabled = pipeline && pipeline->blend.enabled; const u32* palette = bindings ? bindings->palette : NULL; - const u8* colormap = bindings ? bindings->colormap : NULL; for (i32 y = setup->y_start; y <= setup->y_end; y++) { f32 yf = (f32)y + 0.5f; @@ -548,7 +540,7 @@ static void rasterize_triangle( if (color != 0) { u8 out_color = color; if (blend_enabled) { - out_color = blend_indexed(pipeline, color, prow[px], palette, colormap); + out_color = blend_indexed(pipeline, color, prow[px], palette); } prow[px] = out_color; @@ -594,7 +586,7 @@ static void rasterize_triangle( if (color != 0) { u8 out_color = color; if (blend_enabled) { - out_color = blend_indexed(pipeline, color, prow[px], palette, colormap); + out_color = blend_indexed(pipeline, color, prow[px], palette); } prow[px] = out_color; @@ -1142,6 +1134,12 @@ void pxl8_begin_pass(pxl8_gfx_cmdbuf* cb, pxl8_gfx_pass pass) { cmd->begin_pass.pass = pass; } +void pxl8_cmdbuf_clear_depth(pxl8_gfx_cmdbuf* cb, pxl8_gfx_texture texture) { + pxl8_gfx_cmd* cmd = cmd_alloc(cb); + cmd->type = PXL8_GFX_CMD_CLEAR_DEPTH; + cmd->clear_depth.texture = texture; +} + void pxl8_end_pass(pxl8_gfx_cmdbuf* cb) { pxl8_gfx_cmd* cmd = cmd_alloc(cb); cmd->type = PXL8_GFX_CMD_END_PASS; @@ -1370,17 +1368,16 @@ static void execute_draw( if (is_wireframe) { f32 hw = (f32)vp_w * 0.5f; f32 hh = (f32)vp_h * 0.5f; + f32 vp_xf = (f32)vp_x; + f32 vp_yf = (f32)vp_y; - raster_vertex* wv0 = &clipped[t]; - raster_vertex* wv1 = &clipped[t+1]; - raster_vertex* wv2 = &clipped[t+2]; + pxl8_vec3 s0 = clip_to_screen(clipped[t].clip_pos, vp_xf, vp_yf, hw, hh); + pxl8_vec3 s1 = clip_to_screen(clipped[t+1].clip_pos, vp_xf, vp_yf, hw, hh); + pxl8_vec3 s2 = clip_to_screen(clipped[t+2].clip_pos, vp_xf, vp_yf, hw, hh); - i32 sx0 = (i32)((f32)vp_x + hw + wv0->clip_pos.x / wv0->clip_pos.w * hw); - i32 sy0 = (i32)((f32)vp_y + hh - wv0->clip_pos.y / wv0->clip_pos.w * hh); - i32 sx1 = (i32)((f32)vp_x + hw + wv1->clip_pos.x / wv1->clip_pos.w * hw); - i32 sy1 = (i32)((f32)vp_y + hh - wv1->clip_pos.y / wv1->clip_pos.w * hh); - i32 sx2 = (i32)((f32)vp_x + hw + wv2->clip_pos.x / wv2->clip_pos.w * hw); - i32 sy2 = (i32)((f32)vp_y + hh - wv2->clip_pos.y / wv2->clip_pos.w * hh); + i32 sx0 = (i32)s0.x, sy0 = (i32)s0.y; + i32 sx1 = (i32)s1.x, sy1 = (i32)s1.y; + i32 sx2 = (i32)s2.x, sy2 = (i32)s2.y; f32 cross = (f32)(sx1 - sx0) * (f32)(sy2 - sy0) - (f32)(sy1 - sy0) * (f32)(sx2 - sx0); if (!double_sided) { @@ -1427,6 +1424,9 @@ void pxl8_gfx_submit(pxl8_renderer* r, pxl8_gfx_cmdbuf* cb) { } } break; + case PXL8_GFX_CMD_CLEAR_DEPTH: + pxl8_clear_depth(r, cmd->clear_depth.texture); + break; case PXL8_GFX_CMD_END_PASS: r->current_pass = (pxl8_gfx_pass){ PXL8_GFX_INVALID_ID }; break; diff --git a/src/gfx/pxl8_render.h b/src/gfx/pxl8_render.h index 04c624f..d8db971 100644 --- a/src/gfx/pxl8_render.h +++ b/src/gfx/pxl8_render.h @@ -48,6 +48,7 @@ void pxl8_cmdbuf_destroy(pxl8_gfx_cmdbuf* cb); void pxl8_cmdbuf_reset(pxl8_gfx_cmdbuf* cb); void pxl8_begin_pass(pxl8_gfx_cmdbuf* cb, pxl8_gfx_pass pass); +void pxl8_cmdbuf_clear_depth(pxl8_gfx_cmdbuf* cb, pxl8_gfx_texture texture); void pxl8_end_pass(pxl8_gfx_cmdbuf* cb); void pxl8_set_bindings(pxl8_gfx_cmdbuf* cb, pxl8_gfx_bindings bindings); void pxl8_set_draw_params(pxl8_gfx_cmdbuf* cb, const pxl8_gfx_cmd_draw_params* p); diff --git a/src/gfx/pxl8_render_types.h b/src/gfx/pxl8_render_types.h index c3d3836..6790bc7 100644 --- a/src/gfx/pxl8_render_types.h +++ b/src/gfx/pxl8_render_types.h @@ -177,14 +177,15 @@ typedef struct pxl8_gfx_cmd_draw_params { typedef enum pxl8_gfx_cmd_type { PXL8_GFX_CMD_BEGIN_PASS, - PXL8_GFX_CMD_END_PASS, - PXL8_GFX_CMD_SET_PIPELINE, - PXL8_GFX_CMD_SET_BINDINGS, - PXL8_GFX_CMD_SET_VIEWPORT, - PXL8_GFX_CMD_SET_SCISSOR, - PXL8_GFX_CMD_SET_DRAW_PARAMS, + PXL8_GFX_CMD_CLEAR_DEPTH, PXL8_GFX_CMD_DRAW, + PXL8_GFX_CMD_END_PASS, PXL8_GFX_CMD_RESOLVE, + PXL8_GFX_CMD_SET_BINDINGS, + PXL8_GFX_CMD_SET_DRAW_PARAMS, + PXL8_GFX_CMD_SET_PIPELINE, + PXL8_GFX_CMD_SET_SCISSOR, + PXL8_GFX_CMD_SET_VIEWPORT, } pxl8_gfx_cmd_type; typedef struct pxl8_gfx_cmd_begin_pass { @@ -217,6 +218,10 @@ typedef struct pxl8_gfx_cmd_draw { u32 index_count; } pxl8_gfx_cmd_draw; +typedef struct pxl8_gfx_cmd_clear_depth { + pxl8_gfx_texture texture; +} pxl8_gfx_cmd_clear_depth; + typedef struct pxl8_gfx_cmd_resolve { pxl8_gfx_texture src; u32* output; @@ -226,13 +231,14 @@ typedef struct pxl8_gfx_cmd { pxl8_gfx_cmd_type type; union { pxl8_gfx_cmd_begin_pass begin_pass; - pxl8_gfx_cmd_set_pipeline set_pipeline; - pxl8_gfx_cmd_set_bindings set_bindings; - pxl8_gfx_cmd_set_viewport set_viewport; - pxl8_gfx_cmd_set_scissor set_scissor; + pxl8_gfx_cmd_clear_depth clear_depth; pxl8_gfx_cmd_draw draw; pxl8_gfx_cmd_draw_params draw_params; pxl8_gfx_cmd_resolve resolve; + pxl8_gfx_cmd_set_bindings set_bindings; + pxl8_gfx_cmd_set_pipeline set_pipeline; + pxl8_gfx_cmd_set_scissor set_scissor; + pxl8_gfx_cmd_set_viewport set_viewport; }; } pxl8_gfx_cmd; diff --git a/src/gfx/pxl8_shader.h b/src/gfx/pxl8_shader.h index 3c41386..a4f47fe 100644 --- a/src/gfx/pxl8_shader.h +++ b/src/gfx/pxl8_shader.h @@ -28,6 +28,7 @@ typedef struct pxl8_vertex_out { typedef struct pxl8_shader_uniforms { u8 ambient; bool baked_lighting; + pxl8_vec3 camera_pos; pxl8_vec3 celestial_dir; f32 celestial_intensity; bool dither; diff --git a/src/gfx/shaders/cpu/lit.c b/src/gfx/shaders/cpu/lit.c index b776fef..fa71b19 100644 --- a/src/gfx/shaders/cpu/lit.c +++ b/src/gfx/shaders/cpu/lit.c @@ -32,6 +32,7 @@ void pxl8_shader_lit( } pxl8_f32_simd light = ctx->v_light; + pxl8_f32_simd dynamic_total = pxl8_f32_simd_zero(); f32 max_strength[4] = {0, 0, 0, 0}; u8 dominant_color[4] = {0, 0, 0, 0}; @@ -101,10 +102,31 @@ void pxl8_shader_lit( } light = pxl8_f32_simd_add(light, strength); + dynamic_total = pxl8_f32_simd_add(dynamic_total, strength); } } light = pxl8_f32_simd_clamp(light, pxl8_f32_simd_zero(), pxl8_f32_simd_set(1.0f)); + dynamic_total = pxl8_f32_simd_clamp(dynamic_total, pxl8_f32_simd_zero(), pxl8_f32_simd_set(1.0f)); + + if (uniforms && uniforms->fog_density > 0.0f) { + pxl8_vec3_simd cam = pxl8_vec3_simd_set(uniforms->camera_pos); + pxl8_vec3_simd to_frag = pxl8_vec3_simd_sub(ctx->v_world, cam); + pxl8_f32_simd dist_sq = pxl8_vec3_simd_dot(to_frag, to_frag); + pxl8_f32_simd fog_sq = pxl8_f32_simd_set(uniforms->fog_density * uniforms->fog_density); + pxl8_f32_simd fog = pxl8_f32_simd_clamp( + pxl8_f32_simd_mul(dist_sq, fog_sq), + pxl8_f32_simd_zero(), pxl8_f32_simd_set(1.0f) + ); + light = pxl8_f32_simd_mul(light, pxl8_f32_simd_sub(pxl8_f32_simd_set(1.0f), fog)); + pxl8_f32_simd scatter = pxl8_f32_simd_mul( + pxl8_f32_simd_mul(dynamic_total, fog), + pxl8_f32_simd_set(0.4f) + ); + light = pxl8_f32_simd_add(light, scatter); + light = pxl8_f32_simd_clamp(light, pxl8_f32_simd_zero(), pxl8_f32_simd_set(1.0f)); + } + pxl8_f32_simd light_f = pxl8_f32_simd_mul(light, pxl8_f32_simd_set(255.0f)); f32 light_arr[4]; @@ -133,6 +155,7 @@ void pxl8_shader_lit( } f32 light = ctx->v_light; + f32 dynamic_total = 0.0f; f32 max_strength = 0; u8 dominant_color = 0; @@ -178,11 +201,25 @@ void pxl8_shader_lit( dominant_color = l->color; } light += strength; + dynamic_total += strength; } } if (light > 1.0f) light = 1.0f; if (light < 0.0f) light = 0.0f; + if (dynamic_total > 1.0f) dynamic_total = 1.0f; + + if (uniforms && uniforms->fog_density > 0.0f) { + f32 dx = ctx->v_world.x - uniforms->camera_pos.x; + f32 dy = ctx->v_world.y - uniforms->camera_pos.y; + f32 dz = ctx->v_world.z - uniforms->camera_pos.z; + f32 dist_sq = dx * dx + dy * dy + dz * dz; + f32 fog = dist_sq * uniforms->fog_density * uniforms->fog_density; + if (fog > 1.0f) fog = 1.0f; + light *= (1.0f - fog); + light += dynamic_total * fog * 0.4f; + if (light > 1.0f) light = 1.0f; + } f32 light_f = light * 255.0f; u8 light_u8 = (u8)light_f; diff --git a/src/lua/pxl8.lua b/src/lua/pxl8.lua index 0f5c486..1bc830c 100644 --- a/src/lua/pxl8.lua +++ b/src/lua/pxl8.lua @@ -106,6 +106,20 @@ pxl8.get_wireframe = gfx.get_wireframe pxl8.Lights = effects.Lights pxl8.create_lights = effects.Lights.new +pxl8.Glows = effects.Glows +pxl8.create_glows = effects.Glows.new +pxl8.GLOW_CIRCLE = 0 +pxl8.GLOW_DIAMOND = 1 +pxl8.GLOW_SHAFT = 2 + +pxl8.LIGHT_WHITE = 0 +pxl8.LIGHT_RED = 1 +pxl8.LIGHT_ORANGE = 2 +pxl8.LIGHT_YELLOW = 3 +pxl8.LIGHT_GREEN = 4 +pxl8.LIGHT_CYAN = 5 +pxl8.LIGHT_BLUE = 6 +pxl8.LIGHT_PURPLE = 7 pxl8.Compressor = sfx.Compressor pxl8.create_compressor = sfx.Compressor.new diff --git a/src/lua/pxl8/effects.lua b/src/lua/pxl8/effects.lua index 567d64c..43fa741 100644 --- a/src/lua/pxl8/effects.lua +++ b/src/lua/pxl8/effects.lua @@ -1,5 +1,6 @@ local ffi = require("ffi") local C = ffi.C +local core = require("pxl8.core") local effects = {} @@ -35,4 +36,40 @@ end effects.Lights = Lights +local Glows = {} +Glows.__index = Glows + +function Glows.new(capacity) + local ptr = C.pxl8_glows_create(capacity or 256) + if ptr == nil then + return nil + end + return setmetatable({ _ptr = ptr }, Glows) +end + +function Glows:add(x, y, radius, intensity, color, shape, depth) + C.pxl8_glows_add(self._ptr, x, y, radius or 32, intensity or 128, color or 0, shape or 0, depth or 0xFFFF) +end + +function Glows:clear() + C.pxl8_glows_clear(self._ptr) +end + +function Glows:count() + return C.pxl8_glows_count(self._ptr) +end + +function Glows:render() + C.pxl8_glows_render(self._ptr, core.gfx) +end + +function Glows:destroy() + if self._ptr then + C.pxl8_glows_destroy(self._ptr) + self._ptr = nil + end +end + +effects.Glows = Glows + return effects diff --git a/src/lua/pxl8/world.lua b/src/lua/pxl8/world.lua index 990e53b..27bc6b6 100644 --- a/src/lua/pxl8/world.lua +++ b/src/lua/pxl8/world.lua @@ -18,6 +18,10 @@ function Bsp:face_normal(face_id) return C.pxl8_bsp_face_normal(self._ptr, face_id) end +function Bsp:light_at(x, y, z, ambient) + return C.pxl8_bsp_light_at(self._ptr, x, y, z, ambient or 0) +end + function Bsp:face_set_material(face_id, material_id) C.pxl8_bsp_face_set_material(self._ptr, face_id, material_id) end diff --git a/src/math/pxl8_math.h b/src/math/pxl8_math.h index 4288732..23f5c3d 100644 --- a/src/math/pxl8_math.h +++ b/src/math/pxl8_math.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include "pxl8_types.h" diff --git a/src/script/pxl8_script_ffi.h b/src/script/pxl8_script_ffi.h index a7577a3..9f2206a 100644 --- a/src/script/pxl8_script_ffi.h +++ b/src/script/pxl8_script_ffi.h @@ -220,8 +220,17 @@ static const char* pxl8_ffi_cdefs = "u32 pxl8_lights_count(const pxl8_lights* lights);\n" "const pxl8_light* pxl8_lights_data(const pxl8_lights* lights);\n" "\n" +"typedef struct pxl8_glows pxl8_glows;\n" +"pxl8_glows* pxl8_glows_create(u32 capacity);\n" +"void pxl8_glows_destroy(pxl8_glows* glows);\n" +"void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape, u16 depth);\n" +"void pxl8_glows_clear(pxl8_glows* glows);\n" +"u32 pxl8_glows_count(const pxl8_glows* glows);\n" +"void pxl8_glows_render(pxl8_glows* glows, pxl8_gfx* gfx);\n" +"\n" "typedef struct pxl8_3d_uniforms {\n" " u8 ambient;\n" +" pxl8_vec3 camera_pos;\n" " pxl8_vec3 celestial_dir;\n" " f32 celestial_intensity;\n" " u8 fog_color;\n" @@ -392,6 +401,7 @@ static const char* pxl8_ffi_cdefs = "\n" "u32 pxl8_bsp_face_count(const pxl8_bsp* bsp);\n" "pxl8_vec3 pxl8_bsp_face_normal(const pxl8_bsp* bsp, u32 face_id);\n" +"u8 pxl8_bsp_light_at(const pxl8_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient);\n" "\n" "typedef enum { PXL8_WORLD_CHUNK_VXL = 0, PXL8_WORLD_CHUNK_BSP = 1 } pxl8_world_chunk_type;\n" "\n"