Forge 1.18.1 Client Log

#ZL6JYRd
176 errors
20697 lines
Raw
Analysis
Minecraft version:
1.18.1
Forge version:
39.0.17
Java version:
17.0.1
1[11Jan2022 17:17:12.316] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, DvI_y, --version, 1.18.1-forge-39.0.17, --gameDir, C:\Users\PC\AppData\Roaming\.minecraft, --assetsDir, C:\Users\PC\AppData\Roaming\.minecraft\assets, --assetIndex, 1.18, --uuid, 5e8660f7df7b4aad8405bd65e7b7e8f5, --accessToken, ????????, --clientId, NTg2NDg1ODEtNTBmNC00YTk1LTgyN2EtMTdkZGI0Y2UyY2Yx, --xuid, 2535405237799348, --userType, msa, --versionType, release, --launchTarget, forgeclient, --fml.forgeVersion, 39.0.17, --fml.mcVersion, 1.18.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20211210.034407]
2[11Jan2022 17:17:12.321] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 9.0.7+91+master.8569cdf starting: java version 17.0.1 by Microsoft
3[11Jan2022 17:17:12.569] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.onLoad
4[11Jan2022 17:17:12.570] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file URL: union:/C:/Users/PC/AppData/Roaming/.minecraft/mods/OptiFine_1.18.1_HD_U_H4.jar%2352!
5[11Jan2022 17:17:12.580] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file: C:\Users\PC\AppData\Roaming\.minecraft\mods\OptiFine_1.18.1_HD_U_H4.jar
6[11Jan2022 17:17:12.582] [main/INFO] [optifine.OptiFineTransformer/]: Target.PRE_CLASS is available
7[11Jan2022 17:17:12.653] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/PC/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2319! Service=ModLauncher Env=CLIENT
8[11Jan2022 17:17:12.662] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.initialize
9[11Jan2022 17:17:13.653] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.transformers
10[11Jan2022 17:17:13.659] [main/INFO] [optifine.OptiFineTransformer/]: Targets: 342
11[11Jan2022 17:17:14.110] [main/INFO] [optifine.OptiFineTransformationService/]: additionalClassesLocator: [optifine., net.optifine.]
12[11Jan2022 17:17:14.553] [main/INFO] [mixin/]: Compatibility level set to JAVA_17
13[11Jan2022 17:17:14.559] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeclient' with arguments [--version, 1.18.1-forge-39.0.17, --gameDir, C:\Users\PC\AppData\Roaming\.minecraft, --assetsDir, C:\Users\PC\AppData\Roaming\.minecraft\assets, --uuid, 5e8660f7df7b4aad8405bd65e7b7e8f5, --username, DvI_y, --assetIndex, 1.18, --accessToken, ????????, --clientId, NTg2NDg1ODEtNTBmNC00YTk1LTgyN2EtMTdkZGI0Y2UyY2Yx, --xuid, 2535405237799348, --userType, msa, --versionType, release]
14[11Jan2022 17:17:14.883] [main/WARN] [mixin/]: Error loading class: net/minecraft/client/renderer/LevelRenderer (java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9)
15[11Jan2022 17:17:14.883] [main/WARN] [mixin/]: @Mixin target net.minecraft.client.renderer.LevelRenderer was not found flywheel.mixins.json:CancelEntityRenderMixin
16[17:17:23] [Render thread/WARN]: Assets URL 'union:/C:/Users/PC/AppData/Roaming/.minecraft/libraries/net/minecraft/client/1.18.1-20211210.034407/client-1.18.1-20211210.034407-srg.jar%2357!/assets/.mcassetsroot' uses unexpected schema
17[17:17:23] [Render thread/WARN]: Assets URL 'union:/C:/Users/PC/AppData/Roaming/.minecraft/libraries/net/minecraft/client/1.18.1-20211210.034407/client-1.18.1-20211210.034407-srg.jar%2357!/data/.mcassetsroot' uses unexpected schema
18[11Jan2022 17:17:23.450] [Render thread/INFO] [com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService/]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
19[17:17:24] [Render thread/INFO]: Setting user: DvI_y
20[17:17:24] [Render thread/INFO]: [OptiFine] (Reflector) Class not present: net.minecraft.launchwrapper.Launch
21[17:17:24] [Render thread/INFO]: Backend library: LWJGL version 3.2.2 SNAPSHOT
22[17:17:25] [Render thread/INFO]: [OptiFine]
23[17:17:25] [Render thread/INFO]: [OptiFine] OptiFine_1.18.1_HD_U_H4
24[17:17:25] [Render thread/INFO]: [OptiFine] Build: 20211212-175054
25[17:17:25] [Render thread/INFO]: [OptiFine] OS: Windows 10 (amd64) version 10.0
26[17:17:25] [Render thread/INFO]: [OptiFine] Java: 17.0.1, Microsoft
27[17:17:25] [Render thread/INFO]: [OptiFine] VM: OpenJDK 64-Bit Server VM (mixed mode), Microsoft
28[17:17:25] [Render thread/INFO]: [OptiFine] LWJGL: 3.3.0 Win32 WGL EGL OSMesa VisualC DLL
29[17:17:25] [Render thread/INFO]: [OptiFine] OpenGL: Radeon RX 580 Series, version 3.2.14761 Core Profile Forward-Compatible Context 21.10.2 30.0.13025.5005, ATI Technologies Inc.
30[17:17:25] [Render thread/INFO]: [OptiFine] OpenGL Version: 3.2.14761
31[17:17:25] [Render thread/INFO]: [OptiFine] Maximum texture size: 16384x16384
32[17:17:25] [VersionCheck/INFO]: [OptiFine] Checking for new version
33[17:17:25] [Render thread/INFO]: [Shaders] OpenGL Version: 3.2.14761 Core Profile Forward-Compatible Context 21.10.2 30.0.13025.5005
34[17:17:25] [Render thread/INFO]: [Shaders] Vendor: ATI Technologies Inc.
35[17:17:25] [Render thread/INFO]: [Shaders] Renderer: Radeon RX 580 Series
36[17:17:25] [Render thread/INFO]: [Shaders] Capabilities: 2.0 2.1 3.0 3.2 -
37[17:17:25] [Render thread/INFO]: [Shaders] GL_MAX_DRAW_BUFFERS: 8
38[17:17:25] [Render thread/INFO]: [Shaders] GL_MAX_COLOR_ATTACHMENTS: 8
39[17:17:25] [Render thread/INFO]: [Shaders] GL_MAX_TEXTURE_IMAGE_UNITS: 32
40[17:17:25] [Render thread/INFO]: [Shaders] Load shaders configuration.
41[17:17:25] [Render thread/INFO]: [Shaders] No shaderpack loaded.
42[17:17:25] [Render thread/INFO]: [OptiFine] [Shaders] Delayed loading of item mappings after resources are loaded
43[17:17:25] [Render thread/INFO]: [OptiFine] [Shaders] Delayed loading of entity mappings after resources are loaded
44[17:17:26] [modloading-worker-0/INFO]: Forge mod loading, version 39.0.17, for MC 1.18.1 with MCP 20211210.034407
45[17:17:26] [modloading-worker-0/INFO]: MinecraftForge v39.0.17 Initialized
46[17:17:26] [modloading-worker-0/INFO]: Optifine detected.
47[17:17:26] [modloading-worker-0/INFO]: Successfully loaded com.jozufozu.flywheel.mixin.PausedPartialTickAccessor
48[17:17:26] [VersionCheck/INFO]: [OptiFine] java.io.FileNotFoundException: http://optifine.net/version/1.18.1/HD_U.txt
49[17:17:26] [modloading-worker-0/INFO]: Detected new forge version, registering events reflectively.
50[17:17:29] [Render thread/INFO]: Potentially Dangerous alternative prefix `minecraft` for name `milk`, expected `forge`. This could be a intended override, but in most cases indicates a broken mod.
51[17:17:29] [Render thread/INFO]: Potentially Dangerous alternative prefix `minecraft` for name `flowing_milk`, expected `forge`. This could be a intended override, but in most cases indicates a broken mod.
52[17:17:29] [Render thread/WARN]: [OptiFine] (Reflector) java.lang.ClassNotFoundException: sun.misc.SharedSecrets
53[17:17:29] [Render thread/WARN]: [OptiFine] (Reflector) java.lang.ClassNotFoundException: jdk.internal.misc.SharedSecrets
54[17:17:29] [Render thread/WARN]: [OptiFine] (Reflector) java.lang.ClassNotFoundException: sun.misc.VM
55[17:17:29] [Render thread/WARN]: [OptiFine] (Reflector) java.lang.reflect.InaccessibleObjectException: Unable to make public static long jdk.internal.misc.VM.maxDirectMemory() accessible: module java.base does not "exports jdk.internal.misc" to module net.optifine
56[11Jan2022 17:17:30.466] [Render thread/INFO] [com.mojang.text2speech.NarratorWindows/]: Narrator library for x64 successfully loaded
57[17:17:30] [Render thread/INFO]: Reloading ResourceManager: Default, Mod Resources
58[17:17:30] [Render thread/INFO]: [OptiFine] *** Reloading textures ***
59[17:17:30] [Render thread/INFO]: [OptiFine] Resource packs: Mod Resources
60[17:17:30] [Render thread/INFO]: [OptiFine] *** Reflector Forge ***
61[17:17:30] [Render thread/INFO]: [OptiFine] (Reflector) Class not present: mods.betterfoliage.client.BetterFoliageClient
62[17:17:31] [Render thread/INFO]: [OptiFine] *** Reflector Vanilla ***
63[17:17:31] [Worker-Main-9/INFO]: [OptiFine] Multitexture: false
64[17:17:31] [Worker-Main-15/INFO]: [OptiFine] Multitexture: false
65[17:17:31] [Worker-Main-13/INFO]: [OptiFine] Multitexture: false
66[17:17:31] [Worker-Main-12/INFO]: [OptiFine] Multitexture: false
67[11Jan2022 17:17:31.876] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [forge] Starting version check at https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json
68[17:17:32] [Worker-Main-12/INFO]: [OptiFine] Scaled non power of 2: jei:gui/icons/recipe_transfer, 7 -> 14
69[17:17:32] [Worker-Main-15/INFO]: Loading Xaero's Minimap - Stage 1/2
70[17:17:33] [Render thread/INFO]: Loading Xaero's Minimap - Stage 2/2
71[11Jan2022 17:17:33.167] [Forge Version Check/INFO] [net.minecraftforge.fml.VersionChecker/]: [forge] Found status: BETA_OUTDATED Current: 39.0.17 Target: 39.0.18
72[17:17:39] [Worker-Main-11/WARN]: [OptiFine] Unknown resource pack file: mod_resources
73[17:17:39] [Worker-Main-11/WARN]: [OptiFine] Unknown resource pack file: mod_resources
74[17:17:39] [Worker-Main-11/WARN]: [OptiFine] Unknown resource pack file: mod_resources
75[17:17:39] [Worker-Main-11/WARN]: [OptiFine] Unknown resource pack file: mod_resources
76[17:17:40] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
77[17:17:40] [Worker-Main-11/WARN]: [OptiFine] Unknown resource pack file: mod_resources
78[17:17:40] [Worker-Main-11/INFO]: [OptiFine] Multipass connected textures: false
79[17:17:40] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/00_glass_white/glass_pane_white.properties
80[17:17:40] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/00_glass_white/glass_white.properties
81[17:17:40] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/01_glass_orange/glass_orange.properties
82[17:17:40] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/01_glass_orange/glass_pane_orange.properties
83[17:17:40] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/02_glass_magenta/glass_magenta.properties
84[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/02_glass_magenta/glass_pane_magenta.properties
85[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/03_glass_light_blue/glass_light_blue.properties
86[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/03_glass_light_blue/glass_pane_light_blue.properties
87[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/04_glass_yellow/glass_pane_yellow.properties
88[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/04_glass_yellow/glass_yellow.properties
89[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/05_glass_lime/glass_lime.properties
90[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/05_glass_lime/glass_pane_lime.properties
91[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/06_glass_pink/glass_pane_pink.properties
92[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/06_glass_pink/glass_pink.properties
93[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/07_glass_gray/glass_gray.properties
94[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/07_glass_gray/glass_pane_gray.properties
95[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/08_glass_light_gray/glass_light_gray.properties
96[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/08_glass_light_gray/glass_pane_light_gray.properties
97[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/09_glass_cyan/glass_cyan.properties
98[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/09_glass_cyan/glass_pane_cyan.properties
99[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/10_glass_purple/glass_pane_purple.properties
100[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/10_glass_purple/glass_purple.properties
101[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/11_glass_blue/glass_blue.properties
102[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/11_glass_blue/glass_pane_blue.properties
103[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/12_glass_brown/glass_brown.properties
104[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/12_glass_brown/glass_pane_brown.properties
105[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/13_glass_green/glass_green.properties
106[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/13_glass_green/glass_pane_green.properties
107[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/14_glass_red/glass_pane_red.properties
108[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/14_glass_red/glass_red.properties
109[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/15_glass_black/glass_black.properties
110[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/15_glass_black/glass_pane_black.properties
111[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/20_glass/glass.properties
112[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/20_glass/glass_pane.properties
113[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/21_tinted_glass/tinted_glass.properties
114[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/30_bookshelf/bookshelf.properties
115[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/40_sandstone/sandstone.properties
116[17:17:41] [Worker-Main-11/INFO]: [OptiFine] ConnectedTextures: optifine/ctm/default/41_red_sandstone/red_sandstone.properties
117[17:17:41] [Worker-Main-11/INFO]: [OptiFine] Multipass connected textures: false
118[17:17:41] [Worker-Main-11/INFO]: [OptiFine] BetterGrass: Parsing default configuration optifine/bettergrass.properties
119[17:17:46] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 4
120[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
121[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
122[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
123[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
124[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
125[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
126[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
127[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
128[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
129[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
130[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
131[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
132[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
133[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
134[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
135[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
136[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
137[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
138[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
139[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
140[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Multitexture: false
141[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Sprite size: 64
142[17:17:48] [Worker-Main-11/INFO]: [OptiFine] Mipmap levels: 6
143[17:17:48] [Worker-Main-11/WARN]: Unused frames in sprite minecraft:missingno: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
144[17:17:48] [Render thread/INFO]: Loading context 'flywheel:context/crumbling'
145[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
146
147[17:17:48] [Render thread/ERROR]: #version 150
148#extension GL_ARB_conservative_depth : enable
149#define VERTEX_SHADER
150#if defined(VERTEX_SHADER)
151out float FragDistance;
152#elif defined(FRAGMENT_SHADER)
153in float FragDistance;
154#endif
155uniform vec4 uFogColor;
156uniform vec2 uFogRange;
157
158float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
159 float distXZ = length(worldPos.xz - cameraPos.xz);
160 float distY = abs(worldPos.y - cameraPos.y);
161 return max(distXZ, distY);
162}
163
164float cylindrical_distance(vec3 worldPos) {
165 float distXZ = length(worldPos.xz);
166 float distY = abs(worldPos.y);
167 return max(distXZ, distY);
168}
169
170float FLWFogFactor() {
171 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
172}
173
174
175uniform float uTime;
176uniform mat4 uViewProjection;
177uniform vec3 uCameraPos;
178
179uniform vec2 uTextureScale;
180uniform sampler2D uBlockAtlas;
181uniform sampler2D uLightMap;
182uniform sampler2D uCrumbling;
183
184uniform vec2 uWindowSize;
185
186void FLWFinalizeNormal(inout vec3 normal) {
187 // noop
188}
189
190#if defined(VERTEX_SHADER)
191void FLWFinalizeWorldPos(inout vec4 worldPos) {
192 #if defined(USE_FOG)
193 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
194 #endif
195
196 gl_Position = uViewProjection * worldPos;
197}
198
199#elif defined(FRAGMENT_SHADER)
200
201out vec4 fragColor;
202
203vec4 FLWBlockTexture(vec2 texCoords) {
204 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
205 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
206 cr.a = cr.a * diffuseAlpha;
207 return cr;
208}
209
210void FLWFinalizeColor(vec4 color) {
211 #if defined(USE_FOG)
212 float a = color.a;
213 float fog = clamp(FLWFogFactor(), 0., 1.);
214
215 color = mix(uFogColor, color, fog);
216 color.a = a;
217 #endif
218
219 if (color.a < 0.1) {
220 discard;
221 }
222
223 fragColor = color;
224}
225
226vec4 FLWLight(vec2 lightCoords) {
227 return vec4(1.);
228}
229#endif
230
231
232float diffuse(vec3 normal) {
233 vec3 n2 = normal * normal * vec3(.6, .25, .8);
234 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
235}
236struct Vertex {
237 vec3 pos;
238 vec2 texCoords;
239 vec3 normal;
240};
241
242struct BlockFrag {
243 vec2 texCoords;
244 vec4 color;
245 float diffuse;
246 vec2 light;
247};
248
249#if defined(FRAGMENT_SHADER)
250void fragment(BlockFrag r) {
251 vec4 tex = FLWBlockTexture(r.texCoords);
252
253 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
254
255 FLWFinalizeColor(color);
256}
257#endif
258
259
260
261
262struct Instance {
263 vec2 light;
264 vec4 color;
265 mat4 transform;
266 mat3 normalMat;
267};
268
269#if defined(VERTEX_SHADER)
270BlockFrag vertex(Vertex v, Instance i) {
271 vec4 worldPos = i.transform * vec4(v.pos, 1.);
272
273 vec3 norm = i.normalMat * v.normal;
274
275 FLWFinalizeWorldPos(worldPos);
276 FLWFinalizeNormal(norm);
277
278 norm = normalize(norm);
279
280 BlockFrag b;
281 b.diffuse = diffuse(norm);
282 b.texCoords = v.texCoords;
283 b.light = i.light;
284 #if defined(DEBUG_NORMAL)
285 b.color = vec4(norm, 1.);
286 #else
287 b.color = i.color;
288 #endif
289 return b;
290}
291#endif
292
293in vec3 a_v_pos;
294in vec2 a_v_texCoords;
295in vec3 a_v_normal;
296in vec2 a_i_light;
297in vec4 a_i_color;
298in mat4 a_i_transform;
299in mat3 a_i_normalMat;
300out vec2 v2f_texCoords;
301out vec4 v2f_color;
302out float v2f_diffuse;
303out vec2 v2f_light;
304void main() {
305Vertex v;
306v.pos = a_v_pos;
307v.texCoords = a_v_texCoords;
308v.normal = a_v_normal;
309Instance i;
310i.light = a_i_light;
311i.color = a_i_color;
312i.transform = a_i_transform;
313i.normalMat = a_i_normalMat;
314BlockFrag o = vertex(v, i);
315v2f_texCoords = o.texCoords;
316v2f_color = o.color;
317v2f_diffuse = o.diffuse;
318v2f_light = o.light;
319}
320[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
321
322[17:17:48] [Render thread/ERROR]: #version 150
323#extension GL_ARB_conservative_depth : enable
324#define FRAGMENT_SHADER
325#if defined(VERTEX_SHADER)
326out float FragDistance;
327#elif defined(FRAGMENT_SHADER)
328in float FragDistance;
329#endif
330uniform vec4 uFogColor;
331uniform vec2 uFogRange;
332
333float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
334 float distXZ = length(worldPos.xz - cameraPos.xz);
335 float distY = abs(worldPos.y - cameraPos.y);
336 return max(distXZ, distY);
337}
338
339float cylindrical_distance(vec3 worldPos) {
340 float distXZ = length(worldPos.xz);
341 float distY = abs(worldPos.y);
342 return max(distXZ, distY);
343}
344
345float FLWFogFactor() {
346 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
347}
348
349
350uniform float uTime;
351uniform mat4 uViewProjection;
352uniform vec3 uCameraPos;
353
354uniform vec2 uTextureScale;
355uniform sampler2D uBlockAtlas;
356uniform sampler2D uLightMap;
357uniform sampler2D uCrumbling;
358
359uniform vec2 uWindowSize;
360
361void FLWFinalizeNormal(inout vec3 normal) {
362 // noop
363}
364
365#if defined(VERTEX_SHADER)
366void FLWFinalizeWorldPos(inout vec4 worldPos) {
367 #if defined(USE_FOG)
368 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
369 #endif
370
371 gl_Position = uViewProjection * worldPos;
372}
373
374#elif defined(FRAGMENT_SHADER)
375
376out vec4 fragColor;
377
378vec4 FLWBlockTexture(vec2 texCoords) {
379 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
380 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
381 cr.a = cr.a * diffuseAlpha;
382 return cr;
383}
384
385void FLWFinalizeColor(vec4 color) {
386 #if defined(USE_FOG)
387 float a = color.a;
388 float fog = clamp(FLWFogFactor(), 0., 1.);
389
390 color = mix(uFogColor, color, fog);
391 color.a = a;
392 #endif
393
394 if (color.a < 0.1) {
395 discard;
396 }
397
398 fragColor = color;
399}
400
401vec4 FLWLight(vec2 lightCoords) {
402 return vec4(1.);
403}
404#endif
405
406
407float diffuse(vec3 normal) {
408 vec3 n2 = normal * normal * vec3(.6, .25, .8);
409 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
410}
411struct Vertex {
412 vec3 pos;
413 vec2 texCoords;
414 vec3 normal;
415};
416
417struct BlockFrag {
418 vec2 texCoords;
419 vec4 color;
420 float diffuse;
421 vec2 light;
422};
423
424#if defined(FRAGMENT_SHADER)
425void fragment(BlockFrag r) {
426 vec4 tex = FLWBlockTexture(r.texCoords);
427
428 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
429
430 FLWFinalizeColor(color);
431}
432#endif
433
434
435
436
437struct Instance {
438 vec2 light;
439 vec4 color;
440 mat4 transform;
441 mat3 normalMat;
442};
443
444#if defined(VERTEX_SHADER)
445BlockFrag vertex(Vertex v, Instance i) {
446 vec4 worldPos = i.transform * vec4(v.pos, 1.);
447
448 vec3 norm = i.normalMat * v.normal;
449
450 FLWFinalizeWorldPos(worldPos);
451 FLWFinalizeNormal(norm);
452
453 norm = normalize(norm);
454
455 BlockFrag b;
456 b.diffuse = diffuse(norm);
457 b.texCoords = v.texCoords;
458 b.light = i.light;
459 #if defined(DEBUG_NORMAL)
460 b.color = vec4(norm, 1.);
461 #else
462 b.color = i.color;
463 #endif
464 return b;
465}
466#endif
467
468in vec2 v2f_texCoords;
469in vec4 v2f_color;
470in float v2f_diffuse;
471in vec2 v2f_light;
472void main() {
473BlockFrag o;
474o.texCoords = v2f_texCoords;
475o.color = v2f_color;
476o.diffuse = v2f_diffuse;
477o.light = v2f_light;
478fragment(o);
479}
480[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
481
482[17:17:48] [Render thread/ERROR]: #version 150
483#extension GL_ARB_conservative_depth : enable
484#define VERTEX_SHADER
485#define DEBUG_NORMAL
486#if defined(VERTEX_SHADER)
487out float FragDistance;
488#elif defined(FRAGMENT_SHADER)
489in float FragDistance;
490#endif
491uniform vec4 uFogColor;
492uniform vec2 uFogRange;
493
494float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
495 float distXZ = length(worldPos.xz - cameraPos.xz);
496 float distY = abs(worldPos.y - cameraPos.y);
497 return max(distXZ, distY);
498}
499
500float cylindrical_distance(vec3 worldPos) {
501 float distXZ = length(worldPos.xz);
502 float distY = abs(worldPos.y);
503 return max(distXZ, distY);
504}
505
506float FLWFogFactor() {
507 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
508}
509
510
511uniform float uTime;
512uniform mat4 uViewProjection;
513uniform vec3 uCameraPos;
514
515uniform vec2 uTextureScale;
516uniform sampler2D uBlockAtlas;
517uniform sampler2D uLightMap;
518uniform sampler2D uCrumbling;
519
520uniform vec2 uWindowSize;
521
522void FLWFinalizeNormal(inout vec3 normal) {
523 // noop
524}
525
526#if defined(VERTEX_SHADER)
527void FLWFinalizeWorldPos(inout vec4 worldPos) {
528 #if defined(USE_FOG)
529 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
530 #endif
531
532 gl_Position = uViewProjection * worldPos;
533}
534
535#elif defined(FRAGMENT_SHADER)
536
537out vec4 fragColor;
538
539vec4 FLWBlockTexture(vec2 texCoords) {
540 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
541 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
542 cr.a = cr.a * diffuseAlpha;
543 return cr;
544}
545
546void FLWFinalizeColor(vec4 color) {
547 #if defined(USE_FOG)
548 float a = color.a;
549 float fog = clamp(FLWFogFactor(), 0., 1.);
550
551 color = mix(uFogColor, color, fog);
552 color.a = a;
553 #endif
554
555 if (color.a < 0.1) {
556 discard;
557 }
558
559 fragColor = color;
560}
561
562vec4 FLWLight(vec2 lightCoords) {
563 return vec4(1.);
564}
565#endif
566
567
568float diffuse(vec3 normal) {
569 vec3 n2 = normal * normal * vec3(.6, .25, .8);
570 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
571}
572struct Vertex {
573 vec3 pos;
574 vec2 texCoords;
575 vec3 normal;
576};
577
578struct BlockFrag {
579 vec2 texCoords;
580 vec4 color;
581 float diffuse;
582 vec2 light;
583};
584
585#if defined(FRAGMENT_SHADER)
586void fragment(BlockFrag r) {
587 vec4 tex = FLWBlockTexture(r.texCoords);
588
589 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
590
591 FLWFinalizeColor(color);
592}
593#endif
594
595
596
597
598struct Instance {
599 vec2 light;
600 vec4 color;
601 mat4 transform;
602 mat3 normalMat;
603};
604
605#if defined(VERTEX_SHADER)
606BlockFrag vertex(Vertex v, Instance i) {
607 vec4 worldPos = i.transform * vec4(v.pos, 1.);
608
609 vec3 norm = i.normalMat * v.normal;
610
611 FLWFinalizeWorldPos(worldPos);
612 FLWFinalizeNormal(norm);
613
614 norm = normalize(norm);
615
616 BlockFrag b;
617 b.diffuse = diffuse(norm);
618 b.texCoords = v.texCoords;
619 b.light = i.light;
620 #if defined(DEBUG_NORMAL)
621 b.color = vec4(norm, 1.);
622 #else
623 b.color = i.color;
624 #endif
625 return b;
626}
627#endif
628
629in vec3 a_v_pos;
630in vec2 a_v_texCoords;
631in vec3 a_v_normal;
632in vec2 a_i_light;
633in vec4 a_i_color;
634in mat4 a_i_transform;
635in mat3 a_i_normalMat;
636out vec2 v2f_texCoords;
637out vec4 v2f_color;
638out float v2f_diffuse;
639out vec2 v2f_light;
640void main() {
641Vertex v;
642v.pos = a_v_pos;
643v.texCoords = a_v_texCoords;
644v.normal = a_v_normal;
645Instance i;
646i.light = a_i_light;
647i.color = a_i_color;
648i.transform = a_i_transform;
649i.normalMat = a_i_normalMat;
650BlockFrag o = vertex(v, i);
651v2f_texCoords = o.texCoords;
652v2f_color = o.color;
653v2f_diffuse = o.diffuse;
654v2f_light = o.light;
655}
656[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
657
658[17:17:48] [Render thread/ERROR]: #version 150
659#extension GL_ARB_conservative_depth : enable
660#define FRAGMENT_SHADER
661#define DEBUG_NORMAL
662#if defined(VERTEX_SHADER)
663out float FragDistance;
664#elif defined(FRAGMENT_SHADER)
665in float FragDistance;
666#endif
667uniform vec4 uFogColor;
668uniform vec2 uFogRange;
669
670float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
671 float distXZ = length(worldPos.xz - cameraPos.xz);
672 float distY = abs(worldPos.y - cameraPos.y);
673 return max(distXZ, distY);
674}
675
676float cylindrical_distance(vec3 worldPos) {
677 float distXZ = length(worldPos.xz);
678 float distY = abs(worldPos.y);
679 return max(distXZ, distY);
680}
681
682float FLWFogFactor() {
683 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
684}
685
686
687uniform float uTime;
688uniform mat4 uViewProjection;
689uniform vec3 uCameraPos;
690
691uniform vec2 uTextureScale;
692uniform sampler2D uBlockAtlas;
693uniform sampler2D uLightMap;
694uniform sampler2D uCrumbling;
695
696uniform vec2 uWindowSize;
697
698void FLWFinalizeNormal(inout vec3 normal) {
699 // noop
700}
701
702#if defined(VERTEX_SHADER)
703void FLWFinalizeWorldPos(inout vec4 worldPos) {
704 #if defined(USE_FOG)
705 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
706 #endif
707
708 gl_Position = uViewProjection * worldPos;
709}
710
711#elif defined(FRAGMENT_SHADER)
712
713out vec4 fragColor;
714
715vec4 FLWBlockTexture(vec2 texCoords) {
716 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
717 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
718 cr.a = cr.a * diffuseAlpha;
719 return cr;
720}
721
722void FLWFinalizeColor(vec4 color) {
723 #if defined(USE_FOG)
724 float a = color.a;
725 float fog = clamp(FLWFogFactor(), 0., 1.);
726
727 color = mix(uFogColor, color, fog);
728 color.a = a;
729 #endif
730
731 if (color.a < 0.1) {
732 discard;
733 }
734
735 fragColor = color;
736}
737
738vec4 FLWLight(vec2 lightCoords) {
739 return vec4(1.);
740}
741#endif
742
743
744float diffuse(vec3 normal) {
745 vec3 n2 = normal * normal * vec3(.6, .25, .8);
746 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
747}
748struct Vertex {
749 vec3 pos;
750 vec2 texCoords;
751 vec3 normal;
752};
753
754struct BlockFrag {
755 vec2 texCoords;
756 vec4 color;
757 float diffuse;
758 vec2 light;
759};
760
761#if defined(FRAGMENT_SHADER)
762void fragment(BlockFrag r) {
763 vec4 tex = FLWBlockTexture(r.texCoords);
764
765 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
766
767 FLWFinalizeColor(color);
768}
769#endif
770
771
772
773
774struct Instance {
775 vec2 light;
776 vec4 color;
777 mat4 transform;
778 mat3 normalMat;
779};
780
781#if defined(VERTEX_SHADER)
782BlockFrag vertex(Vertex v, Instance i) {
783 vec4 worldPos = i.transform * vec4(v.pos, 1.);
784
785 vec3 norm = i.normalMat * v.normal;
786
787 FLWFinalizeWorldPos(worldPos);
788 FLWFinalizeNormal(norm);
789
790 norm = normalize(norm);
791
792 BlockFrag b;
793 b.diffuse = diffuse(norm);
794 b.texCoords = v.texCoords;
795 b.light = i.light;
796 #if defined(DEBUG_NORMAL)
797 b.color = vec4(norm, 1.);
798 #else
799 b.color = i.color;
800 #endif
801 return b;
802}
803#endif
804
805in vec2 v2f_texCoords;
806in vec4 v2f_color;
807in float v2f_diffuse;
808in vec2 v2f_light;
809void main() {
810BlockFrag o;
811o.texCoords = v2f_texCoords;
812o.color = v2f_color;
813o.diffuse = v2f_diffuse;
814o.light = v2f_light;
815fragment(o);
816}
817[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
818
819[17:17:48] [Render thread/ERROR]: #version 150
820#extension GL_ARB_conservative_depth : enable
821#define VERTEX_SHADER
822#if defined(VERTEX_SHADER)
823out float FragDistance;
824#elif defined(FRAGMENT_SHADER)
825in float FragDistance;
826#endif
827uniform vec4 uFogColor;
828uniform vec2 uFogRange;
829
830float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
831 float distXZ = length(worldPos.xz - cameraPos.xz);
832 float distY = abs(worldPos.y - cameraPos.y);
833 return max(distXZ, distY);
834}
835
836float cylindrical_distance(vec3 worldPos) {
837 float distXZ = length(worldPos.xz);
838 float distY = abs(worldPos.y);
839 return max(distXZ, distY);
840}
841
842float FLWFogFactor() {
843 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
844}
845
846
847uniform float uTime;
848uniform mat4 uViewProjection;
849uniform vec3 uCameraPos;
850
851uniform vec2 uTextureScale;
852uniform sampler2D uBlockAtlas;
853uniform sampler2D uLightMap;
854uniform sampler2D uCrumbling;
855
856uniform vec2 uWindowSize;
857
858void FLWFinalizeNormal(inout vec3 normal) {
859 // noop
860}
861
862#if defined(VERTEX_SHADER)
863void FLWFinalizeWorldPos(inout vec4 worldPos) {
864 #if defined(USE_FOG)
865 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
866 #endif
867
868 gl_Position = uViewProjection * worldPos;
869}
870
871#elif defined(FRAGMENT_SHADER)
872
873out vec4 fragColor;
874
875vec4 FLWBlockTexture(vec2 texCoords) {
876 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
877 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
878 cr.a = cr.a * diffuseAlpha;
879 return cr;
880}
881
882void FLWFinalizeColor(vec4 color) {
883 #if defined(USE_FOG)
884 float a = color.a;
885 float fog = clamp(FLWFogFactor(), 0., 1.);
886
887 color = mix(uFogColor, color, fog);
888 color.a = a;
889 #endif
890
891 if (color.a < 0.1) {
892 discard;
893 }
894
895 fragColor = color;
896}
897
898vec4 FLWLight(vec2 lightCoords) {
899 return vec4(1.);
900}
901#endif
902
903
904#define PIOVER2 1.5707963268
905
906vec4 quat(vec3 axis, float angle) {
907 float halfAngle = angle * PIOVER2 / 180.0;
908 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
909 return vec4(axis.xyz * cs.y, cs.x);
910}
911
912vec4 quatMult(vec4 q1, vec4 q2) {
913 // disgustingly vectorized quaternion multiplication
914 vec4 a = q1.w * q2.xyzw;
915 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
916 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
917 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
918
919 return a + b + c + d;
920}
921
922vec3 rotateVertexByQuat(vec3 v, vec4 q) {
923 vec3 i = q.xyz;
924 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
925}
926
927vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
928 return rotateVertexByQuat(v, quat(axis, angle));
929}
930
931float diffuse(vec3 normal) {
932 vec3 n2 = normal * normal * vec3(.6, .25, .8);
933 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
934}
935struct Vertex {
936 vec3 pos;
937 vec2 texCoords;
938 vec3 normal;
939};
940
941struct BlockFrag {
942 vec2 texCoords;
943 vec4 color;
944 float diffuse;
945 vec2 light;
946};
947
948#if defined(FRAGMENT_SHADER)
949void fragment(BlockFrag r) {
950 vec4 tex = FLWBlockTexture(r.texCoords);
951
952 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
953
954 FLWFinalizeColor(color);
955}
956#endif
957
958
959
960
961
962
963struct Oriented {
964 vec2 light;
965 vec4 color;
966 vec3 pos;
967 vec3 pivot;
968 vec4 rotation;
969};
970
971#if defined(VERTEX_SHADER)
972BlockFrag vertex(Vertex v, Oriented o) {
973 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
974
975 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
976
977 FLWFinalizeWorldPos(worldPos);
978 FLWFinalizeNormal(norm);
979
980 BlockFrag b;
981 b.diffuse = diffuse(norm);
982 b.texCoords = v.texCoords;
983 b.light = o.light;
984 #if defined(DEBUG_NORMAL)
985 b.color = vec4(norm, 1.);
986 #else
987 b.color = o.color;
988 #endif
989 return b;
990}
991#endif
992
993in vec3 a_v_pos;
994in vec2 a_v_texCoords;
995in vec3 a_v_normal;
996in vec2 a_i_light;
997in vec4 a_i_color;
998in vec3 a_i_pos;
999in vec3 a_i_pivot;
1000in vec4 a_i_rotation;
1001out vec2 v2f_texCoords;
1002out vec4 v2f_color;
1003out float v2f_diffuse;
1004out vec2 v2f_light;
1005void main() {
1006Vertex v;
1007v.pos = a_v_pos;
1008v.texCoords = a_v_texCoords;
1009v.normal = a_v_normal;
1010Oriented i;
1011i.light = a_i_light;
1012i.color = a_i_color;
1013i.pos = a_i_pos;
1014i.pivot = a_i_pivot;
1015i.rotation = a_i_rotation;
1016BlockFrag o = vertex(v, i);
1017v2f_texCoords = o.texCoords;
1018v2f_color = o.color;
1019v2f_diffuse = o.diffuse;
1020v2f_light = o.light;
1021}
1022[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
1023
1024[17:17:48] [Render thread/ERROR]: #version 150
1025#extension GL_ARB_conservative_depth : enable
1026#define FRAGMENT_SHADER
1027#if defined(VERTEX_SHADER)
1028out float FragDistance;
1029#elif defined(FRAGMENT_SHADER)
1030in float FragDistance;
1031#endif
1032uniform vec4 uFogColor;
1033uniform vec2 uFogRange;
1034
1035float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
1036 float distXZ = length(worldPos.xz - cameraPos.xz);
1037 float distY = abs(worldPos.y - cameraPos.y);
1038 return max(distXZ, distY);
1039}
1040
1041float cylindrical_distance(vec3 worldPos) {
1042 float distXZ = length(worldPos.xz);
1043 float distY = abs(worldPos.y);
1044 return max(distXZ, distY);
1045}
1046
1047float FLWFogFactor() {
1048 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
1049}
1050
1051
1052uniform float uTime;
1053uniform mat4 uViewProjection;
1054uniform vec3 uCameraPos;
1055
1056uniform vec2 uTextureScale;
1057uniform sampler2D uBlockAtlas;
1058uniform sampler2D uLightMap;
1059uniform sampler2D uCrumbling;
1060
1061uniform vec2 uWindowSize;
1062
1063void FLWFinalizeNormal(inout vec3 normal) {
1064 // noop
1065}
1066
1067#if defined(VERTEX_SHADER)
1068void FLWFinalizeWorldPos(inout vec4 worldPos) {
1069 #if defined(USE_FOG)
1070 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
1071 #endif
1072
1073 gl_Position = uViewProjection * worldPos;
1074}
1075
1076#elif defined(FRAGMENT_SHADER)
1077
1078out vec4 fragColor;
1079
1080vec4 FLWBlockTexture(vec2 texCoords) {
1081 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
1082 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
1083 cr.a = cr.a * diffuseAlpha;
1084 return cr;
1085}
1086
1087void FLWFinalizeColor(vec4 color) {
1088 #if defined(USE_FOG)
1089 float a = color.a;
1090 float fog = clamp(FLWFogFactor(), 0., 1.);
1091
1092 color = mix(uFogColor, color, fog);
1093 color.a = a;
1094 #endif
1095
1096 if (color.a < 0.1) {
1097 discard;
1098 }
1099
1100 fragColor = color;
1101}
1102
1103vec4 FLWLight(vec2 lightCoords) {
1104 return vec4(1.);
1105}
1106#endif
1107
1108
1109#define PIOVER2 1.5707963268
1110
1111vec4 quat(vec3 axis, float angle) {
1112 float halfAngle = angle * PIOVER2 / 180.0;
1113 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
1114 return vec4(axis.xyz * cs.y, cs.x);
1115}
1116
1117vec4 quatMult(vec4 q1, vec4 q2) {
1118 // disgustingly vectorized quaternion multiplication
1119 vec4 a = q1.w * q2.xyzw;
1120 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
1121 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
1122 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
1123
1124 return a + b + c + d;
1125}
1126
1127vec3 rotateVertexByQuat(vec3 v, vec4 q) {
1128 vec3 i = q.xyz;
1129 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
1130}
1131
1132vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
1133 return rotateVertexByQuat(v, quat(axis, angle));
1134}
1135
1136float diffuse(vec3 normal) {
1137 vec3 n2 = normal * normal * vec3(.6, .25, .8);
1138 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
1139}
1140struct Vertex {
1141 vec3 pos;
1142 vec2 texCoords;
1143 vec3 normal;
1144};
1145
1146struct BlockFrag {
1147 vec2 texCoords;
1148 vec4 color;
1149 float diffuse;
1150 vec2 light;
1151};
1152
1153#if defined(FRAGMENT_SHADER)
1154void fragment(BlockFrag r) {
1155 vec4 tex = FLWBlockTexture(r.texCoords);
1156
1157 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
1158
1159 FLWFinalizeColor(color);
1160}
1161#endif
1162
1163
1164
1165
1166
1167
1168struct Oriented {
1169 vec2 light;
1170 vec4 color;
1171 vec3 pos;
1172 vec3 pivot;
1173 vec4 rotation;
1174};
1175
1176#if defined(VERTEX_SHADER)
1177BlockFrag vertex(Vertex v, Oriented o) {
1178 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
1179
1180 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
1181
1182 FLWFinalizeWorldPos(worldPos);
1183 FLWFinalizeNormal(norm);
1184
1185 BlockFrag b;
1186 b.diffuse = diffuse(norm);
1187 b.texCoords = v.texCoords;
1188 b.light = o.light;
1189 #if defined(DEBUG_NORMAL)
1190 b.color = vec4(norm, 1.);
1191 #else
1192 b.color = o.color;
1193 #endif
1194 return b;
1195}
1196#endif
1197
1198in vec2 v2f_texCoords;
1199in vec4 v2f_color;
1200in float v2f_diffuse;
1201in vec2 v2f_light;
1202void main() {
1203BlockFrag o;
1204o.texCoords = v2f_texCoords;
1205o.color = v2f_color;
1206o.diffuse = v2f_diffuse;
1207o.light = v2f_light;
1208fragment(o);
1209}
1210[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
1211
1212[17:17:48] [Render thread/ERROR]: #version 150
1213#extension GL_ARB_conservative_depth : enable
1214#define VERTEX_SHADER
1215#define DEBUG_NORMAL
1216#if defined(VERTEX_SHADER)
1217out float FragDistance;
1218#elif defined(FRAGMENT_SHADER)
1219in float FragDistance;
1220#endif
1221uniform vec4 uFogColor;
1222uniform vec2 uFogRange;
1223
1224float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
1225 float distXZ = length(worldPos.xz - cameraPos.xz);
1226 float distY = abs(worldPos.y - cameraPos.y);
1227 return max(distXZ, distY);
1228}
1229
1230float cylindrical_distance(vec3 worldPos) {
1231 float distXZ = length(worldPos.xz);
1232 float distY = abs(worldPos.y);
1233 return max(distXZ, distY);
1234}
1235
1236float FLWFogFactor() {
1237 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
1238}
1239
1240
1241uniform float uTime;
1242uniform mat4 uViewProjection;
1243uniform vec3 uCameraPos;
1244
1245uniform vec2 uTextureScale;
1246uniform sampler2D uBlockAtlas;
1247uniform sampler2D uLightMap;
1248uniform sampler2D uCrumbling;
1249
1250uniform vec2 uWindowSize;
1251
1252void FLWFinalizeNormal(inout vec3 normal) {
1253 // noop
1254}
1255
1256#if defined(VERTEX_SHADER)
1257void FLWFinalizeWorldPos(inout vec4 worldPos) {
1258 #if defined(USE_FOG)
1259 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
1260 #endif
1261
1262 gl_Position = uViewProjection * worldPos;
1263}
1264
1265#elif defined(FRAGMENT_SHADER)
1266
1267out vec4 fragColor;
1268
1269vec4 FLWBlockTexture(vec2 texCoords) {
1270 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
1271 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
1272 cr.a = cr.a * diffuseAlpha;
1273 return cr;
1274}
1275
1276void FLWFinalizeColor(vec4 color) {
1277 #if defined(USE_FOG)
1278 float a = color.a;
1279 float fog = clamp(FLWFogFactor(), 0., 1.);
1280
1281 color = mix(uFogColor, color, fog);
1282 color.a = a;
1283 #endif
1284
1285 if (color.a < 0.1) {
1286 discard;
1287 }
1288
1289 fragColor = color;
1290}
1291
1292vec4 FLWLight(vec2 lightCoords) {
1293 return vec4(1.);
1294}
1295#endif
1296
1297
1298#define PIOVER2 1.5707963268
1299
1300vec4 quat(vec3 axis, float angle) {
1301 float halfAngle = angle * PIOVER2 / 180.0;
1302 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
1303 return vec4(axis.xyz * cs.y, cs.x);
1304}
1305
1306vec4 quatMult(vec4 q1, vec4 q2) {
1307 // disgustingly vectorized quaternion multiplication
1308 vec4 a = q1.w * q2.xyzw;
1309 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
1310 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
1311 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
1312
1313 return a + b + c + d;
1314}
1315
1316vec3 rotateVertexByQuat(vec3 v, vec4 q) {
1317 vec3 i = q.xyz;
1318 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
1319}
1320
1321vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
1322 return rotateVertexByQuat(v, quat(axis, angle));
1323}
1324
1325float diffuse(vec3 normal) {
1326 vec3 n2 = normal * normal * vec3(.6, .25, .8);
1327 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
1328}
1329struct Vertex {
1330 vec3 pos;
1331 vec2 texCoords;
1332 vec3 normal;
1333};
1334
1335struct BlockFrag {
1336 vec2 texCoords;
1337 vec4 color;
1338 float diffuse;
1339 vec2 light;
1340};
1341
1342#if defined(FRAGMENT_SHADER)
1343void fragment(BlockFrag r) {
1344 vec4 tex = FLWBlockTexture(r.texCoords);
1345
1346 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
1347
1348 FLWFinalizeColor(color);
1349}
1350#endif
1351
1352
1353
1354
1355
1356
1357struct Oriented {
1358 vec2 light;
1359 vec4 color;
1360 vec3 pos;
1361 vec3 pivot;
1362 vec4 rotation;
1363};
1364
1365#if defined(VERTEX_SHADER)
1366BlockFrag vertex(Vertex v, Oriented o) {
1367 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
1368
1369 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
1370
1371 FLWFinalizeWorldPos(worldPos);
1372 FLWFinalizeNormal(norm);
1373
1374 BlockFrag b;
1375 b.diffuse = diffuse(norm);
1376 b.texCoords = v.texCoords;
1377 b.light = o.light;
1378 #if defined(DEBUG_NORMAL)
1379 b.color = vec4(norm, 1.);
1380 #else
1381 b.color = o.color;
1382 #endif
1383 return b;
1384}
1385#endif
1386
1387in vec3 a_v_pos;
1388in vec2 a_v_texCoords;
1389in vec3 a_v_normal;
1390in vec2 a_i_light;
1391in vec4 a_i_color;
1392in vec3 a_i_pos;
1393in vec3 a_i_pivot;
1394in vec4 a_i_rotation;
1395out vec2 v2f_texCoords;
1396out vec4 v2f_color;
1397out float v2f_diffuse;
1398out vec2 v2f_light;
1399void main() {
1400Vertex v;
1401v.pos = a_v_pos;
1402v.texCoords = a_v_texCoords;
1403v.normal = a_v_normal;
1404Oriented i;
1405i.light = a_i_light;
1406i.color = a_i_color;
1407i.pos = a_i_pos;
1408i.pivot = a_i_pivot;
1409i.rotation = a_i_rotation;
1410BlockFrag o = vertex(v, i);
1411v2f_texCoords = o.texCoords;
1412v2f_color = o.color;
1413v2f_diffuse = o.diffuse;
1414v2f_light = o.light;
1415}
1416[17:17:48] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
1417
1418[17:17:48] [Render thread/ERROR]: #version 150
1419#extension GL_ARB_conservative_depth : enable
1420#define FRAGMENT_SHADER
1421#define DEBUG_NORMAL
1422#if defined(VERTEX_SHADER)
1423out float FragDistance;
1424#elif defined(FRAGMENT_SHADER)
1425in float FragDistance;
1426#endif
1427uniform vec4 uFogColor;
1428uniform vec2 uFogRange;
1429
1430float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
1431 float distXZ = length(worldPos.xz - cameraPos.xz);
1432 float distY = abs(worldPos.y - cameraPos.y);
1433 return max(distXZ, distY);
1434}
1435
1436float cylindrical_distance(vec3 worldPos) {
1437 float distXZ = length(worldPos.xz);
1438 float distY = abs(worldPos.y);
1439 return max(distXZ, distY);
1440}
1441
1442float FLWFogFactor() {
1443 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
1444}
1445
1446
1447uniform float uTime;
1448uniform mat4 uViewProjection;
1449uniform vec3 uCameraPos;
1450
1451uniform vec2 uTextureScale;
1452uniform sampler2D uBlockAtlas;
1453uniform sampler2D uLightMap;
1454uniform sampler2D uCrumbling;
1455
1456uniform vec2 uWindowSize;
1457
1458void FLWFinalizeNormal(inout vec3 normal) {
1459 // noop
1460}
1461
1462#if defined(VERTEX_SHADER)
1463void FLWFinalizeWorldPos(inout vec4 worldPos) {
1464 #if defined(USE_FOG)
1465 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
1466 #endif
1467
1468 gl_Position = uViewProjection * worldPos;
1469}
1470
1471#elif defined(FRAGMENT_SHADER)
1472
1473out vec4 fragColor;
1474
1475vec4 FLWBlockTexture(vec2 texCoords) {
1476 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
1477 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
1478 cr.a = cr.a * diffuseAlpha;
1479 return cr;
1480}
1481
1482void FLWFinalizeColor(vec4 color) {
1483 #if defined(USE_FOG)
1484 float a = color.a;
1485 float fog = clamp(FLWFogFactor(), 0., 1.);
1486
1487 color = mix(uFogColor, color, fog);
1488 color.a = a;
1489 #endif
1490
1491 if (color.a < 0.1) {
1492 discard;
1493 }
1494
1495 fragColor = color;
1496}
1497
1498vec4 FLWLight(vec2 lightCoords) {
1499 return vec4(1.);
1500}
1501#endif
1502
1503
1504#define PIOVER2 1.5707963268
1505
1506vec4 quat(vec3 axis, float angle) {
1507 float halfAngle = angle * PIOVER2 / 180.0;
1508 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
1509 return vec4(axis.xyz * cs.y, cs.x);
1510}
1511
1512vec4 quatMult(vec4 q1, vec4 q2) {
1513 // disgustingly vectorized quaternion multiplication
1514 vec4 a = q1.w * q2.xyzw;
1515 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
1516 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
1517 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
1518
1519 return a + b + c + d;
1520}
1521
1522vec3 rotateVertexByQuat(vec3 v, vec4 q) {
1523 vec3 i = q.xyz;
1524 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
1525}
1526
1527vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
1528 return rotateVertexByQuat(v, quat(axis, angle));
1529}
1530
1531float diffuse(vec3 normal) {
1532 vec3 n2 = normal * normal * vec3(.6, .25, .8);
1533 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
1534}
1535struct Vertex {
1536 vec3 pos;
1537 vec2 texCoords;
1538 vec3 normal;
1539};
1540
1541struct BlockFrag {
1542 vec2 texCoords;
1543 vec4 color;
1544 float diffuse;
1545 vec2 light;
1546};
1547
1548#if defined(FRAGMENT_SHADER)
1549void fragment(BlockFrag r) {
1550 vec4 tex = FLWBlockTexture(r.texCoords);
1551
1552 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
1553
1554 FLWFinalizeColor(color);
1555}
1556#endif
1557
1558
1559
1560
1561
1562
1563struct Oriented {
1564 vec2 light;
1565 vec4 color;
1566 vec3 pos;
1567 vec3 pivot;
1568 vec4 rotation;
1569};
1570
1571#if defined(VERTEX_SHADER)
1572BlockFrag vertex(Vertex v, Oriented o) {
1573 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
1574
1575 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
1576
1577 FLWFinalizeWorldPos(worldPos);
1578 FLWFinalizeNormal(norm);
1579
1580 BlockFrag b;
1581 b.diffuse = diffuse(norm);
1582 b.texCoords = v.texCoords;
1583 b.light = o.light;
1584 #if defined(DEBUG_NORMAL)
1585 b.color = vec4(norm, 1.);
1586 #else
1587 b.color = o.color;
1588 #endif
1589 return b;
1590}
1591#endif
1592
1593in vec2 v2f_texCoords;
1594in vec4 v2f_color;
1595in float v2f_diffuse;
1596in vec2 v2f_light;
1597void main() {
1598BlockFrag o;
1599o.texCoords = v2f_texCoords;
1600o.color = v2f_color;
1601o.diffuse = v2f_diffuse;
1602o.light = v2f_light;
1603fragment(o);
1604}
1605[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
1606
1607[17:17:48] [Render thread/ERROR]: #version 150
1608#extension GL_ARB_conservative_depth : enable
1609#define VERTEX_SHADER
1610#if defined(VERTEX_SHADER)
1611out float FragDistance;
1612#elif defined(FRAGMENT_SHADER)
1613in float FragDistance;
1614#endif
1615uniform vec4 uFogColor;
1616uniform vec2 uFogRange;
1617
1618float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
1619 float distXZ = length(worldPos.xz - cameraPos.xz);
1620 float distY = abs(worldPos.y - cameraPos.y);
1621 return max(distXZ, distY);
1622}
1623
1624float cylindrical_distance(vec3 worldPos) {
1625 float distXZ = length(worldPos.xz);
1626 float distY = abs(worldPos.y);
1627 return max(distXZ, distY);
1628}
1629
1630float FLWFogFactor() {
1631 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
1632}
1633
1634
1635uniform float uTime;
1636uniform mat4 uViewProjection;
1637uniform vec3 uCameraPos;
1638
1639uniform vec2 uTextureScale;
1640uniform sampler2D uBlockAtlas;
1641uniform sampler2D uLightMap;
1642uniform sampler2D uCrumbling;
1643
1644uniform vec2 uWindowSize;
1645
1646void FLWFinalizeNormal(inout vec3 normal) {
1647 // noop
1648}
1649
1650#if defined(VERTEX_SHADER)
1651void FLWFinalizeWorldPos(inout vec4 worldPos) {
1652 #if defined(USE_FOG)
1653 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
1654 #endif
1655
1656 gl_Position = uViewProjection * worldPos;
1657}
1658
1659#elif defined(FRAGMENT_SHADER)
1660
1661out vec4 fragColor;
1662
1663vec4 FLWBlockTexture(vec2 texCoords) {
1664 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
1665 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
1666 cr.a = cr.a * diffuseAlpha;
1667 return cr;
1668}
1669
1670void FLWFinalizeColor(vec4 color) {
1671 #if defined(USE_FOG)
1672 float a = color.a;
1673 float fog = clamp(FLWFogFactor(), 0., 1.);
1674
1675 color = mix(uFogColor, color, fog);
1676 color.a = a;
1677 #endif
1678
1679 if (color.a < 0.1) {
1680 discard;
1681 }
1682
1683 fragColor = color;
1684}
1685
1686vec4 FLWLight(vec2 lightCoords) {
1687 return vec4(1.);
1688}
1689#endif
1690
1691
1692mat4 rotate(vec3 axis, float angle) {
1693 float s = sin(angle);
1694 float c = cos(angle);
1695 float oc = 1. - c;
1696
1697 vec3 sa = axis * s;
1698
1699 mat4 mr = mat4(1.);
1700 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
1701 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
1702 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
1703
1704 return mr;
1705}
1706
1707mat4 rotation(vec3 rot) {
1708 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
1709}
1710
1711mat3 modelToNormal(mat4 mat) {
1712 // Discard the edges. This won't be accurate for scaled or skewed matrices,
1713 // but we don't have to work with those often.
1714 mat3 m;
1715 m[0] = mat[0].xyz;
1716 m[1] = mat[1].xyz;
1717 m[2] = mat[2].xyz;
1718 return m;
1719}
1720
1721float diffuse(vec3 normal) {
1722 vec3 n2 = normal * normal * vec3(.6, .25, .8);
1723 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
1724}
1725struct Vertex {
1726 vec3 pos;
1727 vec2 texCoords;
1728 vec3 normal;
1729};
1730
1731struct BlockFrag {
1732 vec2 texCoords;
1733 vec4 color;
1734 float diffuse;
1735 vec2 light;
1736};
1737
1738#if defined(FRAGMENT_SHADER)
1739void fragment(BlockFrag r) {
1740 vec4 tex = FLWBlockTexture(r.texCoords);
1741
1742 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
1743
1744 FLWFinalizeColor(color);
1745}
1746#endif
1747#define PI 3.1415926538
1748
1749
1750
1751
1752struct Rotating {
1753 vec2 light;
1754 vec4 color;
1755 vec3 pos;
1756 float speed;
1757 float offset;
1758 vec3 axis;
1759};
1760
1761
1762
1763
1764mat4 kineticRotation(float offset, float speed, vec3 axis) {
1765 float degrees = offset + uTime * speed * 3./10.;
1766 float angle = fract(degrees / 360.) * PI * 2.;
1767
1768 return rotate(axis, angle);
1769}
1770
1771#if defined(VERTEX_SHADER)
1772BlockFrag vertex(Vertex v, Rotating instance) {
1773 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
1774
1775 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
1776 worldPos += vec4(instance.pos + .5, 0.);
1777
1778 vec3 norm = modelToNormal(spin) * v.normal;
1779
1780 FLWFinalizeWorldPos(worldPos);
1781 FLWFinalizeNormal(norm);
1782
1783 BlockFrag b;
1784 b.diffuse = diffuse(norm);
1785 b.texCoords = v.texCoords;
1786 b.light = instance.light;
1787
1788 #if defined(DEBUG_RAINBOW)
1789 b.color = instance.color;
1790 #elif defined(DEBUG_NORMAL)
1791 b.color = vec4(norm, 1.);
1792 #else
1793 b.color = vec4(1.);
1794 #endif
1795
1796 return b;
1797}
1798#endif
1799
1800in vec3 a_v_pos;
1801in vec2 a_v_texCoords;
1802in vec3 a_v_normal;
1803in vec2 a_i_light;
1804in vec4 a_i_color;
1805in vec3 a_i_pos;
1806in float a_i_speed;
1807in float a_i_offset;
1808in vec3 a_i_axis;
1809out vec2 v2f_texCoords;
1810out vec4 v2f_color;
1811out float v2f_diffuse;
1812out vec2 v2f_light;
1813void main() {
1814Vertex v;
1815v.pos = a_v_pos;
1816v.texCoords = a_v_texCoords;
1817v.normal = a_v_normal;
1818Rotating i;
1819i.light = a_i_light;
1820i.color = a_i_color;
1821i.pos = a_i_pos;
1822i.speed = a_i_speed;
1823i.offset = a_i_offset;
1824i.axis = a_i_axis;
1825BlockFrag o = vertex(v, i);
1826v2f_texCoords = o.texCoords;
1827v2f_color = o.color;
1828v2f_diffuse = o.diffuse;
1829v2f_light = o.light;
1830}
1831[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
1832
1833[17:17:48] [Render thread/ERROR]: #version 150
1834#extension GL_ARB_conservative_depth : enable
1835#define FRAGMENT_SHADER
1836#if defined(VERTEX_SHADER)
1837out float FragDistance;
1838#elif defined(FRAGMENT_SHADER)
1839in float FragDistance;
1840#endif
1841uniform vec4 uFogColor;
1842uniform vec2 uFogRange;
1843
1844float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
1845 float distXZ = length(worldPos.xz - cameraPos.xz);
1846 float distY = abs(worldPos.y - cameraPos.y);
1847 return max(distXZ, distY);
1848}
1849
1850float cylindrical_distance(vec3 worldPos) {
1851 float distXZ = length(worldPos.xz);
1852 float distY = abs(worldPos.y);
1853 return max(distXZ, distY);
1854}
1855
1856float FLWFogFactor() {
1857 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
1858}
1859
1860
1861uniform float uTime;
1862uniform mat4 uViewProjection;
1863uniform vec3 uCameraPos;
1864
1865uniform vec2 uTextureScale;
1866uniform sampler2D uBlockAtlas;
1867uniform sampler2D uLightMap;
1868uniform sampler2D uCrumbling;
1869
1870uniform vec2 uWindowSize;
1871
1872void FLWFinalizeNormal(inout vec3 normal) {
1873 // noop
1874}
1875
1876#if defined(VERTEX_SHADER)
1877void FLWFinalizeWorldPos(inout vec4 worldPos) {
1878 #if defined(USE_FOG)
1879 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
1880 #endif
1881
1882 gl_Position = uViewProjection * worldPos;
1883}
1884
1885#elif defined(FRAGMENT_SHADER)
1886
1887out vec4 fragColor;
1888
1889vec4 FLWBlockTexture(vec2 texCoords) {
1890 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
1891 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
1892 cr.a = cr.a * diffuseAlpha;
1893 return cr;
1894}
1895
1896void FLWFinalizeColor(vec4 color) {
1897 #if defined(USE_FOG)
1898 float a = color.a;
1899 float fog = clamp(FLWFogFactor(), 0., 1.);
1900
1901 color = mix(uFogColor, color, fog);
1902 color.a = a;
1903 #endif
1904
1905 if (color.a < 0.1) {
1906 discard;
1907 }
1908
1909 fragColor = color;
1910}
1911
1912vec4 FLWLight(vec2 lightCoords) {
1913 return vec4(1.);
1914}
1915#endif
1916
1917
1918mat4 rotate(vec3 axis, float angle) {
1919 float s = sin(angle);
1920 float c = cos(angle);
1921 float oc = 1. - c;
1922
1923 vec3 sa = axis * s;
1924
1925 mat4 mr = mat4(1.);
1926 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
1927 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
1928 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
1929
1930 return mr;
1931}
1932
1933mat4 rotation(vec3 rot) {
1934 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
1935}
1936
1937mat3 modelToNormal(mat4 mat) {
1938 // Discard the edges. This won't be accurate for scaled or skewed matrices,
1939 // but we don't have to work with those often.
1940 mat3 m;
1941 m[0] = mat[0].xyz;
1942 m[1] = mat[1].xyz;
1943 m[2] = mat[2].xyz;
1944 return m;
1945}
1946
1947float diffuse(vec3 normal) {
1948 vec3 n2 = normal * normal * vec3(.6, .25, .8);
1949 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
1950}
1951struct Vertex {
1952 vec3 pos;
1953 vec2 texCoords;
1954 vec3 normal;
1955};
1956
1957struct BlockFrag {
1958 vec2 texCoords;
1959 vec4 color;
1960 float diffuse;
1961 vec2 light;
1962};
1963
1964#if defined(FRAGMENT_SHADER)
1965void fragment(BlockFrag r) {
1966 vec4 tex = FLWBlockTexture(r.texCoords);
1967
1968 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
1969
1970 FLWFinalizeColor(color);
1971}
1972#endif
1973#define PI 3.1415926538
1974
1975
1976
1977
1978struct Rotating {
1979 vec2 light;
1980 vec4 color;
1981 vec3 pos;
1982 float speed;
1983 float offset;
1984 vec3 axis;
1985};
1986
1987
1988
1989
1990mat4 kineticRotation(float offset, float speed, vec3 axis) {
1991 float degrees = offset + uTime * speed * 3./10.;
1992 float angle = fract(degrees / 360.) * PI * 2.;
1993
1994 return rotate(axis, angle);
1995}
1996
1997#if defined(VERTEX_SHADER)
1998BlockFrag vertex(Vertex v, Rotating instance) {
1999 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
2000
2001 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
2002 worldPos += vec4(instance.pos + .5, 0.);
2003
2004 vec3 norm = modelToNormal(spin) * v.normal;
2005
2006 FLWFinalizeWorldPos(worldPos);
2007 FLWFinalizeNormal(norm);
2008
2009 BlockFrag b;
2010 b.diffuse = diffuse(norm);
2011 b.texCoords = v.texCoords;
2012 b.light = instance.light;
2013
2014 #if defined(DEBUG_RAINBOW)
2015 b.color = instance.color;
2016 #elif defined(DEBUG_NORMAL)
2017 b.color = vec4(norm, 1.);
2018 #else
2019 b.color = vec4(1.);
2020 #endif
2021
2022 return b;
2023}
2024#endif
2025
2026in vec2 v2f_texCoords;
2027in vec4 v2f_color;
2028in float v2f_diffuse;
2029in vec2 v2f_light;
2030void main() {
2031BlockFrag o;
2032o.texCoords = v2f_texCoords;
2033o.color = v2f_color;
2034o.diffuse = v2f_diffuse;
2035o.light = v2f_light;
2036fragment(o);
2037}
2038[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
2039
2040[17:17:48] [Render thread/ERROR]: #version 150
2041#extension GL_ARB_conservative_depth : enable
2042#define VERTEX_SHADER
2043#define DEBUG_RAINBOW
2044#if defined(VERTEX_SHADER)
2045out float FragDistance;
2046#elif defined(FRAGMENT_SHADER)
2047in float FragDistance;
2048#endif
2049uniform vec4 uFogColor;
2050uniform vec2 uFogRange;
2051
2052float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
2053 float distXZ = length(worldPos.xz - cameraPos.xz);
2054 float distY = abs(worldPos.y - cameraPos.y);
2055 return max(distXZ, distY);
2056}
2057
2058float cylindrical_distance(vec3 worldPos) {
2059 float distXZ = length(worldPos.xz);
2060 float distY = abs(worldPos.y);
2061 return max(distXZ, distY);
2062}
2063
2064float FLWFogFactor() {
2065 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
2066}
2067
2068
2069uniform float uTime;
2070uniform mat4 uViewProjection;
2071uniform vec3 uCameraPos;
2072
2073uniform vec2 uTextureScale;
2074uniform sampler2D uBlockAtlas;
2075uniform sampler2D uLightMap;
2076uniform sampler2D uCrumbling;
2077
2078uniform vec2 uWindowSize;
2079
2080void FLWFinalizeNormal(inout vec3 normal) {
2081 // noop
2082}
2083
2084#if defined(VERTEX_SHADER)
2085void FLWFinalizeWorldPos(inout vec4 worldPos) {
2086 #if defined(USE_FOG)
2087 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
2088 #endif
2089
2090 gl_Position = uViewProjection * worldPos;
2091}
2092
2093#elif defined(FRAGMENT_SHADER)
2094
2095out vec4 fragColor;
2096
2097vec4 FLWBlockTexture(vec2 texCoords) {
2098 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
2099 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
2100 cr.a = cr.a * diffuseAlpha;
2101 return cr;
2102}
2103
2104void FLWFinalizeColor(vec4 color) {
2105 #if defined(USE_FOG)
2106 float a = color.a;
2107 float fog = clamp(FLWFogFactor(), 0., 1.);
2108
2109 color = mix(uFogColor, color, fog);
2110 color.a = a;
2111 #endif
2112
2113 if (color.a < 0.1) {
2114 discard;
2115 }
2116
2117 fragColor = color;
2118}
2119
2120vec4 FLWLight(vec2 lightCoords) {
2121 return vec4(1.);
2122}
2123#endif
2124
2125
2126mat4 rotate(vec3 axis, float angle) {
2127 float s = sin(angle);
2128 float c = cos(angle);
2129 float oc = 1. - c;
2130
2131 vec3 sa = axis * s;
2132
2133 mat4 mr = mat4(1.);
2134 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
2135 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
2136 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
2137
2138 return mr;
2139}
2140
2141mat4 rotation(vec3 rot) {
2142 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
2143}
2144
2145mat3 modelToNormal(mat4 mat) {
2146 // Discard the edges. This won't be accurate for scaled or skewed matrices,
2147 // but we don't have to work with those often.
2148 mat3 m;
2149 m[0] = mat[0].xyz;
2150 m[1] = mat[1].xyz;
2151 m[2] = mat[2].xyz;
2152 return m;
2153}
2154
2155float diffuse(vec3 normal) {
2156 vec3 n2 = normal * normal * vec3(.6, .25, .8);
2157 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
2158}
2159struct Vertex {
2160 vec3 pos;
2161 vec2 texCoords;
2162 vec3 normal;
2163};
2164
2165struct BlockFrag {
2166 vec2 texCoords;
2167 vec4 color;
2168 float diffuse;
2169 vec2 light;
2170};
2171
2172#if defined(FRAGMENT_SHADER)
2173void fragment(BlockFrag r) {
2174 vec4 tex = FLWBlockTexture(r.texCoords);
2175
2176 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
2177
2178 FLWFinalizeColor(color);
2179}
2180#endif
2181#define PI 3.1415926538
2182
2183
2184
2185
2186struct Rotating {
2187 vec2 light;
2188 vec4 color;
2189 vec3 pos;
2190 float speed;
2191 float offset;
2192 vec3 axis;
2193};
2194
2195
2196
2197
2198mat4 kineticRotation(float offset, float speed, vec3 axis) {
2199 float degrees = offset + uTime * speed * 3./10.;
2200 float angle = fract(degrees / 360.) * PI * 2.;
2201
2202 return rotate(axis, angle);
2203}
2204
2205#if defined(VERTEX_SHADER)
2206BlockFrag vertex(Vertex v, Rotating instance) {
2207 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
2208
2209 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
2210 worldPos += vec4(instance.pos + .5, 0.);
2211
2212 vec3 norm = modelToNormal(spin) * v.normal;
2213
2214 FLWFinalizeWorldPos(worldPos);
2215 FLWFinalizeNormal(norm);
2216
2217 BlockFrag b;
2218 b.diffuse = diffuse(norm);
2219 b.texCoords = v.texCoords;
2220 b.light = instance.light;
2221
2222 #if defined(DEBUG_RAINBOW)
2223 b.color = instance.color;
2224 #elif defined(DEBUG_NORMAL)
2225 b.color = vec4(norm, 1.);
2226 #else
2227 b.color = vec4(1.);
2228 #endif
2229
2230 return b;
2231}
2232#endif
2233
2234in vec3 a_v_pos;
2235in vec2 a_v_texCoords;
2236in vec3 a_v_normal;
2237in vec2 a_i_light;
2238in vec4 a_i_color;
2239in vec3 a_i_pos;
2240in float a_i_speed;
2241in float a_i_offset;
2242in vec3 a_i_axis;
2243out vec2 v2f_texCoords;
2244out vec4 v2f_color;
2245out float v2f_diffuse;
2246out vec2 v2f_light;
2247void main() {
2248Vertex v;
2249v.pos = a_v_pos;
2250v.texCoords = a_v_texCoords;
2251v.normal = a_v_normal;
2252Rotating i;
2253i.light = a_i_light;
2254i.color = a_i_color;
2255i.pos = a_i_pos;
2256i.speed = a_i_speed;
2257i.offset = a_i_offset;
2258i.axis = a_i_axis;
2259BlockFrag o = vertex(v, i);
2260v2f_texCoords = o.texCoords;
2261v2f_color = o.color;
2262v2f_diffuse = o.diffuse;
2263v2f_light = o.light;
2264}
2265[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
2266
2267[17:17:48] [Render thread/ERROR]: #version 150
2268#extension GL_ARB_conservative_depth : enable
2269#define FRAGMENT_SHADER
2270#define DEBUG_RAINBOW
2271#if defined(VERTEX_SHADER)
2272out float FragDistance;
2273#elif defined(FRAGMENT_SHADER)
2274in float FragDistance;
2275#endif
2276uniform vec4 uFogColor;
2277uniform vec2 uFogRange;
2278
2279float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
2280 float distXZ = length(worldPos.xz - cameraPos.xz);
2281 float distY = abs(worldPos.y - cameraPos.y);
2282 return max(distXZ, distY);
2283}
2284
2285float cylindrical_distance(vec3 worldPos) {
2286 float distXZ = length(worldPos.xz);
2287 float distY = abs(worldPos.y);
2288 return max(distXZ, distY);
2289}
2290
2291float FLWFogFactor() {
2292 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
2293}
2294
2295
2296uniform float uTime;
2297uniform mat4 uViewProjection;
2298uniform vec3 uCameraPos;
2299
2300uniform vec2 uTextureScale;
2301uniform sampler2D uBlockAtlas;
2302uniform sampler2D uLightMap;
2303uniform sampler2D uCrumbling;
2304
2305uniform vec2 uWindowSize;
2306
2307void FLWFinalizeNormal(inout vec3 normal) {
2308 // noop
2309}
2310
2311#if defined(VERTEX_SHADER)
2312void FLWFinalizeWorldPos(inout vec4 worldPos) {
2313 #if defined(USE_FOG)
2314 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
2315 #endif
2316
2317 gl_Position = uViewProjection * worldPos;
2318}
2319
2320#elif defined(FRAGMENT_SHADER)
2321
2322out vec4 fragColor;
2323
2324vec4 FLWBlockTexture(vec2 texCoords) {
2325 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
2326 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
2327 cr.a = cr.a * diffuseAlpha;
2328 return cr;
2329}
2330
2331void FLWFinalizeColor(vec4 color) {
2332 #if defined(USE_FOG)
2333 float a = color.a;
2334 float fog = clamp(FLWFogFactor(), 0., 1.);
2335
2336 color = mix(uFogColor, color, fog);
2337 color.a = a;
2338 #endif
2339
2340 if (color.a < 0.1) {
2341 discard;
2342 }
2343
2344 fragColor = color;
2345}
2346
2347vec4 FLWLight(vec2 lightCoords) {
2348 return vec4(1.);
2349}
2350#endif
2351
2352
2353mat4 rotate(vec3 axis, float angle) {
2354 float s = sin(angle);
2355 float c = cos(angle);
2356 float oc = 1. - c;
2357
2358 vec3 sa = axis * s;
2359
2360 mat4 mr = mat4(1.);
2361 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
2362 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
2363 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
2364
2365 return mr;
2366}
2367
2368mat4 rotation(vec3 rot) {
2369 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
2370}
2371
2372mat3 modelToNormal(mat4 mat) {
2373 // Discard the edges. This won't be accurate for scaled or skewed matrices,
2374 // but we don't have to work with those often.
2375 mat3 m;
2376 m[0] = mat[0].xyz;
2377 m[1] = mat[1].xyz;
2378 m[2] = mat[2].xyz;
2379 return m;
2380}
2381
2382float diffuse(vec3 normal) {
2383 vec3 n2 = normal * normal * vec3(.6, .25, .8);
2384 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
2385}
2386struct Vertex {
2387 vec3 pos;
2388 vec2 texCoords;
2389 vec3 normal;
2390};
2391
2392struct BlockFrag {
2393 vec2 texCoords;
2394 vec4 color;
2395 float diffuse;
2396 vec2 light;
2397};
2398
2399#if defined(FRAGMENT_SHADER)
2400void fragment(BlockFrag r) {
2401 vec4 tex = FLWBlockTexture(r.texCoords);
2402
2403 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
2404
2405 FLWFinalizeColor(color);
2406}
2407#endif
2408#define PI 3.1415926538
2409
2410
2411
2412
2413struct Rotating {
2414 vec2 light;
2415 vec4 color;
2416 vec3 pos;
2417 float speed;
2418 float offset;
2419 vec3 axis;
2420};
2421
2422
2423
2424
2425mat4 kineticRotation(float offset, float speed, vec3 axis) {
2426 float degrees = offset + uTime * speed * 3./10.;
2427 float angle = fract(degrees / 360.) * PI * 2.;
2428
2429 return rotate(axis, angle);
2430}
2431
2432#if defined(VERTEX_SHADER)
2433BlockFrag vertex(Vertex v, Rotating instance) {
2434 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
2435
2436 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
2437 worldPos += vec4(instance.pos + .5, 0.);
2438
2439 vec3 norm = modelToNormal(spin) * v.normal;
2440
2441 FLWFinalizeWorldPos(worldPos);
2442 FLWFinalizeNormal(norm);
2443
2444 BlockFrag b;
2445 b.diffuse = diffuse(norm);
2446 b.texCoords = v.texCoords;
2447 b.light = instance.light;
2448
2449 #if defined(DEBUG_RAINBOW)
2450 b.color = instance.color;
2451 #elif defined(DEBUG_NORMAL)
2452 b.color = vec4(norm, 1.);
2453 #else
2454 b.color = vec4(1.);
2455 #endif
2456
2457 return b;
2458}
2459#endif
2460
2461in vec2 v2f_texCoords;
2462in vec4 v2f_color;
2463in float v2f_diffuse;
2464in vec2 v2f_light;
2465void main() {
2466BlockFrag o;
2467o.texCoords = v2f_texCoords;
2468o.color = v2f_color;
2469o.diffuse = v2f_diffuse;
2470o.light = v2f_light;
2471fragment(o);
2472}
2473[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
2474
2475[17:17:48] [Render thread/ERROR]: #version 150
2476#extension GL_ARB_conservative_depth : enable
2477#define VERTEX_SHADER
2478#define DEBUG_NORMAL
2479#if defined(VERTEX_SHADER)
2480out float FragDistance;
2481#elif defined(FRAGMENT_SHADER)
2482in float FragDistance;
2483#endif
2484uniform vec4 uFogColor;
2485uniform vec2 uFogRange;
2486
2487float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
2488 float distXZ = length(worldPos.xz - cameraPos.xz);
2489 float distY = abs(worldPos.y - cameraPos.y);
2490 return max(distXZ, distY);
2491}
2492
2493float cylindrical_distance(vec3 worldPos) {
2494 float distXZ = length(worldPos.xz);
2495 float distY = abs(worldPos.y);
2496 return max(distXZ, distY);
2497}
2498
2499float FLWFogFactor() {
2500 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
2501}
2502
2503
2504uniform float uTime;
2505uniform mat4 uViewProjection;
2506uniform vec3 uCameraPos;
2507
2508uniform vec2 uTextureScale;
2509uniform sampler2D uBlockAtlas;
2510uniform sampler2D uLightMap;
2511uniform sampler2D uCrumbling;
2512
2513uniform vec2 uWindowSize;
2514
2515void FLWFinalizeNormal(inout vec3 normal) {
2516 // noop
2517}
2518
2519#if defined(VERTEX_SHADER)
2520void FLWFinalizeWorldPos(inout vec4 worldPos) {
2521 #if defined(USE_FOG)
2522 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
2523 #endif
2524
2525 gl_Position = uViewProjection * worldPos;
2526}
2527
2528#elif defined(FRAGMENT_SHADER)
2529
2530out vec4 fragColor;
2531
2532vec4 FLWBlockTexture(vec2 texCoords) {
2533 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
2534 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
2535 cr.a = cr.a * diffuseAlpha;
2536 return cr;
2537}
2538
2539void FLWFinalizeColor(vec4 color) {
2540 #if defined(USE_FOG)
2541 float a = color.a;
2542 float fog = clamp(FLWFogFactor(), 0., 1.);
2543
2544 color = mix(uFogColor, color, fog);
2545 color.a = a;
2546 #endif
2547
2548 if (color.a < 0.1) {
2549 discard;
2550 }
2551
2552 fragColor = color;
2553}
2554
2555vec4 FLWLight(vec2 lightCoords) {
2556 return vec4(1.);
2557}
2558#endif
2559
2560
2561mat4 rotate(vec3 axis, float angle) {
2562 float s = sin(angle);
2563 float c = cos(angle);
2564 float oc = 1. - c;
2565
2566 vec3 sa = axis * s;
2567
2568 mat4 mr = mat4(1.);
2569 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
2570 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
2571 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
2572
2573 return mr;
2574}
2575
2576mat4 rotation(vec3 rot) {
2577 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
2578}
2579
2580mat3 modelToNormal(mat4 mat) {
2581 // Discard the edges. This won't be accurate for scaled or skewed matrices,
2582 // but we don't have to work with those often.
2583 mat3 m;
2584 m[0] = mat[0].xyz;
2585 m[1] = mat[1].xyz;
2586 m[2] = mat[2].xyz;
2587 return m;
2588}
2589
2590float diffuse(vec3 normal) {
2591 vec3 n2 = normal * normal * vec3(.6, .25, .8);
2592 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
2593}
2594struct Vertex {
2595 vec3 pos;
2596 vec2 texCoords;
2597 vec3 normal;
2598};
2599
2600struct BlockFrag {
2601 vec2 texCoords;
2602 vec4 color;
2603 float diffuse;
2604 vec2 light;
2605};
2606
2607#if defined(FRAGMENT_SHADER)
2608void fragment(BlockFrag r) {
2609 vec4 tex = FLWBlockTexture(r.texCoords);
2610
2611 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
2612
2613 FLWFinalizeColor(color);
2614}
2615#endif
2616#define PI 3.1415926538
2617
2618
2619
2620
2621struct Rotating {
2622 vec2 light;
2623 vec4 color;
2624 vec3 pos;
2625 float speed;
2626 float offset;
2627 vec3 axis;
2628};
2629
2630
2631
2632
2633mat4 kineticRotation(float offset, float speed, vec3 axis) {
2634 float degrees = offset + uTime * speed * 3./10.;
2635 float angle = fract(degrees / 360.) * PI * 2.;
2636
2637 return rotate(axis, angle);
2638}
2639
2640#if defined(VERTEX_SHADER)
2641BlockFrag vertex(Vertex v, Rotating instance) {
2642 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
2643
2644 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
2645 worldPos += vec4(instance.pos + .5, 0.);
2646
2647 vec3 norm = modelToNormal(spin) * v.normal;
2648
2649 FLWFinalizeWorldPos(worldPos);
2650 FLWFinalizeNormal(norm);
2651
2652 BlockFrag b;
2653 b.diffuse = diffuse(norm);
2654 b.texCoords = v.texCoords;
2655 b.light = instance.light;
2656
2657 #if defined(DEBUG_RAINBOW)
2658 b.color = instance.color;
2659 #elif defined(DEBUG_NORMAL)
2660 b.color = vec4(norm, 1.);
2661 #else
2662 b.color = vec4(1.);
2663 #endif
2664
2665 return b;
2666}
2667#endif
2668
2669in vec3 a_v_pos;
2670in vec2 a_v_texCoords;
2671in vec3 a_v_normal;
2672in vec2 a_i_light;
2673in vec4 a_i_color;
2674in vec3 a_i_pos;
2675in float a_i_speed;
2676in float a_i_offset;
2677in vec3 a_i_axis;
2678out vec2 v2f_texCoords;
2679out vec4 v2f_color;
2680out float v2f_diffuse;
2681out vec2 v2f_light;
2682void main() {
2683Vertex v;
2684v.pos = a_v_pos;
2685v.texCoords = a_v_texCoords;
2686v.normal = a_v_normal;
2687Rotating i;
2688i.light = a_i_light;
2689i.color = a_i_color;
2690i.pos = a_i_pos;
2691i.speed = a_i_speed;
2692i.offset = a_i_offset;
2693i.axis = a_i_axis;
2694BlockFrag o = vertex(v, i);
2695v2f_texCoords = o.texCoords;
2696v2f_color = o.color;
2697v2f_diffuse = o.diffuse;
2698v2f_light = o.light;
2699}
2700[17:17:48] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
2701
2702[17:17:48] [Render thread/ERROR]: #version 150
2703#extension GL_ARB_conservative_depth : enable
2704#define FRAGMENT_SHADER
2705#define DEBUG_NORMAL
2706#if defined(VERTEX_SHADER)
2707out float FragDistance;
2708#elif defined(FRAGMENT_SHADER)
2709in float FragDistance;
2710#endif
2711uniform vec4 uFogColor;
2712uniform vec2 uFogRange;
2713
2714float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
2715 float distXZ = length(worldPos.xz - cameraPos.xz);
2716 float distY = abs(worldPos.y - cameraPos.y);
2717 return max(distXZ, distY);
2718}
2719
2720float cylindrical_distance(vec3 worldPos) {
2721 float distXZ = length(worldPos.xz);
2722 float distY = abs(worldPos.y);
2723 return max(distXZ, distY);
2724}
2725
2726float FLWFogFactor() {
2727 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
2728}
2729
2730
2731uniform float uTime;
2732uniform mat4 uViewProjection;
2733uniform vec3 uCameraPos;
2734
2735uniform vec2 uTextureScale;
2736uniform sampler2D uBlockAtlas;
2737uniform sampler2D uLightMap;
2738uniform sampler2D uCrumbling;
2739
2740uniform vec2 uWindowSize;
2741
2742void FLWFinalizeNormal(inout vec3 normal) {
2743 // noop
2744}
2745
2746#if defined(VERTEX_SHADER)
2747void FLWFinalizeWorldPos(inout vec4 worldPos) {
2748 #if defined(USE_FOG)
2749 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
2750 #endif
2751
2752 gl_Position = uViewProjection * worldPos;
2753}
2754
2755#elif defined(FRAGMENT_SHADER)
2756
2757out vec4 fragColor;
2758
2759vec4 FLWBlockTexture(vec2 texCoords) {
2760 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
2761 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
2762 cr.a = cr.a * diffuseAlpha;
2763 return cr;
2764}
2765
2766void FLWFinalizeColor(vec4 color) {
2767 #if defined(USE_FOG)
2768 float a = color.a;
2769 float fog = clamp(FLWFogFactor(), 0., 1.);
2770
2771 color = mix(uFogColor, color, fog);
2772 color.a = a;
2773 #endif
2774
2775 if (color.a < 0.1) {
2776 discard;
2777 }
2778
2779 fragColor = color;
2780}
2781
2782vec4 FLWLight(vec2 lightCoords) {
2783 return vec4(1.);
2784}
2785#endif
2786
2787
2788mat4 rotate(vec3 axis, float angle) {
2789 float s = sin(angle);
2790 float c = cos(angle);
2791 float oc = 1. - c;
2792
2793 vec3 sa = axis * s;
2794
2795 mat4 mr = mat4(1.);
2796 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
2797 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
2798 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
2799
2800 return mr;
2801}
2802
2803mat4 rotation(vec3 rot) {
2804 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
2805}
2806
2807mat3 modelToNormal(mat4 mat) {
2808 // Discard the edges. This won't be accurate for scaled or skewed matrices,
2809 // but we don't have to work with those often.
2810 mat3 m;
2811 m[0] = mat[0].xyz;
2812 m[1] = mat[1].xyz;
2813 m[2] = mat[2].xyz;
2814 return m;
2815}
2816
2817float diffuse(vec3 normal) {
2818 vec3 n2 = normal * normal * vec3(.6, .25, .8);
2819 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
2820}
2821struct Vertex {
2822 vec3 pos;
2823 vec2 texCoords;
2824 vec3 normal;
2825};
2826
2827struct BlockFrag {
2828 vec2 texCoords;
2829 vec4 color;
2830 float diffuse;
2831 vec2 light;
2832};
2833
2834#if defined(FRAGMENT_SHADER)
2835void fragment(BlockFrag r) {
2836 vec4 tex = FLWBlockTexture(r.texCoords);
2837
2838 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
2839
2840 FLWFinalizeColor(color);
2841}
2842#endif
2843#define PI 3.1415926538
2844
2845
2846
2847
2848struct Rotating {
2849 vec2 light;
2850 vec4 color;
2851 vec3 pos;
2852 float speed;
2853 float offset;
2854 vec3 axis;
2855};
2856
2857
2858
2859
2860mat4 kineticRotation(float offset, float speed, vec3 axis) {
2861 float degrees = offset + uTime * speed * 3./10.;
2862 float angle = fract(degrees / 360.) * PI * 2.;
2863
2864 return rotate(axis, angle);
2865}
2866
2867#if defined(VERTEX_SHADER)
2868BlockFrag vertex(Vertex v, Rotating instance) {
2869 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
2870
2871 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
2872 worldPos += vec4(instance.pos + .5, 0.);
2873
2874 vec3 norm = modelToNormal(spin) * v.normal;
2875
2876 FLWFinalizeWorldPos(worldPos);
2877 FLWFinalizeNormal(norm);
2878
2879 BlockFrag b;
2880 b.diffuse = diffuse(norm);
2881 b.texCoords = v.texCoords;
2882 b.light = instance.light;
2883
2884 #if defined(DEBUG_RAINBOW)
2885 b.color = instance.color;
2886 #elif defined(DEBUG_NORMAL)
2887 b.color = vec4(norm, 1.);
2888 #else
2889 b.color = vec4(1.);
2890 #endif
2891
2892 return b;
2893}
2894#endif
2895
2896in vec2 v2f_texCoords;
2897in vec4 v2f_color;
2898in float v2f_diffuse;
2899in vec2 v2f_light;
2900void main() {
2901BlockFrag o;
2902o.texCoords = v2f_texCoords;
2903o.color = v2f_color;
2904o.diffuse = v2f_diffuse;
2905o.light = v2f_light;
2906fragment(o);
2907}
2908[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
2909
2910[17:17:49] [Render thread/ERROR]: #version 150
2911#extension GL_ARB_conservative_depth : enable
2912#define VERTEX_SHADER
2913#if defined(VERTEX_SHADER)
2914out float FragDistance;
2915#elif defined(FRAGMENT_SHADER)
2916in float FragDistance;
2917#endif
2918uniform vec4 uFogColor;
2919uniform vec2 uFogRange;
2920
2921float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
2922 float distXZ = length(worldPos.xz - cameraPos.xz);
2923 float distY = abs(worldPos.y - cameraPos.y);
2924 return max(distXZ, distY);
2925}
2926
2927float cylindrical_distance(vec3 worldPos) {
2928 float distXZ = length(worldPos.xz);
2929 float distY = abs(worldPos.y);
2930 return max(distXZ, distY);
2931}
2932
2933float FLWFogFactor() {
2934 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
2935}
2936
2937
2938uniform float uTime;
2939uniform mat4 uViewProjection;
2940uniform vec3 uCameraPos;
2941
2942uniform vec2 uTextureScale;
2943uniform sampler2D uBlockAtlas;
2944uniform sampler2D uLightMap;
2945uniform sampler2D uCrumbling;
2946
2947uniform vec2 uWindowSize;
2948
2949void FLWFinalizeNormal(inout vec3 normal) {
2950 // noop
2951}
2952
2953#if defined(VERTEX_SHADER)
2954void FLWFinalizeWorldPos(inout vec4 worldPos) {
2955 #if defined(USE_FOG)
2956 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
2957 #endif
2958
2959 gl_Position = uViewProjection * worldPos;
2960}
2961
2962#elif defined(FRAGMENT_SHADER)
2963
2964out vec4 fragColor;
2965
2966vec4 FLWBlockTexture(vec2 texCoords) {
2967 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
2968 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
2969 cr.a = cr.a * diffuseAlpha;
2970 return cr;
2971}
2972
2973void FLWFinalizeColor(vec4 color) {
2974 #if defined(USE_FOG)
2975 float a = color.a;
2976 float fog = clamp(FLWFogFactor(), 0., 1.);
2977
2978 color = mix(uFogColor, color, fog);
2979 color.a = a;
2980 #endif
2981
2982 if (color.a < 0.1) {
2983 discard;
2984 }
2985
2986 fragColor = color;
2987}
2988
2989vec4 FLWLight(vec2 lightCoords) {
2990 return vec4(1.);
2991}
2992#endif
2993
2994
2995mat4 rotate(vec3 axis, float angle) {
2996 float s = sin(angle);
2997 float c = cos(angle);
2998 float oc = 1. - c;
2999
3000 vec3 sa = axis * s;
3001
3002 mat4 mr = mat4(1.);
3003 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
3004 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
3005 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
3006
3007 return mr;
3008}
3009
3010mat4 rotation(vec3 rot) {
3011 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
3012}
3013
3014mat3 modelToNormal(mat4 mat) {
3015 // Discard the edges. This won't be accurate for scaled or skewed matrices,
3016 // but we don't have to work with those often.
3017 mat3 m;
3018 m[0] = mat[0].xyz;
3019 m[1] = mat[1].xyz;
3020 m[2] = mat[2].xyz;
3021 return m;
3022}
3023
3024#define PIOVER2 1.5707963268
3025
3026vec4 quat(vec3 axis, float angle) {
3027 float halfAngle = angle * PIOVER2 / 180.0;
3028 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
3029 return vec4(axis.xyz * cs.y, cs.x);
3030}
3031
3032vec4 quatMult(vec4 q1, vec4 q2) {
3033 // disgustingly vectorized quaternion multiplication
3034 vec4 a = q1.w * q2.xyzw;
3035 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
3036 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
3037 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
3038
3039 return a + b + c + d;
3040}
3041
3042vec3 rotateVertexByQuat(vec3 v, vec4 q) {
3043 vec3 i = q.xyz;
3044 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
3045}
3046
3047vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
3048 return rotateVertexByQuat(v, quat(axis, angle));
3049}
3050
3051float diffuse(vec3 normal) {
3052 vec3 n2 = normal * normal * vec3(.6, .25, .8);
3053 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
3054}
3055struct Vertex {
3056 vec3 pos;
3057 vec2 texCoords;
3058 vec3 normal;
3059};
3060
3061struct BlockFrag {
3062 vec2 texCoords;
3063 vec4 color;
3064 float diffuse;
3065 vec2 light;
3066};
3067
3068#if defined(FRAGMENT_SHADER)
3069void fragment(BlockFrag r) {
3070 vec4 tex = FLWBlockTexture(r.texCoords);
3071
3072 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
3073
3074 FLWFinalizeColor(color);
3075}
3076#endif
3077#define PI 3.1415926538
3078
3079
3080
3081
3082
3083struct Actor {
3084 vec3 pos;
3085 vec2 light;
3086 float offset;
3087 vec3 axis;
3088 vec4 rotation;
3089 vec3 rotationCenter;
3090 float speed;
3091};
3092
3093
3094
3095
3096#if defined(VERTEX_SHADER)
3097BlockFrag vertex(Vertex v, Actor instance) {
3098 float degrees = instance.offset + uTime * instance.speed / 20.;
3099 //float angle = fract(degrees / 360.) * PI * 2.;
3100
3101 vec4 kineticRot = quat(instance.axis, degrees);
3102 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
3103
3104 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
3105 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
3106
3107 FLWFinalizeWorldPos(worldPos);
3108 FLWFinalizeNormal(norm);
3109
3110 BlockFrag b;
3111 b.diffuse = diffuse(norm);
3112 b.texCoords = v.texCoords;
3113 b.light = instance.light;
3114
3115 #if defined(DEBUG_NORMAL)
3116 b.color = vec4(norm, 1.);
3117 #else
3118 b.color = vec4(1.);
3119 #endif
3120
3121 return b;
3122}
3123#endif
3124
3125in vec3 a_v_pos;
3126in vec2 a_v_texCoords;
3127in vec3 a_v_normal;
3128in vec3 a_i_pos;
3129in vec2 a_i_light;
3130in float a_i_offset;
3131in vec3 a_i_axis;
3132in vec4 a_i_rotation;
3133in vec3 a_i_rotationCenter;
3134in float a_i_speed;
3135out vec2 v2f_texCoords;
3136out vec4 v2f_color;
3137out float v2f_diffuse;
3138out vec2 v2f_light;
3139void main() {
3140Vertex v;
3141v.pos = a_v_pos;
3142v.texCoords = a_v_texCoords;
3143v.normal = a_v_normal;
3144Actor i;
3145i.pos = a_i_pos;
3146i.light = a_i_light;
3147i.offset = a_i_offset;
3148i.axis = a_i_axis;
3149i.rotation = a_i_rotation;
3150i.rotationCenter = a_i_rotationCenter;
3151i.speed = a_i_speed;
3152BlockFrag o = vertex(v, i);
3153v2f_texCoords = o.texCoords;
3154v2f_color = o.color;
3155v2f_diffuse = o.diffuse;
3156v2f_light = o.light;
3157}
3158[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
3159
3160[17:17:49] [Render thread/ERROR]: #version 150
3161#extension GL_ARB_conservative_depth : enable
3162#define FRAGMENT_SHADER
3163#if defined(VERTEX_SHADER)
3164out float FragDistance;
3165#elif defined(FRAGMENT_SHADER)
3166in float FragDistance;
3167#endif
3168uniform vec4 uFogColor;
3169uniform vec2 uFogRange;
3170
3171float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
3172 float distXZ = length(worldPos.xz - cameraPos.xz);
3173 float distY = abs(worldPos.y - cameraPos.y);
3174 return max(distXZ, distY);
3175}
3176
3177float cylindrical_distance(vec3 worldPos) {
3178 float distXZ = length(worldPos.xz);
3179 float distY = abs(worldPos.y);
3180 return max(distXZ, distY);
3181}
3182
3183float FLWFogFactor() {
3184 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
3185}
3186
3187
3188uniform float uTime;
3189uniform mat4 uViewProjection;
3190uniform vec3 uCameraPos;
3191
3192uniform vec2 uTextureScale;
3193uniform sampler2D uBlockAtlas;
3194uniform sampler2D uLightMap;
3195uniform sampler2D uCrumbling;
3196
3197uniform vec2 uWindowSize;
3198
3199void FLWFinalizeNormal(inout vec3 normal) {
3200 // noop
3201}
3202
3203#if defined(VERTEX_SHADER)
3204void FLWFinalizeWorldPos(inout vec4 worldPos) {
3205 #if defined(USE_FOG)
3206 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
3207 #endif
3208
3209 gl_Position = uViewProjection * worldPos;
3210}
3211
3212#elif defined(FRAGMENT_SHADER)
3213
3214out vec4 fragColor;
3215
3216vec4 FLWBlockTexture(vec2 texCoords) {
3217 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
3218 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
3219 cr.a = cr.a * diffuseAlpha;
3220 return cr;
3221}
3222
3223void FLWFinalizeColor(vec4 color) {
3224 #if defined(USE_FOG)
3225 float a = color.a;
3226 float fog = clamp(FLWFogFactor(), 0., 1.);
3227
3228 color = mix(uFogColor, color, fog);
3229 color.a = a;
3230 #endif
3231
3232 if (color.a < 0.1) {
3233 discard;
3234 }
3235
3236 fragColor = color;
3237}
3238
3239vec4 FLWLight(vec2 lightCoords) {
3240 return vec4(1.);
3241}
3242#endif
3243
3244
3245mat4 rotate(vec3 axis, float angle) {
3246 float s = sin(angle);
3247 float c = cos(angle);
3248 float oc = 1. - c;
3249
3250 vec3 sa = axis * s;
3251
3252 mat4 mr = mat4(1.);
3253 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
3254 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
3255 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
3256
3257 return mr;
3258}
3259
3260mat4 rotation(vec3 rot) {
3261 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
3262}
3263
3264mat3 modelToNormal(mat4 mat) {
3265 // Discard the edges. This won't be accurate for scaled or skewed matrices,
3266 // but we don't have to work with those often.
3267 mat3 m;
3268 m[0] = mat[0].xyz;
3269 m[1] = mat[1].xyz;
3270 m[2] = mat[2].xyz;
3271 return m;
3272}
3273
3274#define PIOVER2 1.5707963268
3275
3276vec4 quat(vec3 axis, float angle) {
3277 float halfAngle = angle * PIOVER2 / 180.0;
3278 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
3279 return vec4(axis.xyz * cs.y, cs.x);
3280}
3281
3282vec4 quatMult(vec4 q1, vec4 q2) {
3283 // disgustingly vectorized quaternion multiplication
3284 vec4 a = q1.w * q2.xyzw;
3285 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
3286 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
3287 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
3288
3289 return a + b + c + d;
3290}
3291
3292vec3 rotateVertexByQuat(vec3 v, vec4 q) {
3293 vec3 i = q.xyz;
3294 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
3295}
3296
3297vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
3298 return rotateVertexByQuat(v, quat(axis, angle));
3299}
3300
3301float diffuse(vec3 normal) {
3302 vec3 n2 = normal * normal * vec3(.6, .25, .8);
3303 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
3304}
3305struct Vertex {
3306 vec3 pos;
3307 vec2 texCoords;
3308 vec3 normal;
3309};
3310
3311struct BlockFrag {
3312 vec2 texCoords;
3313 vec4 color;
3314 float diffuse;
3315 vec2 light;
3316};
3317
3318#if defined(FRAGMENT_SHADER)
3319void fragment(BlockFrag r) {
3320 vec4 tex = FLWBlockTexture(r.texCoords);
3321
3322 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
3323
3324 FLWFinalizeColor(color);
3325}
3326#endif
3327#define PI 3.1415926538
3328
3329
3330
3331
3332
3333struct Actor {
3334 vec3 pos;
3335 vec2 light;
3336 float offset;
3337 vec3 axis;
3338 vec4 rotation;
3339 vec3 rotationCenter;
3340 float speed;
3341};
3342
3343
3344
3345
3346#if defined(VERTEX_SHADER)
3347BlockFrag vertex(Vertex v, Actor instance) {
3348 float degrees = instance.offset + uTime * instance.speed / 20.;
3349 //float angle = fract(degrees / 360.) * PI * 2.;
3350
3351 vec4 kineticRot = quat(instance.axis, degrees);
3352 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
3353
3354 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
3355 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
3356
3357 FLWFinalizeWorldPos(worldPos);
3358 FLWFinalizeNormal(norm);
3359
3360 BlockFrag b;
3361 b.diffuse = diffuse(norm);
3362 b.texCoords = v.texCoords;
3363 b.light = instance.light;
3364
3365 #if defined(DEBUG_NORMAL)
3366 b.color = vec4(norm, 1.);
3367 #else
3368 b.color = vec4(1.);
3369 #endif
3370
3371 return b;
3372}
3373#endif
3374
3375in vec2 v2f_texCoords;
3376in vec4 v2f_color;
3377in float v2f_diffuse;
3378in vec2 v2f_light;
3379void main() {
3380BlockFrag o;
3381o.texCoords = v2f_texCoords;
3382o.color = v2f_color;
3383o.diffuse = v2f_diffuse;
3384o.light = v2f_light;
3385fragment(o);
3386}
3387[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
3388
3389[17:17:49] [Render thread/ERROR]: #version 150
3390#extension GL_ARB_conservative_depth : enable
3391#define VERTEX_SHADER
3392#define DEBUG_NORMAL
3393#if defined(VERTEX_SHADER)
3394out float FragDistance;
3395#elif defined(FRAGMENT_SHADER)
3396in float FragDistance;
3397#endif
3398uniform vec4 uFogColor;
3399uniform vec2 uFogRange;
3400
3401float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
3402 float distXZ = length(worldPos.xz - cameraPos.xz);
3403 float distY = abs(worldPos.y - cameraPos.y);
3404 return max(distXZ, distY);
3405}
3406
3407float cylindrical_distance(vec3 worldPos) {
3408 float distXZ = length(worldPos.xz);
3409 float distY = abs(worldPos.y);
3410 return max(distXZ, distY);
3411}
3412
3413float FLWFogFactor() {
3414 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
3415}
3416
3417
3418uniform float uTime;
3419uniform mat4 uViewProjection;
3420uniform vec3 uCameraPos;
3421
3422uniform vec2 uTextureScale;
3423uniform sampler2D uBlockAtlas;
3424uniform sampler2D uLightMap;
3425uniform sampler2D uCrumbling;
3426
3427uniform vec2 uWindowSize;
3428
3429void FLWFinalizeNormal(inout vec3 normal) {
3430 // noop
3431}
3432
3433#if defined(VERTEX_SHADER)
3434void FLWFinalizeWorldPos(inout vec4 worldPos) {
3435 #if defined(USE_FOG)
3436 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
3437 #endif
3438
3439 gl_Position = uViewProjection * worldPos;
3440}
3441
3442#elif defined(FRAGMENT_SHADER)
3443
3444out vec4 fragColor;
3445
3446vec4 FLWBlockTexture(vec2 texCoords) {
3447 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
3448 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
3449 cr.a = cr.a * diffuseAlpha;
3450 return cr;
3451}
3452
3453void FLWFinalizeColor(vec4 color) {
3454 #if defined(USE_FOG)
3455 float a = color.a;
3456 float fog = clamp(FLWFogFactor(), 0., 1.);
3457
3458 color = mix(uFogColor, color, fog);
3459 color.a = a;
3460 #endif
3461
3462 if (color.a < 0.1) {
3463 discard;
3464 }
3465
3466 fragColor = color;
3467}
3468
3469vec4 FLWLight(vec2 lightCoords) {
3470 return vec4(1.);
3471}
3472#endif
3473
3474
3475mat4 rotate(vec3 axis, float angle) {
3476 float s = sin(angle);
3477 float c = cos(angle);
3478 float oc = 1. - c;
3479
3480 vec3 sa = axis * s;
3481
3482 mat4 mr = mat4(1.);
3483 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
3484 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
3485 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
3486
3487 return mr;
3488}
3489
3490mat4 rotation(vec3 rot) {
3491 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
3492}
3493
3494mat3 modelToNormal(mat4 mat) {
3495 // Discard the edges. This won't be accurate for scaled or skewed matrices,
3496 // but we don't have to work with those often.
3497 mat3 m;
3498 m[0] = mat[0].xyz;
3499 m[1] = mat[1].xyz;
3500 m[2] = mat[2].xyz;
3501 return m;
3502}
3503
3504#define PIOVER2 1.5707963268
3505
3506vec4 quat(vec3 axis, float angle) {
3507 float halfAngle = angle * PIOVER2 / 180.0;
3508 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
3509 return vec4(axis.xyz * cs.y, cs.x);
3510}
3511
3512vec4 quatMult(vec4 q1, vec4 q2) {
3513 // disgustingly vectorized quaternion multiplication
3514 vec4 a = q1.w * q2.xyzw;
3515 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
3516 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
3517 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
3518
3519 return a + b + c + d;
3520}
3521
3522vec3 rotateVertexByQuat(vec3 v, vec4 q) {
3523 vec3 i = q.xyz;
3524 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
3525}
3526
3527vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
3528 return rotateVertexByQuat(v, quat(axis, angle));
3529}
3530
3531float diffuse(vec3 normal) {
3532 vec3 n2 = normal * normal * vec3(.6, .25, .8);
3533 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
3534}
3535struct Vertex {
3536 vec3 pos;
3537 vec2 texCoords;
3538 vec3 normal;
3539};
3540
3541struct BlockFrag {
3542 vec2 texCoords;
3543 vec4 color;
3544 float diffuse;
3545 vec2 light;
3546};
3547
3548#if defined(FRAGMENT_SHADER)
3549void fragment(BlockFrag r) {
3550 vec4 tex = FLWBlockTexture(r.texCoords);
3551
3552 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
3553
3554 FLWFinalizeColor(color);
3555}
3556#endif
3557#define PI 3.1415926538
3558
3559
3560
3561
3562
3563struct Actor {
3564 vec3 pos;
3565 vec2 light;
3566 float offset;
3567 vec3 axis;
3568 vec4 rotation;
3569 vec3 rotationCenter;
3570 float speed;
3571};
3572
3573
3574
3575
3576#if defined(VERTEX_SHADER)
3577BlockFrag vertex(Vertex v, Actor instance) {
3578 float degrees = instance.offset + uTime * instance.speed / 20.;
3579 //float angle = fract(degrees / 360.) * PI * 2.;
3580
3581 vec4 kineticRot = quat(instance.axis, degrees);
3582 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
3583
3584 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
3585 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
3586
3587 FLWFinalizeWorldPos(worldPos);
3588 FLWFinalizeNormal(norm);
3589
3590 BlockFrag b;
3591 b.diffuse = diffuse(norm);
3592 b.texCoords = v.texCoords;
3593 b.light = instance.light;
3594
3595 #if defined(DEBUG_NORMAL)
3596 b.color = vec4(norm, 1.);
3597 #else
3598 b.color = vec4(1.);
3599 #endif
3600
3601 return b;
3602}
3603#endif
3604
3605in vec3 a_v_pos;
3606in vec2 a_v_texCoords;
3607in vec3 a_v_normal;
3608in vec3 a_i_pos;
3609in vec2 a_i_light;
3610in float a_i_offset;
3611in vec3 a_i_axis;
3612in vec4 a_i_rotation;
3613in vec3 a_i_rotationCenter;
3614in float a_i_speed;
3615out vec2 v2f_texCoords;
3616out vec4 v2f_color;
3617out float v2f_diffuse;
3618out vec2 v2f_light;
3619void main() {
3620Vertex v;
3621v.pos = a_v_pos;
3622v.texCoords = a_v_texCoords;
3623v.normal = a_v_normal;
3624Actor i;
3625i.pos = a_i_pos;
3626i.light = a_i_light;
3627i.offset = a_i_offset;
3628i.axis = a_i_axis;
3629i.rotation = a_i_rotation;
3630i.rotationCenter = a_i_rotationCenter;
3631i.speed = a_i_speed;
3632BlockFrag o = vertex(v, i);
3633v2f_texCoords = o.texCoords;
3634v2f_color = o.color;
3635v2f_diffuse = o.diffuse;
3636v2f_light = o.light;
3637}
3638[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
3639
3640[17:17:49] [Render thread/ERROR]: #version 150
3641#extension GL_ARB_conservative_depth : enable
3642#define FRAGMENT_SHADER
3643#define DEBUG_NORMAL
3644#if defined(VERTEX_SHADER)
3645out float FragDistance;
3646#elif defined(FRAGMENT_SHADER)
3647in float FragDistance;
3648#endif
3649uniform vec4 uFogColor;
3650uniform vec2 uFogRange;
3651
3652float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
3653 float distXZ = length(worldPos.xz - cameraPos.xz);
3654 float distY = abs(worldPos.y - cameraPos.y);
3655 return max(distXZ, distY);
3656}
3657
3658float cylindrical_distance(vec3 worldPos) {
3659 float distXZ = length(worldPos.xz);
3660 float distY = abs(worldPos.y);
3661 return max(distXZ, distY);
3662}
3663
3664float FLWFogFactor() {
3665 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
3666}
3667
3668
3669uniform float uTime;
3670uniform mat4 uViewProjection;
3671uniform vec3 uCameraPos;
3672
3673uniform vec2 uTextureScale;
3674uniform sampler2D uBlockAtlas;
3675uniform sampler2D uLightMap;
3676uniform sampler2D uCrumbling;
3677
3678uniform vec2 uWindowSize;
3679
3680void FLWFinalizeNormal(inout vec3 normal) {
3681 // noop
3682}
3683
3684#if defined(VERTEX_SHADER)
3685void FLWFinalizeWorldPos(inout vec4 worldPos) {
3686 #if defined(USE_FOG)
3687 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
3688 #endif
3689
3690 gl_Position = uViewProjection * worldPos;
3691}
3692
3693#elif defined(FRAGMENT_SHADER)
3694
3695out vec4 fragColor;
3696
3697vec4 FLWBlockTexture(vec2 texCoords) {
3698 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
3699 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
3700 cr.a = cr.a * diffuseAlpha;
3701 return cr;
3702}
3703
3704void FLWFinalizeColor(vec4 color) {
3705 #if defined(USE_FOG)
3706 float a = color.a;
3707 float fog = clamp(FLWFogFactor(), 0., 1.);
3708
3709 color = mix(uFogColor, color, fog);
3710 color.a = a;
3711 #endif
3712
3713 if (color.a < 0.1) {
3714 discard;
3715 }
3716
3717 fragColor = color;
3718}
3719
3720vec4 FLWLight(vec2 lightCoords) {
3721 return vec4(1.);
3722}
3723#endif
3724
3725
3726mat4 rotate(vec3 axis, float angle) {
3727 float s = sin(angle);
3728 float c = cos(angle);
3729 float oc = 1. - c;
3730
3731 vec3 sa = axis * s;
3732
3733 mat4 mr = mat4(1.);
3734 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
3735 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
3736 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
3737
3738 return mr;
3739}
3740
3741mat4 rotation(vec3 rot) {
3742 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
3743}
3744
3745mat3 modelToNormal(mat4 mat) {
3746 // Discard the edges. This won't be accurate for scaled or skewed matrices,
3747 // but we don't have to work with those often.
3748 mat3 m;
3749 m[0] = mat[0].xyz;
3750 m[1] = mat[1].xyz;
3751 m[2] = mat[2].xyz;
3752 return m;
3753}
3754
3755#define PIOVER2 1.5707963268
3756
3757vec4 quat(vec3 axis, float angle) {
3758 float halfAngle = angle * PIOVER2 / 180.0;
3759 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
3760 return vec4(axis.xyz * cs.y, cs.x);
3761}
3762
3763vec4 quatMult(vec4 q1, vec4 q2) {
3764 // disgustingly vectorized quaternion multiplication
3765 vec4 a = q1.w * q2.xyzw;
3766 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
3767 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
3768 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
3769
3770 return a + b + c + d;
3771}
3772
3773vec3 rotateVertexByQuat(vec3 v, vec4 q) {
3774 vec3 i = q.xyz;
3775 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
3776}
3777
3778vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
3779 return rotateVertexByQuat(v, quat(axis, angle));
3780}
3781
3782float diffuse(vec3 normal) {
3783 vec3 n2 = normal * normal * vec3(.6, .25, .8);
3784 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
3785}
3786struct Vertex {
3787 vec3 pos;
3788 vec2 texCoords;
3789 vec3 normal;
3790};
3791
3792struct BlockFrag {
3793 vec2 texCoords;
3794 vec4 color;
3795 float diffuse;
3796 vec2 light;
3797};
3798
3799#if defined(FRAGMENT_SHADER)
3800void fragment(BlockFrag r) {
3801 vec4 tex = FLWBlockTexture(r.texCoords);
3802
3803 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
3804
3805 FLWFinalizeColor(color);
3806}
3807#endif
3808#define PI 3.1415926538
3809
3810
3811
3812
3813
3814struct Actor {
3815 vec3 pos;
3816 vec2 light;
3817 float offset;
3818 vec3 axis;
3819 vec4 rotation;
3820 vec3 rotationCenter;
3821 float speed;
3822};
3823
3824
3825
3826
3827#if defined(VERTEX_SHADER)
3828BlockFrag vertex(Vertex v, Actor instance) {
3829 float degrees = instance.offset + uTime * instance.speed / 20.;
3830 //float angle = fract(degrees / 360.) * PI * 2.;
3831
3832 vec4 kineticRot = quat(instance.axis, degrees);
3833 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
3834
3835 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
3836 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
3837
3838 FLWFinalizeWorldPos(worldPos);
3839 FLWFinalizeNormal(norm);
3840
3841 BlockFrag b;
3842 b.diffuse = diffuse(norm);
3843 b.texCoords = v.texCoords;
3844 b.light = instance.light;
3845
3846 #if defined(DEBUG_NORMAL)
3847 b.color = vec4(norm, 1.);
3848 #else
3849 b.color = vec4(1.);
3850 #endif
3851
3852 return b;
3853}
3854#endif
3855
3856in vec2 v2f_texCoords;
3857in vec4 v2f_color;
3858in float v2f_diffuse;
3859in vec2 v2f_light;
3860void main() {
3861BlockFrag o;
3862o.texCoords = v2f_texCoords;
3863o.color = v2f_color;
3864o.diffuse = v2f_diffuse;
3865o.light = v2f_light;
3866fragment(o);
3867}
3868[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
3869
3870[17:17:49] [Render thread/ERROR]: #version 150
3871#extension GL_ARB_conservative_depth : enable
3872#define VERTEX_SHADER
3873#if defined(VERTEX_SHADER)
3874out float FragDistance;
3875#elif defined(FRAGMENT_SHADER)
3876in float FragDistance;
3877#endif
3878uniform vec4 uFogColor;
3879uniform vec2 uFogRange;
3880
3881float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
3882 float distXZ = length(worldPos.xz - cameraPos.xz);
3883 float distY = abs(worldPos.y - cameraPos.y);
3884 return max(distXZ, distY);
3885}
3886
3887float cylindrical_distance(vec3 worldPos) {
3888 float distXZ = length(worldPos.xz);
3889 float distY = abs(worldPos.y);
3890 return max(distXZ, distY);
3891}
3892
3893float FLWFogFactor() {
3894 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
3895}
3896
3897
3898uniform float uTime;
3899uniform mat4 uViewProjection;
3900uniform vec3 uCameraPos;
3901
3902uniform vec2 uTextureScale;
3903uniform sampler2D uBlockAtlas;
3904uniform sampler2D uLightMap;
3905uniform sampler2D uCrumbling;
3906
3907uniform vec2 uWindowSize;
3908
3909void FLWFinalizeNormal(inout vec3 normal) {
3910 // noop
3911}
3912
3913#if defined(VERTEX_SHADER)
3914void FLWFinalizeWorldPos(inout vec4 worldPos) {
3915 #if defined(USE_FOG)
3916 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
3917 #endif
3918
3919 gl_Position = uViewProjection * worldPos;
3920}
3921
3922#elif defined(FRAGMENT_SHADER)
3923
3924out vec4 fragColor;
3925
3926vec4 FLWBlockTexture(vec2 texCoords) {
3927 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
3928 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
3929 cr.a = cr.a * diffuseAlpha;
3930 return cr;
3931}
3932
3933void FLWFinalizeColor(vec4 color) {
3934 #if defined(USE_FOG)
3935 float a = color.a;
3936 float fog = clamp(FLWFogFactor(), 0., 1.);
3937
3938 color = mix(uFogColor, color, fog);
3939 color.a = a;
3940 #endif
3941
3942 if (color.a < 0.1) {
3943 discard;
3944 }
3945
3946 fragColor = color;
3947}
3948
3949vec4 FLWLight(vec2 lightCoords) {
3950 return vec4(1.);
3951}
3952#endif
3953
3954
3955mat4 rotate(vec3 axis, float angle) {
3956 float s = sin(angle);
3957 float c = cos(angle);
3958 float oc = 1. - c;
3959
3960 vec3 sa = axis * s;
3961
3962 mat4 mr = mat4(1.);
3963 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
3964 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
3965 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
3966
3967 return mr;
3968}
3969
3970mat4 rotation(vec3 rot) {
3971 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
3972}
3973
3974mat3 modelToNormal(mat4 mat) {
3975 // Discard the edges. This won't be accurate for scaled or skewed matrices,
3976 // but we don't have to work with those often.
3977 mat3 m;
3978 m[0] = mat[0].xyz;
3979 m[1] = mat[1].xyz;
3980 m[2] = mat[2].xyz;
3981 return m;
3982}
3983
3984#define PIOVER2 1.5707963268
3985
3986vec4 quat(vec3 axis, float angle) {
3987 float halfAngle = angle * PIOVER2 / 180.0;
3988 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
3989 return vec4(axis.xyz * cs.y, cs.x);
3990}
3991
3992vec4 quatMult(vec4 q1, vec4 q2) {
3993 // disgustingly vectorized quaternion multiplication
3994 vec4 a = q1.w * q2.xyzw;
3995 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
3996 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
3997 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
3998
3999 return a + b + c + d;
4000}
4001
4002vec3 rotateVertexByQuat(vec3 v, vec4 q) {
4003 vec3 i = q.xyz;
4004 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
4005}
4006
4007vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
4008 return rotateVertexByQuat(v, quat(axis, angle));
4009}
4010
4011float diffuse(vec3 normal) {
4012 vec3 n2 = normal * normal * vec3(.6, .25, .8);
4013 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
4014}
4015struct Vertex {
4016 vec3 pos;
4017 vec2 texCoords;
4018 vec3 normal;
4019};
4020
4021struct BlockFrag {
4022 vec2 texCoords;
4023 vec4 color;
4024 float diffuse;
4025 vec2 light;
4026};
4027
4028#if defined(FRAGMENT_SHADER)
4029void fragment(BlockFrag r) {
4030 vec4 tex = FLWBlockTexture(r.texCoords);
4031
4032 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
4033
4034 FLWFinalizeColor(color);
4035}
4036#endif
4037#define PI 3.1415926538
4038
4039
4040
4041
4042
4043struct Flap {
4044 vec3 instancePos;
4045 vec2 light;
4046 vec3 segmentOffset;
4047 vec3 pivot;
4048 float horizontalAngle;
4049 float intensity;
4050 float flapScale;
4051 float flapness;
4052};
4053
4054
4055
4056
4057#if defined(VERTEX_SHADER)
4058
4059float toRad(float degrees) {
4060 return fract(degrees / 360.) * PI * 2.;
4061}
4062
4063float getFlapAngle(float flapness, float intensity, float scale) {
4064 float absFlap = abs(flapness);
4065
4066 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
4067
4068 float halfAngle = angle * 0.5;
4069
4070 float which = step(0., flapness); // 0 if negative, 1 if positive
4071 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
4072
4073 return degrees;
4074}
4075
4076BlockFrag vertex(Vertex v, Flap flap) {
4077 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
4078
4079 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
4080 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
4081
4082 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
4083 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
4084
4085 vec4 worldPos = vec4(rotated, 1.);
4086 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
4087
4088 FLWFinalizeWorldPos(worldPos);
4089 FLWFinalizeNormal(norm);
4090
4091 BlockFrag b;
4092 b.diffuse = diffuse(norm);
4093 b.texCoords = v.texCoords;
4094 b.light = flap.light;
4095 #if defined(DEBUG_NORMAL)
4096 b.color = vec4(norm, 1.);
4097 #else
4098 b.color = vec4(1.);
4099 #endif
4100 return b;
4101}
4102#endif
4103
4104in vec3 a_v_pos;
4105in vec2 a_v_texCoords;
4106in vec3 a_v_normal;
4107in vec3 a_i_instancePos;
4108in vec2 a_i_light;
4109in vec3 a_i_segmentOffset;
4110in vec3 a_i_pivot;
4111in float a_i_horizontalAngle;
4112in float a_i_intensity;
4113in float a_i_flapScale;
4114in float a_i_flapness;
4115out vec2 v2f_texCoords;
4116out vec4 v2f_color;
4117out float v2f_diffuse;
4118out vec2 v2f_light;
4119void main() {
4120Vertex v;
4121v.pos = a_v_pos;
4122v.texCoords = a_v_texCoords;
4123v.normal = a_v_normal;
4124Flap i;
4125i.instancePos = a_i_instancePos;
4126i.light = a_i_light;
4127i.segmentOffset = a_i_segmentOffset;
4128i.pivot = a_i_pivot;
4129i.horizontalAngle = a_i_horizontalAngle;
4130i.intensity = a_i_intensity;
4131i.flapScale = a_i_flapScale;
4132i.flapness = a_i_flapness;
4133BlockFrag o = vertex(v, i);
4134v2f_texCoords = o.texCoords;
4135v2f_color = o.color;
4136v2f_diffuse = o.diffuse;
4137v2f_light = o.light;
4138}
4139[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
4140
4141[17:17:49] [Render thread/ERROR]: #version 150
4142#extension GL_ARB_conservative_depth : enable
4143#define FRAGMENT_SHADER
4144#if defined(VERTEX_SHADER)
4145out float FragDistance;
4146#elif defined(FRAGMENT_SHADER)
4147in float FragDistance;
4148#endif
4149uniform vec4 uFogColor;
4150uniform vec2 uFogRange;
4151
4152float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
4153 float distXZ = length(worldPos.xz - cameraPos.xz);
4154 float distY = abs(worldPos.y - cameraPos.y);
4155 return max(distXZ, distY);
4156}
4157
4158float cylindrical_distance(vec3 worldPos) {
4159 float distXZ = length(worldPos.xz);
4160 float distY = abs(worldPos.y);
4161 return max(distXZ, distY);
4162}
4163
4164float FLWFogFactor() {
4165 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
4166}
4167
4168
4169uniform float uTime;
4170uniform mat4 uViewProjection;
4171uniform vec3 uCameraPos;
4172
4173uniform vec2 uTextureScale;
4174uniform sampler2D uBlockAtlas;
4175uniform sampler2D uLightMap;
4176uniform sampler2D uCrumbling;
4177
4178uniform vec2 uWindowSize;
4179
4180void FLWFinalizeNormal(inout vec3 normal) {
4181 // noop
4182}
4183
4184#if defined(VERTEX_SHADER)
4185void FLWFinalizeWorldPos(inout vec4 worldPos) {
4186 #if defined(USE_FOG)
4187 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
4188 #endif
4189
4190 gl_Position = uViewProjection * worldPos;
4191}
4192
4193#elif defined(FRAGMENT_SHADER)
4194
4195out vec4 fragColor;
4196
4197vec4 FLWBlockTexture(vec2 texCoords) {
4198 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
4199 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
4200 cr.a = cr.a * diffuseAlpha;
4201 return cr;
4202}
4203
4204void FLWFinalizeColor(vec4 color) {
4205 #if defined(USE_FOG)
4206 float a = color.a;
4207 float fog = clamp(FLWFogFactor(), 0., 1.);
4208
4209 color = mix(uFogColor, color, fog);
4210 color.a = a;
4211 #endif
4212
4213 if (color.a < 0.1) {
4214 discard;
4215 }
4216
4217 fragColor = color;
4218}
4219
4220vec4 FLWLight(vec2 lightCoords) {
4221 return vec4(1.);
4222}
4223#endif
4224
4225
4226mat4 rotate(vec3 axis, float angle) {
4227 float s = sin(angle);
4228 float c = cos(angle);
4229 float oc = 1. - c;
4230
4231 vec3 sa = axis * s;
4232
4233 mat4 mr = mat4(1.);
4234 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
4235 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
4236 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
4237
4238 return mr;
4239}
4240
4241mat4 rotation(vec3 rot) {
4242 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
4243}
4244
4245mat3 modelToNormal(mat4 mat) {
4246 // Discard the edges. This won't be accurate for scaled or skewed matrices,
4247 // but we don't have to work with those often.
4248 mat3 m;
4249 m[0] = mat[0].xyz;
4250 m[1] = mat[1].xyz;
4251 m[2] = mat[2].xyz;
4252 return m;
4253}
4254
4255#define PIOVER2 1.5707963268
4256
4257vec4 quat(vec3 axis, float angle) {
4258 float halfAngle = angle * PIOVER2 / 180.0;
4259 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
4260 return vec4(axis.xyz * cs.y, cs.x);
4261}
4262
4263vec4 quatMult(vec4 q1, vec4 q2) {
4264 // disgustingly vectorized quaternion multiplication
4265 vec4 a = q1.w * q2.xyzw;
4266 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
4267 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
4268 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
4269
4270 return a + b + c + d;
4271}
4272
4273vec3 rotateVertexByQuat(vec3 v, vec4 q) {
4274 vec3 i = q.xyz;
4275 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
4276}
4277
4278vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
4279 return rotateVertexByQuat(v, quat(axis, angle));
4280}
4281
4282float diffuse(vec3 normal) {
4283 vec3 n2 = normal * normal * vec3(.6, .25, .8);
4284 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
4285}
4286struct Vertex {
4287 vec3 pos;
4288 vec2 texCoords;
4289 vec3 normal;
4290};
4291
4292struct BlockFrag {
4293 vec2 texCoords;
4294 vec4 color;
4295 float diffuse;
4296 vec2 light;
4297};
4298
4299#if defined(FRAGMENT_SHADER)
4300void fragment(BlockFrag r) {
4301 vec4 tex = FLWBlockTexture(r.texCoords);
4302
4303 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
4304
4305 FLWFinalizeColor(color);
4306}
4307#endif
4308#define PI 3.1415926538
4309
4310
4311
4312
4313
4314struct Flap {
4315 vec3 instancePos;
4316 vec2 light;
4317 vec3 segmentOffset;
4318 vec3 pivot;
4319 float horizontalAngle;
4320 float intensity;
4321 float flapScale;
4322 float flapness;
4323};
4324
4325
4326
4327
4328#if defined(VERTEX_SHADER)
4329
4330float toRad(float degrees) {
4331 return fract(degrees / 360.) * PI * 2.;
4332}
4333
4334float getFlapAngle(float flapness, float intensity, float scale) {
4335 float absFlap = abs(flapness);
4336
4337 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
4338
4339 float halfAngle = angle * 0.5;
4340
4341 float which = step(0., flapness); // 0 if negative, 1 if positive
4342 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
4343
4344 return degrees;
4345}
4346
4347BlockFrag vertex(Vertex v, Flap flap) {
4348 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
4349
4350 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
4351 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
4352
4353 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
4354 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
4355
4356 vec4 worldPos = vec4(rotated, 1.);
4357 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
4358
4359 FLWFinalizeWorldPos(worldPos);
4360 FLWFinalizeNormal(norm);
4361
4362 BlockFrag b;
4363 b.diffuse = diffuse(norm);
4364 b.texCoords = v.texCoords;
4365 b.light = flap.light;
4366 #if defined(DEBUG_NORMAL)
4367 b.color = vec4(norm, 1.);
4368 #else
4369 b.color = vec4(1.);
4370 #endif
4371 return b;
4372}
4373#endif
4374
4375in vec2 v2f_texCoords;
4376in vec4 v2f_color;
4377in float v2f_diffuse;
4378in vec2 v2f_light;
4379void main() {
4380BlockFrag o;
4381o.texCoords = v2f_texCoords;
4382o.color = v2f_color;
4383o.diffuse = v2f_diffuse;
4384o.light = v2f_light;
4385fragment(o);
4386}
4387[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
4388
4389[17:17:49] [Render thread/ERROR]: #version 150
4390#extension GL_ARB_conservative_depth : enable
4391#define VERTEX_SHADER
4392#define DEBUG_NORMAL
4393#if defined(VERTEX_SHADER)
4394out float FragDistance;
4395#elif defined(FRAGMENT_SHADER)
4396in float FragDistance;
4397#endif
4398uniform vec4 uFogColor;
4399uniform vec2 uFogRange;
4400
4401float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
4402 float distXZ = length(worldPos.xz - cameraPos.xz);
4403 float distY = abs(worldPos.y - cameraPos.y);
4404 return max(distXZ, distY);
4405}
4406
4407float cylindrical_distance(vec3 worldPos) {
4408 float distXZ = length(worldPos.xz);
4409 float distY = abs(worldPos.y);
4410 return max(distXZ, distY);
4411}
4412
4413float FLWFogFactor() {
4414 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
4415}
4416
4417
4418uniform float uTime;
4419uniform mat4 uViewProjection;
4420uniform vec3 uCameraPos;
4421
4422uniform vec2 uTextureScale;
4423uniform sampler2D uBlockAtlas;
4424uniform sampler2D uLightMap;
4425uniform sampler2D uCrumbling;
4426
4427uniform vec2 uWindowSize;
4428
4429void FLWFinalizeNormal(inout vec3 normal) {
4430 // noop
4431}
4432
4433#if defined(VERTEX_SHADER)
4434void FLWFinalizeWorldPos(inout vec4 worldPos) {
4435 #if defined(USE_FOG)
4436 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
4437 #endif
4438
4439 gl_Position = uViewProjection * worldPos;
4440}
4441
4442#elif defined(FRAGMENT_SHADER)
4443
4444out vec4 fragColor;
4445
4446vec4 FLWBlockTexture(vec2 texCoords) {
4447 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
4448 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
4449 cr.a = cr.a * diffuseAlpha;
4450 return cr;
4451}
4452
4453void FLWFinalizeColor(vec4 color) {
4454 #if defined(USE_FOG)
4455 float a = color.a;
4456 float fog = clamp(FLWFogFactor(), 0., 1.);
4457
4458 color = mix(uFogColor, color, fog);
4459 color.a = a;
4460 #endif
4461
4462 if (color.a < 0.1) {
4463 discard;
4464 }
4465
4466 fragColor = color;
4467}
4468
4469vec4 FLWLight(vec2 lightCoords) {
4470 return vec4(1.);
4471}
4472#endif
4473
4474
4475mat4 rotate(vec3 axis, float angle) {
4476 float s = sin(angle);
4477 float c = cos(angle);
4478 float oc = 1. - c;
4479
4480 vec3 sa = axis * s;
4481
4482 mat4 mr = mat4(1.);
4483 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
4484 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
4485 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
4486
4487 return mr;
4488}
4489
4490mat4 rotation(vec3 rot) {
4491 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
4492}
4493
4494mat3 modelToNormal(mat4 mat) {
4495 // Discard the edges. This won't be accurate for scaled or skewed matrices,
4496 // but we don't have to work with those often.
4497 mat3 m;
4498 m[0] = mat[0].xyz;
4499 m[1] = mat[1].xyz;
4500 m[2] = mat[2].xyz;
4501 return m;
4502}
4503
4504#define PIOVER2 1.5707963268
4505
4506vec4 quat(vec3 axis, float angle) {
4507 float halfAngle = angle * PIOVER2 / 180.0;
4508 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
4509 return vec4(axis.xyz * cs.y, cs.x);
4510}
4511
4512vec4 quatMult(vec4 q1, vec4 q2) {
4513 // disgustingly vectorized quaternion multiplication
4514 vec4 a = q1.w * q2.xyzw;
4515 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
4516 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
4517 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
4518
4519 return a + b + c + d;
4520}
4521
4522vec3 rotateVertexByQuat(vec3 v, vec4 q) {
4523 vec3 i = q.xyz;
4524 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
4525}
4526
4527vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
4528 return rotateVertexByQuat(v, quat(axis, angle));
4529}
4530
4531float diffuse(vec3 normal) {
4532 vec3 n2 = normal * normal * vec3(.6, .25, .8);
4533 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
4534}
4535struct Vertex {
4536 vec3 pos;
4537 vec2 texCoords;
4538 vec3 normal;
4539};
4540
4541struct BlockFrag {
4542 vec2 texCoords;
4543 vec4 color;
4544 float diffuse;
4545 vec2 light;
4546};
4547
4548#if defined(FRAGMENT_SHADER)
4549void fragment(BlockFrag r) {
4550 vec4 tex = FLWBlockTexture(r.texCoords);
4551
4552 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
4553
4554 FLWFinalizeColor(color);
4555}
4556#endif
4557#define PI 3.1415926538
4558
4559
4560
4561
4562
4563struct Flap {
4564 vec3 instancePos;
4565 vec2 light;
4566 vec3 segmentOffset;
4567 vec3 pivot;
4568 float horizontalAngle;
4569 float intensity;
4570 float flapScale;
4571 float flapness;
4572};
4573
4574
4575
4576
4577#if defined(VERTEX_SHADER)
4578
4579float toRad(float degrees) {
4580 return fract(degrees / 360.) * PI * 2.;
4581}
4582
4583float getFlapAngle(float flapness, float intensity, float scale) {
4584 float absFlap = abs(flapness);
4585
4586 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
4587
4588 float halfAngle = angle * 0.5;
4589
4590 float which = step(0., flapness); // 0 if negative, 1 if positive
4591 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
4592
4593 return degrees;
4594}
4595
4596BlockFrag vertex(Vertex v, Flap flap) {
4597 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
4598
4599 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
4600 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
4601
4602 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
4603 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
4604
4605 vec4 worldPos = vec4(rotated, 1.);
4606 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
4607
4608 FLWFinalizeWorldPos(worldPos);
4609 FLWFinalizeNormal(norm);
4610
4611 BlockFrag b;
4612 b.diffuse = diffuse(norm);
4613 b.texCoords = v.texCoords;
4614 b.light = flap.light;
4615 #if defined(DEBUG_NORMAL)
4616 b.color = vec4(norm, 1.);
4617 #else
4618 b.color = vec4(1.);
4619 #endif
4620 return b;
4621}
4622#endif
4623
4624in vec3 a_v_pos;
4625in vec2 a_v_texCoords;
4626in vec3 a_v_normal;
4627in vec3 a_i_instancePos;
4628in vec2 a_i_light;
4629in vec3 a_i_segmentOffset;
4630in vec3 a_i_pivot;
4631in float a_i_horizontalAngle;
4632in float a_i_intensity;
4633in float a_i_flapScale;
4634in float a_i_flapness;
4635out vec2 v2f_texCoords;
4636out vec4 v2f_color;
4637out float v2f_diffuse;
4638out vec2 v2f_light;
4639void main() {
4640Vertex v;
4641v.pos = a_v_pos;
4642v.texCoords = a_v_texCoords;
4643v.normal = a_v_normal;
4644Flap i;
4645i.instancePos = a_i_instancePos;
4646i.light = a_i_light;
4647i.segmentOffset = a_i_segmentOffset;
4648i.pivot = a_i_pivot;
4649i.horizontalAngle = a_i_horizontalAngle;
4650i.intensity = a_i_intensity;
4651i.flapScale = a_i_flapScale;
4652i.flapness = a_i_flapness;
4653BlockFrag o = vertex(v, i);
4654v2f_texCoords = o.texCoords;
4655v2f_color = o.color;
4656v2f_diffuse = o.diffuse;
4657v2f_light = o.light;
4658}
4659[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
4660
4661[17:17:49] [Render thread/ERROR]: #version 150
4662#extension GL_ARB_conservative_depth : enable
4663#define FRAGMENT_SHADER
4664#define DEBUG_NORMAL
4665#if defined(VERTEX_SHADER)
4666out float FragDistance;
4667#elif defined(FRAGMENT_SHADER)
4668in float FragDistance;
4669#endif
4670uniform vec4 uFogColor;
4671uniform vec2 uFogRange;
4672
4673float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
4674 float distXZ = length(worldPos.xz - cameraPos.xz);
4675 float distY = abs(worldPos.y - cameraPos.y);
4676 return max(distXZ, distY);
4677}
4678
4679float cylindrical_distance(vec3 worldPos) {
4680 float distXZ = length(worldPos.xz);
4681 float distY = abs(worldPos.y);
4682 return max(distXZ, distY);
4683}
4684
4685float FLWFogFactor() {
4686 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
4687}
4688
4689
4690uniform float uTime;
4691uniform mat4 uViewProjection;
4692uniform vec3 uCameraPos;
4693
4694uniform vec2 uTextureScale;
4695uniform sampler2D uBlockAtlas;
4696uniform sampler2D uLightMap;
4697uniform sampler2D uCrumbling;
4698
4699uniform vec2 uWindowSize;
4700
4701void FLWFinalizeNormal(inout vec3 normal) {
4702 // noop
4703}
4704
4705#if defined(VERTEX_SHADER)
4706void FLWFinalizeWorldPos(inout vec4 worldPos) {
4707 #if defined(USE_FOG)
4708 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
4709 #endif
4710
4711 gl_Position = uViewProjection * worldPos;
4712}
4713
4714#elif defined(FRAGMENT_SHADER)
4715
4716out vec4 fragColor;
4717
4718vec4 FLWBlockTexture(vec2 texCoords) {
4719 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
4720 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
4721 cr.a = cr.a * diffuseAlpha;
4722 return cr;
4723}
4724
4725void FLWFinalizeColor(vec4 color) {
4726 #if defined(USE_FOG)
4727 float a = color.a;
4728 float fog = clamp(FLWFogFactor(), 0., 1.);
4729
4730 color = mix(uFogColor, color, fog);
4731 color.a = a;
4732 #endif
4733
4734 if (color.a < 0.1) {
4735 discard;
4736 }
4737
4738 fragColor = color;
4739}
4740
4741vec4 FLWLight(vec2 lightCoords) {
4742 return vec4(1.);
4743}
4744#endif
4745
4746
4747mat4 rotate(vec3 axis, float angle) {
4748 float s = sin(angle);
4749 float c = cos(angle);
4750 float oc = 1. - c;
4751
4752 vec3 sa = axis * s;
4753
4754 mat4 mr = mat4(1.);
4755 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
4756 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
4757 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
4758
4759 return mr;
4760}
4761
4762mat4 rotation(vec3 rot) {
4763 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
4764}
4765
4766mat3 modelToNormal(mat4 mat) {
4767 // Discard the edges. This won't be accurate for scaled or skewed matrices,
4768 // but we don't have to work with those often.
4769 mat3 m;
4770 m[0] = mat[0].xyz;
4771 m[1] = mat[1].xyz;
4772 m[2] = mat[2].xyz;
4773 return m;
4774}
4775
4776#define PIOVER2 1.5707963268
4777
4778vec4 quat(vec3 axis, float angle) {
4779 float halfAngle = angle * PIOVER2 / 180.0;
4780 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
4781 return vec4(axis.xyz * cs.y, cs.x);
4782}
4783
4784vec4 quatMult(vec4 q1, vec4 q2) {
4785 // disgustingly vectorized quaternion multiplication
4786 vec4 a = q1.w * q2.xyzw;
4787 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
4788 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
4789 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
4790
4791 return a + b + c + d;
4792}
4793
4794vec3 rotateVertexByQuat(vec3 v, vec4 q) {
4795 vec3 i = q.xyz;
4796 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
4797}
4798
4799vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
4800 return rotateVertexByQuat(v, quat(axis, angle));
4801}
4802
4803float diffuse(vec3 normal) {
4804 vec3 n2 = normal * normal * vec3(.6, .25, .8);
4805 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
4806}
4807struct Vertex {
4808 vec3 pos;
4809 vec2 texCoords;
4810 vec3 normal;
4811};
4812
4813struct BlockFrag {
4814 vec2 texCoords;
4815 vec4 color;
4816 float diffuse;
4817 vec2 light;
4818};
4819
4820#if defined(FRAGMENT_SHADER)
4821void fragment(BlockFrag r) {
4822 vec4 tex = FLWBlockTexture(r.texCoords);
4823
4824 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
4825
4826 FLWFinalizeColor(color);
4827}
4828#endif
4829#define PI 3.1415926538
4830
4831
4832
4833
4834
4835struct Flap {
4836 vec3 instancePos;
4837 vec2 light;
4838 vec3 segmentOffset;
4839 vec3 pivot;
4840 float horizontalAngle;
4841 float intensity;
4842 float flapScale;
4843 float flapness;
4844};
4845
4846
4847
4848
4849#if defined(VERTEX_SHADER)
4850
4851float toRad(float degrees) {
4852 return fract(degrees / 360.) * PI * 2.;
4853}
4854
4855float getFlapAngle(float flapness, float intensity, float scale) {
4856 float absFlap = abs(flapness);
4857
4858 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
4859
4860 float halfAngle = angle * 0.5;
4861
4862 float which = step(0., flapness); // 0 if negative, 1 if positive
4863 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
4864
4865 return degrees;
4866}
4867
4868BlockFrag vertex(Vertex v, Flap flap) {
4869 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
4870
4871 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
4872 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
4873
4874 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
4875 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
4876
4877 vec4 worldPos = vec4(rotated, 1.);
4878 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
4879
4880 FLWFinalizeWorldPos(worldPos);
4881 FLWFinalizeNormal(norm);
4882
4883 BlockFrag b;
4884 b.diffuse = diffuse(norm);
4885 b.texCoords = v.texCoords;
4886 b.light = flap.light;
4887 #if defined(DEBUG_NORMAL)
4888 b.color = vec4(norm, 1.);
4889 #else
4890 b.color = vec4(1.);
4891 #endif
4892 return b;
4893}
4894#endif
4895
4896in vec2 v2f_texCoords;
4897in vec4 v2f_color;
4898in float v2f_diffuse;
4899in vec2 v2f_light;
4900void main() {
4901BlockFrag o;
4902o.texCoords = v2f_texCoords;
4903o.color = v2f_color;
4904o.diffuse = v2f_diffuse;
4905o.light = v2f_light;
4906fragment(o);
4907}
4908[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
4909
4910[17:17:49] [Render thread/ERROR]: #version 150
4911#extension GL_ARB_conservative_depth : enable
4912#define VERTEX_SHADER
4913#if defined(VERTEX_SHADER)
4914out float FragDistance;
4915#elif defined(FRAGMENT_SHADER)
4916in float FragDistance;
4917#endif
4918uniform vec4 uFogColor;
4919uniform vec2 uFogRange;
4920
4921float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
4922 float distXZ = length(worldPos.xz - cameraPos.xz);
4923 float distY = abs(worldPos.y - cameraPos.y);
4924 return max(distXZ, distY);
4925}
4926
4927float cylindrical_distance(vec3 worldPos) {
4928 float distXZ = length(worldPos.xz);
4929 float distY = abs(worldPos.y);
4930 return max(distXZ, distY);
4931}
4932
4933float FLWFogFactor() {
4934 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
4935}
4936
4937
4938uniform float uTime;
4939uniform mat4 uViewProjection;
4940uniform vec3 uCameraPos;
4941
4942uniform vec2 uTextureScale;
4943uniform sampler2D uBlockAtlas;
4944uniform sampler2D uLightMap;
4945uniform sampler2D uCrumbling;
4946
4947uniform vec2 uWindowSize;
4948
4949void FLWFinalizeNormal(inout vec3 normal) {
4950 // noop
4951}
4952
4953#if defined(VERTEX_SHADER)
4954void FLWFinalizeWorldPos(inout vec4 worldPos) {
4955 #if defined(USE_FOG)
4956 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
4957 #endif
4958
4959 gl_Position = uViewProjection * worldPos;
4960}
4961
4962#elif defined(FRAGMENT_SHADER)
4963
4964out vec4 fragColor;
4965
4966vec4 FLWBlockTexture(vec2 texCoords) {
4967 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
4968 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
4969 cr.a = cr.a * diffuseAlpha;
4970 return cr;
4971}
4972
4973void FLWFinalizeColor(vec4 color) {
4974 #if defined(USE_FOG)
4975 float a = color.a;
4976 float fog = clamp(FLWFogFactor(), 0., 1.);
4977
4978 color = mix(uFogColor, color, fog);
4979 color.a = a;
4980 #endif
4981
4982 if (color.a < 0.1) {
4983 discard;
4984 }
4985
4986 fragColor = color;
4987}
4988
4989vec4 FLWLight(vec2 lightCoords) {
4990 return vec4(1.);
4991}
4992#endif
4993
4994
4995#define PIOVER2 1.5707963268
4996
4997vec4 quat(vec3 axis, float angle) {
4998 float halfAngle = angle * PIOVER2 / 180.0;
4999 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
5000 return vec4(axis.xyz * cs.y, cs.x);
5001}
5002
5003vec4 quatMult(vec4 q1, vec4 q2) {
5004 // disgustingly vectorized quaternion multiplication
5005 vec4 a = q1.w * q2.xyzw;
5006 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
5007 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
5008 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
5009
5010 return a + b + c + d;
5011}
5012
5013vec3 rotateVertexByQuat(vec3 v, vec4 q) {
5014 vec3 i = q.xyz;
5015 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
5016}
5017
5018vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
5019 return rotateVertexByQuat(v, quat(axis, angle));
5020}
5021
5022mat4 rotate(vec3 axis, float angle) {
5023 float s = sin(angle);
5024 float c = cos(angle);
5025 float oc = 1. - c;
5026
5027 vec3 sa = axis * s;
5028
5029 mat4 mr = mat4(1.);
5030 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
5031 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
5032 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
5033
5034 return mr;
5035}
5036
5037mat4 rotation(vec3 rot) {
5038 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
5039}
5040
5041mat3 modelToNormal(mat4 mat) {
5042 // Discard the edges. This won't be accurate for scaled or skewed matrices,
5043 // but we don't have to work with those often.
5044 mat3 m;
5045 m[0] = mat[0].xyz;
5046 m[1] = mat[1].xyz;
5047 m[2] = mat[2].xyz;
5048 return m;
5049}
5050
5051float diffuse(vec3 normal) {
5052 vec3 n2 = normal * normal * vec3(.6, .25, .8);
5053 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
5054}
5055struct Vertex {
5056 vec3 pos;
5057 vec2 texCoords;
5058 vec3 normal;
5059};
5060
5061struct BlockFrag {
5062 vec2 texCoords;
5063 vec4 color;
5064 float diffuse;
5065 vec2 light;
5066};
5067
5068#if defined(FRAGMENT_SHADER)
5069void fragment(BlockFrag r) {
5070 vec4 tex = FLWBlockTexture(r.texCoords);
5071
5072 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
5073
5074 FLWFinalizeColor(color);
5075}
5076#endif
5077#define PI 3.1415926538
5078
5079
5080
5081
5082
5083struct Belt {
5084 vec2 light;
5085 vec4 color;
5086 vec3 pos;
5087 float speed;
5088 float offset;
5089 vec4 rotation;
5090 vec2 sourceTexture;
5091 vec4 scrollTexture;
5092 float scrollMult;
5093};
5094
5095
5096
5097
5098#if defined(VERTEX_SHADER)
5099BlockFrag vertex(Vertex v, Belt instance) {
5100 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
5101
5102 vec4 worldPos = vec4(rotated, 1.);
5103
5104 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
5105
5106 FLWFinalizeWorldPos(worldPos);
5107 FLWFinalizeNormal(norm);
5108
5109 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
5110 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
5111
5112 BlockFrag b;
5113 b.diffuse = diffuse(norm);
5114 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
5115 b.light = instance.light;
5116
5117 #if defined(DEBUG_RAINBOW)
5118 b.color = instance.color;
5119 #elif defined(DEBUG_NORMAL)
5120 b.color = vec4(norm, 1.);
5121 #else
5122 b.color = vec4(1.);
5123 #endif
5124
5125 return b;
5126}
5127#endif
5128
5129in vec3 a_v_pos;
5130in vec2 a_v_texCoords;
5131in vec3 a_v_normal;
5132in vec2 a_i_light;
5133in vec4 a_i_color;
5134in vec3 a_i_pos;
5135in float a_i_speed;
5136in float a_i_offset;
5137in vec4 a_i_rotation;
5138in vec2 a_i_sourceTexture;
5139in vec4 a_i_scrollTexture;
5140in float a_i_scrollMult;
5141out vec2 v2f_texCoords;
5142out vec4 v2f_color;
5143out float v2f_diffuse;
5144out vec2 v2f_light;
5145void main() {
5146Vertex v;
5147v.pos = a_v_pos;
5148v.texCoords = a_v_texCoords;
5149v.normal = a_v_normal;
5150Belt i;
5151i.light = a_i_light;
5152i.color = a_i_color;
5153i.pos = a_i_pos;
5154i.speed = a_i_speed;
5155i.offset = a_i_offset;
5156i.rotation = a_i_rotation;
5157i.sourceTexture = a_i_sourceTexture;
5158i.scrollTexture = a_i_scrollTexture;
5159i.scrollMult = a_i_scrollMult;
5160BlockFrag o = vertex(v, i);
5161v2f_texCoords = o.texCoords;
5162v2f_color = o.color;
5163v2f_diffuse = o.diffuse;
5164v2f_light = o.light;
5165}
5166[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
5167
5168[17:17:49] [Render thread/ERROR]: #version 150
5169#extension GL_ARB_conservative_depth : enable
5170#define FRAGMENT_SHADER
5171#if defined(VERTEX_SHADER)
5172out float FragDistance;
5173#elif defined(FRAGMENT_SHADER)
5174in float FragDistance;
5175#endif
5176uniform vec4 uFogColor;
5177uniform vec2 uFogRange;
5178
5179float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
5180 float distXZ = length(worldPos.xz - cameraPos.xz);
5181 float distY = abs(worldPos.y - cameraPos.y);
5182 return max(distXZ, distY);
5183}
5184
5185float cylindrical_distance(vec3 worldPos) {
5186 float distXZ = length(worldPos.xz);
5187 float distY = abs(worldPos.y);
5188 return max(distXZ, distY);
5189}
5190
5191float FLWFogFactor() {
5192 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
5193}
5194
5195
5196uniform float uTime;
5197uniform mat4 uViewProjection;
5198uniform vec3 uCameraPos;
5199
5200uniform vec2 uTextureScale;
5201uniform sampler2D uBlockAtlas;
5202uniform sampler2D uLightMap;
5203uniform sampler2D uCrumbling;
5204
5205uniform vec2 uWindowSize;
5206
5207void FLWFinalizeNormal(inout vec3 normal) {
5208 // noop
5209}
5210
5211#if defined(VERTEX_SHADER)
5212void FLWFinalizeWorldPos(inout vec4 worldPos) {
5213 #if defined(USE_FOG)
5214 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
5215 #endif
5216
5217 gl_Position = uViewProjection * worldPos;
5218}
5219
5220#elif defined(FRAGMENT_SHADER)
5221
5222out vec4 fragColor;
5223
5224vec4 FLWBlockTexture(vec2 texCoords) {
5225 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
5226 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
5227 cr.a = cr.a * diffuseAlpha;
5228 return cr;
5229}
5230
5231void FLWFinalizeColor(vec4 color) {
5232 #if defined(USE_FOG)
5233 float a = color.a;
5234 float fog = clamp(FLWFogFactor(), 0., 1.);
5235
5236 color = mix(uFogColor, color, fog);
5237 color.a = a;
5238 #endif
5239
5240 if (color.a < 0.1) {
5241 discard;
5242 }
5243
5244 fragColor = color;
5245}
5246
5247vec4 FLWLight(vec2 lightCoords) {
5248 return vec4(1.);
5249}
5250#endif
5251
5252
5253#define PIOVER2 1.5707963268
5254
5255vec4 quat(vec3 axis, float angle) {
5256 float halfAngle = angle * PIOVER2 / 180.0;
5257 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
5258 return vec4(axis.xyz * cs.y, cs.x);
5259}
5260
5261vec4 quatMult(vec4 q1, vec4 q2) {
5262 // disgustingly vectorized quaternion multiplication
5263 vec4 a = q1.w * q2.xyzw;
5264 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
5265 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
5266 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
5267
5268 return a + b + c + d;
5269}
5270
5271vec3 rotateVertexByQuat(vec3 v, vec4 q) {
5272 vec3 i = q.xyz;
5273 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
5274}
5275
5276vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
5277 return rotateVertexByQuat(v, quat(axis, angle));
5278}
5279
5280mat4 rotate(vec3 axis, float angle) {
5281 float s = sin(angle);
5282 float c = cos(angle);
5283 float oc = 1. - c;
5284
5285 vec3 sa = axis * s;
5286
5287 mat4 mr = mat4(1.);
5288 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
5289 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
5290 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
5291
5292 return mr;
5293}
5294
5295mat4 rotation(vec3 rot) {
5296 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
5297}
5298
5299mat3 modelToNormal(mat4 mat) {
5300 // Discard the edges. This won't be accurate for scaled or skewed matrices,
5301 // but we don't have to work with those often.
5302 mat3 m;
5303 m[0] = mat[0].xyz;
5304 m[1] = mat[1].xyz;
5305 m[2] = mat[2].xyz;
5306 return m;
5307}
5308
5309float diffuse(vec3 normal) {
5310 vec3 n2 = normal * normal * vec3(.6, .25, .8);
5311 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
5312}
5313struct Vertex {
5314 vec3 pos;
5315 vec2 texCoords;
5316 vec3 normal;
5317};
5318
5319struct BlockFrag {
5320 vec2 texCoords;
5321 vec4 color;
5322 float diffuse;
5323 vec2 light;
5324};
5325
5326#if defined(FRAGMENT_SHADER)
5327void fragment(BlockFrag r) {
5328 vec4 tex = FLWBlockTexture(r.texCoords);
5329
5330 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
5331
5332 FLWFinalizeColor(color);
5333}
5334#endif
5335#define PI 3.1415926538
5336
5337
5338
5339
5340
5341struct Belt {
5342 vec2 light;
5343 vec4 color;
5344 vec3 pos;
5345 float speed;
5346 float offset;
5347 vec4 rotation;
5348 vec2 sourceTexture;
5349 vec4 scrollTexture;
5350 float scrollMult;
5351};
5352
5353
5354
5355
5356#if defined(VERTEX_SHADER)
5357BlockFrag vertex(Vertex v, Belt instance) {
5358 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
5359
5360 vec4 worldPos = vec4(rotated, 1.);
5361
5362 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
5363
5364 FLWFinalizeWorldPos(worldPos);
5365 FLWFinalizeNormal(norm);
5366
5367 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
5368 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
5369
5370 BlockFrag b;
5371 b.diffuse = diffuse(norm);
5372 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
5373 b.light = instance.light;
5374
5375 #if defined(DEBUG_RAINBOW)
5376 b.color = instance.color;
5377 #elif defined(DEBUG_NORMAL)
5378 b.color = vec4(norm, 1.);
5379 #else
5380 b.color = vec4(1.);
5381 #endif
5382
5383 return b;
5384}
5385#endif
5386
5387in vec2 v2f_texCoords;
5388in vec4 v2f_color;
5389in float v2f_diffuse;
5390in vec2 v2f_light;
5391void main() {
5392BlockFrag o;
5393o.texCoords = v2f_texCoords;
5394o.color = v2f_color;
5395o.diffuse = v2f_diffuse;
5396o.light = v2f_light;
5397fragment(o);
5398}
5399[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
5400
5401[17:17:49] [Render thread/ERROR]: #version 150
5402#extension GL_ARB_conservative_depth : enable
5403#define VERTEX_SHADER
5404#define DEBUG_RAINBOW
5405#if defined(VERTEX_SHADER)
5406out float FragDistance;
5407#elif defined(FRAGMENT_SHADER)
5408in float FragDistance;
5409#endif
5410uniform vec4 uFogColor;
5411uniform vec2 uFogRange;
5412
5413float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
5414 float distXZ = length(worldPos.xz - cameraPos.xz);
5415 float distY = abs(worldPos.y - cameraPos.y);
5416 return max(distXZ, distY);
5417}
5418
5419float cylindrical_distance(vec3 worldPos) {
5420 float distXZ = length(worldPos.xz);
5421 float distY = abs(worldPos.y);
5422 return max(distXZ, distY);
5423}
5424
5425float FLWFogFactor() {
5426 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
5427}
5428
5429
5430uniform float uTime;
5431uniform mat4 uViewProjection;
5432uniform vec3 uCameraPos;
5433
5434uniform vec2 uTextureScale;
5435uniform sampler2D uBlockAtlas;
5436uniform sampler2D uLightMap;
5437uniform sampler2D uCrumbling;
5438
5439uniform vec2 uWindowSize;
5440
5441void FLWFinalizeNormal(inout vec3 normal) {
5442 // noop
5443}
5444
5445#if defined(VERTEX_SHADER)
5446void FLWFinalizeWorldPos(inout vec4 worldPos) {
5447 #if defined(USE_FOG)
5448 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
5449 #endif
5450
5451 gl_Position = uViewProjection * worldPos;
5452}
5453
5454#elif defined(FRAGMENT_SHADER)
5455
5456out vec4 fragColor;
5457
5458vec4 FLWBlockTexture(vec2 texCoords) {
5459 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
5460 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
5461 cr.a = cr.a * diffuseAlpha;
5462 return cr;
5463}
5464
5465void FLWFinalizeColor(vec4 color) {
5466 #if defined(USE_FOG)
5467 float a = color.a;
5468 float fog = clamp(FLWFogFactor(), 0., 1.);
5469
5470 color = mix(uFogColor, color, fog);
5471 color.a = a;
5472 #endif
5473
5474 if (color.a < 0.1) {
5475 discard;
5476 }
5477
5478 fragColor = color;
5479}
5480
5481vec4 FLWLight(vec2 lightCoords) {
5482 return vec4(1.);
5483}
5484#endif
5485
5486
5487#define PIOVER2 1.5707963268
5488
5489vec4 quat(vec3 axis, float angle) {
5490 float halfAngle = angle * PIOVER2 / 180.0;
5491 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
5492 return vec4(axis.xyz * cs.y, cs.x);
5493}
5494
5495vec4 quatMult(vec4 q1, vec4 q2) {
5496 // disgustingly vectorized quaternion multiplication
5497 vec4 a = q1.w * q2.xyzw;
5498 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
5499 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
5500 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
5501
5502 return a + b + c + d;
5503}
5504
5505vec3 rotateVertexByQuat(vec3 v, vec4 q) {
5506 vec3 i = q.xyz;
5507 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
5508}
5509
5510vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
5511 return rotateVertexByQuat(v, quat(axis, angle));
5512}
5513
5514mat4 rotate(vec3 axis, float angle) {
5515 float s = sin(angle);
5516 float c = cos(angle);
5517 float oc = 1. - c;
5518
5519 vec3 sa = axis * s;
5520
5521 mat4 mr = mat4(1.);
5522 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
5523 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
5524 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
5525
5526 return mr;
5527}
5528
5529mat4 rotation(vec3 rot) {
5530 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
5531}
5532
5533mat3 modelToNormal(mat4 mat) {
5534 // Discard the edges. This won't be accurate for scaled or skewed matrices,
5535 // but we don't have to work with those often.
5536 mat3 m;
5537 m[0] = mat[0].xyz;
5538 m[1] = mat[1].xyz;
5539 m[2] = mat[2].xyz;
5540 return m;
5541}
5542
5543float diffuse(vec3 normal) {
5544 vec3 n2 = normal * normal * vec3(.6, .25, .8);
5545 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
5546}
5547struct Vertex {
5548 vec3 pos;
5549 vec2 texCoords;
5550 vec3 normal;
5551};
5552
5553struct BlockFrag {
5554 vec2 texCoords;
5555 vec4 color;
5556 float diffuse;
5557 vec2 light;
5558};
5559
5560#if defined(FRAGMENT_SHADER)
5561void fragment(BlockFrag r) {
5562 vec4 tex = FLWBlockTexture(r.texCoords);
5563
5564 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
5565
5566 FLWFinalizeColor(color);
5567}
5568#endif
5569#define PI 3.1415926538
5570
5571
5572
5573
5574
5575struct Belt {
5576 vec2 light;
5577 vec4 color;
5578 vec3 pos;
5579 float speed;
5580 float offset;
5581 vec4 rotation;
5582 vec2 sourceTexture;
5583 vec4 scrollTexture;
5584 float scrollMult;
5585};
5586
5587
5588
5589
5590#if defined(VERTEX_SHADER)
5591BlockFrag vertex(Vertex v, Belt instance) {
5592 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
5593
5594 vec4 worldPos = vec4(rotated, 1.);
5595
5596 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
5597
5598 FLWFinalizeWorldPos(worldPos);
5599 FLWFinalizeNormal(norm);
5600
5601 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
5602 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
5603
5604 BlockFrag b;
5605 b.diffuse = diffuse(norm);
5606 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
5607 b.light = instance.light;
5608
5609 #if defined(DEBUG_RAINBOW)
5610 b.color = instance.color;
5611 #elif defined(DEBUG_NORMAL)
5612 b.color = vec4(norm, 1.);
5613 #else
5614 b.color = vec4(1.);
5615 #endif
5616
5617 return b;
5618}
5619#endif
5620
5621in vec3 a_v_pos;
5622in vec2 a_v_texCoords;
5623in vec3 a_v_normal;
5624in vec2 a_i_light;
5625in vec4 a_i_color;
5626in vec3 a_i_pos;
5627in float a_i_speed;
5628in float a_i_offset;
5629in vec4 a_i_rotation;
5630in vec2 a_i_sourceTexture;
5631in vec4 a_i_scrollTexture;
5632in float a_i_scrollMult;
5633out vec2 v2f_texCoords;
5634out vec4 v2f_color;
5635out float v2f_diffuse;
5636out vec2 v2f_light;
5637void main() {
5638Vertex v;
5639v.pos = a_v_pos;
5640v.texCoords = a_v_texCoords;
5641v.normal = a_v_normal;
5642Belt i;
5643i.light = a_i_light;
5644i.color = a_i_color;
5645i.pos = a_i_pos;
5646i.speed = a_i_speed;
5647i.offset = a_i_offset;
5648i.rotation = a_i_rotation;
5649i.sourceTexture = a_i_sourceTexture;
5650i.scrollTexture = a_i_scrollTexture;
5651i.scrollMult = a_i_scrollMult;
5652BlockFrag o = vertex(v, i);
5653v2f_texCoords = o.texCoords;
5654v2f_color = o.color;
5655v2f_diffuse = o.diffuse;
5656v2f_light = o.light;
5657}
5658[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
5659
5660[17:17:49] [Render thread/ERROR]: #version 150
5661#extension GL_ARB_conservative_depth : enable
5662#define FRAGMENT_SHADER
5663#define DEBUG_RAINBOW
5664#if defined(VERTEX_SHADER)
5665out float FragDistance;
5666#elif defined(FRAGMENT_SHADER)
5667in float FragDistance;
5668#endif
5669uniform vec4 uFogColor;
5670uniform vec2 uFogRange;
5671
5672float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
5673 float distXZ = length(worldPos.xz - cameraPos.xz);
5674 float distY = abs(worldPos.y - cameraPos.y);
5675 return max(distXZ, distY);
5676}
5677
5678float cylindrical_distance(vec3 worldPos) {
5679 float distXZ = length(worldPos.xz);
5680 float distY = abs(worldPos.y);
5681 return max(distXZ, distY);
5682}
5683
5684float FLWFogFactor() {
5685 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
5686}
5687
5688
5689uniform float uTime;
5690uniform mat4 uViewProjection;
5691uniform vec3 uCameraPos;
5692
5693uniform vec2 uTextureScale;
5694uniform sampler2D uBlockAtlas;
5695uniform sampler2D uLightMap;
5696uniform sampler2D uCrumbling;
5697
5698uniform vec2 uWindowSize;
5699
5700void FLWFinalizeNormal(inout vec3 normal) {
5701 // noop
5702}
5703
5704#if defined(VERTEX_SHADER)
5705void FLWFinalizeWorldPos(inout vec4 worldPos) {
5706 #if defined(USE_FOG)
5707 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
5708 #endif
5709
5710 gl_Position = uViewProjection * worldPos;
5711}
5712
5713#elif defined(FRAGMENT_SHADER)
5714
5715out vec4 fragColor;
5716
5717vec4 FLWBlockTexture(vec2 texCoords) {
5718 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
5719 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
5720 cr.a = cr.a * diffuseAlpha;
5721 return cr;
5722}
5723
5724void FLWFinalizeColor(vec4 color) {
5725 #if defined(USE_FOG)
5726 float a = color.a;
5727 float fog = clamp(FLWFogFactor(), 0., 1.);
5728
5729 color = mix(uFogColor, color, fog);
5730 color.a = a;
5731 #endif
5732
5733 if (color.a < 0.1) {
5734 discard;
5735 }
5736
5737 fragColor = color;
5738}
5739
5740vec4 FLWLight(vec2 lightCoords) {
5741 return vec4(1.);
5742}
5743#endif
5744
5745
5746#define PIOVER2 1.5707963268
5747
5748vec4 quat(vec3 axis, float angle) {
5749 float halfAngle = angle * PIOVER2 / 180.0;
5750 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
5751 return vec4(axis.xyz * cs.y, cs.x);
5752}
5753
5754vec4 quatMult(vec4 q1, vec4 q2) {
5755 // disgustingly vectorized quaternion multiplication
5756 vec4 a = q1.w * q2.xyzw;
5757 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
5758 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
5759 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
5760
5761 return a + b + c + d;
5762}
5763
5764vec3 rotateVertexByQuat(vec3 v, vec4 q) {
5765 vec3 i = q.xyz;
5766 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
5767}
5768
5769vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
5770 return rotateVertexByQuat(v, quat(axis, angle));
5771}
5772
5773mat4 rotate(vec3 axis, float angle) {
5774 float s = sin(angle);
5775 float c = cos(angle);
5776 float oc = 1. - c;
5777
5778 vec3 sa = axis * s;
5779
5780 mat4 mr = mat4(1.);
5781 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
5782 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
5783 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
5784
5785 return mr;
5786}
5787
5788mat4 rotation(vec3 rot) {
5789 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
5790}
5791
5792mat3 modelToNormal(mat4 mat) {
5793 // Discard the edges. This won't be accurate for scaled or skewed matrices,
5794 // but we don't have to work with those often.
5795 mat3 m;
5796 m[0] = mat[0].xyz;
5797 m[1] = mat[1].xyz;
5798 m[2] = mat[2].xyz;
5799 return m;
5800}
5801
5802float diffuse(vec3 normal) {
5803 vec3 n2 = normal * normal * vec3(.6, .25, .8);
5804 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
5805}
5806struct Vertex {
5807 vec3 pos;
5808 vec2 texCoords;
5809 vec3 normal;
5810};
5811
5812struct BlockFrag {
5813 vec2 texCoords;
5814 vec4 color;
5815 float diffuse;
5816 vec2 light;
5817};
5818
5819#if defined(FRAGMENT_SHADER)
5820void fragment(BlockFrag r) {
5821 vec4 tex = FLWBlockTexture(r.texCoords);
5822
5823 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
5824
5825 FLWFinalizeColor(color);
5826}
5827#endif
5828#define PI 3.1415926538
5829
5830
5831
5832
5833
5834struct Belt {
5835 vec2 light;
5836 vec4 color;
5837 vec3 pos;
5838 float speed;
5839 float offset;
5840 vec4 rotation;
5841 vec2 sourceTexture;
5842 vec4 scrollTexture;
5843 float scrollMult;
5844};
5845
5846
5847
5848
5849#if defined(VERTEX_SHADER)
5850BlockFrag vertex(Vertex v, Belt instance) {
5851 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
5852
5853 vec4 worldPos = vec4(rotated, 1.);
5854
5855 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
5856
5857 FLWFinalizeWorldPos(worldPos);
5858 FLWFinalizeNormal(norm);
5859
5860 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
5861 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
5862
5863 BlockFrag b;
5864 b.diffuse = diffuse(norm);
5865 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
5866 b.light = instance.light;
5867
5868 #if defined(DEBUG_RAINBOW)
5869 b.color = instance.color;
5870 #elif defined(DEBUG_NORMAL)
5871 b.color = vec4(norm, 1.);
5872 #else
5873 b.color = vec4(1.);
5874 #endif
5875
5876 return b;
5877}
5878#endif
5879
5880in vec2 v2f_texCoords;
5881in vec4 v2f_color;
5882in float v2f_diffuse;
5883in vec2 v2f_light;
5884void main() {
5885BlockFrag o;
5886o.texCoords = v2f_texCoords;
5887o.color = v2f_color;
5888o.diffuse = v2f_diffuse;
5889o.light = v2f_light;
5890fragment(o);
5891}
5892[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
5893
5894[17:17:49] [Render thread/ERROR]: #version 150
5895#extension GL_ARB_conservative_depth : enable
5896#define VERTEX_SHADER
5897#define DEBUG_NORMAL
5898#if defined(VERTEX_SHADER)
5899out float FragDistance;
5900#elif defined(FRAGMENT_SHADER)
5901in float FragDistance;
5902#endif
5903uniform vec4 uFogColor;
5904uniform vec2 uFogRange;
5905
5906float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
5907 float distXZ = length(worldPos.xz - cameraPos.xz);
5908 float distY = abs(worldPos.y - cameraPos.y);
5909 return max(distXZ, distY);
5910}
5911
5912float cylindrical_distance(vec3 worldPos) {
5913 float distXZ = length(worldPos.xz);
5914 float distY = abs(worldPos.y);
5915 return max(distXZ, distY);
5916}
5917
5918float FLWFogFactor() {
5919 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
5920}
5921
5922
5923uniform float uTime;
5924uniform mat4 uViewProjection;
5925uniform vec3 uCameraPos;
5926
5927uniform vec2 uTextureScale;
5928uniform sampler2D uBlockAtlas;
5929uniform sampler2D uLightMap;
5930uniform sampler2D uCrumbling;
5931
5932uniform vec2 uWindowSize;
5933
5934void FLWFinalizeNormal(inout vec3 normal) {
5935 // noop
5936}
5937
5938#if defined(VERTEX_SHADER)
5939void FLWFinalizeWorldPos(inout vec4 worldPos) {
5940 #if defined(USE_FOG)
5941 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
5942 #endif
5943
5944 gl_Position = uViewProjection * worldPos;
5945}
5946
5947#elif defined(FRAGMENT_SHADER)
5948
5949out vec4 fragColor;
5950
5951vec4 FLWBlockTexture(vec2 texCoords) {
5952 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
5953 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
5954 cr.a = cr.a * diffuseAlpha;
5955 return cr;
5956}
5957
5958void FLWFinalizeColor(vec4 color) {
5959 #if defined(USE_FOG)
5960 float a = color.a;
5961 float fog = clamp(FLWFogFactor(), 0., 1.);
5962
5963 color = mix(uFogColor, color, fog);
5964 color.a = a;
5965 #endif
5966
5967 if (color.a < 0.1) {
5968 discard;
5969 }
5970
5971 fragColor = color;
5972}
5973
5974vec4 FLWLight(vec2 lightCoords) {
5975 return vec4(1.);
5976}
5977#endif
5978
5979
5980#define PIOVER2 1.5707963268
5981
5982vec4 quat(vec3 axis, float angle) {
5983 float halfAngle = angle * PIOVER2 / 180.0;
5984 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
5985 return vec4(axis.xyz * cs.y, cs.x);
5986}
5987
5988vec4 quatMult(vec4 q1, vec4 q2) {
5989 // disgustingly vectorized quaternion multiplication
5990 vec4 a = q1.w * q2.xyzw;
5991 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
5992 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
5993 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
5994
5995 return a + b + c + d;
5996}
5997
5998vec3 rotateVertexByQuat(vec3 v, vec4 q) {
5999 vec3 i = q.xyz;
6000 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
6001}
6002
6003vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
6004 return rotateVertexByQuat(v, quat(axis, angle));
6005}
6006
6007mat4 rotate(vec3 axis, float angle) {
6008 float s = sin(angle);
6009 float c = cos(angle);
6010 float oc = 1. - c;
6011
6012 vec3 sa = axis * s;
6013
6014 mat4 mr = mat4(1.);
6015 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
6016 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
6017 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
6018
6019 return mr;
6020}
6021
6022mat4 rotation(vec3 rot) {
6023 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
6024}
6025
6026mat3 modelToNormal(mat4 mat) {
6027 // Discard the edges. This won't be accurate for scaled or skewed matrices,
6028 // but we don't have to work with those often.
6029 mat3 m;
6030 m[0] = mat[0].xyz;
6031 m[1] = mat[1].xyz;
6032 m[2] = mat[2].xyz;
6033 return m;
6034}
6035
6036float diffuse(vec3 normal) {
6037 vec3 n2 = normal * normal * vec3(.6, .25, .8);
6038 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
6039}
6040struct Vertex {
6041 vec3 pos;
6042 vec2 texCoords;
6043 vec3 normal;
6044};
6045
6046struct BlockFrag {
6047 vec2 texCoords;
6048 vec4 color;
6049 float diffuse;
6050 vec2 light;
6051};
6052
6053#if defined(FRAGMENT_SHADER)
6054void fragment(BlockFrag r) {
6055 vec4 tex = FLWBlockTexture(r.texCoords);
6056
6057 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
6058
6059 FLWFinalizeColor(color);
6060}
6061#endif
6062#define PI 3.1415926538
6063
6064
6065
6066
6067
6068struct Belt {
6069 vec2 light;
6070 vec4 color;
6071 vec3 pos;
6072 float speed;
6073 float offset;
6074 vec4 rotation;
6075 vec2 sourceTexture;
6076 vec4 scrollTexture;
6077 float scrollMult;
6078};
6079
6080
6081
6082
6083#if defined(VERTEX_SHADER)
6084BlockFrag vertex(Vertex v, Belt instance) {
6085 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
6086
6087 vec4 worldPos = vec4(rotated, 1.);
6088
6089 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
6090
6091 FLWFinalizeWorldPos(worldPos);
6092 FLWFinalizeNormal(norm);
6093
6094 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
6095 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
6096
6097 BlockFrag b;
6098 b.diffuse = diffuse(norm);
6099 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
6100 b.light = instance.light;
6101
6102 #if defined(DEBUG_RAINBOW)
6103 b.color = instance.color;
6104 #elif defined(DEBUG_NORMAL)
6105 b.color = vec4(norm, 1.);
6106 #else
6107 b.color = vec4(1.);
6108 #endif
6109
6110 return b;
6111}
6112#endif
6113
6114in vec3 a_v_pos;
6115in vec2 a_v_texCoords;
6116in vec3 a_v_normal;
6117in vec2 a_i_light;
6118in vec4 a_i_color;
6119in vec3 a_i_pos;
6120in float a_i_speed;
6121in float a_i_offset;
6122in vec4 a_i_rotation;
6123in vec2 a_i_sourceTexture;
6124in vec4 a_i_scrollTexture;
6125in float a_i_scrollMult;
6126out vec2 v2f_texCoords;
6127out vec4 v2f_color;
6128out float v2f_diffuse;
6129out vec2 v2f_light;
6130void main() {
6131Vertex v;
6132v.pos = a_v_pos;
6133v.texCoords = a_v_texCoords;
6134v.normal = a_v_normal;
6135Belt i;
6136i.light = a_i_light;
6137i.color = a_i_color;
6138i.pos = a_i_pos;
6139i.speed = a_i_speed;
6140i.offset = a_i_offset;
6141i.rotation = a_i_rotation;
6142i.sourceTexture = a_i_sourceTexture;
6143i.scrollTexture = a_i_scrollTexture;
6144i.scrollMult = a_i_scrollMult;
6145BlockFrag o = vertex(v, i);
6146v2f_texCoords = o.texCoords;
6147v2f_color = o.color;
6148v2f_diffuse = o.diffuse;
6149v2f_light = o.light;
6150}
6151[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
6152
6153[17:17:49] [Render thread/ERROR]: #version 150
6154#extension GL_ARB_conservative_depth : enable
6155#define FRAGMENT_SHADER
6156#define DEBUG_NORMAL
6157#if defined(VERTEX_SHADER)
6158out float FragDistance;
6159#elif defined(FRAGMENT_SHADER)
6160in float FragDistance;
6161#endif
6162uniform vec4 uFogColor;
6163uniform vec2 uFogRange;
6164
6165float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
6166 float distXZ = length(worldPos.xz - cameraPos.xz);
6167 float distY = abs(worldPos.y - cameraPos.y);
6168 return max(distXZ, distY);
6169}
6170
6171float cylindrical_distance(vec3 worldPos) {
6172 float distXZ = length(worldPos.xz);
6173 float distY = abs(worldPos.y);
6174 return max(distXZ, distY);
6175}
6176
6177float FLWFogFactor() {
6178 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
6179}
6180
6181
6182uniform float uTime;
6183uniform mat4 uViewProjection;
6184uniform vec3 uCameraPos;
6185
6186uniform vec2 uTextureScale;
6187uniform sampler2D uBlockAtlas;
6188uniform sampler2D uLightMap;
6189uniform sampler2D uCrumbling;
6190
6191uniform vec2 uWindowSize;
6192
6193void FLWFinalizeNormal(inout vec3 normal) {
6194 // noop
6195}
6196
6197#if defined(VERTEX_SHADER)
6198void FLWFinalizeWorldPos(inout vec4 worldPos) {
6199 #if defined(USE_FOG)
6200 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
6201 #endif
6202
6203 gl_Position = uViewProjection * worldPos;
6204}
6205
6206#elif defined(FRAGMENT_SHADER)
6207
6208out vec4 fragColor;
6209
6210vec4 FLWBlockTexture(vec2 texCoords) {
6211 vec4 cr = texture(uCrumbling, texCoords * uTextureScale);
6212 float diffuseAlpha = texture(uBlockAtlas, texCoords).a;
6213 cr.a = cr.a * diffuseAlpha;
6214 return cr;
6215}
6216
6217void FLWFinalizeColor(vec4 color) {
6218 #if defined(USE_FOG)
6219 float a = color.a;
6220 float fog = clamp(FLWFogFactor(), 0., 1.);
6221
6222 color = mix(uFogColor, color, fog);
6223 color.a = a;
6224 #endif
6225
6226 if (color.a < 0.1) {
6227 discard;
6228 }
6229
6230 fragColor = color;
6231}
6232
6233vec4 FLWLight(vec2 lightCoords) {
6234 return vec4(1.);
6235}
6236#endif
6237
6238
6239#define PIOVER2 1.5707963268
6240
6241vec4 quat(vec3 axis, float angle) {
6242 float halfAngle = angle * PIOVER2 / 180.0;
6243 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
6244 return vec4(axis.xyz * cs.y, cs.x);
6245}
6246
6247vec4 quatMult(vec4 q1, vec4 q2) {
6248 // disgustingly vectorized quaternion multiplication
6249 vec4 a = q1.w * q2.xyzw;
6250 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
6251 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
6252 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
6253
6254 return a + b + c + d;
6255}
6256
6257vec3 rotateVertexByQuat(vec3 v, vec4 q) {
6258 vec3 i = q.xyz;
6259 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
6260}
6261
6262vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
6263 return rotateVertexByQuat(v, quat(axis, angle));
6264}
6265
6266mat4 rotate(vec3 axis, float angle) {
6267 float s = sin(angle);
6268 float c = cos(angle);
6269 float oc = 1. - c;
6270
6271 vec3 sa = axis * s;
6272
6273 mat4 mr = mat4(1.);
6274 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
6275 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
6276 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
6277
6278 return mr;
6279}
6280
6281mat4 rotation(vec3 rot) {
6282 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
6283}
6284
6285mat3 modelToNormal(mat4 mat) {
6286 // Discard the edges. This won't be accurate for scaled or skewed matrices,
6287 // but we don't have to work with those often.
6288 mat3 m;
6289 m[0] = mat[0].xyz;
6290 m[1] = mat[1].xyz;
6291 m[2] = mat[2].xyz;
6292 return m;
6293}
6294
6295float diffuse(vec3 normal) {
6296 vec3 n2 = normal * normal * vec3(.6, .25, .8);
6297 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
6298}
6299struct Vertex {
6300 vec3 pos;
6301 vec2 texCoords;
6302 vec3 normal;
6303};
6304
6305struct BlockFrag {
6306 vec2 texCoords;
6307 vec4 color;
6308 float diffuse;
6309 vec2 light;
6310};
6311
6312#if defined(FRAGMENT_SHADER)
6313void fragment(BlockFrag r) {
6314 vec4 tex = FLWBlockTexture(r.texCoords);
6315
6316 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
6317
6318 FLWFinalizeColor(color);
6319}
6320#endif
6321#define PI 3.1415926538
6322
6323
6324
6325
6326
6327struct Belt {
6328 vec2 light;
6329 vec4 color;
6330 vec3 pos;
6331 float speed;
6332 float offset;
6333 vec4 rotation;
6334 vec2 sourceTexture;
6335 vec4 scrollTexture;
6336 float scrollMult;
6337};
6338
6339
6340
6341
6342#if defined(VERTEX_SHADER)
6343BlockFrag vertex(Vertex v, Belt instance) {
6344 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
6345
6346 vec4 worldPos = vec4(rotated, 1.);
6347
6348 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
6349
6350 FLWFinalizeWorldPos(worldPos);
6351 FLWFinalizeNormal(norm);
6352
6353 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
6354 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
6355
6356 BlockFrag b;
6357 b.diffuse = diffuse(norm);
6358 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
6359 b.light = instance.light;
6360
6361 #if defined(DEBUG_RAINBOW)
6362 b.color = instance.color;
6363 #elif defined(DEBUG_NORMAL)
6364 b.color = vec4(norm, 1.);
6365 #else
6366 b.color = vec4(1.);
6367 #endif
6368
6369 return b;
6370}
6371#endif
6372
6373in vec2 v2f_texCoords;
6374in vec4 v2f_color;
6375in float v2f_diffuse;
6376in vec2 v2f_light;
6377void main() {
6378BlockFrag o;
6379o.texCoords = v2f_texCoords;
6380o.color = v2f_color;
6381o.diffuse = v2f_diffuse;
6382o.light = v2f_light;
6383fragment(o);
6384}
6385[17:17:49] [Render thread/INFO]: Loading context 'flywheel:context/world'
6386[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
6387
6388[17:17:49] [Render thread/ERROR]: #version 150
6389#extension GL_ARB_conservative_depth : enable
6390#define VERTEX_SHADER
6391#if defined(VERTEX_SHADER)
6392out float FragDistance;
6393#elif defined(FRAGMENT_SHADER)
6394in float FragDistance;
6395#endif
6396uniform vec4 uFogColor;
6397uniform vec2 uFogRange;
6398
6399float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
6400 float distXZ = length(worldPos.xz - cameraPos.xz);
6401 float distY = abs(worldPos.y - cameraPos.y);
6402 return max(distXZ, distY);
6403}
6404
6405float cylindrical_distance(vec3 worldPos) {
6406 float distXZ = length(worldPos.xz);
6407 float distY = abs(worldPos.y);
6408 return max(distXZ, distY);
6409}
6410
6411float FLWFogFactor() {
6412 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
6413}
6414// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
6415vec2 shiftLight(vec2 lm) {
6416 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
6417}
6418
6419
6420uniform float uTime;
6421uniform mat4 uViewProjection;
6422uniform vec3 uCameraPos;
6423
6424uniform vec2 uTextureScale;
6425uniform sampler2D uBlockAtlas;
6426uniform sampler2D uLightMap;
6427
6428uniform vec2 uWindowSize;
6429
6430void FLWFinalizeNormal(inout vec3 normal) {
6431 // noop
6432}
6433
6434#if defined(VERTEX_SHADER)
6435void FLWFinalizeWorldPos(inout vec4 worldPos) {
6436 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
6437
6438 gl_Position = uViewProjection * worldPos;
6439}
6440
6441#elif defined(FRAGMENT_SHADER)
6442
6443
6444#define ALPHA_DISCARD 0.1
6445// optimize discard usage
6446#if defined(ALPHA_DISCARD)
6447#if defined(GL_ARB_conservative_depth)
6448layout (depth_greater) out float gl_FragDepth;
6449#endif
6450#endif
6451out vec4 fragColor;
6452
6453vec4 FLWBlockTexture(vec2 texCoords) {
6454 return texture(uBlockAtlas, texCoords);
6455}
6456
6457void FLWFinalizeColor(vec4 color) {
6458 float a = color.a;
6459 float fog = clamp(FLWFogFactor(), 0., 1.);
6460
6461 color = mix(uFogColor, color, fog);
6462 color.a = a;
6463
6464 #if defined(ALPHA_DISCARD)
6465 if (color.a < ALPHA_DISCARD) {
6466 discard;
6467 }
6468 #endif
6469
6470 fragColor = color;
6471}
6472
6473vec4 FLWLight(vec2 lightCoords) {
6474 return texture(uLightMap, shiftLight(lightCoords));
6475}
6476#endif
6477
6478
6479float diffuse(vec3 normal) {
6480 vec3 n2 = normal * normal * vec3(.6, .25, .8);
6481 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
6482}
6483struct Vertex {
6484 vec3 pos;
6485 vec2 texCoords;
6486 vec3 normal;
6487};
6488
6489struct BlockFrag {
6490 vec2 texCoords;
6491 vec4 color;
6492 float diffuse;
6493 vec2 light;
6494};
6495
6496#if defined(FRAGMENT_SHADER)
6497void fragment(BlockFrag r) {
6498 vec4 tex = FLWBlockTexture(r.texCoords);
6499
6500 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
6501
6502 FLWFinalizeColor(color);
6503}
6504#endif
6505
6506
6507
6508
6509struct Instance {
6510 vec2 light;
6511 vec4 color;
6512 mat4 transform;
6513 mat3 normalMat;
6514};
6515
6516#if defined(VERTEX_SHADER)
6517BlockFrag vertex(Vertex v, Instance i) {
6518 vec4 worldPos = i.transform * vec4(v.pos, 1.);
6519
6520 vec3 norm = i.normalMat * v.normal;
6521
6522 FLWFinalizeWorldPos(worldPos);
6523 FLWFinalizeNormal(norm);
6524
6525 norm = normalize(norm);
6526
6527 BlockFrag b;
6528 b.diffuse = diffuse(norm);
6529 b.texCoords = v.texCoords;
6530 b.light = i.light;
6531 #if defined(DEBUG_NORMAL)
6532 b.color = vec4(norm, 1.);
6533 #else
6534 b.color = i.color;
6535 #endif
6536 return b;
6537}
6538#endif
6539
6540in vec3 a_v_pos;
6541in vec2 a_v_texCoords;
6542in vec3 a_v_normal;
6543in vec2 a_i_light;
6544in vec4 a_i_color;
6545in mat4 a_i_transform;
6546in mat3 a_i_normalMat;
6547out vec2 v2f_texCoords;
6548out vec4 v2f_color;
6549out float v2f_diffuse;
6550out vec2 v2f_light;
6551void main() {
6552Vertex v;
6553v.pos = a_v_pos;
6554v.texCoords = a_v_texCoords;
6555v.normal = a_v_normal;
6556Instance i;
6557i.light = a_i_light;
6558i.color = a_i_color;
6559i.transform = a_i_transform;
6560i.normalMat = a_i_normalMat;
6561BlockFrag o = vertex(v, i);
6562v2f_texCoords = o.texCoords;
6563v2f_color = o.color;
6564v2f_diffuse = o.diffuse;
6565v2f_light = o.light;
6566}
6567[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
6568
6569[17:17:49] [Render thread/ERROR]: #version 150
6570#extension GL_ARB_conservative_depth : enable
6571#define FRAGMENT_SHADER
6572#if defined(VERTEX_SHADER)
6573out float FragDistance;
6574#elif defined(FRAGMENT_SHADER)
6575in float FragDistance;
6576#endif
6577uniform vec4 uFogColor;
6578uniform vec2 uFogRange;
6579
6580float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
6581 float distXZ = length(worldPos.xz - cameraPos.xz);
6582 float distY = abs(worldPos.y - cameraPos.y);
6583 return max(distXZ, distY);
6584}
6585
6586float cylindrical_distance(vec3 worldPos) {
6587 float distXZ = length(worldPos.xz);
6588 float distY = abs(worldPos.y);
6589 return max(distXZ, distY);
6590}
6591
6592float FLWFogFactor() {
6593 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
6594}
6595// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
6596vec2 shiftLight(vec2 lm) {
6597 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
6598}
6599
6600
6601uniform float uTime;
6602uniform mat4 uViewProjection;
6603uniform vec3 uCameraPos;
6604
6605uniform vec2 uTextureScale;
6606uniform sampler2D uBlockAtlas;
6607uniform sampler2D uLightMap;
6608
6609uniform vec2 uWindowSize;
6610
6611void FLWFinalizeNormal(inout vec3 normal) {
6612 // noop
6613}
6614
6615#if defined(VERTEX_SHADER)
6616void FLWFinalizeWorldPos(inout vec4 worldPos) {
6617 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
6618
6619 gl_Position = uViewProjection * worldPos;
6620}
6621
6622#elif defined(FRAGMENT_SHADER)
6623
6624
6625#define ALPHA_DISCARD 0.1
6626// optimize discard usage
6627#if defined(ALPHA_DISCARD)
6628#if defined(GL_ARB_conservative_depth)
6629layout (depth_greater) out float gl_FragDepth;
6630#endif
6631#endif
6632out vec4 fragColor;
6633
6634vec4 FLWBlockTexture(vec2 texCoords) {
6635 return texture(uBlockAtlas, texCoords);
6636}
6637
6638void FLWFinalizeColor(vec4 color) {
6639 float a = color.a;
6640 float fog = clamp(FLWFogFactor(), 0., 1.);
6641
6642 color = mix(uFogColor, color, fog);
6643 color.a = a;
6644
6645 #if defined(ALPHA_DISCARD)
6646 if (color.a < ALPHA_DISCARD) {
6647 discard;
6648 }
6649 #endif
6650
6651 fragColor = color;
6652}
6653
6654vec4 FLWLight(vec2 lightCoords) {
6655 return texture(uLightMap, shiftLight(lightCoords));
6656}
6657#endif
6658
6659
6660float diffuse(vec3 normal) {
6661 vec3 n2 = normal * normal * vec3(.6, .25, .8);
6662 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
6663}
6664struct Vertex {
6665 vec3 pos;
6666 vec2 texCoords;
6667 vec3 normal;
6668};
6669
6670struct BlockFrag {
6671 vec2 texCoords;
6672 vec4 color;
6673 float diffuse;
6674 vec2 light;
6675};
6676
6677#if defined(FRAGMENT_SHADER)
6678void fragment(BlockFrag r) {
6679 vec4 tex = FLWBlockTexture(r.texCoords);
6680
6681 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
6682
6683 FLWFinalizeColor(color);
6684}
6685#endif
6686
6687
6688
6689
6690struct Instance {
6691 vec2 light;
6692 vec4 color;
6693 mat4 transform;
6694 mat3 normalMat;
6695};
6696
6697#if defined(VERTEX_SHADER)
6698BlockFrag vertex(Vertex v, Instance i) {
6699 vec4 worldPos = i.transform * vec4(v.pos, 1.);
6700
6701 vec3 norm = i.normalMat * v.normal;
6702
6703 FLWFinalizeWorldPos(worldPos);
6704 FLWFinalizeNormal(norm);
6705
6706 norm = normalize(norm);
6707
6708 BlockFrag b;
6709 b.diffuse = diffuse(norm);
6710 b.texCoords = v.texCoords;
6711 b.light = i.light;
6712 #if defined(DEBUG_NORMAL)
6713 b.color = vec4(norm, 1.);
6714 #else
6715 b.color = i.color;
6716 #endif
6717 return b;
6718}
6719#endif
6720
6721in vec2 v2f_texCoords;
6722in vec4 v2f_color;
6723in float v2f_diffuse;
6724in vec2 v2f_light;
6725void main() {
6726BlockFrag o;
6727o.texCoords = v2f_texCoords;
6728o.color = v2f_color;
6729o.diffuse = v2f_diffuse;
6730o.light = v2f_light;
6731fragment(o);
6732}
6733[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
6734
6735[17:17:49] [Render thread/ERROR]: #version 150
6736#extension GL_ARB_conservative_depth : enable
6737#define VERTEX_SHADER
6738#define DEBUG_NORMAL
6739#if defined(VERTEX_SHADER)
6740out float FragDistance;
6741#elif defined(FRAGMENT_SHADER)
6742in float FragDistance;
6743#endif
6744uniform vec4 uFogColor;
6745uniform vec2 uFogRange;
6746
6747float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
6748 float distXZ = length(worldPos.xz - cameraPos.xz);
6749 float distY = abs(worldPos.y - cameraPos.y);
6750 return max(distXZ, distY);
6751}
6752
6753float cylindrical_distance(vec3 worldPos) {
6754 float distXZ = length(worldPos.xz);
6755 float distY = abs(worldPos.y);
6756 return max(distXZ, distY);
6757}
6758
6759float FLWFogFactor() {
6760 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
6761}
6762// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
6763vec2 shiftLight(vec2 lm) {
6764 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
6765}
6766
6767
6768uniform float uTime;
6769uniform mat4 uViewProjection;
6770uniform vec3 uCameraPos;
6771
6772uniform vec2 uTextureScale;
6773uniform sampler2D uBlockAtlas;
6774uniform sampler2D uLightMap;
6775
6776uniform vec2 uWindowSize;
6777
6778void FLWFinalizeNormal(inout vec3 normal) {
6779 // noop
6780}
6781
6782#if defined(VERTEX_SHADER)
6783void FLWFinalizeWorldPos(inout vec4 worldPos) {
6784 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
6785
6786 gl_Position = uViewProjection * worldPos;
6787}
6788
6789#elif defined(FRAGMENT_SHADER)
6790
6791
6792#define ALPHA_DISCARD 0.1
6793// optimize discard usage
6794#if defined(ALPHA_DISCARD)
6795#if defined(GL_ARB_conservative_depth)
6796layout (depth_greater) out float gl_FragDepth;
6797#endif
6798#endif
6799out vec4 fragColor;
6800
6801vec4 FLWBlockTexture(vec2 texCoords) {
6802 return texture(uBlockAtlas, texCoords);
6803}
6804
6805void FLWFinalizeColor(vec4 color) {
6806 float a = color.a;
6807 float fog = clamp(FLWFogFactor(), 0., 1.);
6808
6809 color = mix(uFogColor, color, fog);
6810 color.a = a;
6811
6812 #if defined(ALPHA_DISCARD)
6813 if (color.a < ALPHA_DISCARD) {
6814 discard;
6815 }
6816 #endif
6817
6818 fragColor = color;
6819}
6820
6821vec4 FLWLight(vec2 lightCoords) {
6822 return texture(uLightMap, shiftLight(lightCoords));
6823}
6824#endif
6825
6826
6827float diffuse(vec3 normal) {
6828 vec3 n2 = normal * normal * vec3(.6, .25, .8);
6829 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
6830}
6831struct Vertex {
6832 vec3 pos;
6833 vec2 texCoords;
6834 vec3 normal;
6835};
6836
6837struct BlockFrag {
6838 vec2 texCoords;
6839 vec4 color;
6840 float diffuse;
6841 vec2 light;
6842};
6843
6844#if defined(FRAGMENT_SHADER)
6845void fragment(BlockFrag r) {
6846 vec4 tex = FLWBlockTexture(r.texCoords);
6847
6848 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
6849
6850 FLWFinalizeColor(color);
6851}
6852#endif
6853
6854
6855
6856
6857struct Instance {
6858 vec2 light;
6859 vec4 color;
6860 mat4 transform;
6861 mat3 normalMat;
6862};
6863
6864#if defined(VERTEX_SHADER)
6865BlockFrag vertex(Vertex v, Instance i) {
6866 vec4 worldPos = i.transform * vec4(v.pos, 1.);
6867
6868 vec3 norm = i.normalMat * v.normal;
6869
6870 FLWFinalizeWorldPos(worldPos);
6871 FLWFinalizeNormal(norm);
6872
6873 norm = normalize(norm);
6874
6875 BlockFrag b;
6876 b.diffuse = diffuse(norm);
6877 b.texCoords = v.texCoords;
6878 b.light = i.light;
6879 #if defined(DEBUG_NORMAL)
6880 b.color = vec4(norm, 1.);
6881 #else
6882 b.color = i.color;
6883 #endif
6884 return b;
6885}
6886#endif
6887
6888in vec3 a_v_pos;
6889in vec2 a_v_texCoords;
6890in vec3 a_v_normal;
6891in vec2 a_i_light;
6892in vec4 a_i_color;
6893in mat4 a_i_transform;
6894in mat3 a_i_normalMat;
6895out vec2 v2f_texCoords;
6896out vec4 v2f_color;
6897out float v2f_diffuse;
6898out vec2 v2f_light;
6899void main() {
6900Vertex v;
6901v.pos = a_v_pos;
6902v.texCoords = a_v_texCoords;
6903v.normal = a_v_normal;
6904Instance i;
6905i.light = a_i_light;
6906i.color = a_i_color;
6907i.transform = a_i_transform;
6908i.normalMat = a_i_normalMat;
6909BlockFrag o = vertex(v, i);
6910v2f_texCoords = o.texCoords;
6911v2f_color = o.color;
6912v2f_diffuse = o.diffuse;
6913v2f_light = o.light;
6914}
6915[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
6916
6917[17:17:49] [Render thread/ERROR]: #version 150
6918#extension GL_ARB_conservative_depth : enable
6919#define FRAGMENT_SHADER
6920#define DEBUG_NORMAL
6921#if defined(VERTEX_SHADER)
6922out float FragDistance;
6923#elif defined(FRAGMENT_SHADER)
6924in float FragDistance;
6925#endif
6926uniform vec4 uFogColor;
6927uniform vec2 uFogRange;
6928
6929float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
6930 float distXZ = length(worldPos.xz - cameraPos.xz);
6931 float distY = abs(worldPos.y - cameraPos.y);
6932 return max(distXZ, distY);
6933}
6934
6935float cylindrical_distance(vec3 worldPos) {
6936 float distXZ = length(worldPos.xz);
6937 float distY = abs(worldPos.y);
6938 return max(distXZ, distY);
6939}
6940
6941float FLWFogFactor() {
6942 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
6943}
6944// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
6945vec2 shiftLight(vec2 lm) {
6946 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
6947}
6948
6949
6950uniform float uTime;
6951uniform mat4 uViewProjection;
6952uniform vec3 uCameraPos;
6953
6954uniform vec2 uTextureScale;
6955uniform sampler2D uBlockAtlas;
6956uniform sampler2D uLightMap;
6957
6958uniform vec2 uWindowSize;
6959
6960void FLWFinalizeNormal(inout vec3 normal) {
6961 // noop
6962}
6963
6964#if defined(VERTEX_SHADER)
6965void FLWFinalizeWorldPos(inout vec4 worldPos) {
6966 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
6967
6968 gl_Position = uViewProjection * worldPos;
6969}
6970
6971#elif defined(FRAGMENT_SHADER)
6972
6973
6974#define ALPHA_DISCARD 0.1
6975// optimize discard usage
6976#if defined(ALPHA_DISCARD)
6977#if defined(GL_ARB_conservative_depth)
6978layout (depth_greater) out float gl_FragDepth;
6979#endif
6980#endif
6981out vec4 fragColor;
6982
6983vec4 FLWBlockTexture(vec2 texCoords) {
6984 return texture(uBlockAtlas, texCoords);
6985}
6986
6987void FLWFinalizeColor(vec4 color) {
6988 float a = color.a;
6989 float fog = clamp(FLWFogFactor(), 0., 1.);
6990
6991 color = mix(uFogColor, color, fog);
6992 color.a = a;
6993
6994 #if defined(ALPHA_DISCARD)
6995 if (color.a < ALPHA_DISCARD) {
6996 discard;
6997 }
6998 #endif
6999
7000 fragColor = color;
7001}
7002
7003vec4 FLWLight(vec2 lightCoords) {
7004 return texture(uLightMap, shiftLight(lightCoords));
7005}
7006#endif
7007
7008
7009float diffuse(vec3 normal) {
7010 vec3 n2 = normal * normal * vec3(.6, .25, .8);
7011 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
7012}
7013struct Vertex {
7014 vec3 pos;
7015 vec2 texCoords;
7016 vec3 normal;
7017};
7018
7019struct BlockFrag {
7020 vec2 texCoords;
7021 vec4 color;
7022 float diffuse;
7023 vec2 light;
7024};
7025
7026#if defined(FRAGMENT_SHADER)
7027void fragment(BlockFrag r) {
7028 vec4 tex = FLWBlockTexture(r.texCoords);
7029
7030 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
7031
7032 FLWFinalizeColor(color);
7033}
7034#endif
7035
7036
7037
7038
7039struct Instance {
7040 vec2 light;
7041 vec4 color;
7042 mat4 transform;
7043 mat3 normalMat;
7044};
7045
7046#if defined(VERTEX_SHADER)
7047BlockFrag vertex(Vertex v, Instance i) {
7048 vec4 worldPos = i.transform * vec4(v.pos, 1.);
7049
7050 vec3 norm = i.normalMat * v.normal;
7051
7052 FLWFinalizeWorldPos(worldPos);
7053 FLWFinalizeNormal(norm);
7054
7055 norm = normalize(norm);
7056
7057 BlockFrag b;
7058 b.diffuse = diffuse(norm);
7059 b.texCoords = v.texCoords;
7060 b.light = i.light;
7061 #if defined(DEBUG_NORMAL)
7062 b.color = vec4(norm, 1.);
7063 #else
7064 b.color = i.color;
7065 #endif
7066 return b;
7067}
7068#endif
7069
7070in vec2 v2f_texCoords;
7071in vec4 v2f_color;
7072in float v2f_diffuse;
7073in vec2 v2f_light;
7074void main() {
7075BlockFrag o;
7076o.texCoords = v2f_texCoords;
7077o.color = v2f_color;
7078o.diffuse = v2f_diffuse;
7079o.light = v2f_light;
7080fragment(o);
7081}
7082[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
7083
7084[17:17:49] [Render thread/ERROR]: #version 150
7085#extension GL_ARB_conservative_depth : enable
7086#define VERTEX_SHADER
7087#if defined(VERTEX_SHADER)
7088out float FragDistance;
7089#elif defined(FRAGMENT_SHADER)
7090in float FragDistance;
7091#endif
7092uniform vec4 uFogColor;
7093uniform vec2 uFogRange;
7094
7095float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
7096 float distXZ = length(worldPos.xz - cameraPos.xz);
7097 float distY = abs(worldPos.y - cameraPos.y);
7098 return max(distXZ, distY);
7099}
7100
7101float cylindrical_distance(vec3 worldPos) {
7102 float distXZ = length(worldPos.xz);
7103 float distY = abs(worldPos.y);
7104 return max(distXZ, distY);
7105}
7106
7107float FLWFogFactor() {
7108 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
7109}
7110// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
7111vec2 shiftLight(vec2 lm) {
7112 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
7113}
7114
7115
7116uniform float uTime;
7117uniform mat4 uViewProjection;
7118uniform vec3 uCameraPos;
7119
7120uniform vec2 uTextureScale;
7121uniform sampler2D uBlockAtlas;
7122uniform sampler2D uLightMap;
7123
7124uniform vec2 uWindowSize;
7125
7126void FLWFinalizeNormal(inout vec3 normal) {
7127 // noop
7128}
7129
7130#if defined(VERTEX_SHADER)
7131void FLWFinalizeWorldPos(inout vec4 worldPos) {
7132 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
7133
7134 gl_Position = uViewProjection * worldPos;
7135}
7136
7137#elif defined(FRAGMENT_SHADER)
7138
7139
7140#define ALPHA_DISCARD 0.1
7141// optimize discard usage
7142#if defined(ALPHA_DISCARD)
7143#if defined(GL_ARB_conservative_depth)
7144layout (depth_greater) out float gl_FragDepth;
7145#endif
7146#endif
7147out vec4 fragColor;
7148
7149vec4 FLWBlockTexture(vec2 texCoords) {
7150 return texture(uBlockAtlas, texCoords);
7151}
7152
7153void FLWFinalizeColor(vec4 color) {
7154 float a = color.a;
7155 float fog = clamp(FLWFogFactor(), 0., 1.);
7156
7157 color = mix(uFogColor, color, fog);
7158 color.a = a;
7159
7160 #if defined(ALPHA_DISCARD)
7161 if (color.a < ALPHA_DISCARD) {
7162 discard;
7163 }
7164 #endif
7165
7166 fragColor = color;
7167}
7168
7169vec4 FLWLight(vec2 lightCoords) {
7170 return texture(uLightMap, shiftLight(lightCoords));
7171}
7172#endif
7173
7174
7175#define PIOVER2 1.5707963268
7176
7177vec4 quat(vec3 axis, float angle) {
7178 float halfAngle = angle * PIOVER2 / 180.0;
7179 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
7180 return vec4(axis.xyz * cs.y, cs.x);
7181}
7182
7183vec4 quatMult(vec4 q1, vec4 q2) {
7184 // disgustingly vectorized quaternion multiplication
7185 vec4 a = q1.w * q2.xyzw;
7186 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
7187 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
7188 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
7189
7190 return a + b + c + d;
7191}
7192
7193vec3 rotateVertexByQuat(vec3 v, vec4 q) {
7194 vec3 i = q.xyz;
7195 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
7196}
7197
7198vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
7199 return rotateVertexByQuat(v, quat(axis, angle));
7200}
7201
7202float diffuse(vec3 normal) {
7203 vec3 n2 = normal * normal * vec3(.6, .25, .8);
7204 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
7205}
7206struct Vertex {
7207 vec3 pos;
7208 vec2 texCoords;
7209 vec3 normal;
7210};
7211
7212struct BlockFrag {
7213 vec2 texCoords;
7214 vec4 color;
7215 float diffuse;
7216 vec2 light;
7217};
7218
7219#if defined(FRAGMENT_SHADER)
7220void fragment(BlockFrag r) {
7221 vec4 tex = FLWBlockTexture(r.texCoords);
7222
7223 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
7224
7225 FLWFinalizeColor(color);
7226}
7227#endif
7228
7229
7230
7231
7232
7233
7234struct Oriented {
7235 vec2 light;
7236 vec4 color;
7237 vec3 pos;
7238 vec3 pivot;
7239 vec4 rotation;
7240};
7241
7242#if defined(VERTEX_SHADER)
7243BlockFrag vertex(Vertex v, Oriented o) {
7244 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
7245
7246 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
7247
7248 FLWFinalizeWorldPos(worldPos);
7249 FLWFinalizeNormal(norm);
7250
7251 BlockFrag b;
7252 b.diffuse = diffuse(norm);
7253 b.texCoords = v.texCoords;
7254 b.light = o.light;
7255 #if defined(DEBUG_NORMAL)
7256 b.color = vec4(norm, 1.);
7257 #else
7258 b.color = o.color;
7259 #endif
7260 return b;
7261}
7262#endif
7263
7264in vec3 a_v_pos;
7265in vec2 a_v_texCoords;
7266in vec3 a_v_normal;
7267in vec2 a_i_light;
7268in vec4 a_i_color;
7269in vec3 a_i_pos;
7270in vec3 a_i_pivot;
7271in vec4 a_i_rotation;
7272out vec2 v2f_texCoords;
7273out vec4 v2f_color;
7274out float v2f_diffuse;
7275out vec2 v2f_light;
7276void main() {
7277Vertex v;
7278v.pos = a_v_pos;
7279v.texCoords = a_v_texCoords;
7280v.normal = a_v_normal;
7281Oriented i;
7282i.light = a_i_light;
7283i.color = a_i_color;
7284i.pos = a_i_pos;
7285i.pivot = a_i_pivot;
7286i.rotation = a_i_rotation;
7287BlockFrag o = vertex(v, i);
7288v2f_texCoords = o.texCoords;
7289v2f_color = o.color;
7290v2f_diffuse = o.diffuse;
7291v2f_light = o.light;
7292}
7293[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
7294
7295[17:17:49] [Render thread/ERROR]: #version 150
7296#extension GL_ARB_conservative_depth : enable
7297#define FRAGMENT_SHADER
7298#if defined(VERTEX_SHADER)
7299out float FragDistance;
7300#elif defined(FRAGMENT_SHADER)
7301in float FragDistance;
7302#endif
7303uniform vec4 uFogColor;
7304uniform vec2 uFogRange;
7305
7306float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
7307 float distXZ = length(worldPos.xz - cameraPos.xz);
7308 float distY = abs(worldPos.y - cameraPos.y);
7309 return max(distXZ, distY);
7310}
7311
7312float cylindrical_distance(vec3 worldPos) {
7313 float distXZ = length(worldPos.xz);
7314 float distY = abs(worldPos.y);
7315 return max(distXZ, distY);
7316}
7317
7318float FLWFogFactor() {
7319 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
7320}
7321// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
7322vec2 shiftLight(vec2 lm) {
7323 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
7324}
7325
7326
7327uniform float uTime;
7328uniform mat4 uViewProjection;
7329uniform vec3 uCameraPos;
7330
7331uniform vec2 uTextureScale;
7332uniform sampler2D uBlockAtlas;
7333uniform sampler2D uLightMap;
7334
7335uniform vec2 uWindowSize;
7336
7337void FLWFinalizeNormal(inout vec3 normal) {
7338 // noop
7339}
7340
7341#if defined(VERTEX_SHADER)
7342void FLWFinalizeWorldPos(inout vec4 worldPos) {
7343 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
7344
7345 gl_Position = uViewProjection * worldPos;
7346}
7347
7348#elif defined(FRAGMENT_SHADER)
7349
7350
7351#define ALPHA_DISCARD 0.1
7352// optimize discard usage
7353#if defined(ALPHA_DISCARD)
7354#if defined(GL_ARB_conservative_depth)
7355layout (depth_greater) out float gl_FragDepth;
7356#endif
7357#endif
7358out vec4 fragColor;
7359
7360vec4 FLWBlockTexture(vec2 texCoords) {
7361 return texture(uBlockAtlas, texCoords);
7362}
7363
7364void FLWFinalizeColor(vec4 color) {
7365 float a = color.a;
7366 float fog = clamp(FLWFogFactor(), 0., 1.);
7367
7368 color = mix(uFogColor, color, fog);
7369 color.a = a;
7370
7371 #if defined(ALPHA_DISCARD)
7372 if (color.a < ALPHA_DISCARD) {
7373 discard;
7374 }
7375 #endif
7376
7377 fragColor = color;
7378}
7379
7380vec4 FLWLight(vec2 lightCoords) {
7381 return texture(uLightMap, shiftLight(lightCoords));
7382}
7383#endif
7384
7385
7386#define PIOVER2 1.5707963268
7387
7388vec4 quat(vec3 axis, float angle) {
7389 float halfAngle = angle * PIOVER2 / 180.0;
7390 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
7391 return vec4(axis.xyz * cs.y, cs.x);
7392}
7393
7394vec4 quatMult(vec4 q1, vec4 q2) {
7395 // disgustingly vectorized quaternion multiplication
7396 vec4 a = q1.w * q2.xyzw;
7397 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
7398 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
7399 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
7400
7401 return a + b + c + d;
7402}
7403
7404vec3 rotateVertexByQuat(vec3 v, vec4 q) {
7405 vec3 i = q.xyz;
7406 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
7407}
7408
7409vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
7410 return rotateVertexByQuat(v, quat(axis, angle));
7411}
7412
7413float diffuse(vec3 normal) {
7414 vec3 n2 = normal * normal * vec3(.6, .25, .8);
7415 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
7416}
7417struct Vertex {
7418 vec3 pos;
7419 vec2 texCoords;
7420 vec3 normal;
7421};
7422
7423struct BlockFrag {
7424 vec2 texCoords;
7425 vec4 color;
7426 float diffuse;
7427 vec2 light;
7428};
7429
7430#if defined(FRAGMENT_SHADER)
7431void fragment(BlockFrag r) {
7432 vec4 tex = FLWBlockTexture(r.texCoords);
7433
7434 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
7435
7436 FLWFinalizeColor(color);
7437}
7438#endif
7439
7440
7441
7442
7443
7444
7445struct Oriented {
7446 vec2 light;
7447 vec4 color;
7448 vec3 pos;
7449 vec3 pivot;
7450 vec4 rotation;
7451};
7452
7453#if defined(VERTEX_SHADER)
7454BlockFrag vertex(Vertex v, Oriented o) {
7455 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
7456
7457 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
7458
7459 FLWFinalizeWorldPos(worldPos);
7460 FLWFinalizeNormal(norm);
7461
7462 BlockFrag b;
7463 b.diffuse = diffuse(norm);
7464 b.texCoords = v.texCoords;
7465 b.light = o.light;
7466 #if defined(DEBUG_NORMAL)
7467 b.color = vec4(norm, 1.);
7468 #else
7469 b.color = o.color;
7470 #endif
7471 return b;
7472}
7473#endif
7474
7475in vec2 v2f_texCoords;
7476in vec4 v2f_color;
7477in float v2f_diffuse;
7478in vec2 v2f_light;
7479void main() {
7480BlockFrag o;
7481o.texCoords = v2f_texCoords;
7482o.color = v2f_color;
7483o.diffuse = v2f_diffuse;
7484o.light = v2f_light;
7485fragment(o);
7486}
7487[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
7488
7489[17:17:49] [Render thread/ERROR]: #version 150
7490#extension GL_ARB_conservative_depth : enable
7491#define VERTEX_SHADER
7492#define DEBUG_NORMAL
7493#if defined(VERTEX_SHADER)
7494out float FragDistance;
7495#elif defined(FRAGMENT_SHADER)
7496in float FragDistance;
7497#endif
7498uniform vec4 uFogColor;
7499uniform vec2 uFogRange;
7500
7501float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
7502 float distXZ = length(worldPos.xz - cameraPos.xz);
7503 float distY = abs(worldPos.y - cameraPos.y);
7504 return max(distXZ, distY);
7505}
7506
7507float cylindrical_distance(vec3 worldPos) {
7508 float distXZ = length(worldPos.xz);
7509 float distY = abs(worldPos.y);
7510 return max(distXZ, distY);
7511}
7512
7513float FLWFogFactor() {
7514 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
7515}
7516// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
7517vec2 shiftLight(vec2 lm) {
7518 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
7519}
7520
7521
7522uniform float uTime;
7523uniform mat4 uViewProjection;
7524uniform vec3 uCameraPos;
7525
7526uniform vec2 uTextureScale;
7527uniform sampler2D uBlockAtlas;
7528uniform sampler2D uLightMap;
7529
7530uniform vec2 uWindowSize;
7531
7532void FLWFinalizeNormal(inout vec3 normal) {
7533 // noop
7534}
7535
7536#if defined(VERTEX_SHADER)
7537void FLWFinalizeWorldPos(inout vec4 worldPos) {
7538 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
7539
7540 gl_Position = uViewProjection * worldPos;
7541}
7542
7543#elif defined(FRAGMENT_SHADER)
7544
7545
7546#define ALPHA_DISCARD 0.1
7547// optimize discard usage
7548#if defined(ALPHA_DISCARD)
7549#if defined(GL_ARB_conservative_depth)
7550layout (depth_greater) out float gl_FragDepth;
7551#endif
7552#endif
7553out vec4 fragColor;
7554
7555vec4 FLWBlockTexture(vec2 texCoords) {
7556 return texture(uBlockAtlas, texCoords);
7557}
7558
7559void FLWFinalizeColor(vec4 color) {
7560 float a = color.a;
7561 float fog = clamp(FLWFogFactor(), 0., 1.);
7562
7563 color = mix(uFogColor, color, fog);
7564 color.a = a;
7565
7566 #if defined(ALPHA_DISCARD)
7567 if (color.a < ALPHA_DISCARD) {
7568 discard;
7569 }
7570 #endif
7571
7572 fragColor = color;
7573}
7574
7575vec4 FLWLight(vec2 lightCoords) {
7576 return texture(uLightMap, shiftLight(lightCoords));
7577}
7578#endif
7579
7580
7581#define PIOVER2 1.5707963268
7582
7583vec4 quat(vec3 axis, float angle) {
7584 float halfAngle = angle * PIOVER2 / 180.0;
7585 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
7586 return vec4(axis.xyz * cs.y, cs.x);
7587}
7588
7589vec4 quatMult(vec4 q1, vec4 q2) {
7590 // disgustingly vectorized quaternion multiplication
7591 vec4 a = q1.w * q2.xyzw;
7592 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
7593 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
7594 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
7595
7596 return a + b + c + d;
7597}
7598
7599vec3 rotateVertexByQuat(vec3 v, vec4 q) {
7600 vec3 i = q.xyz;
7601 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
7602}
7603
7604vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
7605 return rotateVertexByQuat(v, quat(axis, angle));
7606}
7607
7608float diffuse(vec3 normal) {
7609 vec3 n2 = normal * normal * vec3(.6, .25, .8);
7610 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
7611}
7612struct Vertex {
7613 vec3 pos;
7614 vec2 texCoords;
7615 vec3 normal;
7616};
7617
7618struct BlockFrag {
7619 vec2 texCoords;
7620 vec4 color;
7621 float diffuse;
7622 vec2 light;
7623};
7624
7625#if defined(FRAGMENT_SHADER)
7626void fragment(BlockFrag r) {
7627 vec4 tex = FLWBlockTexture(r.texCoords);
7628
7629 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
7630
7631 FLWFinalizeColor(color);
7632}
7633#endif
7634
7635
7636
7637
7638
7639
7640struct Oriented {
7641 vec2 light;
7642 vec4 color;
7643 vec3 pos;
7644 vec3 pivot;
7645 vec4 rotation;
7646};
7647
7648#if defined(VERTEX_SHADER)
7649BlockFrag vertex(Vertex v, Oriented o) {
7650 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
7651
7652 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
7653
7654 FLWFinalizeWorldPos(worldPos);
7655 FLWFinalizeNormal(norm);
7656
7657 BlockFrag b;
7658 b.diffuse = diffuse(norm);
7659 b.texCoords = v.texCoords;
7660 b.light = o.light;
7661 #if defined(DEBUG_NORMAL)
7662 b.color = vec4(norm, 1.);
7663 #else
7664 b.color = o.color;
7665 #endif
7666 return b;
7667}
7668#endif
7669
7670in vec3 a_v_pos;
7671in vec2 a_v_texCoords;
7672in vec3 a_v_normal;
7673in vec2 a_i_light;
7674in vec4 a_i_color;
7675in vec3 a_i_pos;
7676in vec3 a_i_pivot;
7677in vec4 a_i_rotation;
7678out vec2 v2f_texCoords;
7679out vec4 v2f_color;
7680out float v2f_diffuse;
7681out vec2 v2f_light;
7682void main() {
7683Vertex v;
7684v.pos = a_v_pos;
7685v.texCoords = a_v_texCoords;
7686v.normal = a_v_normal;
7687Oriented i;
7688i.light = a_i_light;
7689i.color = a_i_color;
7690i.pos = a_i_pos;
7691i.pivot = a_i_pivot;
7692i.rotation = a_i_rotation;
7693BlockFrag o = vertex(v, i);
7694v2f_texCoords = o.texCoords;
7695v2f_color = o.color;
7696v2f_diffuse = o.diffuse;
7697v2f_light = o.light;
7698}
7699[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
7700
7701[17:17:49] [Render thread/ERROR]: #version 150
7702#extension GL_ARB_conservative_depth : enable
7703#define FRAGMENT_SHADER
7704#define DEBUG_NORMAL
7705#if defined(VERTEX_SHADER)
7706out float FragDistance;
7707#elif defined(FRAGMENT_SHADER)
7708in float FragDistance;
7709#endif
7710uniform vec4 uFogColor;
7711uniform vec2 uFogRange;
7712
7713float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
7714 float distXZ = length(worldPos.xz - cameraPos.xz);
7715 float distY = abs(worldPos.y - cameraPos.y);
7716 return max(distXZ, distY);
7717}
7718
7719float cylindrical_distance(vec3 worldPos) {
7720 float distXZ = length(worldPos.xz);
7721 float distY = abs(worldPos.y);
7722 return max(distXZ, distY);
7723}
7724
7725float FLWFogFactor() {
7726 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
7727}
7728// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
7729vec2 shiftLight(vec2 lm) {
7730 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
7731}
7732
7733
7734uniform float uTime;
7735uniform mat4 uViewProjection;
7736uniform vec3 uCameraPos;
7737
7738uniform vec2 uTextureScale;
7739uniform sampler2D uBlockAtlas;
7740uniform sampler2D uLightMap;
7741
7742uniform vec2 uWindowSize;
7743
7744void FLWFinalizeNormal(inout vec3 normal) {
7745 // noop
7746}
7747
7748#if defined(VERTEX_SHADER)
7749void FLWFinalizeWorldPos(inout vec4 worldPos) {
7750 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
7751
7752 gl_Position = uViewProjection * worldPos;
7753}
7754
7755#elif defined(FRAGMENT_SHADER)
7756
7757
7758#define ALPHA_DISCARD 0.1
7759// optimize discard usage
7760#if defined(ALPHA_DISCARD)
7761#if defined(GL_ARB_conservative_depth)
7762layout (depth_greater) out float gl_FragDepth;
7763#endif
7764#endif
7765out vec4 fragColor;
7766
7767vec4 FLWBlockTexture(vec2 texCoords) {
7768 return texture(uBlockAtlas, texCoords);
7769}
7770
7771void FLWFinalizeColor(vec4 color) {
7772 float a = color.a;
7773 float fog = clamp(FLWFogFactor(), 0., 1.);
7774
7775 color = mix(uFogColor, color, fog);
7776 color.a = a;
7777
7778 #if defined(ALPHA_DISCARD)
7779 if (color.a < ALPHA_DISCARD) {
7780 discard;
7781 }
7782 #endif
7783
7784 fragColor = color;
7785}
7786
7787vec4 FLWLight(vec2 lightCoords) {
7788 return texture(uLightMap, shiftLight(lightCoords));
7789}
7790#endif
7791
7792
7793#define PIOVER2 1.5707963268
7794
7795vec4 quat(vec3 axis, float angle) {
7796 float halfAngle = angle * PIOVER2 / 180.0;
7797 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
7798 return vec4(axis.xyz * cs.y, cs.x);
7799}
7800
7801vec4 quatMult(vec4 q1, vec4 q2) {
7802 // disgustingly vectorized quaternion multiplication
7803 vec4 a = q1.w * q2.xyzw;
7804 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
7805 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
7806 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
7807
7808 return a + b + c + d;
7809}
7810
7811vec3 rotateVertexByQuat(vec3 v, vec4 q) {
7812 vec3 i = q.xyz;
7813 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
7814}
7815
7816vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
7817 return rotateVertexByQuat(v, quat(axis, angle));
7818}
7819
7820float diffuse(vec3 normal) {
7821 vec3 n2 = normal * normal * vec3(.6, .25, .8);
7822 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
7823}
7824struct Vertex {
7825 vec3 pos;
7826 vec2 texCoords;
7827 vec3 normal;
7828};
7829
7830struct BlockFrag {
7831 vec2 texCoords;
7832 vec4 color;
7833 float diffuse;
7834 vec2 light;
7835};
7836
7837#if defined(FRAGMENT_SHADER)
7838void fragment(BlockFrag r) {
7839 vec4 tex = FLWBlockTexture(r.texCoords);
7840
7841 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
7842
7843 FLWFinalizeColor(color);
7844}
7845#endif
7846
7847
7848
7849
7850
7851
7852struct Oriented {
7853 vec2 light;
7854 vec4 color;
7855 vec3 pos;
7856 vec3 pivot;
7857 vec4 rotation;
7858};
7859
7860#if defined(VERTEX_SHADER)
7861BlockFrag vertex(Vertex v, Oriented o) {
7862 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
7863
7864 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
7865
7866 FLWFinalizeWorldPos(worldPos);
7867 FLWFinalizeNormal(norm);
7868
7869 BlockFrag b;
7870 b.diffuse = diffuse(norm);
7871 b.texCoords = v.texCoords;
7872 b.light = o.light;
7873 #if defined(DEBUG_NORMAL)
7874 b.color = vec4(norm, 1.);
7875 #else
7876 b.color = o.color;
7877 #endif
7878 return b;
7879}
7880#endif
7881
7882in vec2 v2f_texCoords;
7883in vec4 v2f_color;
7884in float v2f_diffuse;
7885in vec2 v2f_light;
7886void main() {
7887BlockFrag o;
7888o.texCoords = v2f_texCoords;
7889o.color = v2f_color;
7890o.diffuse = v2f_diffuse;
7891o.light = v2f_light;
7892fragment(o);
7893}
7894[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
7895
7896[17:17:49] [Render thread/ERROR]: #version 150
7897#extension GL_ARB_conservative_depth : enable
7898#define VERTEX_SHADER
7899#if defined(VERTEX_SHADER)
7900out float FragDistance;
7901#elif defined(FRAGMENT_SHADER)
7902in float FragDistance;
7903#endif
7904uniform vec4 uFogColor;
7905uniform vec2 uFogRange;
7906
7907float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
7908 float distXZ = length(worldPos.xz - cameraPos.xz);
7909 float distY = abs(worldPos.y - cameraPos.y);
7910 return max(distXZ, distY);
7911}
7912
7913float cylindrical_distance(vec3 worldPos) {
7914 float distXZ = length(worldPos.xz);
7915 float distY = abs(worldPos.y);
7916 return max(distXZ, distY);
7917}
7918
7919float FLWFogFactor() {
7920 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
7921}
7922// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
7923vec2 shiftLight(vec2 lm) {
7924 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
7925}
7926
7927
7928uniform float uTime;
7929uniform mat4 uViewProjection;
7930uniform vec3 uCameraPos;
7931
7932uniform vec2 uTextureScale;
7933uniform sampler2D uBlockAtlas;
7934uniform sampler2D uLightMap;
7935
7936uniform vec2 uWindowSize;
7937
7938void FLWFinalizeNormal(inout vec3 normal) {
7939 // noop
7940}
7941
7942#if defined(VERTEX_SHADER)
7943void FLWFinalizeWorldPos(inout vec4 worldPos) {
7944 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
7945
7946 gl_Position = uViewProjection * worldPos;
7947}
7948
7949#elif defined(FRAGMENT_SHADER)
7950
7951
7952#define ALPHA_DISCARD 0.1
7953// optimize discard usage
7954#if defined(ALPHA_DISCARD)
7955#if defined(GL_ARB_conservative_depth)
7956layout (depth_greater) out float gl_FragDepth;
7957#endif
7958#endif
7959out vec4 fragColor;
7960
7961vec4 FLWBlockTexture(vec2 texCoords) {
7962 return texture(uBlockAtlas, texCoords);
7963}
7964
7965void FLWFinalizeColor(vec4 color) {
7966 float a = color.a;
7967 float fog = clamp(FLWFogFactor(), 0., 1.);
7968
7969 color = mix(uFogColor, color, fog);
7970 color.a = a;
7971
7972 #if defined(ALPHA_DISCARD)
7973 if (color.a < ALPHA_DISCARD) {
7974 discard;
7975 }
7976 #endif
7977
7978 fragColor = color;
7979}
7980
7981vec4 FLWLight(vec2 lightCoords) {
7982 return texture(uLightMap, shiftLight(lightCoords));
7983}
7984#endif
7985
7986
7987mat4 rotate(vec3 axis, float angle) {
7988 float s = sin(angle);
7989 float c = cos(angle);
7990 float oc = 1. - c;
7991
7992 vec3 sa = axis * s;
7993
7994 mat4 mr = mat4(1.);
7995 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
7996 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
7997 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
7998
7999 return mr;
8000}
8001
8002mat4 rotation(vec3 rot) {
8003 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
8004}
8005
8006mat3 modelToNormal(mat4 mat) {
8007 // Discard the edges. This won't be accurate for scaled or skewed matrices,
8008 // but we don't have to work with those often.
8009 mat3 m;
8010 m[0] = mat[0].xyz;
8011 m[1] = mat[1].xyz;
8012 m[2] = mat[2].xyz;
8013 return m;
8014}
8015
8016float diffuse(vec3 normal) {
8017 vec3 n2 = normal * normal * vec3(.6, .25, .8);
8018 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
8019}
8020struct Vertex {
8021 vec3 pos;
8022 vec2 texCoords;
8023 vec3 normal;
8024};
8025
8026struct BlockFrag {
8027 vec2 texCoords;
8028 vec4 color;
8029 float diffuse;
8030 vec2 light;
8031};
8032
8033#if defined(FRAGMENT_SHADER)
8034void fragment(BlockFrag r) {
8035 vec4 tex = FLWBlockTexture(r.texCoords);
8036
8037 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
8038
8039 FLWFinalizeColor(color);
8040}
8041#endif
8042#define PI 3.1415926538
8043
8044
8045
8046
8047struct Rotating {
8048 vec2 light;
8049 vec4 color;
8050 vec3 pos;
8051 float speed;
8052 float offset;
8053 vec3 axis;
8054};
8055
8056
8057
8058
8059mat4 kineticRotation(float offset, float speed, vec3 axis) {
8060 float degrees = offset + uTime * speed * 3./10.;
8061 float angle = fract(degrees / 360.) * PI * 2.;
8062
8063 return rotate(axis, angle);
8064}
8065
8066#if defined(VERTEX_SHADER)
8067BlockFrag vertex(Vertex v, Rotating instance) {
8068 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
8069
8070 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
8071 worldPos += vec4(instance.pos + .5, 0.);
8072
8073 vec3 norm = modelToNormal(spin) * v.normal;
8074
8075 FLWFinalizeWorldPos(worldPos);
8076 FLWFinalizeNormal(norm);
8077
8078 BlockFrag b;
8079 b.diffuse = diffuse(norm);
8080 b.texCoords = v.texCoords;
8081 b.light = instance.light;
8082
8083 #if defined(DEBUG_RAINBOW)
8084 b.color = instance.color;
8085 #elif defined(DEBUG_NORMAL)
8086 b.color = vec4(norm, 1.);
8087 #else
8088 b.color = vec4(1.);
8089 #endif
8090
8091 return b;
8092}
8093#endif
8094
8095in vec3 a_v_pos;
8096in vec2 a_v_texCoords;
8097in vec3 a_v_normal;
8098in vec2 a_i_light;
8099in vec4 a_i_color;
8100in vec3 a_i_pos;
8101in float a_i_speed;
8102in float a_i_offset;
8103in vec3 a_i_axis;
8104out vec2 v2f_texCoords;
8105out vec4 v2f_color;
8106out float v2f_diffuse;
8107out vec2 v2f_light;
8108void main() {
8109Vertex v;
8110v.pos = a_v_pos;
8111v.texCoords = a_v_texCoords;
8112v.normal = a_v_normal;
8113Rotating i;
8114i.light = a_i_light;
8115i.color = a_i_color;
8116i.pos = a_i_pos;
8117i.speed = a_i_speed;
8118i.offset = a_i_offset;
8119i.axis = a_i_axis;
8120BlockFrag o = vertex(v, i);
8121v2f_texCoords = o.texCoords;
8122v2f_color = o.color;
8123v2f_diffuse = o.diffuse;
8124v2f_light = o.light;
8125}
8126[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
8127
8128[17:17:49] [Render thread/ERROR]: #version 150
8129#extension GL_ARB_conservative_depth : enable
8130#define FRAGMENT_SHADER
8131#if defined(VERTEX_SHADER)
8132out float FragDistance;
8133#elif defined(FRAGMENT_SHADER)
8134in float FragDistance;
8135#endif
8136uniform vec4 uFogColor;
8137uniform vec2 uFogRange;
8138
8139float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
8140 float distXZ = length(worldPos.xz - cameraPos.xz);
8141 float distY = abs(worldPos.y - cameraPos.y);
8142 return max(distXZ, distY);
8143}
8144
8145float cylindrical_distance(vec3 worldPos) {
8146 float distXZ = length(worldPos.xz);
8147 float distY = abs(worldPos.y);
8148 return max(distXZ, distY);
8149}
8150
8151float FLWFogFactor() {
8152 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
8153}
8154// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
8155vec2 shiftLight(vec2 lm) {
8156 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
8157}
8158
8159
8160uniform float uTime;
8161uniform mat4 uViewProjection;
8162uniform vec3 uCameraPos;
8163
8164uniform vec2 uTextureScale;
8165uniform sampler2D uBlockAtlas;
8166uniform sampler2D uLightMap;
8167
8168uniform vec2 uWindowSize;
8169
8170void FLWFinalizeNormal(inout vec3 normal) {
8171 // noop
8172}
8173
8174#if defined(VERTEX_SHADER)
8175void FLWFinalizeWorldPos(inout vec4 worldPos) {
8176 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
8177
8178 gl_Position = uViewProjection * worldPos;
8179}
8180
8181#elif defined(FRAGMENT_SHADER)
8182
8183
8184#define ALPHA_DISCARD 0.1
8185// optimize discard usage
8186#if defined(ALPHA_DISCARD)
8187#if defined(GL_ARB_conservative_depth)
8188layout (depth_greater) out float gl_FragDepth;
8189#endif
8190#endif
8191out vec4 fragColor;
8192
8193vec4 FLWBlockTexture(vec2 texCoords) {
8194 return texture(uBlockAtlas, texCoords);
8195}
8196
8197void FLWFinalizeColor(vec4 color) {
8198 float a = color.a;
8199 float fog = clamp(FLWFogFactor(), 0., 1.);
8200
8201 color = mix(uFogColor, color, fog);
8202 color.a = a;
8203
8204 #if defined(ALPHA_DISCARD)
8205 if (color.a < ALPHA_DISCARD) {
8206 discard;
8207 }
8208 #endif
8209
8210 fragColor = color;
8211}
8212
8213vec4 FLWLight(vec2 lightCoords) {
8214 return texture(uLightMap, shiftLight(lightCoords));
8215}
8216#endif
8217
8218
8219mat4 rotate(vec3 axis, float angle) {
8220 float s = sin(angle);
8221 float c = cos(angle);
8222 float oc = 1. - c;
8223
8224 vec3 sa = axis * s;
8225
8226 mat4 mr = mat4(1.);
8227 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
8228 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
8229 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
8230
8231 return mr;
8232}
8233
8234mat4 rotation(vec3 rot) {
8235 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
8236}
8237
8238mat3 modelToNormal(mat4 mat) {
8239 // Discard the edges. This won't be accurate for scaled or skewed matrices,
8240 // but we don't have to work with those often.
8241 mat3 m;
8242 m[0] = mat[0].xyz;
8243 m[1] = mat[1].xyz;
8244 m[2] = mat[2].xyz;
8245 return m;
8246}
8247
8248float diffuse(vec3 normal) {
8249 vec3 n2 = normal * normal * vec3(.6, .25, .8);
8250 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
8251}
8252struct Vertex {
8253 vec3 pos;
8254 vec2 texCoords;
8255 vec3 normal;
8256};
8257
8258struct BlockFrag {
8259 vec2 texCoords;
8260 vec4 color;
8261 float diffuse;
8262 vec2 light;
8263};
8264
8265#if defined(FRAGMENT_SHADER)
8266void fragment(BlockFrag r) {
8267 vec4 tex = FLWBlockTexture(r.texCoords);
8268
8269 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
8270
8271 FLWFinalizeColor(color);
8272}
8273#endif
8274#define PI 3.1415926538
8275
8276
8277
8278
8279struct Rotating {
8280 vec2 light;
8281 vec4 color;
8282 vec3 pos;
8283 float speed;
8284 float offset;
8285 vec3 axis;
8286};
8287
8288
8289
8290
8291mat4 kineticRotation(float offset, float speed, vec3 axis) {
8292 float degrees = offset + uTime * speed * 3./10.;
8293 float angle = fract(degrees / 360.) * PI * 2.;
8294
8295 return rotate(axis, angle);
8296}
8297
8298#if defined(VERTEX_SHADER)
8299BlockFrag vertex(Vertex v, Rotating instance) {
8300 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
8301
8302 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
8303 worldPos += vec4(instance.pos + .5, 0.);
8304
8305 vec3 norm = modelToNormal(spin) * v.normal;
8306
8307 FLWFinalizeWorldPos(worldPos);
8308 FLWFinalizeNormal(norm);
8309
8310 BlockFrag b;
8311 b.diffuse = diffuse(norm);
8312 b.texCoords = v.texCoords;
8313 b.light = instance.light;
8314
8315 #if defined(DEBUG_RAINBOW)
8316 b.color = instance.color;
8317 #elif defined(DEBUG_NORMAL)
8318 b.color = vec4(norm, 1.);
8319 #else
8320 b.color = vec4(1.);
8321 #endif
8322
8323 return b;
8324}
8325#endif
8326
8327in vec2 v2f_texCoords;
8328in vec4 v2f_color;
8329in float v2f_diffuse;
8330in vec2 v2f_light;
8331void main() {
8332BlockFrag o;
8333o.texCoords = v2f_texCoords;
8334o.color = v2f_color;
8335o.diffuse = v2f_diffuse;
8336o.light = v2f_light;
8337fragment(o);
8338}
8339[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
8340
8341[17:17:49] [Render thread/ERROR]: #version 150
8342#extension GL_ARB_conservative_depth : enable
8343#define VERTEX_SHADER
8344#define DEBUG_RAINBOW
8345#if defined(VERTEX_SHADER)
8346out float FragDistance;
8347#elif defined(FRAGMENT_SHADER)
8348in float FragDistance;
8349#endif
8350uniform vec4 uFogColor;
8351uniform vec2 uFogRange;
8352
8353float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
8354 float distXZ = length(worldPos.xz - cameraPos.xz);
8355 float distY = abs(worldPos.y - cameraPos.y);
8356 return max(distXZ, distY);
8357}
8358
8359float cylindrical_distance(vec3 worldPos) {
8360 float distXZ = length(worldPos.xz);
8361 float distY = abs(worldPos.y);
8362 return max(distXZ, distY);
8363}
8364
8365float FLWFogFactor() {
8366 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
8367}
8368// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
8369vec2 shiftLight(vec2 lm) {
8370 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
8371}
8372
8373
8374uniform float uTime;
8375uniform mat4 uViewProjection;
8376uniform vec3 uCameraPos;
8377
8378uniform vec2 uTextureScale;
8379uniform sampler2D uBlockAtlas;
8380uniform sampler2D uLightMap;
8381
8382uniform vec2 uWindowSize;
8383
8384void FLWFinalizeNormal(inout vec3 normal) {
8385 // noop
8386}
8387
8388#if defined(VERTEX_SHADER)
8389void FLWFinalizeWorldPos(inout vec4 worldPos) {
8390 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
8391
8392 gl_Position = uViewProjection * worldPos;
8393}
8394
8395#elif defined(FRAGMENT_SHADER)
8396
8397
8398#define ALPHA_DISCARD 0.1
8399// optimize discard usage
8400#if defined(ALPHA_DISCARD)
8401#if defined(GL_ARB_conservative_depth)
8402layout (depth_greater) out float gl_FragDepth;
8403#endif
8404#endif
8405out vec4 fragColor;
8406
8407vec4 FLWBlockTexture(vec2 texCoords) {
8408 return texture(uBlockAtlas, texCoords);
8409}
8410
8411void FLWFinalizeColor(vec4 color) {
8412 float a = color.a;
8413 float fog = clamp(FLWFogFactor(), 0., 1.);
8414
8415 color = mix(uFogColor, color, fog);
8416 color.a = a;
8417
8418 #if defined(ALPHA_DISCARD)
8419 if (color.a < ALPHA_DISCARD) {
8420 discard;
8421 }
8422 #endif
8423
8424 fragColor = color;
8425}
8426
8427vec4 FLWLight(vec2 lightCoords) {
8428 return texture(uLightMap, shiftLight(lightCoords));
8429}
8430#endif
8431
8432
8433mat4 rotate(vec3 axis, float angle) {
8434 float s = sin(angle);
8435 float c = cos(angle);
8436 float oc = 1. - c;
8437
8438 vec3 sa = axis * s;
8439
8440 mat4 mr = mat4(1.);
8441 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
8442 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
8443 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
8444
8445 return mr;
8446}
8447
8448mat4 rotation(vec3 rot) {
8449 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
8450}
8451
8452mat3 modelToNormal(mat4 mat) {
8453 // Discard the edges. This won't be accurate for scaled or skewed matrices,
8454 // but we don't have to work with those often.
8455 mat3 m;
8456 m[0] = mat[0].xyz;
8457 m[1] = mat[1].xyz;
8458 m[2] = mat[2].xyz;
8459 return m;
8460}
8461
8462float diffuse(vec3 normal) {
8463 vec3 n2 = normal * normal * vec3(.6, .25, .8);
8464 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
8465}
8466struct Vertex {
8467 vec3 pos;
8468 vec2 texCoords;
8469 vec3 normal;
8470};
8471
8472struct BlockFrag {
8473 vec2 texCoords;
8474 vec4 color;
8475 float diffuse;
8476 vec2 light;
8477};
8478
8479#if defined(FRAGMENT_SHADER)
8480void fragment(BlockFrag r) {
8481 vec4 tex = FLWBlockTexture(r.texCoords);
8482
8483 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
8484
8485 FLWFinalizeColor(color);
8486}
8487#endif
8488#define PI 3.1415926538
8489
8490
8491
8492
8493struct Rotating {
8494 vec2 light;
8495 vec4 color;
8496 vec3 pos;
8497 float speed;
8498 float offset;
8499 vec3 axis;
8500};
8501
8502
8503
8504
8505mat4 kineticRotation(float offset, float speed, vec3 axis) {
8506 float degrees = offset + uTime * speed * 3./10.;
8507 float angle = fract(degrees / 360.) * PI * 2.;
8508
8509 return rotate(axis, angle);
8510}
8511
8512#if defined(VERTEX_SHADER)
8513BlockFrag vertex(Vertex v, Rotating instance) {
8514 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
8515
8516 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
8517 worldPos += vec4(instance.pos + .5, 0.);
8518
8519 vec3 norm = modelToNormal(spin) * v.normal;
8520
8521 FLWFinalizeWorldPos(worldPos);
8522 FLWFinalizeNormal(norm);
8523
8524 BlockFrag b;
8525 b.diffuse = diffuse(norm);
8526 b.texCoords = v.texCoords;
8527 b.light = instance.light;
8528
8529 #if defined(DEBUG_RAINBOW)
8530 b.color = instance.color;
8531 #elif defined(DEBUG_NORMAL)
8532 b.color = vec4(norm, 1.);
8533 #else
8534 b.color = vec4(1.);
8535 #endif
8536
8537 return b;
8538}
8539#endif
8540
8541in vec3 a_v_pos;
8542in vec2 a_v_texCoords;
8543in vec3 a_v_normal;
8544in vec2 a_i_light;
8545in vec4 a_i_color;
8546in vec3 a_i_pos;
8547in float a_i_speed;
8548in float a_i_offset;
8549in vec3 a_i_axis;
8550out vec2 v2f_texCoords;
8551out vec4 v2f_color;
8552out float v2f_diffuse;
8553out vec2 v2f_light;
8554void main() {
8555Vertex v;
8556v.pos = a_v_pos;
8557v.texCoords = a_v_texCoords;
8558v.normal = a_v_normal;
8559Rotating i;
8560i.light = a_i_light;
8561i.color = a_i_color;
8562i.pos = a_i_pos;
8563i.speed = a_i_speed;
8564i.offset = a_i_offset;
8565i.axis = a_i_axis;
8566BlockFrag o = vertex(v, i);
8567v2f_texCoords = o.texCoords;
8568v2f_color = o.color;
8569v2f_diffuse = o.diffuse;
8570v2f_light = o.light;
8571}
8572[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
8573
8574[17:17:49] [Render thread/ERROR]: #version 150
8575#extension GL_ARB_conservative_depth : enable
8576#define FRAGMENT_SHADER
8577#define DEBUG_RAINBOW
8578#if defined(VERTEX_SHADER)
8579out float FragDistance;
8580#elif defined(FRAGMENT_SHADER)
8581in float FragDistance;
8582#endif
8583uniform vec4 uFogColor;
8584uniform vec2 uFogRange;
8585
8586float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
8587 float distXZ = length(worldPos.xz - cameraPos.xz);
8588 float distY = abs(worldPos.y - cameraPos.y);
8589 return max(distXZ, distY);
8590}
8591
8592float cylindrical_distance(vec3 worldPos) {
8593 float distXZ = length(worldPos.xz);
8594 float distY = abs(worldPos.y);
8595 return max(distXZ, distY);
8596}
8597
8598float FLWFogFactor() {
8599 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
8600}
8601// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
8602vec2 shiftLight(vec2 lm) {
8603 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
8604}
8605
8606
8607uniform float uTime;
8608uniform mat4 uViewProjection;
8609uniform vec3 uCameraPos;
8610
8611uniform vec2 uTextureScale;
8612uniform sampler2D uBlockAtlas;
8613uniform sampler2D uLightMap;
8614
8615uniform vec2 uWindowSize;
8616
8617void FLWFinalizeNormal(inout vec3 normal) {
8618 // noop
8619}
8620
8621#if defined(VERTEX_SHADER)
8622void FLWFinalizeWorldPos(inout vec4 worldPos) {
8623 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
8624
8625 gl_Position = uViewProjection * worldPos;
8626}
8627
8628#elif defined(FRAGMENT_SHADER)
8629
8630
8631#define ALPHA_DISCARD 0.1
8632// optimize discard usage
8633#if defined(ALPHA_DISCARD)
8634#if defined(GL_ARB_conservative_depth)
8635layout (depth_greater) out float gl_FragDepth;
8636#endif
8637#endif
8638out vec4 fragColor;
8639
8640vec4 FLWBlockTexture(vec2 texCoords) {
8641 return texture(uBlockAtlas, texCoords);
8642}
8643
8644void FLWFinalizeColor(vec4 color) {
8645 float a = color.a;
8646 float fog = clamp(FLWFogFactor(), 0., 1.);
8647
8648 color = mix(uFogColor, color, fog);
8649 color.a = a;
8650
8651 #if defined(ALPHA_DISCARD)
8652 if (color.a < ALPHA_DISCARD) {
8653 discard;
8654 }
8655 #endif
8656
8657 fragColor = color;
8658}
8659
8660vec4 FLWLight(vec2 lightCoords) {
8661 return texture(uLightMap, shiftLight(lightCoords));
8662}
8663#endif
8664
8665
8666mat4 rotate(vec3 axis, float angle) {
8667 float s = sin(angle);
8668 float c = cos(angle);
8669 float oc = 1. - c;
8670
8671 vec3 sa = axis * s;
8672
8673 mat4 mr = mat4(1.);
8674 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
8675 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
8676 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
8677
8678 return mr;
8679}
8680
8681mat4 rotation(vec3 rot) {
8682 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
8683}
8684
8685mat3 modelToNormal(mat4 mat) {
8686 // Discard the edges. This won't be accurate for scaled or skewed matrices,
8687 // but we don't have to work with those often.
8688 mat3 m;
8689 m[0] = mat[0].xyz;
8690 m[1] = mat[1].xyz;
8691 m[2] = mat[2].xyz;
8692 return m;
8693}
8694
8695float diffuse(vec3 normal) {
8696 vec3 n2 = normal * normal * vec3(.6, .25, .8);
8697 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
8698}
8699struct Vertex {
8700 vec3 pos;
8701 vec2 texCoords;
8702 vec3 normal;
8703};
8704
8705struct BlockFrag {
8706 vec2 texCoords;
8707 vec4 color;
8708 float diffuse;
8709 vec2 light;
8710};
8711
8712#if defined(FRAGMENT_SHADER)
8713void fragment(BlockFrag r) {
8714 vec4 tex = FLWBlockTexture(r.texCoords);
8715
8716 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
8717
8718 FLWFinalizeColor(color);
8719}
8720#endif
8721#define PI 3.1415926538
8722
8723
8724
8725
8726struct Rotating {
8727 vec2 light;
8728 vec4 color;
8729 vec3 pos;
8730 float speed;
8731 float offset;
8732 vec3 axis;
8733};
8734
8735
8736
8737
8738mat4 kineticRotation(float offset, float speed, vec3 axis) {
8739 float degrees = offset + uTime * speed * 3./10.;
8740 float angle = fract(degrees / 360.) * PI * 2.;
8741
8742 return rotate(axis, angle);
8743}
8744
8745#if defined(VERTEX_SHADER)
8746BlockFrag vertex(Vertex v, Rotating instance) {
8747 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
8748
8749 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
8750 worldPos += vec4(instance.pos + .5, 0.);
8751
8752 vec3 norm = modelToNormal(spin) * v.normal;
8753
8754 FLWFinalizeWorldPos(worldPos);
8755 FLWFinalizeNormal(norm);
8756
8757 BlockFrag b;
8758 b.diffuse = diffuse(norm);
8759 b.texCoords = v.texCoords;
8760 b.light = instance.light;
8761
8762 #if defined(DEBUG_RAINBOW)
8763 b.color = instance.color;
8764 #elif defined(DEBUG_NORMAL)
8765 b.color = vec4(norm, 1.);
8766 #else
8767 b.color = vec4(1.);
8768 #endif
8769
8770 return b;
8771}
8772#endif
8773
8774in vec2 v2f_texCoords;
8775in vec4 v2f_color;
8776in float v2f_diffuse;
8777in vec2 v2f_light;
8778void main() {
8779BlockFrag o;
8780o.texCoords = v2f_texCoords;
8781o.color = v2f_color;
8782o.diffuse = v2f_diffuse;
8783o.light = v2f_light;
8784fragment(o);
8785}
8786[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
8787
8788[17:17:49] [Render thread/ERROR]: #version 150
8789#extension GL_ARB_conservative_depth : enable
8790#define VERTEX_SHADER
8791#define DEBUG_NORMAL
8792#if defined(VERTEX_SHADER)
8793out float FragDistance;
8794#elif defined(FRAGMENT_SHADER)
8795in float FragDistance;
8796#endif
8797uniform vec4 uFogColor;
8798uniform vec2 uFogRange;
8799
8800float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
8801 float distXZ = length(worldPos.xz - cameraPos.xz);
8802 float distY = abs(worldPos.y - cameraPos.y);
8803 return max(distXZ, distY);
8804}
8805
8806float cylindrical_distance(vec3 worldPos) {
8807 float distXZ = length(worldPos.xz);
8808 float distY = abs(worldPos.y);
8809 return max(distXZ, distY);
8810}
8811
8812float FLWFogFactor() {
8813 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
8814}
8815// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
8816vec2 shiftLight(vec2 lm) {
8817 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
8818}
8819
8820
8821uniform float uTime;
8822uniform mat4 uViewProjection;
8823uniform vec3 uCameraPos;
8824
8825uniform vec2 uTextureScale;
8826uniform sampler2D uBlockAtlas;
8827uniform sampler2D uLightMap;
8828
8829uniform vec2 uWindowSize;
8830
8831void FLWFinalizeNormal(inout vec3 normal) {
8832 // noop
8833}
8834
8835#if defined(VERTEX_SHADER)
8836void FLWFinalizeWorldPos(inout vec4 worldPos) {
8837 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
8838
8839 gl_Position = uViewProjection * worldPos;
8840}
8841
8842#elif defined(FRAGMENT_SHADER)
8843
8844
8845#define ALPHA_DISCARD 0.1
8846// optimize discard usage
8847#if defined(ALPHA_DISCARD)
8848#if defined(GL_ARB_conservative_depth)
8849layout (depth_greater) out float gl_FragDepth;
8850#endif
8851#endif
8852out vec4 fragColor;
8853
8854vec4 FLWBlockTexture(vec2 texCoords) {
8855 return texture(uBlockAtlas, texCoords);
8856}
8857
8858void FLWFinalizeColor(vec4 color) {
8859 float a = color.a;
8860 float fog = clamp(FLWFogFactor(), 0., 1.);
8861
8862 color = mix(uFogColor, color, fog);
8863 color.a = a;
8864
8865 #if defined(ALPHA_DISCARD)
8866 if (color.a < ALPHA_DISCARD) {
8867 discard;
8868 }
8869 #endif
8870
8871 fragColor = color;
8872}
8873
8874vec4 FLWLight(vec2 lightCoords) {
8875 return texture(uLightMap, shiftLight(lightCoords));
8876}
8877#endif
8878
8879
8880mat4 rotate(vec3 axis, float angle) {
8881 float s = sin(angle);
8882 float c = cos(angle);
8883 float oc = 1. - c;
8884
8885 vec3 sa = axis * s;
8886
8887 mat4 mr = mat4(1.);
8888 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
8889 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
8890 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
8891
8892 return mr;
8893}
8894
8895mat4 rotation(vec3 rot) {
8896 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
8897}
8898
8899mat3 modelToNormal(mat4 mat) {
8900 // Discard the edges. This won't be accurate for scaled or skewed matrices,
8901 // but we don't have to work with those often.
8902 mat3 m;
8903 m[0] = mat[0].xyz;
8904 m[1] = mat[1].xyz;
8905 m[2] = mat[2].xyz;
8906 return m;
8907}
8908
8909float diffuse(vec3 normal) {
8910 vec3 n2 = normal * normal * vec3(.6, .25, .8);
8911 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
8912}
8913struct Vertex {
8914 vec3 pos;
8915 vec2 texCoords;
8916 vec3 normal;
8917};
8918
8919struct BlockFrag {
8920 vec2 texCoords;
8921 vec4 color;
8922 float diffuse;
8923 vec2 light;
8924};
8925
8926#if defined(FRAGMENT_SHADER)
8927void fragment(BlockFrag r) {
8928 vec4 tex = FLWBlockTexture(r.texCoords);
8929
8930 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
8931
8932 FLWFinalizeColor(color);
8933}
8934#endif
8935#define PI 3.1415926538
8936
8937
8938
8939
8940struct Rotating {
8941 vec2 light;
8942 vec4 color;
8943 vec3 pos;
8944 float speed;
8945 float offset;
8946 vec3 axis;
8947};
8948
8949
8950
8951
8952mat4 kineticRotation(float offset, float speed, vec3 axis) {
8953 float degrees = offset + uTime * speed * 3./10.;
8954 float angle = fract(degrees / 360.) * PI * 2.;
8955
8956 return rotate(axis, angle);
8957}
8958
8959#if defined(VERTEX_SHADER)
8960BlockFrag vertex(Vertex v, Rotating instance) {
8961 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
8962
8963 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
8964 worldPos += vec4(instance.pos + .5, 0.);
8965
8966 vec3 norm = modelToNormal(spin) * v.normal;
8967
8968 FLWFinalizeWorldPos(worldPos);
8969 FLWFinalizeNormal(norm);
8970
8971 BlockFrag b;
8972 b.diffuse = diffuse(norm);
8973 b.texCoords = v.texCoords;
8974 b.light = instance.light;
8975
8976 #if defined(DEBUG_RAINBOW)
8977 b.color = instance.color;
8978 #elif defined(DEBUG_NORMAL)
8979 b.color = vec4(norm, 1.);
8980 #else
8981 b.color = vec4(1.);
8982 #endif
8983
8984 return b;
8985}
8986#endif
8987
8988in vec3 a_v_pos;
8989in vec2 a_v_texCoords;
8990in vec3 a_v_normal;
8991in vec2 a_i_light;
8992in vec4 a_i_color;
8993in vec3 a_i_pos;
8994in float a_i_speed;
8995in float a_i_offset;
8996in vec3 a_i_axis;
8997out vec2 v2f_texCoords;
8998out vec4 v2f_color;
8999out float v2f_diffuse;
9000out vec2 v2f_light;
9001void main() {
9002Vertex v;
9003v.pos = a_v_pos;
9004v.texCoords = a_v_texCoords;
9005v.normal = a_v_normal;
9006Rotating i;
9007i.light = a_i_light;
9008i.color = a_i_color;
9009i.pos = a_i_pos;
9010i.speed = a_i_speed;
9011i.offset = a_i_offset;
9012i.axis = a_i_axis;
9013BlockFrag o = vertex(v, i);
9014v2f_texCoords = o.texCoords;
9015v2f_color = o.color;
9016v2f_diffuse = o.diffuse;
9017v2f_light = o.light;
9018}
9019[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
9020
9021[17:17:49] [Render thread/ERROR]: #version 150
9022#extension GL_ARB_conservative_depth : enable
9023#define FRAGMENT_SHADER
9024#define DEBUG_NORMAL
9025#if defined(VERTEX_SHADER)
9026out float FragDistance;
9027#elif defined(FRAGMENT_SHADER)
9028in float FragDistance;
9029#endif
9030uniform vec4 uFogColor;
9031uniform vec2 uFogRange;
9032
9033float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
9034 float distXZ = length(worldPos.xz - cameraPos.xz);
9035 float distY = abs(worldPos.y - cameraPos.y);
9036 return max(distXZ, distY);
9037}
9038
9039float cylindrical_distance(vec3 worldPos) {
9040 float distXZ = length(worldPos.xz);
9041 float distY = abs(worldPos.y);
9042 return max(distXZ, distY);
9043}
9044
9045float FLWFogFactor() {
9046 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
9047}
9048// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
9049vec2 shiftLight(vec2 lm) {
9050 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
9051}
9052
9053
9054uniform float uTime;
9055uniform mat4 uViewProjection;
9056uniform vec3 uCameraPos;
9057
9058uniform vec2 uTextureScale;
9059uniform sampler2D uBlockAtlas;
9060uniform sampler2D uLightMap;
9061
9062uniform vec2 uWindowSize;
9063
9064void FLWFinalizeNormal(inout vec3 normal) {
9065 // noop
9066}
9067
9068#if defined(VERTEX_SHADER)
9069void FLWFinalizeWorldPos(inout vec4 worldPos) {
9070 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
9071
9072 gl_Position = uViewProjection * worldPos;
9073}
9074
9075#elif defined(FRAGMENT_SHADER)
9076
9077
9078#define ALPHA_DISCARD 0.1
9079// optimize discard usage
9080#if defined(ALPHA_DISCARD)
9081#if defined(GL_ARB_conservative_depth)
9082layout (depth_greater) out float gl_FragDepth;
9083#endif
9084#endif
9085out vec4 fragColor;
9086
9087vec4 FLWBlockTexture(vec2 texCoords) {
9088 return texture(uBlockAtlas, texCoords);
9089}
9090
9091void FLWFinalizeColor(vec4 color) {
9092 float a = color.a;
9093 float fog = clamp(FLWFogFactor(), 0., 1.);
9094
9095 color = mix(uFogColor, color, fog);
9096 color.a = a;
9097
9098 #if defined(ALPHA_DISCARD)
9099 if (color.a < ALPHA_DISCARD) {
9100 discard;
9101 }
9102 #endif
9103
9104 fragColor = color;
9105}
9106
9107vec4 FLWLight(vec2 lightCoords) {
9108 return texture(uLightMap, shiftLight(lightCoords));
9109}
9110#endif
9111
9112
9113mat4 rotate(vec3 axis, float angle) {
9114 float s = sin(angle);
9115 float c = cos(angle);
9116 float oc = 1. - c;
9117
9118 vec3 sa = axis * s;
9119
9120 mat4 mr = mat4(1.);
9121 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
9122 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
9123 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
9124
9125 return mr;
9126}
9127
9128mat4 rotation(vec3 rot) {
9129 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
9130}
9131
9132mat3 modelToNormal(mat4 mat) {
9133 // Discard the edges. This won't be accurate for scaled or skewed matrices,
9134 // but we don't have to work with those often.
9135 mat3 m;
9136 m[0] = mat[0].xyz;
9137 m[1] = mat[1].xyz;
9138 m[2] = mat[2].xyz;
9139 return m;
9140}
9141
9142float diffuse(vec3 normal) {
9143 vec3 n2 = normal * normal * vec3(.6, .25, .8);
9144 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
9145}
9146struct Vertex {
9147 vec3 pos;
9148 vec2 texCoords;
9149 vec3 normal;
9150};
9151
9152struct BlockFrag {
9153 vec2 texCoords;
9154 vec4 color;
9155 float diffuse;
9156 vec2 light;
9157};
9158
9159#if defined(FRAGMENT_SHADER)
9160void fragment(BlockFrag r) {
9161 vec4 tex = FLWBlockTexture(r.texCoords);
9162
9163 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
9164
9165 FLWFinalizeColor(color);
9166}
9167#endif
9168#define PI 3.1415926538
9169
9170
9171
9172
9173struct Rotating {
9174 vec2 light;
9175 vec4 color;
9176 vec3 pos;
9177 float speed;
9178 float offset;
9179 vec3 axis;
9180};
9181
9182
9183
9184
9185mat4 kineticRotation(float offset, float speed, vec3 axis) {
9186 float degrees = offset + uTime * speed * 3./10.;
9187 float angle = fract(degrees / 360.) * PI * 2.;
9188
9189 return rotate(axis, angle);
9190}
9191
9192#if defined(VERTEX_SHADER)
9193BlockFrag vertex(Vertex v, Rotating instance) {
9194 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
9195
9196 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
9197 worldPos += vec4(instance.pos + .5, 0.);
9198
9199 vec3 norm = modelToNormal(spin) * v.normal;
9200
9201 FLWFinalizeWorldPos(worldPos);
9202 FLWFinalizeNormal(norm);
9203
9204 BlockFrag b;
9205 b.diffuse = diffuse(norm);
9206 b.texCoords = v.texCoords;
9207 b.light = instance.light;
9208
9209 #if defined(DEBUG_RAINBOW)
9210 b.color = instance.color;
9211 #elif defined(DEBUG_NORMAL)
9212 b.color = vec4(norm, 1.);
9213 #else
9214 b.color = vec4(1.);
9215 #endif
9216
9217 return b;
9218}
9219#endif
9220
9221in vec2 v2f_texCoords;
9222in vec4 v2f_color;
9223in float v2f_diffuse;
9224in vec2 v2f_light;
9225void main() {
9226BlockFrag o;
9227o.texCoords = v2f_texCoords;
9228o.color = v2f_color;
9229o.diffuse = v2f_diffuse;
9230o.light = v2f_light;
9231fragment(o);
9232}
9233[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
9234
9235[17:17:49] [Render thread/ERROR]: #version 150
9236#extension GL_ARB_conservative_depth : enable
9237#define VERTEX_SHADER
9238#if defined(VERTEX_SHADER)
9239out float FragDistance;
9240#elif defined(FRAGMENT_SHADER)
9241in float FragDistance;
9242#endif
9243uniform vec4 uFogColor;
9244uniform vec2 uFogRange;
9245
9246float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
9247 float distXZ = length(worldPos.xz - cameraPos.xz);
9248 float distY = abs(worldPos.y - cameraPos.y);
9249 return max(distXZ, distY);
9250}
9251
9252float cylindrical_distance(vec3 worldPos) {
9253 float distXZ = length(worldPos.xz);
9254 float distY = abs(worldPos.y);
9255 return max(distXZ, distY);
9256}
9257
9258float FLWFogFactor() {
9259 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
9260}
9261// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
9262vec2 shiftLight(vec2 lm) {
9263 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
9264}
9265
9266
9267uniform float uTime;
9268uniform mat4 uViewProjection;
9269uniform vec3 uCameraPos;
9270
9271uniform vec2 uTextureScale;
9272uniform sampler2D uBlockAtlas;
9273uniform sampler2D uLightMap;
9274
9275uniform vec2 uWindowSize;
9276
9277void FLWFinalizeNormal(inout vec3 normal) {
9278 // noop
9279}
9280
9281#if defined(VERTEX_SHADER)
9282void FLWFinalizeWorldPos(inout vec4 worldPos) {
9283 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
9284
9285 gl_Position = uViewProjection * worldPos;
9286}
9287
9288#elif defined(FRAGMENT_SHADER)
9289
9290
9291#define ALPHA_DISCARD 0.1
9292// optimize discard usage
9293#if defined(ALPHA_DISCARD)
9294#if defined(GL_ARB_conservative_depth)
9295layout (depth_greater) out float gl_FragDepth;
9296#endif
9297#endif
9298out vec4 fragColor;
9299
9300vec4 FLWBlockTexture(vec2 texCoords) {
9301 return texture(uBlockAtlas, texCoords);
9302}
9303
9304void FLWFinalizeColor(vec4 color) {
9305 float a = color.a;
9306 float fog = clamp(FLWFogFactor(), 0., 1.);
9307
9308 color = mix(uFogColor, color, fog);
9309 color.a = a;
9310
9311 #if defined(ALPHA_DISCARD)
9312 if (color.a < ALPHA_DISCARD) {
9313 discard;
9314 }
9315 #endif
9316
9317 fragColor = color;
9318}
9319
9320vec4 FLWLight(vec2 lightCoords) {
9321 return texture(uLightMap, shiftLight(lightCoords));
9322}
9323#endif
9324
9325
9326mat4 rotate(vec3 axis, float angle) {
9327 float s = sin(angle);
9328 float c = cos(angle);
9329 float oc = 1. - c;
9330
9331 vec3 sa = axis * s;
9332
9333 mat4 mr = mat4(1.);
9334 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
9335 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
9336 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
9337
9338 return mr;
9339}
9340
9341mat4 rotation(vec3 rot) {
9342 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
9343}
9344
9345mat3 modelToNormal(mat4 mat) {
9346 // Discard the edges. This won't be accurate for scaled or skewed matrices,
9347 // but we don't have to work with those often.
9348 mat3 m;
9349 m[0] = mat[0].xyz;
9350 m[1] = mat[1].xyz;
9351 m[2] = mat[2].xyz;
9352 return m;
9353}
9354
9355#define PIOVER2 1.5707963268
9356
9357vec4 quat(vec3 axis, float angle) {
9358 float halfAngle = angle * PIOVER2 / 180.0;
9359 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
9360 return vec4(axis.xyz * cs.y, cs.x);
9361}
9362
9363vec4 quatMult(vec4 q1, vec4 q2) {
9364 // disgustingly vectorized quaternion multiplication
9365 vec4 a = q1.w * q2.xyzw;
9366 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
9367 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
9368 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
9369
9370 return a + b + c + d;
9371}
9372
9373vec3 rotateVertexByQuat(vec3 v, vec4 q) {
9374 vec3 i = q.xyz;
9375 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
9376}
9377
9378vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
9379 return rotateVertexByQuat(v, quat(axis, angle));
9380}
9381
9382float diffuse(vec3 normal) {
9383 vec3 n2 = normal * normal * vec3(.6, .25, .8);
9384 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
9385}
9386struct Vertex {
9387 vec3 pos;
9388 vec2 texCoords;
9389 vec3 normal;
9390};
9391
9392struct BlockFrag {
9393 vec2 texCoords;
9394 vec4 color;
9395 float diffuse;
9396 vec2 light;
9397};
9398
9399#if defined(FRAGMENT_SHADER)
9400void fragment(BlockFrag r) {
9401 vec4 tex = FLWBlockTexture(r.texCoords);
9402
9403 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
9404
9405 FLWFinalizeColor(color);
9406}
9407#endif
9408#define PI 3.1415926538
9409
9410
9411
9412
9413
9414struct Actor {
9415 vec3 pos;
9416 vec2 light;
9417 float offset;
9418 vec3 axis;
9419 vec4 rotation;
9420 vec3 rotationCenter;
9421 float speed;
9422};
9423
9424
9425
9426
9427#if defined(VERTEX_SHADER)
9428BlockFrag vertex(Vertex v, Actor instance) {
9429 float degrees = instance.offset + uTime * instance.speed / 20.;
9430 //float angle = fract(degrees / 360.) * PI * 2.;
9431
9432 vec4 kineticRot = quat(instance.axis, degrees);
9433 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
9434
9435 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
9436 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
9437
9438 FLWFinalizeWorldPos(worldPos);
9439 FLWFinalizeNormal(norm);
9440
9441 BlockFrag b;
9442 b.diffuse = diffuse(norm);
9443 b.texCoords = v.texCoords;
9444 b.light = instance.light;
9445
9446 #if defined(DEBUG_NORMAL)
9447 b.color = vec4(norm, 1.);
9448 #else
9449 b.color = vec4(1.);
9450 #endif
9451
9452 return b;
9453}
9454#endif
9455
9456in vec3 a_v_pos;
9457in vec2 a_v_texCoords;
9458in vec3 a_v_normal;
9459in vec3 a_i_pos;
9460in vec2 a_i_light;
9461in float a_i_offset;
9462in vec3 a_i_axis;
9463in vec4 a_i_rotation;
9464in vec3 a_i_rotationCenter;
9465in float a_i_speed;
9466out vec2 v2f_texCoords;
9467out vec4 v2f_color;
9468out float v2f_diffuse;
9469out vec2 v2f_light;
9470void main() {
9471Vertex v;
9472v.pos = a_v_pos;
9473v.texCoords = a_v_texCoords;
9474v.normal = a_v_normal;
9475Actor i;
9476i.pos = a_i_pos;
9477i.light = a_i_light;
9478i.offset = a_i_offset;
9479i.axis = a_i_axis;
9480i.rotation = a_i_rotation;
9481i.rotationCenter = a_i_rotationCenter;
9482i.speed = a_i_speed;
9483BlockFrag o = vertex(v, i);
9484v2f_texCoords = o.texCoords;
9485v2f_color = o.color;
9486v2f_diffuse = o.diffuse;
9487v2f_light = o.light;
9488}
9489[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
9490
9491[17:17:49] [Render thread/ERROR]: #version 150
9492#extension GL_ARB_conservative_depth : enable
9493#define FRAGMENT_SHADER
9494#if defined(VERTEX_SHADER)
9495out float FragDistance;
9496#elif defined(FRAGMENT_SHADER)
9497in float FragDistance;
9498#endif
9499uniform vec4 uFogColor;
9500uniform vec2 uFogRange;
9501
9502float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
9503 float distXZ = length(worldPos.xz - cameraPos.xz);
9504 float distY = abs(worldPos.y - cameraPos.y);
9505 return max(distXZ, distY);
9506}
9507
9508float cylindrical_distance(vec3 worldPos) {
9509 float distXZ = length(worldPos.xz);
9510 float distY = abs(worldPos.y);
9511 return max(distXZ, distY);
9512}
9513
9514float FLWFogFactor() {
9515 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
9516}
9517// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
9518vec2 shiftLight(vec2 lm) {
9519 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
9520}
9521
9522
9523uniform float uTime;
9524uniform mat4 uViewProjection;
9525uniform vec3 uCameraPos;
9526
9527uniform vec2 uTextureScale;
9528uniform sampler2D uBlockAtlas;
9529uniform sampler2D uLightMap;
9530
9531uniform vec2 uWindowSize;
9532
9533void FLWFinalizeNormal(inout vec3 normal) {
9534 // noop
9535}
9536
9537#if defined(VERTEX_SHADER)
9538void FLWFinalizeWorldPos(inout vec4 worldPos) {
9539 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
9540
9541 gl_Position = uViewProjection * worldPos;
9542}
9543
9544#elif defined(FRAGMENT_SHADER)
9545
9546
9547#define ALPHA_DISCARD 0.1
9548// optimize discard usage
9549#if defined(ALPHA_DISCARD)
9550#if defined(GL_ARB_conservative_depth)
9551layout (depth_greater) out float gl_FragDepth;
9552#endif
9553#endif
9554out vec4 fragColor;
9555
9556vec4 FLWBlockTexture(vec2 texCoords) {
9557 return texture(uBlockAtlas, texCoords);
9558}
9559
9560void FLWFinalizeColor(vec4 color) {
9561 float a = color.a;
9562 float fog = clamp(FLWFogFactor(), 0., 1.);
9563
9564 color = mix(uFogColor, color, fog);
9565 color.a = a;
9566
9567 #if defined(ALPHA_DISCARD)
9568 if (color.a < ALPHA_DISCARD) {
9569 discard;
9570 }
9571 #endif
9572
9573 fragColor = color;
9574}
9575
9576vec4 FLWLight(vec2 lightCoords) {
9577 return texture(uLightMap, shiftLight(lightCoords));
9578}
9579#endif
9580
9581
9582mat4 rotate(vec3 axis, float angle) {
9583 float s = sin(angle);
9584 float c = cos(angle);
9585 float oc = 1. - c;
9586
9587 vec3 sa = axis * s;
9588
9589 mat4 mr = mat4(1.);
9590 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
9591 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
9592 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
9593
9594 return mr;
9595}
9596
9597mat4 rotation(vec3 rot) {
9598 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
9599}
9600
9601mat3 modelToNormal(mat4 mat) {
9602 // Discard the edges. This won't be accurate for scaled or skewed matrices,
9603 // but we don't have to work with those often.
9604 mat3 m;
9605 m[0] = mat[0].xyz;
9606 m[1] = mat[1].xyz;
9607 m[2] = mat[2].xyz;
9608 return m;
9609}
9610
9611#define PIOVER2 1.5707963268
9612
9613vec4 quat(vec3 axis, float angle) {
9614 float halfAngle = angle * PIOVER2 / 180.0;
9615 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
9616 return vec4(axis.xyz * cs.y, cs.x);
9617}
9618
9619vec4 quatMult(vec4 q1, vec4 q2) {
9620 // disgustingly vectorized quaternion multiplication
9621 vec4 a = q1.w * q2.xyzw;
9622 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
9623 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
9624 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
9625
9626 return a + b + c + d;
9627}
9628
9629vec3 rotateVertexByQuat(vec3 v, vec4 q) {
9630 vec3 i = q.xyz;
9631 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
9632}
9633
9634vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
9635 return rotateVertexByQuat(v, quat(axis, angle));
9636}
9637
9638float diffuse(vec3 normal) {
9639 vec3 n2 = normal * normal * vec3(.6, .25, .8);
9640 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
9641}
9642struct Vertex {
9643 vec3 pos;
9644 vec2 texCoords;
9645 vec3 normal;
9646};
9647
9648struct BlockFrag {
9649 vec2 texCoords;
9650 vec4 color;
9651 float diffuse;
9652 vec2 light;
9653};
9654
9655#if defined(FRAGMENT_SHADER)
9656void fragment(BlockFrag r) {
9657 vec4 tex = FLWBlockTexture(r.texCoords);
9658
9659 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
9660
9661 FLWFinalizeColor(color);
9662}
9663#endif
9664#define PI 3.1415926538
9665
9666
9667
9668
9669
9670struct Actor {
9671 vec3 pos;
9672 vec2 light;
9673 float offset;
9674 vec3 axis;
9675 vec4 rotation;
9676 vec3 rotationCenter;
9677 float speed;
9678};
9679
9680
9681
9682
9683#if defined(VERTEX_SHADER)
9684BlockFrag vertex(Vertex v, Actor instance) {
9685 float degrees = instance.offset + uTime * instance.speed / 20.;
9686 //float angle = fract(degrees / 360.) * PI * 2.;
9687
9688 vec4 kineticRot = quat(instance.axis, degrees);
9689 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
9690
9691 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
9692 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
9693
9694 FLWFinalizeWorldPos(worldPos);
9695 FLWFinalizeNormal(norm);
9696
9697 BlockFrag b;
9698 b.diffuse = diffuse(norm);
9699 b.texCoords = v.texCoords;
9700 b.light = instance.light;
9701
9702 #if defined(DEBUG_NORMAL)
9703 b.color = vec4(norm, 1.);
9704 #else
9705 b.color = vec4(1.);
9706 #endif
9707
9708 return b;
9709}
9710#endif
9711
9712in vec2 v2f_texCoords;
9713in vec4 v2f_color;
9714in float v2f_diffuse;
9715in vec2 v2f_light;
9716void main() {
9717BlockFrag o;
9718o.texCoords = v2f_texCoords;
9719o.color = v2f_color;
9720o.diffuse = v2f_diffuse;
9721o.light = v2f_light;
9722fragment(o);
9723}
9724[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
9725
9726[17:17:49] [Render thread/ERROR]: #version 150
9727#extension GL_ARB_conservative_depth : enable
9728#define VERTEX_SHADER
9729#define DEBUG_NORMAL
9730#if defined(VERTEX_SHADER)
9731out float FragDistance;
9732#elif defined(FRAGMENT_SHADER)
9733in float FragDistance;
9734#endif
9735uniform vec4 uFogColor;
9736uniform vec2 uFogRange;
9737
9738float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
9739 float distXZ = length(worldPos.xz - cameraPos.xz);
9740 float distY = abs(worldPos.y - cameraPos.y);
9741 return max(distXZ, distY);
9742}
9743
9744float cylindrical_distance(vec3 worldPos) {
9745 float distXZ = length(worldPos.xz);
9746 float distY = abs(worldPos.y);
9747 return max(distXZ, distY);
9748}
9749
9750float FLWFogFactor() {
9751 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
9752}
9753// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
9754vec2 shiftLight(vec2 lm) {
9755 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
9756}
9757
9758
9759uniform float uTime;
9760uniform mat4 uViewProjection;
9761uniform vec3 uCameraPos;
9762
9763uniform vec2 uTextureScale;
9764uniform sampler2D uBlockAtlas;
9765uniform sampler2D uLightMap;
9766
9767uniform vec2 uWindowSize;
9768
9769void FLWFinalizeNormal(inout vec3 normal) {
9770 // noop
9771}
9772
9773#if defined(VERTEX_SHADER)
9774void FLWFinalizeWorldPos(inout vec4 worldPos) {
9775 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
9776
9777 gl_Position = uViewProjection * worldPos;
9778}
9779
9780#elif defined(FRAGMENT_SHADER)
9781
9782
9783#define ALPHA_DISCARD 0.1
9784// optimize discard usage
9785#if defined(ALPHA_DISCARD)
9786#if defined(GL_ARB_conservative_depth)
9787layout (depth_greater) out float gl_FragDepth;
9788#endif
9789#endif
9790out vec4 fragColor;
9791
9792vec4 FLWBlockTexture(vec2 texCoords) {
9793 return texture(uBlockAtlas, texCoords);
9794}
9795
9796void FLWFinalizeColor(vec4 color) {
9797 float a = color.a;
9798 float fog = clamp(FLWFogFactor(), 0., 1.);
9799
9800 color = mix(uFogColor, color, fog);
9801 color.a = a;
9802
9803 #if defined(ALPHA_DISCARD)
9804 if (color.a < ALPHA_DISCARD) {
9805 discard;
9806 }
9807 #endif
9808
9809 fragColor = color;
9810}
9811
9812vec4 FLWLight(vec2 lightCoords) {
9813 return texture(uLightMap, shiftLight(lightCoords));
9814}
9815#endif
9816
9817
9818mat4 rotate(vec3 axis, float angle) {
9819 float s = sin(angle);
9820 float c = cos(angle);
9821 float oc = 1. - c;
9822
9823 vec3 sa = axis * s;
9824
9825 mat4 mr = mat4(1.);
9826 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
9827 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
9828 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
9829
9830 return mr;
9831}
9832
9833mat4 rotation(vec3 rot) {
9834 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
9835}
9836
9837mat3 modelToNormal(mat4 mat) {
9838 // Discard the edges. This won't be accurate for scaled or skewed matrices,
9839 // but we don't have to work with those often.
9840 mat3 m;
9841 m[0] = mat[0].xyz;
9842 m[1] = mat[1].xyz;
9843 m[2] = mat[2].xyz;
9844 return m;
9845}
9846
9847#define PIOVER2 1.5707963268
9848
9849vec4 quat(vec3 axis, float angle) {
9850 float halfAngle = angle * PIOVER2 / 180.0;
9851 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
9852 return vec4(axis.xyz * cs.y, cs.x);
9853}
9854
9855vec4 quatMult(vec4 q1, vec4 q2) {
9856 // disgustingly vectorized quaternion multiplication
9857 vec4 a = q1.w * q2.xyzw;
9858 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
9859 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
9860 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
9861
9862 return a + b + c + d;
9863}
9864
9865vec3 rotateVertexByQuat(vec3 v, vec4 q) {
9866 vec3 i = q.xyz;
9867 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
9868}
9869
9870vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
9871 return rotateVertexByQuat(v, quat(axis, angle));
9872}
9873
9874float diffuse(vec3 normal) {
9875 vec3 n2 = normal * normal * vec3(.6, .25, .8);
9876 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
9877}
9878struct Vertex {
9879 vec3 pos;
9880 vec2 texCoords;
9881 vec3 normal;
9882};
9883
9884struct BlockFrag {
9885 vec2 texCoords;
9886 vec4 color;
9887 float diffuse;
9888 vec2 light;
9889};
9890
9891#if defined(FRAGMENT_SHADER)
9892void fragment(BlockFrag r) {
9893 vec4 tex = FLWBlockTexture(r.texCoords);
9894
9895 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
9896
9897 FLWFinalizeColor(color);
9898}
9899#endif
9900#define PI 3.1415926538
9901
9902
9903
9904
9905
9906struct Actor {
9907 vec3 pos;
9908 vec2 light;
9909 float offset;
9910 vec3 axis;
9911 vec4 rotation;
9912 vec3 rotationCenter;
9913 float speed;
9914};
9915
9916
9917
9918
9919#if defined(VERTEX_SHADER)
9920BlockFrag vertex(Vertex v, Actor instance) {
9921 float degrees = instance.offset + uTime * instance.speed / 20.;
9922 //float angle = fract(degrees / 360.) * PI * 2.;
9923
9924 vec4 kineticRot = quat(instance.axis, degrees);
9925 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
9926
9927 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
9928 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
9929
9930 FLWFinalizeWorldPos(worldPos);
9931 FLWFinalizeNormal(norm);
9932
9933 BlockFrag b;
9934 b.diffuse = diffuse(norm);
9935 b.texCoords = v.texCoords;
9936 b.light = instance.light;
9937
9938 #if defined(DEBUG_NORMAL)
9939 b.color = vec4(norm, 1.);
9940 #else
9941 b.color = vec4(1.);
9942 #endif
9943
9944 return b;
9945}
9946#endif
9947
9948in vec3 a_v_pos;
9949in vec2 a_v_texCoords;
9950in vec3 a_v_normal;
9951in vec3 a_i_pos;
9952in vec2 a_i_light;
9953in float a_i_offset;
9954in vec3 a_i_axis;
9955in vec4 a_i_rotation;
9956in vec3 a_i_rotationCenter;
9957in float a_i_speed;
9958out vec2 v2f_texCoords;
9959out vec4 v2f_color;
9960out float v2f_diffuse;
9961out vec2 v2f_light;
9962void main() {
9963Vertex v;
9964v.pos = a_v_pos;
9965v.texCoords = a_v_texCoords;
9966v.normal = a_v_normal;
9967Actor i;
9968i.pos = a_i_pos;
9969i.light = a_i_light;
9970i.offset = a_i_offset;
9971i.axis = a_i_axis;
9972i.rotation = a_i_rotation;
9973i.rotationCenter = a_i_rotationCenter;
9974i.speed = a_i_speed;
9975BlockFrag o = vertex(v, i);
9976v2f_texCoords = o.texCoords;
9977v2f_color = o.color;
9978v2f_diffuse = o.diffuse;
9979v2f_light = o.light;
9980}
9981[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
9982
9983[17:17:49] [Render thread/ERROR]: #version 150
9984#extension GL_ARB_conservative_depth : enable
9985#define FRAGMENT_SHADER
9986#define DEBUG_NORMAL
9987#if defined(VERTEX_SHADER)
9988out float FragDistance;
9989#elif defined(FRAGMENT_SHADER)
9990in float FragDistance;
9991#endif
9992uniform vec4 uFogColor;
9993uniform vec2 uFogRange;
9994
9995float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
9996 float distXZ = length(worldPos.xz - cameraPos.xz);
9997 float distY = abs(worldPos.y - cameraPos.y);
9998 return max(distXZ, distY);
9999}
10000
10001float cylindrical_distance(vec3 worldPos) {
10002 float distXZ = length(worldPos.xz);
10003 float distY = abs(worldPos.y);
10004 return max(distXZ, distY);
10005}
10006
10007float FLWFogFactor() {
10008 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
10009}
10010// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
10011vec2 shiftLight(vec2 lm) {
10012 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
10013}
10014
10015
10016uniform float uTime;
10017uniform mat4 uViewProjection;
10018uniform vec3 uCameraPos;
10019
10020uniform vec2 uTextureScale;
10021uniform sampler2D uBlockAtlas;
10022uniform sampler2D uLightMap;
10023
10024uniform vec2 uWindowSize;
10025
10026void FLWFinalizeNormal(inout vec3 normal) {
10027 // noop
10028}
10029
10030#if defined(VERTEX_SHADER)
10031void FLWFinalizeWorldPos(inout vec4 worldPos) {
10032 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
10033
10034 gl_Position = uViewProjection * worldPos;
10035}
10036
10037#elif defined(FRAGMENT_SHADER)
10038
10039
10040#define ALPHA_DISCARD 0.1
10041// optimize discard usage
10042#if defined(ALPHA_DISCARD)
10043#if defined(GL_ARB_conservative_depth)
10044layout (depth_greater) out float gl_FragDepth;
10045#endif
10046#endif
10047out vec4 fragColor;
10048
10049vec4 FLWBlockTexture(vec2 texCoords) {
10050 return texture(uBlockAtlas, texCoords);
10051}
10052
10053void FLWFinalizeColor(vec4 color) {
10054 float a = color.a;
10055 float fog = clamp(FLWFogFactor(), 0., 1.);
10056
10057 color = mix(uFogColor, color, fog);
10058 color.a = a;
10059
10060 #if defined(ALPHA_DISCARD)
10061 if (color.a < ALPHA_DISCARD) {
10062 discard;
10063 }
10064 #endif
10065
10066 fragColor = color;
10067}
10068
10069vec4 FLWLight(vec2 lightCoords) {
10070 return texture(uLightMap, shiftLight(lightCoords));
10071}
10072#endif
10073
10074
10075mat4 rotate(vec3 axis, float angle) {
10076 float s = sin(angle);
10077 float c = cos(angle);
10078 float oc = 1. - c;
10079
10080 vec3 sa = axis * s;
10081
10082 mat4 mr = mat4(1.);
10083 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
10084 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
10085 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
10086
10087 return mr;
10088}
10089
10090mat4 rotation(vec3 rot) {
10091 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
10092}
10093
10094mat3 modelToNormal(mat4 mat) {
10095 // Discard the edges. This won't be accurate for scaled or skewed matrices,
10096 // but we don't have to work with those often.
10097 mat3 m;
10098 m[0] = mat[0].xyz;
10099 m[1] = mat[1].xyz;
10100 m[2] = mat[2].xyz;
10101 return m;
10102}
10103
10104#define PIOVER2 1.5707963268
10105
10106vec4 quat(vec3 axis, float angle) {
10107 float halfAngle = angle * PIOVER2 / 180.0;
10108 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
10109 return vec4(axis.xyz * cs.y, cs.x);
10110}
10111
10112vec4 quatMult(vec4 q1, vec4 q2) {
10113 // disgustingly vectorized quaternion multiplication
10114 vec4 a = q1.w * q2.xyzw;
10115 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
10116 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
10117 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
10118
10119 return a + b + c + d;
10120}
10121
10122vec3 rotateVertexByQuat(vec3 v, vec4 q) {
10123 vec3 i = q.xyz;
10124 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
10125}
10126
10127vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
10128 return rotateVertexByQuat(v, quat(axis, angle));
10129}
10130
10131float diffuse(vec3 normal) {
10132 vec3 n2 = normal * normal * vec3(.6, .25, .8);
10133 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
10134}
10135struct Vertex {
10136 vec3 pos;
10137 vec2 texCoords;
10138 vec3 normal;
10139};
10140
10141struct BlockFrag {
10142 vec2 texCoords;
10143 vec4 color;
10144 float diffuse;
10145 vec2 light;
10146};
10147
10148#if defined(FRAGMENT_SHADER)
10149void fragment(BlockFrag r) {
10150 vec4 tex = FLWBlockTexture(r.texCoords);
10151
10152 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
10153
10154 FLWFinalizeColor(color);
10155}
10156#endif
10157#define PI 3.1415926538
10158
10159
10160
10161
10162
10163struct Actor {
10164 vec3 pos;
10165 vec2 light;
10166 float offset;
10167 vec3 axis;
10168 vec4 rotation;
10169 vec3 rotationCenter;
10170 float speed;
10171};
10172
10173
10174
10175
10176#if defined(VERTEX_SHADER)
10177BlockFrag vertex(Vertex v, Actor instance) {
10178 float degrees = instance.offset + uTime * instance.speed / 20.;
10179 //float angle = fract(degrees / 360.) * PI * 2.;
10180
10181 vec4 kineticRot = quat(instance.axis, degrees);
10182 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
10183
10184 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
10185 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
10186
10187 FLWFinalizeWorldPos(worldPos);
10188 FLWFinalizeNormal(norm);
10189
10190 BlockFrag b;
10191 b.diffuse = diffuse(norm);
10192 b.texCoords = v.texCoords;
10193 b.light = instance.light;
10194
10195 #if defined(DEBUG_NORMAL)
10196 b.color = vec4(norm, 1.);
10197 #else
10198 b.color = vec4(1.);
10199 #endif
10200
10201 return b;
10202}
10203#endif
10204
10205in vec2 v2f_texCoords;
10206in vec4 v2f_color;
10207in float v2f_diffuse;
10208in vec2 v2f_light;
10209void main() {
10210BlockFrag o;
10211o.texCoords = v2f_texCoords;
10212o.color = v2f_color;
10213o.diffuse = v2f_diffuse;
10214o.light = v2f_light;
10215fragment(o);
10216}
10217[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
10218
10219[17:17:49] [Render thread/ERROR]: #version 150
10220#extension GL_ARB_conservative_depth : enable
10221#define VERTEX_SHADER
10222#if defined(VERTEX_SHADER)
10223out float FragDistance;
10224#elif defined(FRAGMENT_SHADER)
10225in float FragDistance;
10226#endif
10227uniform vec4 uFogColor;
10228uniform vec2 uFogRange;
10229
10230float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
10231 float distXZ = length(worldPos.xz - cameraPos.xz);
10232 float distY = abs(worldPos.y - cameraPos.y);
10233 return max(distXZ, distY);
10234}
10235
10236float cylindrical_distance(vec3 worldPos) {
10237 float distXZ = length(worldPos.xz);
10238 float distY = abs(worldPos.y);
10239 return max(distXZ, distY);
10240}
10241
10242float FLWFogFactor() {
10243 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
10244}
10245// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
10246vec2 shiftLight(vec2 lm) {
10247 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
10248}
10249
10250
10251uniform float uTime;
10252uniform mat4 uViewProjection;
10253uniform vec3 uCameraPos;
10254
10255uniform vec2 uTextureScale;
10256uniform sampler2D uBlockAtlas;
10257uniform sampler2D uLightMap;
10258
10259uniform vec2 uWindowSize;
10260
10261void FLWFinalizeNormal(inout vec3 normal) {
10262 // noop
10263}
10264
10265#if defined(VERTEX_SHADER)
10266void FLWFinalizeWorldPos(inout vec4 worldPos) {
10267 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
10268
10269 gl_Position = uViewProjection * worldPos;
10270}
10271
10272#elif defined(FRAGMENT_SHADER)
10273
10274
10275#define ALPHA_DISCARD 0.1
10276// optimize discard usage
10277#if defined(ALPHA_DISCARD)
10278#if defined(GL_ARB_conservative_depth)
10279layout (depth_greater) out float gl_FragDepth;
10280#endif
10281#endif
10282out vec4 fragColor;
10283
10284vec4 FLWBlockTexture(vec2 texCoords) {
10285 return texture(uBlockAtlas, texCoords);
10286}
10287
10288void FLWFinalizeColor(vec4 color) {
10289 float a = color.a;
10290 float fog = clamp(FLWFogFactor(), 0., 1.);
10291
10292 color = mix(uFogColor, color, fog);
10293 color.a = a;
10294
10295 #if defined(ALPHA_DISCARD)
10296 if (color.a < ALPHA_DISCARD) {
10297 discard;
10298 }
10299 #endif
10300
10301 fragColor = color;
10302}
10303
10304vec4 FLWLight(vec2 lightCoords) {
10305 return texture(uLightMap, shiftLight(lightCoords));
10306}
10307#endif
10308
10309
10310mat4 rotate(vec3 axis, float angle) {
10311 float s = sin(angle);
10312 float c = cos(angle);
10313 float oc = 1. - c;
10314
10315 vec3 sa = axis * s;
10316
10317 mat4 mr = mat4(1.);
10318 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
10319 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
10320 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
10321
10322 return mr;
10323}
10324
10325mat4 rotation(vec3 rot) {
10326 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
10327}
10328
10329mat3 modelToNormal(mat4 mat) {
10330 // Discard the edges. This won't be accurate for scaled or skewed matrices,
10331 // but we don't have to work with those often.
10332 mat3 m;
10333 m[0] = mat[0].xyz;
10334 m[1] = mat[1].xyz;
10335 m[2] = mat[2].xyz;
10336 return m;
10337}
10338
10339#define PIOVER2 1.5707963268
10340
10341vec4 quat(vec3 axis, float angle) {
10342 float halfAngle = angle * PIOVER2 / 180.0;
10343 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
10344 return vec4(axis.xyz * cs.y, cs.x);
10345}
10346
10347vec4 quatMult(vec4 q1, vec4 q2) {
10348 // disgustingly vectorized quaternion multiplication
10349 vec4 a = q1.w * q2.xyzw;
10350 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
10351 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
10352 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
10353
10354 return a + b + c + d;
10355}
10356
10357vec3 rotateVertexByQuat(vec3 v, vec4 q) {
10358 vec3 i = q.xyz;
10359 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
10360}
10361
10362vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
10363 return rotateVertexByQuat(v, quat(axis, angle));
10364}
10365
10366float diffuse(vec3 normal) {
10367 vec3 n2 = normal * normal * vec3(.6, .25, .8);
10368 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
10369}
10370struct Vertex {
10371 vec3 pos;
10372 vec2 texCoords;
10373 vec3 normal;
10374};
10375
10376struct BlockFrag {
10377 vec2 texCoords;
10378 vec4 color;
10379 float diffuse;
10380 vec2 light;
10381};
10382
10383#if defined(FRAGMENT_SHADER)
10384void fragment(BlockFrag r) {
10385 vec4 tex = FLWBlockTexture(r.texCoords);
10386
10387 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
10388
10389 FLWFinalizeColor(color);
10390}
10391#endif
10392#define PI 3.1415926538
10393
10394
10395
10396
10397
10398struct Flap {
10399 vec3 instancePos;
10400 vec2 light;
10401 vec3 segmentOffset;
10402 vec3 pivot;
10403 float horizontalAngle;
10404 float intensity;
10405 float flapScale;
10406 float flapness;
10407};
10408
10409
10410
10411
10412#if defined(VERTEX_SHADER)
10413
10414float toRad(float degrees) {
10415 return fract(degrees / 360.) * PI * 2.;
10416}
10417
10418float getFlapAngle(float flapness, float intensity, float scale) {
10419 float absFlap = abs(flapness);
10420
10421 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
10422
10423 float halfAngle = angle * 0.5;
10424
10425 float which = step(0., flapness); // 0 if negative, 1 if positive
10426 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
10427
10428 return degrees;
10429}
10430
10431BlockFrag vertex(Vertex v, Flap flap) {
10432 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
10433
10434 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
10435 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
10436
10437 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
10438 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
10439
10440 vec4 worldPos = vec4(rotated, 1.);
10441 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
10442
10443 FLWFinalizeWorldPos(worldPos);
10444 FLWFinalizeNormal(norm);
10445
10446 BlockFrag b;
10447 b.diffuse = diffuse(norm);
10448 b.texCoords = v.texCoords;
10449 b.light = flap.light;
10450 #if defined(DEBUG_NORMAL)
10451 b.color = vec4(norm, 1.);
10452 #else
10453 b.color = vec4(1.);
10454 #endif
10455 return b;
10456}
10457#endif
10458
10459in vec3 a_v_pos;
10460in vec2 a_v_texCoords;
10461in vec3 a_v_normal;
10462in vec3 a_i_instancePos;
10463in vec2 a_i_light;
10464in vec3 a_i_segmentOffset;
10465in vec3 a_i_pivot;
10466in float a_i_horizontalAngle;
10467in float a_i_intensity;
10468in float a_i_flapScale;
10469in float a_i_flapness;
10470out vec2 v2f_texCoords;
10471out vec4 v2f_color;
10472out float v2f_diffuse;
10473out vec2 v2f_light;
10474void main() {
10475Vertex v;
10476v.pos = a_v_pos;
10477v.texCoords = a_v_texCoords;
10478v.normal = a_v_normal;
10479Flap i;
10480i.instancePos = a_i_instancePos;
10481i.light = a_i_light;
10482i.segmentOffset = a_i_segmentOffset;
10483i.pivot = a_i_pivot;
10484i.horizontalAngle = a_i_horizontalAngle;
10485i.intensity = a_i_intensity;
10486i.flapScale = a_i_flapScale;
10487i.flapness = a_i_flapness;
10488BlockFrag o = vertex(v, i);
10489v2f_texCoords = o.texCoords;
10490v2f_color = o.color;
10491v2f_diffuse = o.diffuse;
10492v2f_light = o.light;
10493}
10494[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
10495
10496[17:17:49] [Render thread/ERROR]: #version 150
10497#extension GL_ARB_conservative_depth : enable
10498#define FRAGMENT_SHADER
10499#if defined(VERTEX_SHADER)
10500out float FragDistance;
10501#elif defined(FRAGMENT_SHADER)
10502in float FragDistance;
10503#endif
10504uniform vec4 uFogColor;
10505uniform vec2 uFogRange;
10506
10507float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
10508 float distXZ = length(worldPos.xz - cameraPos.xz);
10509 float distY = abs(worldPos.y - cameraPos.y);
10510 return max(distXZ, distY);
10511}
10512
10513float cylindrical_distance(vec3 worldPos) {
10514 float distXZ = length(worldPos.xz);
10515 float distY = abs(worldPos.y);
10516 return max(distXZ, distY);
10517}
10518
10519float FLWFogFactor() {
10520 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
10521}
10522// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
10523vec2 shiftLight(vec2 lm) {
10524 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
10525}
10526
10527
10528uniform float uTime;
10529uniform mat4 uViewProjection;
10530uniform vec3 uCameraPos;
10531
10532uniform vec2 uTextureScale;
10533uniform sampler2D uBlockAtlas;
10534uniform sampler2D uLightMap;
10535
10536uniform vec2 uWindowSize;
10537
10538void FLWFinalizeNormal(inout vec3 normal) {
10539 // noop
10540}
10541
10542#if defined(VERTEX_SHADER)
10543void FLWFinalizeWorldPos(inout vec4 worldPos) {
10544 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
10545
10546 gl_Position = uViewProjection * worldPos;
10547}
10548
10549#elif defined(FRAGMENT_SHADER)
10550
10551
10552#define ALPHA_DISCARD 0.1
10553// optimize discard usage
10554#if defined(ALPHA_DISCARD)
10555#if defined(GL_ARB_conservative_depth)
10556layout (depth_greater) out float gl_FragDepth;
10557#endif
10558#endif
10559out vec4 fragColor;
10560
10561vec4 FLWBlockTexture(vec2 texCoords) {
10562 return texture(uBlockAtlas, texCoords);
10563}
10564
10565void FLWFinalizeColor(vec4 color) {
10566 float a = color.a;
10567 float fog = clamp(FLWFogFactor(), 0., 1.);
10568
10569 color = mix(uFogColor, color, fog);
10570 color.a = a;
10571
10572 #if defined(ALPHA_DISCARD)
10573 if (color.a < ALPHA_DISCARD) {
10574 discard;
10575 }
10576 #endif
10577
10578 fragColor = color;
10579}
10580
10581vec4 FLWLight(vec2 lightCoords) {
10582 return texture(uLightMap, shiftLight(lightCoords));
10583}
10584#endif
10585
10586
10587mat4 rotate(vec3 axis, float angle) {
10588 float s = sin(angle);
10589 float c = cos(angle);
10590 float oc = 1. - c;
10591
10592 vec3 sa = axis * s;
10593
10594 mat4 mr = mat4(1.);
10595 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
10596 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
10597 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
10598
10599 return mr;
10600}
10601
10602mat4 rotation(vec3 rot) {
10603 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
10604}
10605
10606mat3 modelToNormal(mat4 mat) {
10607 // Discard the edges. This won't be accurate for scaled or skewed matrices,
10608 // but we don't have to work with those often.
10609 mat3 m;
10610 m[0] = mat[0].xyz;
10611 m[1] = mat[1].xyz;
10612 m[2] = mat[2].xyz;
10613 return m;
10614}
10615
10616#define PIOVER2 1.5707963268
10617
10618vec4 quat(vec3 axis, float angle) {
10619 float halfAngle = angle * PIOVER2 / 180.0;
10620 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
10621 return vec4(axis.xyz * cs.y, cs.x);
10622}
10623
10624vec4 quatMult(vec4 q1, vec4 q2) {
10625 // disgustingly vectorized quaternion multiplication
10626 vec4 a = q1.w * q2.xyzw;
10627 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
10628 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
10629 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
10630
10631 return a + b + c + d;
10632}
10633
10634vec3 rotateVertexByQuat(vec3 v, vec4 q) {
10635 vec3 i = q.xyz;
10636 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
10637}
10638
10639vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
10640 return rotateVertexByQuat(v, quat(axis, angle));
10641}
10642
10643float diffuse(vec3 normal) {
10644 vec3 n2 = normal * normal * vec3(.6, .25, .8);
10645 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
10646}
10647struct Vertex {
10648 vec3 pos;
10649 vec2 texCoords;
10650 vec3 normal;
10651};
10652
10653struct BlockFrag {
10654 vec2 texCoords;
10655 vec4 color;
10656 float diffuse;
10657 vec2 light;
10658};
10659
10660#if defined(FRAGMENT_SHADER)
10661void fragment(BlockFrag r) {
10662 vec4 tex = FLWBlockTexture(r.texCoords);
10663
10664 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
10665
10666 FLWFinalizeColor(color);
10667}
10668#endif
10669#define PI 3.1415926538
10670
10671
10672
10673
10674
10675struct Flap {
10676 vec3 instancePos;
10677 vec2 light;
10678 vec3 segmentOffset;
10679 vec3 pivot;
10680 float horizontalAngle;
10681 float intensity;
10682 float flapScale;
10683 float flapness;
10684};
10685
10686
10687
10688
10689#if defined(VERTEX_SHADER)
10690
10691float toRad(float degrees) {
10692 return fract(degrees / 360.) * PI * 2.;
10693}
10694
10695float getFlapAngle(float flapness, float intensity, float scale) {
10696 float absFlap = abs(flapness);
10697
10698 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
10699
10700 float halfAngle = angle * 0.5;
10701
10702 float which = step(0., flapness); // 0 if negative, 1 if positive
10703 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
10704
10705 return degrees;
10706}
10707
10708BlockFrag vertex(Vertex v, Flap flap) {
10709 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
10710
10711 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
10712 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
10713
10714 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
10715 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
10716
10717 vec4 worldPos = vec4(rotated, 1.);
10718 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
10719
10720 FLWFinalizeWorldPos(worldPos);
10721 FLWFinalizeNormal(norm);
10722
10723 BlockFrag b;
10724 b.diffuse = diffuse(norm);
10725 b.texCoords = v.texCoords;
10726 b.light = flap.light;
10727 #if defined(DEBUG_NORMAL)
10728 b.color = vec4(norm, 1.);
10729 #else
10730 b.color = vec4(1.);
10731 #endif
10732 return b;
10733}
10734#endif
10735
10736in vec2 v2f_texCoords;
10737in vec4 v2f_color;
10738in float v2f_diffuse;
10739in vec2 v2f_light;
10740void main() {
10741BlockFrag o;
10742o.texCoords = v2f_texCoords;
10743o.color = v2f_color;
10744o.diffuse = v2f_diffuse;
10745o.light = v2f_light;
10746fragment(o);
10747}
10748[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
10749
10750[17:17:49] [Render thread/ERROR]: #version 150
10751#extension GL_ARB_conservative_depth : enable
10752#define VERTEX_SHADER
10753#define DEBUG_NORMAL
10754#if defined(VERTEX_SHADER)
10755out float FragDistance;
10756#elif defined(FRAGMENT_SHADER)
10757in float FragDistance;
10758#endif
10759uniform vec4 uFogColor;
10760uniform vec2 uFogRange;
10761
10762float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
10763 float distXZ = length(worldPos.xz - cameraPos.xz);
10764 float distY = abs(worldPos.y - cameraPos.y);
10765 return max(distXZ, distY);
10766}
10767
10768float cylindrical_distance(vec3 worldPos) {
10769 float distXZ = length(worldPos.xz);
10770 float distY = abs(worldPos.y);
10771 return max(distXZ, distY);
10772}
10773
10774float FLWFogFactor() {
10775 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
10776}
10777// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
10778vec2 shiftLight(vec2 lm) {
10779 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
10780}
10781
10782
10783uniform float uTime;
10784uniform mat4 uViewProjection;
10785uniform vec3 uCameraPos;
10786
10787uniform vec2 uTextureScale;
10788uniform sampler2D uBlockAtlas;
10789uniform sampler2D uLightMap;
10790
10791uniform vec2 uWindowSize;
10792
10793void FLWFinalizeNormal(inout vec3 normal) {
10794 // noop
10795}
10796
10797#if defined(VERTEX_SHADER)
10798void FLWFinalizeWorldPos(inout vec4 worldPos) {
10799 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
10800
10801 gl_Position = uViewProjection * worldPos;
10802}
10803
10804#elif defined(FRAGMENT_SHADER)
10805
10806
10807#define ALPHA_DISCARD 0.1
10808// optimize discard usage
10809#if defined(ALPHA_DISCARD)
10810#if defined(GL_ARB_conservative_depth)
10811layout (depth_greater) out float gl_FragDepth;
10812#endif
10813#endif
10814out vec4 fragColor;
10815
10816vec4 FLWBlockTexture(vec2 texCoords) {
10817 return texture(uBlockAtlas, texCoords);
10818}
10819
10820void FLWFinalizeColor(vec4 color) {
10821 float a = color.a;
10822 float fog = clamp(FLWFogFactor(), 0., 1.);
10823
10824 color = mix(uFogColor, color, fog);
10825 color.a = a;
10826
10827 #if defined(ALPHA_DISCARD)
10828 if (color.a < ALPHA_DISCARD) {
10829 discard;
10830 }
10831 #endif
10832
10833 fragColor = color;
10834}
10835
10836vec4 FLWLight(vec2 lightCoords) {
10837 return texture(uLightMap, shiftLight(lightCoords));
10838}
10839#endif
10840
10841
10842mat4 rotate(vec3 axis, float angle) {
10843 float s = sin(angle);
10844 float c = cos(angle);
10845 float oc = 1. - c;
10846
10847 vec3 sa = axis * s;
10848
10849 mat4 mr = mat4(1.);
10850 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
10851 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
10852 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
10853
10854 return mr;
10855}
10856
10857mat4 rotation(vec3 rot) {
10858 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
10859}
10860
10861mat3 modelToNormal(mat4 mat) {
10862 // Discard the edges. This won't be accurate for scaled or skewed matrices,
10863 // but we don't have to work with those often.
10864 mat3 m;
10865 m[0] = mat[0].xyz;
10866 m[1] = mat[1].xyz;
10867 m[2] = mat[2].xyz;
10868 return m;
10869}
10870
10871#define PIOVER2 1.5707963268
10872
10873vec4 quat(vec3 axis, float angle) {
10874 float halfAngle = angle * PIOVER2 / 180.0;
10875 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
10876 return vec4(axis.xyz * cs.y, cs.x);
10877}
10878
10879vec4 quatMult(vec4 q1, vec4 q2) {
10880 // disgustingly vectorized quaternion multiplication
10881 vec4 a = q1.w * q2.xyzw;
10882 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
10883 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
10884 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
10885
10886 return a + b + c + d;
10887}
10888
10889vec3 rotateVertexByQuat(vec3 v, vec4 q) {
10890 vec3 i = q.xyz;
10891 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
10892}
10893
10894vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
10895 return rotateVertexByQuat(v, quat(axis, angle));
10896}
10897
10898float diffuse(vec3 normal) {
10899 vec3 n2 = normal * normal * vec3(.6, .25, .8);
10900 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
10901}
10902struct Vertex {
10903 vec3 pos;
10904 vec2 texCoords;
10905 vec3 normal;
10906};
10907
10908struct BlockFrag {
10909 vec2 texCoords;
10910 vec4 color;
10911 float diffuse;
10912 vec2 light;
10913};
10914
10915#if defined(FRAGMENT_SHADER)
10916void fragment(BlockFrag r) {
10917 vec4 tex = FLWBlockTexture(r.texCoords);
10918
10919 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
10920
10921 FLWFinalizeColor(color);
10922}
10923#endif
10924#define PI 3.1415926538
10925
10926
10927
10928
10929
10930struct Flap {
10931 vec3 instancePos;
10932 vec2 light;
10933 vec3 segmentOffset;
10934 vec3 pivot;
10935 float horizontalAngle;
10936 float intensity;
10937 float flapScale;
10938 float flapness;
10939};
10940
10941
10942
10943
10944#if defined(VERTEX_SHADER)
10945
10946float toRad(float degrees) {
10947 return fract(degrees / 360.) * PI * 2.;
10948}
10949
10950float getFlapAngle(float flapness, float intensity, float scale) {
10951 float absFlap = abs(flapness);
10952
10953 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
10954
10955 float halfAngle = angle * 0.5;
10956
10957 float which = step(0., flapness); // 0 if negative, 1 if positive
10958 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
10959
10960 return degrees;
10961}
10962
10963BlockFrag vertex(Vertex v, Flap flap) {
10964 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
10965
10966 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
10967 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
10968
10969 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
10970 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
10971
10972 vec4 worldPos = vec4(rotated, 1.);
10973 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
10974
10975 FLWFinalizeWorldPos(worldPos);
10976 FLWFinalizeNormal(norm);
10977
10978 BlockFrag b;
10979 b.diffuse = diffuse(norm);
10980 b.texCoords = v.texCoords;
10981 b.light = flap.light;
10982 #if defined(DEBUG_NORMAL)
10983 b.color = vec4(norm, 1.);
10984 #else
10985 b.color = vec4(1.);
10986 #endif
10987 return b;
10988}
10989#endif
10990
10991in vec3 a_v_pos;
10992in vec2 a_v_texCoords;
10993in vec3 a_v_normal;
10994in vec3 a_i_instancePos;
10995in vec2 a_i_light;
10996in vec3 a_i_segmentOffset;
10997in vec3 a_i_pivot;
10998in float a_i_horizontalAngle;
10999in float a_i_intensity;
11000in float a_i_flapScale;
11001in float a_i_flapness;
11002out vec2 v2f_texCoords;
11003out vec4 v2f_color;
11004out float v2f_diffuse;
11005out vec2 v2f_light;
11006void main() {
11007Vertex v;
11008v.pos = a_v_pos;
11009v.texCoords = a_v_texCoords;
11010v.normal = a_v_normal;
11011Flap i;
11012i.instancePos = a_i_instancePos;
11013i.light = a_i_light;
11014i.segmentOffset = a_i_segmentOffset;
11015i.pivot = a_i_pivot;
11016i.horizontalAngle = a_i_horizontalAngle;
11017i.intensity = a_i_intensity;
11018i.flapScale = a_i_flapScale;
11019i.flapness = a_i_flapness;
11020BlockFrag o = vertex(v, i);
11021v2f_texCoords = o.texCoords;
11022v2f_color = o.color;
11023v2f_diffuse = o.diffuse;
11024v2f_light = o.light;
11025}
11026[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
11027
11028[17:17:49] [Render thread/ERROR]: #version 150
11029#extension GL_ARB_conservative_depth : enable
11030#define FRAGMENT_SHADER
11031#define DEBUG_NORMAL
11032#if defined(VERTEX_SHADER)
11033out float FragDistance;
11034#elif defined(FRAGMENT_SHADER)
11035in float FragDistance;
11036#endif
11037uniform vec4 uFogColor;
11038uniform vec2 uFogRange;
11039
11040float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
11041 float distXZ = length(worldPos.xz - cameraPos.xz);
11042 float distY = abs(worldPos.y - cameraPos.y);
11043 return max(distXZ, distY);
11044}
11045
11046float cylindrical_distance(vec3 worldPos) {
11047 float distXZ = length(worldPos.xz);
11048 float distY = abs(worldPos.y);
11049 return max(distXZ, distY);
11050}
11051
11052float FLWFogFactor() {
11053 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
11054}
11055// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
11056vec2 shiftLight(vec2 lm) {
11057 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
11058}
11059
11060
11061uniform float uTime;
11062uniform mat4 uViewProjection;
11063uniform vec3 uCameraPos;
11064
11065uniform vec2 uTextureScale;
11066uniform sampler2D uBlockAtlas;
11067uniform sampler2D uLightMap;
11068
11069uniform vec2 uWindowSize;
11070
11071void FLWFinalizeNormal(inout vec3 normal) {
11072 // noop
11073}
11074
11075#if defined(VERTEX_SHADER)
11076void FLWFinalizeWorldPos(inout vec4 worldPos) {
11077 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
11078
11079 gl_Position = uViewProjection * worldPos;
11080}
11081
11082#elif defined(FRAGMENT_SHADER)
11083
11084
11085#define ALPHA_DISCARD 0.1
11086// optimize discard usage
11087#if defined(ALPHA_DISCARD)
11088#if defined(GL_ARB_conservative_depth)
11089layout (depth_greater) out float gl_FragDepth;
11090#endif
11091#endif
11092out vec4 fragColor;
11093
11094vec4 FLWBlockTexture(vec2 texCoords) {
11095 return texture(uBlockAtlas, texCoords);
11096}
11097
11098void FLWFinalizeColor(vec4 color) {
11099 float a = color.a;
11100 float fog = clamp(FLWFogFactor(), 0., 1.);
11101
11102 color = mix(uFogColor, color, fog);
11103 color.a = a;
11104
11105 #if defined(ALPHA_DISCARD)
11106 if (color.a < ALPHA_DISCARD) {
11107 discard;
11108 }
11109 #endif
11110
11111 fragColor = color;
11112}
11113
11114vec4 FLWLight(vec2 lightCoords) {
11115 return texture(uLightMap, shiftLight(lightCoords));
11116}
11117#endif
11118
11119
11120mat4 rotate(vec3 axis, float angle) {
11121 float s = sin(angle);
11122 float c = cos(angle);
11123 float oc = 1. - c;
11124
11125 vec3 sa = axis * s;
11126
11127 mat4 mr = mat4(1.);
11128 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
11129 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
11130 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
11131
11132 return mr;
11133}
11134
11135mat4 rotation(vec3 rot) {
11136 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
11137}
11138
11139mat3 modelToNormal(mat4 mat) {
11140 // Discard the edges. This won't be accurate for scaled or skewed matrices,
11141 // but we don't have to work with those often.
11142 mat3 m;
11143 m[0] = mat[0].xyz;
11144 m[1] = mat[1].xyz;
11145 m[2] = mat[2].xyz;
11146 return m;
11147}
11148
11149#define PIOVER2 1.5707963268
11150
11151vec4 quat(vec3 axis, float angle) {
11152 float halfAngle = angle * PIOVER2 / 180.0;
11153 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
11154 return vec4(axis.xyz * cs.y, cs.x);
11155}
11156
11157vec4 quatMult(vec4 q1, vec4 q2) {
11158 // disgustingly vectorized quaternion multiplication
11159 vec4 a = q1.w * q2.xyzw;
11160 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
11161 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
11162 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
11163
11164 return a + b + c + d;
11165}
11166
11167vec3 rotateVertexByQuat(vec3 v, vec4 q) {
11168 vec3 i = q.xyz;
11169 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
11170}
11171
11172vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
11173 return rotateVertexByQuat(v, quat(axis, angle));
11174}
11175
11176float diffuse(vec3 normal) {
11177 vec3 n2 = normal * normal * vec3(.6, .25, .8);
11178 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
11179}
11180struct Vertex {
11181 vec3 pos;
11182 vec2 texCoords;
11183 vec3 normal;
11184};
11185
11186struct BlockFrag {
11187 vec2 texCoords;
11188 vec4 color;
11189 float diffuse;
11190 vec2 light;
11191};
11192
11193#if defined(FRAGMENT_SHADER)
11194void fragment(BlockFrag r) {
11195 vec4 tex = FLWBlockTexture(r.texCoords);
11196
11197 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
11198
11199 FLWFinalizeColor(color);
11200}
11201#endif
11202#define PI 3.1415926538
11203
11204
11205
11206
11207
11208struct Flap {
11209 vec3 instancePos;
11210 vec2 light;
11211 vec3 segmentOffset;
11212 vec3 pivot;
11213 float horizontalAngle;
11214 float intensity;
11215 float flapScale;
11216 float flapness;
11217};
11218
11219
11220
11221
11222#if defined(VERTEX_SHADER)
11223
11224float toRad(float degrees) {
11225 return fract(degrees / 360.) * PI * 2.;
11226}
11227
11228float getFlapAngle(float flapness, float intensity, float scale) {
11229 float absFlap = abs(flapness);
11230
11231 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
11232
11233 float halfAngle = angle * 0.5;
11234
11235 float which = step(0., flapness); // 0 if negative, 1 if positive
11236 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
11237
11238 return degrees;
11239}
11240
11241BlockFrag vertex(Vertex v, Flap flap) {
11242 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
11243
11244 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
11245 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
11246
11247 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
11248 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
11249
11250 vec4 worldPos = vec4(rotated, 1.);
11251 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
11252
11253 FLWFinalizeWorldPos(worldPos);
11254 FLWFinalizeNormal(norm);
11255
11256 BlockFrag b;
11257 b.diffuse = diffuse(norm);
11258 b.texCoords = v.texCoords;
11259 b.light = flap.light;
11260 #if defined(DEBUG_NORMAL)
11261 b.color = vec4(norm, 1.);
11262 #else
11263 b.color = vec4(1.);
11264 #endif
11265 return b;
11266}
11267#endif
11268
11269in vec2 v2f_texCoords;
11270in vec4 v2f_color;
11271in float v2f_diffuse;
11272in vec2 v2f_light;
11273void main() {
11274BlockFrag o;
11275o.texCoords = v2f_texCoords;
11276o.color = v2f_color;
11277o.diffuse = v2f_diffuse;
11278o.light = v2f_light;
11279fragment(o);
11280}
11281[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
11282
11283[17:17:49] [Render thread/ERROR]: #version 150
11284#extension GL_ARB_conservative_depth : enable
11285#define VERTEX_SHADER
11286#if defined(VERTEX_SHADER)
11287out float FragDistance;
11288#elif defined(FRAGMENT_SHADER)
11289in float FragDistance;
11290#endif
11291uniform vec4 uFogColor;
11292uniform vec2 uFogRange;
11293
11294float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
11295 float distXZ = length(worldPos.xz - cameraPos.xz);
11296 float distY = abs(worldPos.y - cameraPos.y);
11297 return max(distXZ, distY);
11298}
11299
11300float cylindrical_distance(vec3 worldPos) {
11301 float distXZ = length(worldPos.xz);
11302 float distY = abs(worldPos.y);
11303 return max(distXZ, distY);
11304}
11305
11306float FLWFogFactor() {
11307 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
11308}
11309// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
11310vec2 shiftLight(vec2 lm) {
11311 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
11312}
11313
11314
11315uniform float uTime;
11316uniform mat4 uViewProjection;
11317uniform vec3 uCameraPos;
11318
11319uniform vec2 uTextureScale;
11320uniform sampler2D uBlockAtlas;
11321uniform sampler2D uLightMap;
11322
11323uniform vec2 uWindowSize;
11324
11325void FLWFinalizeNormal(inout vec3 normal) {
11326 // noop
11327}
11328
11329#if defined(VERTEX_SHADER)
11330void FLWFinalizeWorldPos(inout vec4 worldPos) {
11331 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
11332
11333 gl_Position = uViewProjection * worldPos;
11334}
11335
11336#elif defined(FRAGMENT_SHADER)
11337
11338
11339#define ALPHA_DISCARD 0.1
11340// optimize discard usage
11341#if defined(ALPHA_DISCARD)
11342#if defined(GL_ARB_conservative_depth)
11343layout (depth_greater) out float gl_FragDepth;
11344#endif
11345#endif
11346out vec4 fragColor;
11347
11348vec4 FLWBlockTexture(vec2 texCoords) {
11349 return texture(uBlockAtlas, texCoords);
11350}
11351
11352void FLWFinalizeColor(vec4 color) {
11353 float a = color.a;
11354 float fog = clamp(FLWFogFactor(), 0., 1.);
11355
11356 color = mix(uFogColor, color, fog);
11357 color.a = a;
11358
11359 #if defined(ALPHA_DISCARD)
11360 if (color.a < ALPHA_DISCARD) {
11361 discard;
11362 }
11363 #endif
11364
11365 fragColor = color;
11366}
11367
11368vec4 FLWLight(vec2 lightCoords) {
11369 return texture(uLightMap, shiftLight(lightCoords));
11370}
11371#endif
11372
11373
11374#define PIOVER2 1.5707963268
11375
11376vec4 quat(vec3 axis, float angle) {
11377 float halfAngle = angle * PIOVER2 / 180.0;
11378 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
11379 return vec4(axis.xyz * cs.y, cs.x);
11380}
11381
11382vec4 quatMult(vec4 q1, vec4 q2) {
11383 // disgustingly vectorized quaternion multiplication
11384 vec4 a = q1.w * q2.xyzw;
11385 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
11386 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
11387 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
11388
11389 return a + b + c + d;
11390}
11391
11392vec3 rotateVertexByQuat(vec3 v, vec4 q) {
11393 vec3 i = q.xyz;
11394 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
11395}
11396
11397vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
11398 return rotateVertexByQuat(v, quat(axis, angle));
11399}
11400
11401mat4 rotate(vec3 axis, float angle) {
11402 float s = sin(angle);
11403 float c = cos(angle);
11404 float oc = 1. - c;
11405
11406 vec3 sa = axis * s;
11407
11408 mat4 mr = mat4(1.);
11409 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
11410 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
11411 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
11412
11413 return mr;
11414}
11415
11416mat4 rotation(vec3 rot) {
11417 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
11418}
11419
11420mat3 modelToNormal(mat4 mat) {
11421 // Discard the edges. This won't be accurate for scaled or skewed matrices,
11422 // but we don't have to work with those often.
11423 mat3 m;
11424 m[0] = mat[0].xyz;
11425 m[1] = mat[1].xyz;
11426 m[2] = mat[2].xyz;
11427 return m;
11428}
11429
11430float diffuse(vec3 normal) {
11431 vec3 n2 = normal * normal * vec3(.6, .25, .8);
11432 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
11433}
11434struct Vertex {
11435 vec3 pos;
11436 vec2 texCoords;
11437 vec3 normal;
11438};
11439
11440struct BlockFrag {
11441 vec2 texCoords;
11442 vec4 color;
11443 float diffuse;
11444 vec2 light;
11445};
11446
11447#if defined(FRAGMENT_SHADER)
11448void fragment(BlockFrag r) {
11449 vec4 tex = FLWBlockTexture(r.texCoords);
11450
11451 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
11452
11453 FLWFinalizeColor(color);
11454}
11455#endif
11456#define PI 3.1415926538
11457
11458
11459
11460
11461
11462struct Belt {
11463 vec2 light;
11464 vec4 color;
11465 vec3 pos;
11466 float speed;
11467 float offset;
11468 vec4 rotation;
11469 vec2 sourceTexture;
11470 vec4 scrollTexture;
11471 float scrollMult;
11472};
11473
11474
11475
11476
11477#if defined(VERTEX_SHADER)
11478BlockFrag vertex(Vertex v, Belt instance) {
11479 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
11480
11481 vec4 worldPos = vec4(rotated, 1.);
11482
11483 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
11484
11485 FLWFinalizeWorldPos(worldPos);
11486 FLWFinalizeNormal(norm);
11487
11488 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
11489 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
11490
11491 BlockFrag b;
11492 b.diffuse = diffuse(norm);
11493 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
11494 b.light = instance.light;
11495
11496 #if defined(DEBUG_RAINBOW)
11497 b.color = instance.color;
11498 #elif defined(DEBUG_NORMAL)
11499 b.color = vec4(norm, 1.);
11500 #else
11501 b.color = vec4(1.);
11502 #endif
11503
11504 return b;
11505}
11506#endif
11507
11508in vec3 a_v_pos;
11509in vec2 a_v_texCoords;
11510in vec3 a_v_normal;
11511in vec2 a_i_light;
11512in vec4 a_i_color;
11513in vec3 a_i_pos;
11514in float a_i_speed;
11515in float a_i_offset;
11516in vec4 a_i_rotation;
11517in vec2 a_i_sourceTexture;
11518in vec4 a_i_scrollTexture;
11519in float a_i_scrollMult;
11520out vec2 v2f_texCoords;
11521out vec4 v2f_color;
11522out float v2f_diffuse;
11523out vec2 v2f_light;
11524void main() {
11525Vertex v;
11526v.pos = a_v_pos;
11527v.texCoords = a_v_texCoords;
11528v.normal = a_v_normal;
11529Belt i;
11530i.light = a_i_light;
11531i.color = a_i_color;
11532i.pos = a_i_pos;
11533i.speed = a_i_speed;
11534i.offset = a_i_offset;
11535i.rotation = a_i_rotation;
11536i.sourceTexture = a_i_sourceTexture;
11537i.scrollTexture = a_i_scrollTexture;
11538i.scrollMult = a_i_scrollMult;
11539BlockFrag o = vertex(v, i);
11540v2f_texCoords = o.texCoords;
11541v2f_color = o.color;
11542v2f_diffuse = o.diffuse;
11543v2f_light = o.light;
11544}
11545[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
11546
11547[17:17:49] [Render thread/ERROR]: #version 150
11548#extension GL_ARB_conservative_depth : enable
11549#define FRAGMENT_SHADER
11550#if defined(VERTEX_SHADER)
11551out float FragDistance;
11552#elif defined(FRAGMENT_SHADER)
11553in float FragDistance;
11554#endif
11555uniform vec4 uFogColor;
11556uniform vec2 uFogRange;
11557
11558float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
11559 float distXZ = length(worldPos.xz - cameraPos.xz);
11560 float distY = abs(worldPos.y - cameraPos.y);
11561 return max(distXZ, distY);
11562}
11563
11564float cylindrical_distance(vec3 worldPos) {
11565 float distXZ = length(worldPos.xz);
11566 float distY = abs(worldPos.y);
11567 return max(distXZ, distY);
11568}
11569
11570float FLWFogFactor() {
11571 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
11572}
11573// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
11574vec2 shiftLight(vec2 lm) {
11575 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
11576}
11577
11578
11579uniform float uTime;
11580uniform mat4 uViewProjection;
11581uniform vec3 uCameraPos;
11582
11583uniform vec2 uTextureScale;
11584uniform sampler2D uBlockAtlas;
11585uniform sampler2D uLightMap;
11586
11587uniform vec2 uWindowSize;
11588
11589void FLWFinalizeNormal(inout vec3 normal) {
11590 // noop
11591}
11592
11593#if defined(VERTEX_SHADER)
11594void FLWFinalizeWorldPos(inout vec4 worldPos) {
11595 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
11596
11597 gl_Position = uViewProjection * worldPos;
11598}
11599
11600#elif defined(FRAGMENT_SHADER)
11601
11602
11603#define ALPHA_DISCARD 0.1
11604// optimize discard usage
11605#if defined(ALPHA_DISCARD)
11606#if defined(GL_ARB_conservative_depth)
11607layout (depth_greater) out float gl_FragDepth;
11608#endif
11609#endif
11610out vec4 fragColor;
11611
11612vec4 FLWBlockTexture(vec2 texCoords) {
11613 return texture(uBlockAtlas, texCoords);
11614}
11615
11616void FLWFinalizeColor(vec4 color) {
11617 float a = color.a;
11618 float fog = clamp(FLWFogFactor(), 0., 1.);
11619
11620 color = mix(uFogColor, color, fog);
11621 color.a = a;
11622
11623 #if defined(ALPHA_DISCARD)
11624 if (color.a < ALPHA_DISCARD) {
11625 discard;
11626 }
11627 #endif
11628
11629 fragColor = color;
11630}
11631
11632vec4 FLWLight(vec2 lightCoords) {
11633 return texture(uLightMap, shiftLight(lightCoords));
11634}
11635#endif
11636
11637
11638#define PIOVER2 1.5707963268
11639
11640vec4 quat(vec3 axis, float angle) {
11641 float halfAngle = angle * PIOVER2 / 180.0;
11642 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
11643 return vec4(axis.xyz * cs.y, cs.x);
11644}
11645
11646vec4 quatMult(vec4 q1, vec4 q2) {
11647 // disgustingly vectorized quaternion multiplication
11648 vec4 a = q1.w * q2.xyzw;
11649 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
11650 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
11651 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
11652
11653 return a + b + c + d;
11654}
11655
11656vec3 rotateVertexByQuat(vec3 v, vec4 q) {
11657 vec3 i = q.xyz;
11658 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
11659}
11660
11661vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
11662 return rotateVertexByQuat(v, quat(axis, angle));
11663}
11664
11665mat4 rotate(vec3 axis, float angle) {
11666 float s = sin(angle);
11667 float c = cos(angle);
11668 float oc = 1. - c;
11669
11670 vec3 sa = axis * s;
11671
11672 mat4 mr = mat4(1.);
11673 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
11674 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
11675 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
11676
11677 return mr;
11678}
11679
11680mat4 rotation(vec3 rot) {
11681 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
11682}
11683
11684mat3 modelToNormal(mat4 mat) {
11685 // Discard the edges. This won't be accurate for scaled or skewed matrices,
11686 // but we don't have to work with those often.
11687 mat3 m;
11688 m[0] = mat[0].xyz;
11689 m[1] = mat[1].xyz;
11690 m[2] = mat[2].xyz;
11691 return m;
11692}
11693
11694float diffuse(vec3 normal) {
11695 vec3 n2 = normal * normal * vec3(.6, .25, .8);
11696 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
11697}
11698struct Vertex {
11699 vec3 pos;
11700 vec2 texCoords;
11701 vec3 normal;
11702};
11703
11704struct BlockFrag {
11705 vec2 texCoords;
11706 vec4 color;
11707 float diffuse;
11708 vec2 light;
11709};
11710
11711#if defined(FRAGMENT_SHADER)
11712void fragment(BlockFrag r) {
11713 vec4 tex = FLWBlockTexture(r.texCoords);
11714
11715 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
11716
11717 FLWFinalizeColor(color);
11718}
11719#endif
11720#define PI 3.1415926538
11721
11722
11723
11724
11725
11726struct Belt {
11727 vec2 light;
11728 vec4 color;
11729 vec3 pos;
11730 float speed;
11731 float offset;
11732 vec4 rotation;
11733 vec2 sourceTexture;
11734 vec4 scrollTexture;
11735 float scrollMult;
11736};
11737
11738
11739
11740
11741#if defined(VERTEX_SHADER)
11742BlockFrag vertex(Vertex v, Belt instance) {
11743 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
11744
11745 vec4 worldPos = vec4(rotated, 1.);
11746
11747 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
11748
11749 FLWFinalizeWorldPos(worldPos);
11750 FLWFinalizeNormal(norm);
11751
11752 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
11753 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
11754
11755 BlockFrag b;
11756 b.diffuse = diffuse(norm);
11757 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
11758 b.light = instance.light;
11759
11760 #if defined(DEBUG_RAINBOW)
11761 b.color = instance.color;
11762 #elif defined(DEBUG_NORMAL)
11763 b.color = vec4(norm, 1.);
11764 #else
11765 b.color = vec4(1.);
11766 #endif
11767
11768 return b;
11769}
11770#endif
11771
11772in vec2 v2f_texCoords;
11773in vec4 v2f_color;
11774in float v2f_diffuse;
11775in vec2 v2f_light;
11776void main() {
11777BlockFrag o;
11778o.texCoords = v2f_texCoords;
11779o.color = v2f_color;
11780o.diffuse = v2f_diffuse;
11781o.light = v2f_light;
11782fragment(o);
11783}
11784[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
11785
11786[17:17:49] [Render thread/ERROR]: #version 150
11787#extension GL_ARB_conservative_depth : enable
11788#define VERTEX_SHADER
11789#define DEBUG_RAINBOW
11790#if defined(VERTEX_SHADER)
11791out float FragDistance;
11792#elif defined(FRAGMENT_SHADER)
11793in float FragDistance;
11794#endif
11795uniform vec4 uFogColor;
11796uniform vec2 uFogRange;
11797
11798float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
11799 float distXZ = length(worldPos.xz - cameraPos.xz);
11800 float distY = abs(worldPos.y - cameraPos.y);
11801 return max(distXZ, distY);
11802}
11803
11804float cylindrical_distance(vec3 worldPos) {
11805 float distXZ = length(worldPos.xz);
11806 float distY = abs(worldPos.y);
11807 return max(distXZ, distY);
11808}
11809
11810float FLWFogFactor() {
11811 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
11812}
11813// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
11814vec2 shiftLight(vec2 lm) {
11815 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
11816}
11817
11818
11819uniform float uTime;
11820uniform mat4 uViewProjection;
11821uniform vec3 uCameraPos;
11822
11823uniform vec2 uTextureScale;
11824uniform sampler2D uBlockAtlas;
11825uniform sampler2D uLightMap;
11826
11827uniform vec2 uWindowSize;
11828
11829void FLWFinalizeNormal(inout vec3 normal) {
11830 // noop
11831}
11832
11833#if defined(VERTEX_SHADER)
11834void FLWFinalizeWorldPos(inout vec4 worldPos) {
11835 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
11836
11837 gl_Position = uViewProjection * worldPos;
11838}
11839
11840#elif defined(FRAGMENT_SHADER)
11841
11842
11843#define ALPHA_DISCARD 0.1
11844// optimize discard usage
11845#if defined(ALPHA_DISCARD)
11846#if defined(GL_ARB_conservative_depth)
11847layout (depth_greater) out float gl_FragDepth;
11848#endif
11849#endif
11850out vec4 fragColor;
11851
11852vec4 FLWBlockTexture(vec2 texCoords) {
11853 return texture(uBlockAtlas, texCoords);
11854}
11855
11856void FLWFinalizeColor(vec4 color) {
11857 float a = color.a;
11858 float fog = clamp(FLWFogFactor(), 0., 1.);
11859
11860 color = mix(uFogColor, color, fog);
11861 color.a = a;
11862
11863 #if defined(ALPHA_DISCARD)
11864 if (color.a < ALPHA_DISCARD) {
11865 discard;
11866 }
11867 #endif
11868
11869 fragColor = color;
11870}
11871
11872vec4 FLWLight(vec2 lightCoords) {
11873 return texture(uLightMap, shiftLight(lightCoords));
11874}
11875#endif
11876
11877
11878#define PIOVER2 1.5707963268
11879
11880vec4 quat(vec3 axis, float angle) {
11881 float halfAngle = angle * PIOVER2 / 180.0;
11882 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
11883 return vec4(axis.xyz * cs.y, cs.x);
11884}
11885
11886vec4 quatMult(vec4 q1, vec4 q2) {
11887 // disgustingly vectorized quaternion multiplication
11888 vec4 a = q1.w * q2.xyzw;
11889 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
11890 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
11891 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
11892
11893 return a + b + c + d;
11894}
11895
11896vec3 rotateVertexByQuat(vec3 v, vec4 q) {
11897 vec3 i = q.xyz;
11898 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
11899}
11900
11901vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
11902 return rotateVertexByQuat(v, quat(axis, angle));
11903}
11904
11905mat4 rotate(vec3 axis, float angle) {
11906 float s = sin(angle);
11907 float c = cos(angle);
11908 float oc = 1. - c;
11909
11910 vec3 sa = axis * s;
11911
11912 mat4 mr = mat4(1.);
11913 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
11914 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
11915 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
11916
11917 return mr;
11918}
11919
11920mat4 rotation(vec3 rot) {
11921 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
11922}
11923
11924mat3 modelToNormal(mat4 mat) {
11925 // Discard the edges. This won't be accurate for scaled or skewed matrices,
11926 // but we don't have to work with those often.
11927 mat3 m;
11928 m[0] = mat[0].xyz;
11929 m[1] = mat[1].xyz;
11930 m[2] = mat[2].xyz;
11931 return m;
11932}
11933
11934float diffuse(vec3 normal) {
11935 vec3 n2 = normal * normal * vec3(.6, .25, .8);
11936 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
11937}
11938struct Vertex {
11939 vec3 pos;
11940 vec2 texCoords;
11941 vec3 normal;
11942};
11943
11944struct BlockFrag {
11945 vec2 texCoords;
11946 vec4 color;
11947 float diffuse;
11948 vec2 light;
11949};
11950
11951#if defined(FRAGMENT_SHADER)
11952void fragment(BlockFrag r) {
11953 vec4 tex = FLWBlockTexture(r.texCoords);
11954
11955 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
11956
11957 FLWFinalizeColor(color);
11958}
11959#endif
11960#define PI 3.1415926538
11961
11962
11963
11964
11965
11966struct Belt {
11967 vec2 light;
11968 vec4 color;
11969 vec3 pos;
11970 float speed;
11971 float offset;
11972 vec4 rotation;
11973 vec2 sourceTexture;
11974 vec4 scrollTexture;
11975 float scrollMult;
11976};
11977
11978
11979
11980
11981#if defined(VERTEX_SHADER)
11982BlockFrag vertex(Vertex v, Belt instance) {
11983 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
11984
11985 vec4 worldPos = vec4(rotated, 1.);
11986
11987 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
11988
11989 FLWFinalizeWorldPos(worldPos);
11990 FLWFinalizeNormal(norm);
11991
11992 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
11993 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
11994
11995 BlockFrag b;
11996 b.diffuse = diffuse(norm);
11997 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
11998 b.light = instance.light;
11999
12000 #if defined(DEBUG_RAINBOW)
12001 b.color = instance.color;
12002 #elif defined(DEBUG_NORMAL)
12003 b.color = vec4(norm, 1.);
12004 #else
12005 b.color = vec4(1.);
12006 #endif
12007
12008 return b;
12009}
12010#endif
12011
12012in vec3 a_v_pos;
12013in vec2 a_v_texCoords;
12014in vec3 a_v_normal;
12015in vec2 a_i_light;
12016in vec4 a_i_color;
12017in vec3 a_i_pos;
12018in float a_i_speed;
12019in float a_i_offset;
12020in vec4 a_i_rotation;
12021in vec2 a_i_sourceTexture;
12022in vec4 a_i_scrollTexture;
12023in float a_i_scrollMult;
12024out vec2 v2f_texCoords;
12025out vec4 v2f_color;
12026out float v2f_diffuse;
12027out vec2 v2f_light;
12028void main() {
12029Vertex v;
12030v.pos = a_v_pos;
12031v.texCoords = a_v_texCoords;
12032v.normal = a_v_normal;
12033Belt i;
12034i.light = a_i_light;
12035i.color = a_i_color;
12036i.pos = a_i_pos;
12037i.speed = a_i_speed;
12038i.offset = a_i_offset;
12039i.rotation = a_i_rotation;
12040i.sourceTexture = a_i_sourceTexture;
12041i.scrollTexture = a_i_scrollTexture;
12042i.scrollMult = a_i_scrollMult;
12043BlockFrag o = vertex(v, i);
12044v2f_texCoords = o.texCoords;
12045v2f_color = o.color;
12046v2f_diffuse = o.diffuse;
12047v2f_light = o.light;
12048}
12049[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
12050
12051[17:17:49] [Render thread/ERROR]: #version 150
12052#extension GL_ARB_conservative_depth : enable
12053#define FRAGMENT_SHADER
12054#define DEBUG_RAINBOW
12055#if defined(VERTEX_SHADER)
12056out float FragDistance;
12057#elif defined(FRAGMENT_SHADER)
12058in float FragDistance;
12059#endif
12060uniform vec4 uFogColor;
12061uniform vec2 uFogRange;
12062
12063float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
12064 float distXZ = length(worldPos.xz - cameraPos.xz);
12065 float distY = abs(worldPos.y - cameraPos.y);
12066 return max(distXZ, distY);
12067}
12068
12069float cylindrical_distance(vec3 worldPos) {
12070 float distXZ = length(worldPos.xz);
12071 float distY = abs(worldPos.y);
12072 return max(distXZ, distY);
12073}
12074
12075float FLWFogFactor() {
12076 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
12077}
12078// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
12079vec2 shiftLight(vec2 lm) {
12080 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
12081}
12082
12083
12084uniform float uTime;
12085uniform mat4 uViewProjection;
12086uniform vec3 uCameraPos;
12087
12088uniform vec2 uTextureScale;
12089uniform sampler2D uBlockAtlas;
12090uniform sampler2D uLightMap;
12091
12092uniform vec2 uWindowSize;
12093
12094void FLWFinalizeNormal(inout vec3 normal) {
12095 // noop
12096}
12097
12098#if defined(VERTEX_SHADER)
12099void FLWFinalizeWorldPos(inout vec4 worldPos) {
12100 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
12101
12102 gl_Position = uViewProjection * worldPos;
12103}
12104
12105#elif defined(FRAGMENT_SHADER)
12106
12107
12108#define ALPHA_DISCARD 0.1
12109// optimize discard usage
12110#if defined(ALPHA_DISCARD)
12111#if defined(GL_ARB_conservative_depth)
12112layout (depth_greater) out float gl_FragDepth;
12113#endif
12114#endif
12115out vec4 fragColor;
12116
12117vec4 FLWBlockTexture(vec2 texCoords) {
12118 return texture(uBlockAtlas, texCoords);
12119}
12120
12121void FLWFinalizeColor(vec4 color) {
12122 float a = color.a;
12123 float fog = clamp(FLWFogFactor(), 0., 1.);
12124
12125 color = mix(uFogColor, color, fog);
12126 color.a = a;
12127
12128 #if defined(ALPHA_DISCARD)
12129 if (color.a < ALPHA_DISCARD) {
12130 discard;
12131 }
12132 #endif
12133
12134 fragColor = color;
12135}
12136
12137vec4 FLWLight(vec2 lightCoords) {
12138 return texture(uLightMap, shiftLight(lightCoords));
12139}
12140#endif
12141
12142
12143#define PIOVER2 1.5707963268
12144
12145vec4 quat(vec3 axis, float angle) {
12146 float halfAngle = angle * PIOVER2 / 180.0;
12147 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
12148 return vec4(axis.xyz * cs.y, cs.x);
12149}
12150
12151vec4 quatMult(vec4 q1, vec4 q2) {
12152 // disgustingly vectorized quaternion multiplication
12153 vec4 a = q1.w * q2.xyzw;
12154 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
12155 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
12156 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
12157
12158 return a + b + c + d;
12159}
12160
12161vec3 rotateVertexByQuat(vec3 v, vec4 q) {
12162 vec3 i = q.xyz;
12163 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
12164}
12165
12166vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
12167 return rotateVertexByQuat(v, quat(axis, angle));
12168}
12169
12170mat4 rotate(vec3 axis, float angle) {
12171 float s = sin(angle);
12172 float c = cos(angle);
12173 float oc = 1. - c;
12174
12175 vec3 sa = axis * s;
12176
12177 mat4 mr = mat4(1.);
12178 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
12179 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
12180 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
12181
12182 return mr;
12183}
12184
12185mat4 rotation(vec3 rot) {
12186 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
12187}
12188
12189mat3 modelToNormal(mat4 mat) {
12190 // Discard the edges. This won't be accurate for scaled or skewed matrices,
12191 // but we don't have to work with those often.
12192 mat3 m;
12193 m[0] = mat[0].xyz;
12194 m[1] = mat[1].xyz;
12195 m[2] = mat[2].xyz;
12196 return m;
12197}
12198
12199float diffuse(vec3 normal) {
12200 vec3 n2 = normal * normal * vec3(.6, .25, .8);
12201 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
12202}
12203struct Vertex {
12204 vec3 pos;
12205 vec2 texCoords;
12206 vec3 normal;
12207};
12208
12209struct BlockFrag {
12210 vec2 texCoords;
12211 vec4 color;
12212 float diffuse;
12213 vec2 light;
12214};
12215
12216#if defined(FRAGMENT_SHADER)
12217void fragment(BlockFrag r) {
12218 vec4 tex = FLWBlockTexture(r.texCoords);
12219
12220 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
12221
12222 FLWFinalizeColor(color);
12223}
12224#endif
12225#define PI 3.1415926538
12226
12227
12228
12229
12230
12231struct Belt {
12232 vec2 light;
12233 vec4 color;
12234 vec3 pos;
12235 float speed;
12236 float offset;
12237 vec4 rotation;
12238 vec2 sourceTexture;
12239 vec4 scrollTexture;
12240 float scrollMult;
12241};
12242
12243
12244
12245
12246#if defined(VERTEX_SHADER)
12247BlockFrag vertex(Vertex v, Belt instance) {
12248 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
12249
12250 vec4 worldPos = vec4(rotated, 1.);
12251
12252 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
12253
12254 FLWFinalizeWorldPos(worldPos);
12255 FLWFinalizeNormal(norm);
12256
12257 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
12258 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
12259
12260 BlockFrag b;
12261 b.diffuse = diffuse(norm);
12262 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
12263 b.light = instance.light;
12264
12265 #if defined(DEBUG_RAINBOW)
12266 b.color = instance.color;
12267 #elif defined(DEBUG_NORMAL)
12268 b.color = vec4(norm, 1.);
12269 #else
12270 b.color = vec4(1.);
12271 #endif
12272
12273 return b;
12274}
12275#endif
12276
12277in vec2 v2f_texCoords;
12278in vec4 v2f_color;
12279in float v2f_diffuse;
12280in vec2 v2f_light;
12281void main() {
12282BlockFrag o;
12283o.texCoords = v2f_texCoords;
12284o.color = v2f_color;
12285o.diffuse = v2f_diffuse;
12286o.light = v2f_light;
12287fragment(o);
12288}
12289[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
12290
12291[17:17:49] [Render thread/ERROR]: #version 150
12292#extension GL_ARB_conservative_depth : enable
12293#define VERTEX_SHADER
12294#define DEBUG_NORMAL
12295#if defined(VERTEX_SHADER)
12296out float FragDistance;
12297#elif defined(FRAGMENT_SHADER)
12298in float FragDistance;
12299#endif
12300uniform vec4 uFogColor;
12301uniform vec2 uFogRange;
12302
12303float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
12304 float distXZ = length(worldPos.xz - cameraPos.xz);
12305 float distY = abs(worldPos.y - cameraPos.y);
12306 return max(distXZ, distY);
12307}
12308
12309float cylindrical_distance(vec3 worldPos) {
12310 float distXZ = length(worldPos.xz);
12311 float distY = abs(worldPos.y);
12312 return max(distXZ, distY);
12313}
12314
12315float FLWFogFactor() {
12316 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
12317}
12318// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
12319vec2 shiftLight(vec2 lm) {
12320 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
12321}
12322
12323
12324uniform float uTime;
12325uniform mat4 uViewProjection;
12326uniform vec3 uCameraPos;
12327
12328uniform vec2 uTextureScale;
12329uniform sampler2D uBlockAtlas;
12330uniform sampler2D uLightMap;
12331
12332uniform vec2 uWindowSize;
12333
12334void FLWFinalizeNormal(inout vec3 normal) {
12335 // noop
12336}
12337
12338#if defined(VERTEX_SHADER)
12339void FLWFinalizeWorldPos(inout vec4 worldPos) {
12340 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
12341
12342 gl_Position = uViewProjection * worldPos;
12343}
12344
12345#elif defined(FRAGMENT_SHADER)
12346
12347
12348#define ALPHA_DISCARD 0.1
12349// optimize discard usage
12350#if defined(ALPHA_DISCARD)
12351#if defined(GL_ARB_conservative_depth)
12352layout (depth_greater) out float gl_FragDepth;
12353#endif
12354#endif
12355out vec4 fragColor;
12356
12357vec4 FLWBlockTexture(vec2 texCoords) {
12358 return texture(uBlockAtlas, texCoords);
12359}
12360
12361void FLWFinalizeColor(vec4 color) {
12362 float a = color.a;
12363 float fog = clamp(FLWFogFactor(), 0., 1.);
12364
12365 color = mix(uFogColor, color, fog);
12366 color.a = a;
12367
12368 #if defined(ALPHA_DISCARD)
12369 if (color.a < ALPHA_DISCARD) {
12370 discard;
12371 }
12372 #endif
12373
12374 fragColor = color;
12375}
12376
12377vec4 FLWLight(vec2 lightCoords) {
12378 return texture(uLightMap, shiftLight(lightCoords));
12379}
12380#endif
12381
12382
12383#define PIOVER2 1.5707963268
12384
12385vec4 quat(vec3 axis, float angle) {
12386 float halfAngle = angle * PIOVER2 / 180.0;
12387 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
12388 return vec4(axis.xyz * cs.y, cs.x);
12389}
12390
12391vec4 quatMult(vec4 q1, vec4 q2) {
12392 // disgustingly vectorized quaternion multiplication
12393 vec4 a = q1.w * q2.xyzw;
12394 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
12395 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
12396 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
12397
12398 return a + b + c + d;
12399}
12400
12401vec3 rotateVertexByQuat(vec3 v, vec4 q) {
12402 vec3 i = q.xyz;
12403 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
12404}
12405
12406vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
12407 return rotateVertexByQuat(v, quat(axis, angle));
12408}
12409
12410mat4 rotate(vec3 axis, float angle) {
12411 float s = sin(angle);
12412 float c = cos(angle);
12413 float oc = 1. - c;
12414
12415 vec3 sa = axis * s;
12416
12417 mat4 mr = mat4(1.);
12418 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
12419 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
12420 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
12421
12422 return mr;
12423}
12424
12425mat4 rotation(vec3 rot) {
12426 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
12427}
12428
12429mat3 modelToNormal(mat4 mat) {
12430 // Discard the edges. This won't be accurate for scaled or skewed matrices,
12431 // but we don't have to work with those often.
12432 mat3 m;
12433 m[0] = mat[0].xyz;
12434 m[1] = mat[1].xyz;
12435 m[2] = mat[2].xyz;
12436 return m;
12437}
12438
12439float diffuse(vec3 normal) {
12440 vec3 n2 = normal * normal * vec3(.6, .25, .8);
12441 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
12442}
12443struct Vertex {
12444 vec3 pos;
12445 vec2 texCoords;
12446 vec3 normal;
12447};
12448
12449struct BlockFrag {
12450 vec2 texCoords;
12451 vec4 color;
12452 float diffuse;
12453 vec2 light;
12454};
12455
12456#if defined(FRAGMENT_SHADER)
12457void fragment(BlockFrag r) {
12458 vec4 tex = FLWBlockTexture(r.texCoords);
12459
12460 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
12461
12462 FLWFinalizeColor(color);
12463}
12464#endif
12465#define PI 3.1415926538
12466
12467
12468
12469
12470
12471struct Belt {
12472 vec2 light;
12473 vec4 color;
12474 vec3 pos;
12475 float speed;
12476 float offset;
12477 vec4 rotation;
12478 vec2 sourceTexture;
12479 vec4 scrollTexture;
12480 float scrollMult;
12481};
12482
12483
12484
12485
12486#if defined(VERTEX_SHADER)
12487BlockFrag vertex(Vertex v, Belt instance) {
12488 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
12489
12490 vec4 worldPos = vec4(rotated, 1.);
12491
12492 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
12493
12494 FLWFinalizeWorldPos(worldPos);
12495 FLWFinalizeNormal(norm);
12496
12497 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
12498 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
12499
12500 BlockFrag b;
12501 b.diffuse = diffuse(norm);
12502 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
12503 b.light = instance.light;
12504
12505 #if defined(DEBUG_RAINBOW)
12506 b.color = instance.color;
12507 #elif defined(DEBUG_NORMAL)
12508 b.color = vec4(norm, 1.);
12509 #else
12510 b.color = vec4(1.);
12511 #endif
12512
12513 return b;
12514}
12515#endif
12516
12517in vec3 a_v_pos;
12518in vec2 a_v_texCoords;
12519in vec3 a_v_normal;
12520in vec2 a_i_light;
12521in vec4 a_i_color;
12522in vec3 a_i_pos;
12523in float a_i_speed;
12524in float a_i_offset;
12525in vec4 a_i_rotation;
12526in vec2 a_i_sourceTexture;
12527in vec4 a_i_scrollTexture;
12528in float a_i_scrollMult;
12529out vec2 v2f_texCoords;
12530out vec4 v2f_color;
12531out float v2f_diffuse;
12532out vec2 v2f_light;
12533void main() {
12534Vertex v;
12535v.pos = a_v_pos;
12536v.texCoords = a_v_texCoords;
12537v.normal = a_v_normal;
12538Belt i;
12539i.light = a_i_light;
12540i.color = a_i_color;
12541i.pos = a_i_pos;
12542i.speed = a_i_speed;
12543i.offset = a_i_offset;
12544i.rotation = a_i_rotation;
12545i.sourceTexture = a_i_sourceTexture;
12546i.scrollTexture = a_i_scrollTexture;
12547i.scrollMult = a_i_scrollMult;
12548BlockFrag o = vertex(v, i);
12549v2f_texCoords = o.texCoords;
12550v2f_color = o.color;
12551v2f_diffuse = o.diffuse;
12552v2f_light = o.light;
12553}
12554[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
12555
12556[17:17:49] [Render thread/ERROR]: #version 150
12557#extension GL_ARB_conservative_depth : enable
12558#define FRAGMENT_SHADER
12559#define DEBUG_NORMAL
12560#if defined(VERTEX_SHADER)
12561out float FragDistance;
12562#elif defined(FRAGMENT_SHADER)
12563in float FragDistance;
12564#endif
12565uniform vec4 uFogColor;
12566uniform vec2 uFogRange;
12567
12568float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
12569 float distXZ = length(worldPos.xz - cameraPos.xz);
12570 float distY = abs(worldPos.y - cameraPos.y);
12571 return max(distXZ, distY);
12572}
12573
12574float cylindrical_distance(vec3 worldPos) {
12575 float distXZ = length(worldPos.xz);
12576 float distY = abs(worldPos.y);
12577 return max(distXZ, distY);
12578}
12579
12580float FLWFogFactor() {
12581 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
12582}
12583// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
12584vec2 shiftLight(vec2 lm) {
12585 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
12586}
12587
12588
12589uniform float uTime;
12590uniform mat4 uViewProjection;
12591uniform vec3 uCameraPos;
12592
12593uniform vec2 uTextureScale;
12594uniform sampler2D uBlockAtlas;
12595uniform sampler2D uLightMap;
12596
12597uniform vec2 uWindowSize;
12598
12599void FLWFinalizeNormal(inout vec3 normal) {
12600 // noop
12601}
12602
12603#if defined(VERTEX_SHADER)
12604void FLWFinalizeWorldPos(inout vec4 worldPos) {
12605 FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
12606
12607 gl_Position = uViewProjection * worldPos;
12608}
12609
12610#elif defined(FRAGMENT_SHADER)
12611
12612
12613#define ALPHA_DISCARD 0.1
12614// optimize discard usage
12615#if defined(ALPHA_DISCARD)
12616#if defined(GL_ARB_conservative_depth)
12617layout (depth_greater) out float gl_FragDepth;
12618#endif
12619#endif
12620out vec4 fragColor;
12621
12622vec4 FLWBlockTexture(vec2 texCoords) {
12623 return texture(uBlockAtlas, texCoords);
12624}
12625
12626void FLWFinalizeColor(vec4 color) {
12627 float a = color.a;
12628 float fog = clamp(FLWFogFactor(), 0., 1.);
12629
12630 color = mix(uFogColor, color, fog);
12631 color.a = a;
12632
12633 #if defined(ALPHA_DISCARD)
12634 if (color.a < ALPHA_DISCARD) {
12635 discard;
12636 }
12637 #endif
12638
12639 fragColor = color;
12640}
12641
12642vec4 FLWLight(vec2 lightCoords) {
12643 return texture(uLightMap, shiftLight(lightCoords));
12644}
12645#endif
12646
12647
12648#define PIOVER2 1.5707963268
12649
12650vec4 quat(vec3 axis, float angle) {
12651 float halfAngle = angle * PIOVER2 / 180.0;
12652 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
12653 return vec4(axis.xyz * cs.y, cs.x);
12654}
12655
12656vec4 quatMult(vec4 q1, vec4 q2) {
12657 // disgustingly vectorized quaternion multiplication
12658 vec4 a = q1.w * q2.xyzw;
12659 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
12660 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
12661 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
12662
12663 return a + b + c + d;
12664}
12665
12666vec3 rotateVertexByQuat(vec3 v, vec4 q) {
12667 vec3 i = q.xyz;
12668 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
12669}
12670
12671vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
12672 return rotateVertexByQuat(v, quat(axis, angle));
12673}
12674
12675mat4 rotate(vec3 axis, float angle) {
12676 float s = sin(angle);
12677 float c = cos(angle);
12678 float oc = 1. - c;
12679
12680 vec3 sa = axis * s;
12681
12682 mat4 mr = mat4(1.);
12683 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
12684 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
12685 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
12686
12687 return mr;
12688}
12689
12690mat4 rotation(vec3 rot) {
12691 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
12692}
12693
12694mat3 modelToNormal(mat4 mat) {
12695 // Discard the edges. This won't be accurate for scaled or skewed matrices,
12696 // but we don't have to work with those often.
12697 mat3 m;
12698 m[0] = mat[0].xyz;
12699 m[1] = mat[1].xyz;
12700 m[2] = mat[2].xyz;
12701 return m;
12702}
12703
12704float diffuse(vec3 normal) {
12705 vec3 n2 = normal * normal * vec3(.6, .25, .8);
12706 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
12707}
12708struct Vertex {
12709 vec3 pos;
12710 vec2 texCoords;
12711 vec3 normal;
12712};
12713
12714struct BlockFrag {
12715 vec2 texCoords;
12716 vec4 color;
12717 float diffuse;
12718 vec2 light;
12719};
12720
12721#if defined(FRAGMENT_SHADER)
12722void fragment(BlockFrag r) {
12723 vec4 tex = FLWBlockTexture(r.texCoords);
12724
12725 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
12726
12727 FLWFinalizeColor(color);
12728}
12729#endif
12730#define PI 3.1415926538
12731
12732
12733
12734
12735
12736struct Belt {
12737 vec2 light;
12738 vec4 color;
12739 vec3 pos;
12740 float speed;
12741 float offset;
12742 vec4 rotation;
12743 vec2 sourceTexture;
12744 vec4 scrollTexture;
12745 float scrollMult;
12746};
12747
12748
12749
12750
12751#if defined(VERTEX_SHADER)
12752BlockFrag vertex(Vertex v, Belt instance) {
12753 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
12754
12755 vec4 worldPos = vec4(rotated, 1.);
12756
12757 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
12758
12759 FLWFinalizeWorldPos(worldPos);
12760 FLWFinalizeNormal(norm);
12761
12762 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
12763 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
12764
12765 BlockFrag b;
12766 b.diffuse = diffuse(norm);
12767 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
12768 b.light = instance.light;
12769
12770 #if defined(DEBUG_RAINBOW)
12771 b.color = instance.color;
12772 #elif defined(DEBUG_NORMAL)
12773 b.color = vec4(norm, 1.);
12774 #else
12775 b.color = vec4(1.);
12776 #endif
12777
12778 return b;
12779}
12780#endif
12781
12782in vec2 v2f_texCoords;
12783in vec4 v2f_color;
12784in float v2f_diffuse;
12785in vec2 v2f_light;
12786void main() {
12787BlockFrag o;
12788o.texCoords = v2f_texCoords;
12789o.color = v2f_color;
12790o.diffuse = v2f_diffuse;
12791o.light = v2f_light;
12792fragment(o);
12793}
12794[17:17:49] [Render thread/INFO]: Loading context 'create:context/contraption'
12795[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
12796
12797[17:17:49] [Render thread/ERROR]: #version 150
12798#extension GL_ARB_conservative_depth : enable
12799#define VERTEX_SHADER
12800#if defined(VERTEX_SHADER)
12801out float FragDistance;
12802#elif defined(FRAGMENT_SHADER)
12803in float FragDistance;
12804#endif
12805uniform vec4 uFogColor;
12806uniform vec2 uFogRange;
12807
12808float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
12809 float distXZ = length(worldPos.xz - cameraPos.xz);
12810 float distY = abs(worldPos.y - cameraPos.y);
12811 return max(distXZ, distY);
12812}
12813
12814float cylindrical_distance(vec3 worldPos) {
12815 float distXZ = length(worldPos.xz);
12816 float distY = abs(worldPos.y);
12817 return max(distXZ, distY);
12818}
12819
12820float FLWFogFactor() {
12821 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
12822}
12823// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
12824vec2 shiftLight(vec2 lm) {
12825 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
12826}
12827
12828
12829uniform sampler3D uLightVolume;
12830
12831uniform sampler2D uBlockAtlas;
12832uniform sampler2D uLightMap;
12833
12834uniform vec3 uLightBoxSize;
12835uniform vec3 uLightBoxMin;
12836uniform mat4 uModel;
12837
12838uniform float uTime;
12839uniform mat4 uViewProjection;
12840uniform vec3 uCameraPos;
12841
12842void FLWFinalizeNormal(inout vec3 normal) {
12843 mat3 m;
12844 m[0] = uModel[0].xyz;
12845 m[1] = uModel[1].xyz;
12846 m[2] = uModel[2].xyz;
12847 normal = m * normal;
12848}
12849
12850#if defined(VERTEX_SHADER)
12851
12852out vec3 BoxCoord;
12853
12854void FLWFinalizeWorldPos(inout vec4 worldPos) {
12855 worldPos = uModel * worldPos;
12856
12857 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
12858
12859 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
12860
12861 gl_Position = uViewProjection * worldPos;
12862}
12863
12864#elif defined(FRAGMENT_SHADER)
12865
12866
12867#define ALPHA_DISCARD 0.1
12868// optimize discard usage
12869#if defined(ALPHA_DISCARD)
12870#if defined(GL_ARB_conservative_depth)
12871layout (depth_greater) out float gl_FragDepth;
12872#endif
12873#endif
12874
12875in vec3 BoxCoord;
12876
12877out vec4 FragColor;
12878
12879vec4 FLWBlockTexture(vec2 texCoords) {
12880 return texture(uBlockAtlas, texCoords);
12881}
12882
12883void FLWFinalizeColor(vec4 color) {
12884 float a = color.a;
12885 float fog = clamp(FLWFogFactor(), 0., 1.);
12886
12887 color = mix(uFogColor, color, fog);
12888 color.a = a;
12889
12890 #if defined(ALPHA_DISCARD)
12891 if (color.a < ALPHA_DISCARD) {
12892 discard;
12893 }
12894 #endif
12895
12896 FragColor = color;
12897}
12898
12899vec4 FLWLight(vec2 lightCoords) {
12900 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
12901
12902 return texture(uLightMap, shiftLight(lightCoords));
12903}
12904
12905#endif
12906
12907
12908float diffuse(vec3 normal) {
12909 vec3 n2 = normal * normal * vec3(.6, .25, .8);
12910 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
12911}
12912struct Vertex {
12913 vec3 pos;
12914 vec2 texCoords;
12915 vec3 normal;
12916};
12917
12918struct BlockFrag {
12919 vec2 texCoords;
12920 vec4 color;
12921 float diffuse;
12922 vec2 light;
12923};
12924
12925#if defined(FRAGMENT_SHADER)
12926void fragment(BlockFrag r) {
12927 vec4 tex = FLWBlockTexture(r.texCoords);
12928
12929 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
12930
12931 FLWFinalizeColor(color);
12932}
12933#endif
12934
12935
12936
12937
12938struct Instance {
12939 vec2 light;
12940 vec4 color;
12941 mat4 transform;
12942 mat3 normalMat;
12943};
12944
12945#if defined(VERTEX_SHADER)
12946BlockFrag vertex(Vertex v, Instance i) {
12947 vec4 worldPos = i.transform * vec4(v.pos, 1.);
12948
12949 vec3 norm = i.normalMat * v.normal;
12950
12951 FLWFinalizeWorldPos(worldPos);
12952 FLWFinalizeNormal(norm);
12953
12954 norm = normalize(norm);
12955
12956 BlockFrag b;
12957 b.diffuse = diffuse(norm);
12958 b.texCoords = v.texCoords;
12959 b.light = i.light;
12960 #if defined(DEBUG_NORMAL)
12961 b.color = vec4(norm, 1.);
12962 #else
12963 b.color = i.color;
12964 #endif
12965 return b;
12966}
12967#endif
12968
12969in vec3 a_v_pos;
12970in vec2 a_v_texCoords;
12971in vec3 a_v_normal;
12972in vec2 a_i_light;
12973in vec4 a_i_color;
12974in mat4 a_i_transform;
12975in mat3 a_i_normalMat;
12976out vec2 v2f_texCoords;
12977out vec4 v2f_color;
12978out float v2f_diffuse;
12979out vec2 v2f_light;
12980void main() {
12981Vertex v;
12982v.pos = a_v_pos;
12983v.texCoords = a_v_texCoords;
12984v.normal = a_v_normal;
12985Instance i;
12986i.light = a_i_light;
12987i.color = a_i_color;
12988i.transform = a_i_transform;
12989i.normalMat = a_i_normalMat;
12990BlockFrag o = vertex(v, i);
12991v2f_texCoords = o.texCoords;
12992v2f_color = o.color;
12993v2f_diffuse = o.diffuse;
12994v2f_light = o.light;
12995}
12996[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
12997
12998[17:17:49] [Render thread/ERROR]: #version 150
12999#extension GL_ARB_conservative_depth : enable
13000#define FRAGMENT_SHADER
13001#if defined(VERTEX_SHADER)
13002out float FragDistance;
13003#elif defined(FRAGMENT_SHADER)
13004in float FragDistance;
13005#endif
13006uniform vec4 uFogColor;
13007uniform vec2 uFogRange;
13008
13009float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
13010 float distXZ = length(worldPos.xz - cameraPos.xz);
13011 float distY = abs(worldPos.y - cameraPos.y);
13012 return max(distXZ, distY);
13013}
13014
13015float cylindrical_distance(vec3 worldPos) {
13016 float distXZ = length(worldPos.xz);
13017 float distY = abs(worldPos.y);
13018 return max(distXZ, distY);
13019}
13020
13021float FLWFogFactor() {
13022 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
13023}
13024// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
13025vec2 shiftLight(vec2 lm) {
13026 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
13027}
13028
13029
13030uniform sampler3D uLightVolume;
13031
13032uniform sampler2D uBlockAtlas;
13033uniform sampler2D uLightMap;
13034
13035uniform vec3 uLightBoxSize;
13036uniform vec3 uLightBoxMin;
13037uniform mat4 uModel;
13038
13039uniform float uTime;
13040uniform mat4 uViewProjection;
13041uniform vec3 uCameraPos;
13042
13043void FLWFinalizeNormal(inout vec3 normal) {
13044 mat3 m;
13045 m[0] = uModel[0].xyz;
13046 m[1] = uModel[1].xyz;
13047 m[2] = uModel[2].xyz;
13048 normal = m * normal;
13049}
13050
13051#if defined(VERTEX_SHADER)
13052
13053out vec3 BoxCoord;
13054
13055void FLWFinalizeWorldPos(inout vec4 worldPos) {
13056 worldPos = uModel * worldPos;
13057
13058 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
13059
13060 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
13061
13062 gl_Position = uViewProjection * worldPos;
13063}
13064
13065#elif defined(FRAGMENT_SHADER)
13066
13067
13068#define ALPHA_DISCARD 0.1
13069// optimize discard usage
13070#if defined(ALPHA_DISCARD)
13071#if defined(GL_ARB_conservative_depth)
13072layout (depth_greater) out float gl_FragDepth;
13073#endif
13074#endif
13075
13076in vec3 BoxCoord;
13077
13078out vec4 FragColor;
13079
13080vec4 FLWBlockTexture(vec2 texCoords) {
13081 return texture(uBlockAtlas, texCoords);
13082}
13083
13084void FLWFinalizeColor(vec4 color) {
13085 float a = color.a;
13086 float fog = clamp(FLWFogFactor(), 0., 1.);
13087
13088 color = mix(uFogColor, color, fog);
13089 color.a = a;
13090
13091 #if defined(ALPHA_DISCARD)
13092 if (color.a < ALPHA_DISCARD) {
13093 discard;
13094 }
13095 #endif
13096
13097 FragColor = color;
13098}
13099
13100vec4 FLWLight(vec2 lightCoords) {
13101 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
13102
13103 return texture(uLightMap, shiftLight(lightCoords));
13104}
13105
13106#endif
13107
13108
13109float diffuse(vec3 normal) {
13110 vec3 n2 = normal * normal * vec3(.6, .25, .8);
13111 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
13112}
13113struct Vertex {
13114 vec3 pos;
13115 vec2 texCoords;
13116 vec3 normal;
13117};
13118
13119struct BlockFrag {
13120 vec2 texCoords;
13121 vec4 color;
13122 float diffuse;
13123 vec2 light;
13124};
13125
13126#if defined(FRAGMENT_SHADER)
13127void fragment(BlockFrag r) {
13128 vec4 tex = FLWBlockTexture(r.texCoords);
13129
13130 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
13131
13132 FLWFinalizeColor(color);
13133}
13134#endif
13135
13136
13137
13138
13139struct Instance {
13140 vec2 light;
13141 vec4 color;
13142 mat4 transform;
13143 mat3 normalMat;
13144};
13145
13146#if defined(VERTEX_SHADER)
13147BlockFrag vertex(Vertex v, Instance i) {
13148 vec4 worldPos = i.transform * vec4(v.pos, 1.);
13149
13150 vec3 norm = i.normalMat * v.normal;
13151
13152 FLWFinalizeWorldPos(worldPos);
13153 FLWFinalizeNormal(norm);
13154
13155 norm = normalize(norm);
13156
13157 BlockFrag b;
13158 b.diffuse = diffuse(norm);
13159 b.texCoords = v.texCoords;
13160 b.light = i.light;
13161 #if defined(DEBUG_NORMAL)
13162 b.color = vec4(norm, 1.);
13163 #else
13164 b.color = i.color;
13165 #endif
13166 return b;
13167}
13168#endif
13169
13170in vec2 v2f_texCoords;
13171in vec4 v2f_color;
13172in float v2f_diffuse;
13173in vec2 v2f_light;
13174void main() {
13175BlockFrag o;
13176o.texCoords = v2f_texCoords;
13177o.color = v2f_color;
13178o.diffuse = v2f_diffuse;
13179o.light = v2f_light;
13180fragment(o);
13181}
13182[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
13183
13184[17:17:49] [Render thread/ERROR]: #version 150
13185#extension GL_ARB_conservative_depth : enable
13186#define VERTEX_SHADER
13187#define DEBUG_NORMAL
13188#if defined(VERTEX_SHADER)
13189out float FragDistance;
13190#elif defined(FRAGMENT_SHADER)
13191in float FragDistance;
13192#endif
13193uniform vec4 uFogColor;
13194uniform vec2 uFogRange;
13195
13196float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
13197 float distXZ = length(worldPos.xz - cameraPos.xz);
13198 float distY = abs(worldPos.y - cameraPos.y);
13199 return max(distXZ, distY);
13200}
13201
13202float cylindrical_distance(vec3 worldPos) {
13203 float distXZ = length(worldPos.xz);
13204 float distY = abs(worldPos.y);
13205 return max(distXZ, distY);
13206}
13207
13208float FLWFogFactor() {
13209 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
13210}
13211// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
13212vec2 shiftLight(vec2 lm) {
13213 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
13214}
13215
13216
13217uniform sampler3D uLightVolume;
13218
13219uniform sampler2D uBlockAtlas;
13220uniform sampler2D uLightMap;
13221
13222uniform vec3 uLightBoxSize;
13223uniform vec3 uLightBoxMin;
13224uniform mat4 uModel;
13225
13226uniform float uTime;
13227uniform mat4 uViewProjection;
13228uniform vec3 uCameraPos;
13229
13230void FLWFinalizeNormal(inout vec3 normal) {
13231 mat3 m;
13232 m[0] = uModel[0].xyz;
13233 m[1] = uModel[1].xyz;
13234 m[2] = uModel[2].xyz;
13235 normal = m * normal;
13236}
13237
13238#if defined(VERTEX_SHADER)
13239
13240out vec3 BoxCoord;
13241
13242void FLWFinalizeWorldPos(inout vec4 worldPos) {
13243 worldPos = uModel * worldPos;
13244
13245 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
13246
13247 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
13248
13249 gl_Position = uViewProjection * worldPos;
13250}
13251
13252#elif defined(FRAGMENT_SHADER)
13253
13254
13255#define ALPHA_DISCARD 0.1
13256// optimize discard usage
13257#if defined(ALPHA_DISCARD)
13258#if defined(GL_ARB_conservative_depth)
13259layout (depth_greater) out float gl_FragDepth;
13260#endif
13261#endif
13262
13263in vec3 BoxCoord;
13264
13265out vec4 FragColor;
13266
13267vec4 FLWBlockTexture(vec2 texCoords) {
13268 return texture(uBlockAtlas, texCoords);
13269}
13270
13271void FLWFinalizeColor(vec4 color) {
13272 float a = color.a;
13273 float fog = clamp(FLWFogFactor(), 0., 1.);
13274
13275 color = mix(uFogColor, color, fog);
13276 color.a = a;
13277
13278 #if defined(ALPHA_DISCARD)
13279 if (color.a < ALPHA_DISCARD) {
13280 discard;
13281 }
13282 #endif
13283
13284 FragColor = color;
13285}
13286
13287vec4 FLWLight(vec2 lightCoords) {
13288 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
13289
13290 return texture(uLightMap, shiftLight(lightCoords));
13291}
13292
13293#endif
13294
13295
13296float diffuse(vec3 normal) {
13297 vec3 n2 = normal * normal * vec3(.6, .25, .8);
13298 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
13299}
13300struct Vertex {
13301 vec3 pos;
13302 vec2 texCoords;
13303 vec3 normal;
13304};
13305
13306struct BlockFrag {
13307 vec2 texCoords;
13308 vec4 color;
13309 float diffuse;
13310 vec2 light;
13311};
13312
13313#if defined(FRAGMENT_SHADER)
13314void fragment(BlockFrag r) {
13315 vec4 tex = FLWBlockTexture(r.texCoords);
13316
13317 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
13318
13319 FLWFinalizeColor(color);
13320}
13321#endif
13322
13323
13324
13325
13326struct Instance {
13327 vec2 light;
13328 vec4 color;
13329 mat4 transform;
13330 mat3 normalMat;
13331};
13332
13333#if defined(VERTEX_SHADER)
13334BlockFrag vertex(Vertex v, Instance i) {
13335 vec4 worldPos = i.transform * vec4(v.pos, 1.);
13336
13337 vec3 norm = i.normalMat * v.normal;
13338
13339 FLWFinalizeWorldPos(worldPos);
13340 FLWFinalizeNormal(norm);
13341
13342 norm = normalize(norm);
13343
13344 BlockFrag b;
13345 b.diffuse = diffuse(norm);
13346 b.texCoords = v.texCoords;
13347 b.light = i.light;
13348 #if defined(DEBUG_NORMAL)
13349 b.color = vec4(norm, 1.);
13350 #else
13351 b.color = i.color;
13352 #endif
13353 return b;
13354}
13355#endif
13356
13357in vec3 a_v_pos;
13358in vec2 a_v_texCoords;
13359in vec3 a_v_normal;
13360in vec2 a_i_light;
13361in vec4 a_i_color;
13362in mat4 a_i_transform;
13363in mat3 a_i_normalMat;
13364out vec2 v2f_texCoords;
13365out vec4 v2f_color;
13366out float v2f_diffuse;
13367out vec2 v2f_light;
13368void main() {
13369Vertex v;
13370v.pos = a_v_pos;
13371v.texCoords = a_v_texCoords;
13372v.normal = a_v_normal;
13373Instance i;
13374i.light = a_i_light;
13375i.color = a_i_color;
13376i.transform = a_i_transform;
13377i.normalMat = a_i_normalMat;
13378BlockFrag o = vertex(v, i);
13379v2f_texCoords = o.texCoords;
13380v2f_color = o.color;
13381v2f_diffuse = o.diffuse;
13382v2f_light = o.light;
13383}
13384[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:model: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
13385
13386[17:17:49] [Render thread/ERROR]: #version 150
13387#extension GL_ARB_conservative_depth : enable
13388#define FRAGMENT_SHADER
13389#define DEBUG_NORMAL
13390#if defined(VERTEX_SHADER)
13391out float FragDistance;
13392#elif defined(FRAGMENT_SHADER)
13393in float FragDistance;
13394#endif
13395uniform vec4 uFogColor;
13396uniform vec2 uFogRange;
13397
13398float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
13399 float distXZ = length(worldPos.xz - cameraPos.xz);
13400 float distY = abs(worldPos.y - cameraPos.y);
13401 return max(distXZ, distY);
13402}
13403
13404float cylindrical_distance(vec3 worldPos) {
13405 float distXZ = length(worldPos.xz);
13406 float distY = abs(worldPos.y);
13407 return max(distXZ, distY);
13408}
13409
13410float FLWFogFactor() {
13411 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
13412}
13413// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
13414vec2 shiftLight(vec2 lm) {
13415 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
13416}
13417
13418
13419uniform sampler3D uLightVolume;
13420
13421uniform sampler2D uBlockAtlas;
13422uniform sampler2D uLightMap;
13423
13424uniform vec3 uLightBoxSize;
13425uniform vec3 uLightBoxMin;
13426uniform mat4 uModel;
13427
13428uniform float uTime;
13429uniform mat4 uViewProjection;
13430uniform vec3 uCameraPos;
13431
13432void FLWFinalizeNormal(inout vec3 normal) {
13433 mat3 m;
13434 m[0] = uModel[0].xyz;
13435 m[1] = uModel[1].xyz;
13436 m[2] = uModel[2].xyz;
13437 normal = m * normal;
13438}
13439
13440#if defined(VERTEX_SHADER)
13441
13442out vec3 BoxCoord;
13443
13444void FLWFinalizeWorldPos(inout vec4 worldPos) {
13445 worldPos = uModel * worldPos;
13446
13447 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
13448
13449 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
13450
13451 gl_Position = uViewProjection * worldPos;
13452}
13453
13454#elif defined(FRAGMENT_SHADER)
13455
13456
13457#define ALPHA_DISCARD 0.1
13458// optimize discard usage
13459#if defined(ALPHA_DISCARD)
13460#if defined(GL_ARB_conservative_depth)
13461layout (depth_greater) out float gl_FragDepth;
13462#endif
13463#endif
13464
13465in vec3 BoxCoord;
13466
13467out vec4 FragColor;
13468
13469vec4 FLWBlockTexture(vec2 texCoords) {
13470 return texture(uBlockAtlas, texCoords);
13471}
13472
13473void FLWFinalizeColor(vec4 color) {
13474 float a = color.a;
13475 float fog = clamp(FLWFogFactor(), 0., 1.);
13476
13477 color = mix(uFogColor, color, fog);
13478 color.a = a;
13479
13480 #if defined(ALPHA_DISCARD)
13481 if (color.a < ALPHA_DISCARD) {
13482 discard;
13483 }
13484 #endif
13485
13486 FragColor = color;
13487}
13488
13489vec4 FLWLight(vec2 lightCoords) {
13490 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
13491
13492 return texture(uLightMap, shiftLight(lightCoords));
13493}
13494
13495#endif
13496
13497
13498float diffuse(vec3 normal) {
13499 vec3 n2 = normal * normal * vec3(.6, .25, .8);
13500 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
13501}
13502struct Vertex {
13503 vec3 pos;
13504 vec2 texCoords;
13505 vec3 normal;
13506};
13507
13508struct BlockFrag {
13509 vec2 texCoords;
13510 vec4 color;
13511 float diffuse;
13512 vec2 light;
13513};
13514
13515#if defined(FRAGMENT_SHADER)
13516void fragment(BlockFrag r) {
13517 vec4 tex = FLWBlockTexture(r.texCoords);
13518
13519 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
13520
13521 FLWFinalizeColor(color);
13522}
13523#endif
13524
13525
13526
13527
13528struct Instance {
13529 vec2 light;
13530 vec4 color;
13531 mat4 transform;
13532 mat3 normalMat;
13533};
13534
13535#if defined(VERTEX_SHADER)
13536BlockFrag vertex(Vertex v, Instance i) {
13537 vec4 worldPos = i.transform * vec4(v.pos, 1.);
13538
13539 vec3 norm = i.normalMat * v.normal;
13540
13541 FLWFinalizeWorldPos(worldPos);
13542 FLWFinalizeNormal(norm);
13543
13544 norm = normalize(norm);
13545
13546 BlockFrag b;
13547 b.diffuse = diffuse(norm);
13548 b.texCoords = v.texCoords;
13549 b.light = i.light;
13550 #if defined(DEBUG_NORMAL)
13551 b.color = vec4(norm, 1.);
13552 #else
13553 b.color = i.color;
13554 #endif
13555 return b;
13556}
13557#endif
13558
13559in vec2 v2f_texCoords;
13560in vec4 v2f_color;
13561in float v2f_diffuse;
13562in vec2 v2f_light;
13563void main() {
13564BlockFrag o;
13565o.texCoords = v2f_texCoords;
13566o.color = v2f_color;
13567o.diffuse = v2f_diffuse;
13568o.light = v2f_light;
13569fragment(o);
13570}
13571[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
13572
13573[17:17:49] [Render thread/ERROR]: #version 150
13574#extension GL_ARB_conservative_depth : enable
13575#define VERTEX_SHADER
13576#if defined(VERTEX_SHADER)
13577out float FragDistance;
13578#elif defined(FRAGMENT_SHADER)
13579in float FragDistance;
13580#endif
13581uniform vec4 uFogColor;
13582uniform vec2 uFogRange;
13583
13584float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
13585 float distXZ = length(worldPos.xz - cameraPos.xz);
13586 float distY = abs(worldPos.y - cameraPos.y);
13587 return max(distXZ, distY);
13588}
13589
13590float cylindrical_distance(vec3 worldPos) {
13591 float distXZ = length(worldPos.xz);
13592 float distY = abs(worldPos.y);
13593 return max(distXZ, distY);
13594}
13595
13596float FLWFogFactor() {
13597 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
13598}
13599// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
13600vec2 shiftLight(vec2 lm) {
13601 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
13602}
13603
13604
13605uniform sampler3D uLightVolume;
13606
13607uniform sampler2D uBlockAtlas;
13608uniform sampler2D uLightMap;
13609
13610uniform vec3 uLightBoxSize;
13611uniform vec3 uLightBoxMin;
13612uniform mat4 uModel;
13613
13614uniform float uTime;
13615uniform mat4 uViewProjection;
13616uniform vec3 uCameraPos;
13617
13618void FLWFinalizeNormal(inout vec3 normal) {
13619 mat3 m;
13620 m[0] = uModel[0].xyz;
13621 m[1] = uModel[1].xyz;
13622 m[2] = uModel[2].xyz;
13623 normal = m * normal;
13624}
13625
13626#if defined(VERTEX_SHADER)
13627
13628out vec3 BoxCoord;
13629
13630void FLWFinalizeWorldPos(inout vec4 worldPos) {
13631 worldPos = uModel * worldPos;
13632
13633 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
13634
13635 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
13636
13637 gl_Position = uViewProjection * worldPos;
13638}
13639
13640#elif defined(FRAGMENT_SHADER)
13641
13642
13643#define ALPHA_DISCARD 0.1
13644// optimize discard usage
13645#if defined(ALPHA_DISCARD)
13646#if defined(GL_ARB_conservative_depth)
13647layout (depth_greater) out float gl_FragDepth;
13648#endif
13649#endif
13650
13651in vec3 BoxCoord;
13652
13653out vec4 FragColor;
13654
13655vec4 FLWBlockTexture(vec2 texCoords) {
13656 return texture(uBlockAtlas, texCoords);
13657}
13658
13659void FLWFinalizeColor(vec4 color) {
13660 float a = color.a;
13661 float fog = clamp(FLWFogFactor(), 0., 1.);
13662
13663 color = mix(uFogColor, color, fog);
13664 color.a = a;
13665
13666 #if defined(ALPHA_DISCARD)
13667 if (color.a < ALPHA_DISCARD) {
13668 discard;
13669 }
13670 #endif
13671
13672 FragColor = color;
13673}
13674
13675vec4 FLWLight(vec2 lightCoords) {
13676 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
13677
13678 return texture(uLightMap, shiftLight(lightCoords));
13679}
13680
13681#endif
13682
13683
13684#define PIOVER2 1.5707963268
13685
13686vec4 quat(vec3 axis, float angle) {
13687 float halfAngle = angle * PIOVER2 / 180.0;
13688 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
13689 return vec4(axis.xyz * cs.y, cs.x);
13690}
13691
13692vec4 quatMult(vec4 q1, vec4 q2) {
13693 // disgustingly vectorized quaternion multiplication
13694 vec4 a = q1.w * q2.xyzw;
13695 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
13696 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
13697 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
13698
13699 return a + b + c + d;
13700}
13701
13702vec3 rotateVertexByQuat(vec3 v, vec4 q) {
13703 vec3 i = q.xyz;
13704 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
13705}
13706
13707vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
13708 return rotateVertexByQuat(v, quat(axis, angle));
13709}
13710
13711float diffuse(vec3 normal) {
13712 vec3 n2 = normal * normal * vec3(.6, .25, .8);
13713 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
13714}
13715struct Vertex {
13716 vec3 pos;
13717 vec2 texCoords;
13718 vec3 normal;
13719};
13720
13721struct BlockFrag {
13722 vec2 texCoords;
13723 vec4 color;
13724 float diffuse;
13725 vec2 light;
13726};
13727
13728#if defined(FRAGMENT_SHADER)
13729void fragment(BlockFrag r) {
13730 vec4 tex = FLWBlockTexture(r.texCoords);
13731
13732 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
13733
13734 FLWFinalizeColor(color);
13735}
13736#endif
13737
13738
13739
13740
13741
13742
13743struct Oriented {
13744 vec2 light;
13745 vec4 color;
13746 vec3 pos;
13747 vec3 pivot;
13748 vec4 rotation;
13749};
13750
13751#if defined(VERTEX_SHADER)
13752BlockFrag vertex(Vertex v, Oriented o) {
13753 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
13754
13755 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
13756
13757 FLWFinalizeWorldPos(worldPos);
13758 FLWFinalizeNormal(norm);
13759
13760 BlockFrag b;
13761 b.diffuse = diffuse(norm);
13762 b.texCoords = v.texCoords;
13763 b.light = o.light;
13764 #if defined(DEBUG_NORMAL)
13765 b.color = vec4(norm, 1.);
13766 #else
13767 b.color = o.color;
13768 #endif
13769 return b;
13770}
13771#endif
13772
13773in vec3 a_v_pos;
13774in vec2 a_v_texCoords;
13775in vec3 a_v_normal;
13776in vec2 a_i_light;
13777in vec4 a_i_color;
13778in vec3 a_i_pos;
13779in vec3 a_i_pivot;
13780in vec4 a_i_rotation;
13781out vec2 v2f_texCoords;
13782out vec4 v2f_color;
13783out float v2f_diffuse;
13784out vec2 v2f_light;
13785void main() {
13786Vertex v;
13787v.pos = a_v_pos;
13788v.texCoords = a_v_texCoords;
13789v.normal = a_v_normal;
13790Oriented i;
13791i.light = a_i_light;
13792i.color = a_i_color;
13793i.pos = a_i_pos;
13794i.pivot = a_i_pivot;
13795i.rotation = a_i_rotation;
13796BlockFrag o = vertex(v, i);
13797v2f_texCoords = o.texCoords;
13798v2f_color = o.color;
13799v2f_diffuse = o.diffuse;
13800v2f_light = o.light;
13801}
13802[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
13803
13804[17:17:49] [Render thread/ERROR]: #version 150
13805#extension GL_ARB_conservative_depth : enable
13806#define FRAGMENT_SHADER
13807#if defined(VERTEX_SHADER)
13808out float FragDistance;
13809#elif defined(FRAGMENT_SHADER)
13810in float FragDistance;
13811#endif
13812uniform vec4 uFogColor;
13813uniform vec2 uFogRange;
13814
13815float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
13816 float distXZ = length(worldPos.xz - cameraPos.xz);
13817 float distY = abs(worldPos.y - cameraPos.y);
13818 return max(distXZ, distY);
13819}
13820
13821float cylindrical_distance(vec3 worldPos) {
13822 float distXZ = length(worldPos.xz);
13823 float distY = abs(worldPos.y);
13824 return max(distXZ, distY);
13825}
13826
13827float FLWFogFactor() {
13828 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
13829}
13830// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
13831vec2 shiftLight(vec2 lm) {
13832 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
13833}
13834
13835
13836uniform sampler3D uLightVolume;
13837
13838uniform sampler2D uBlockAtlas;
13839uniform sampler2D uLightMap;
13840
13841uniform vec3 uLightBoxSize;
13842uniform vec3 uLightBoxMin;
13843uniform mat4 uModel;
13844
13845uniform float uTime;
13846uniform mat4 uViewProjection;
13847uniform vec3 uCameraPos;
13848
13849void FLWFinalizeNormal(inout vec3 normal) {
13850 mat3 m;
13851 m[0] = uModel[0].xyz;
13852 m[1] = uModel[1].xyz;
13853 m[2] = uModel[2].xyz;
13854 normal = m * normal;
13855}
13856
13857#if defined(VERTEX_SHADER)
13858
13859out vec3 BoxCoord;
13860
13861void FLWFinalizeWorldPos(inout vec4 worldPos) {
13862 worldPos = uModel * worldPos;
13863
13864 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
13865
13866 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
13867
13868 gl_Position = uViewProjection * worldPos;
13869}
13870
13871#elif defined(FRAGMENT_SHADER)
13872
13873
13874#define ALPHA_DISCARD 0.1
13875// optimize discard usage
13876#if defined(ALPHA_DISCARD)
13877#if defined(GL_ARB_conservative_depth)
13878layout (depth_greater) out float gl_FragDepth;
13879#endif
13880#endif
13881
13882in vec3 BoxCoord;
13883
13884out vec4 FragColor;
13885
13886vec4 FLWBlockTexture(vec2 texCoords) {
13887 return texture(uBlockAtlas, texCoords);
13888}
13889
13890void FLWFinalizeColor(vec4 color) {
13891 float a = color.a;
13892 float fog = clamp(FLWFogFactor(), 0., 1.);
13893
13894 color = mix(uFogColor, color, fog);
13895 color.a = a;
13896
13897 #if defined(ALPHA_DISCARD)
13898 if (color.a < ALPHA_DISCARD) {
13899 discard;
13900 }
13901 #endif
13902
13903 FragColor = color;
13904}
13905
13906vec4 FLWLight(vec2 lightCoords) {
13907 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
13908
13909 return texture(uLightMap, shiftLight(lightCoords));
13910}
13911
13912#endif
13913
13914
13915#define PIOVER2 1.5707963268
13916
13917vec4 quat(vec3 axis, float angle) {
13918 float halfAngle = angle * PIOVER2 / 180.0;
13919 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
13920 return vec4(axis.xyz * cs.y, cs.x);
13921}
13922
13923vec4 quatMult(vec4 q1, vec4 q2) {
13924 // disgustingly vectorized quaternion multiplication
13925 vec4 a = q1.w * q2.xyzw;
13926 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
13927 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
13928 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
13929
13930 return a + b + c + d;
13931}
13932
13933vec3 rotateVertexByQuat(vec3 v, vec4 q) {
13934 vec3 i = q.xyz;
13935 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
13936}
13937
13938vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
13939 return rotateVertexByQuat(v, quat(axis, angle));
13940}
13941
13942float diffuse(vec3 normal) {
13943 vec3 n2 = normal * normal * vec3(.6, .25, .8);
13944 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
13945}
13946struct Vertex {
13947 vec3 pos;
13948 vec2 texCoords;
13949 vec3 normal;
13950};
13951
13952struct BlockFrag {
13953 vec2 texCoords;
13954 vec4 color;
13955 float diffuse;
13956 vec2 light;
13957};
13958
13959#if defined(FRAGMENT_SHADER)
13960void fragment(BlockFrag r) {
13961 vec4 tex = FLWBlockTexture(r.texCoords);
13962
13963 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
13964
13965 FLWFinalizeColor(color);
13966}
13967#endif
13968
13969
13970
13971
13972
13973
13974struct Oriented {
13975 vec2 light;
13976 vec4 color;
13977 vec3 pos;
13978 vec3 pivot;
13979 vec4 rotation;
13980};
13981
13982#if defined(VERTEX_SHADER)
13983BlockFrag vertex(Vertex v, Oriented o) {
13984 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
13985
13986 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
13987
13988 FLWFinalizeWorldPos(worldPos);
13989 FLWFinalizeNormal(norm);
13990
13991 BlockFrag b;
13992 b.diffuse = diffuse(norm);
13993 b.texCoords = v.texCoords;
13994 b.light = o.light;
13995 #if defined(DEBUG_NORMAL)
13996 b.color = vec4(norm, 1.);
13997 #else
13998 b.color = o.color;
13999 #endif
14000 return b;
14001}
14002#endif
14003
14004in vec2 v2f_texCoords;
14005in vec4 v2f_color;
14006in float v2f_diffuse;
14007in vec2 v2f_light;
14008void main() {
14009BlockFrag o;
14010o.texCoords = v2f_texCoords;
14011o.color = v2f_color;
14012o.diffuse = v2f_diffuse;
14013o.light = v2f_light;
14014fragment(o);
14015}
14016[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
14017
14018[17:17:49] [Render thread/ERROR]: #version 150
14019#extension GL_ARB_conservative_depth : enable
14020#define VERTEX_SHADER
14021#define DEBUG_NORMAL
14022#if defined(VERTEX_SHADER)
14023out float FragDistance;
14024#elif defined(FRAGMENT_SHADER)
14025in float FragDistance;
14026#endif
14027uniform vec4 uFogColor;
14028uniform vec2 uFogRange;
14029
14030float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
14031 float distXZ = length(worldPos.xz - cameraPos.xz);
14032 float distY = abs(worldPos.y - cameraPos.y);
14033 return max(distXZ, distY);
14034}
14035
14036float cylindrical_distance(vec3 worldPos) {
14037 float distXZ = length(worldPos.xz);
14038 float distY = abs(worldPos.y);
14039 return max(distXZ, distY);
14040}
14041
14042float FLWFogFactor() {
14043 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
14044}
14045// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
14046vec2 shiftLight(vec2 lm) {
14047 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
14048}
14049
14050
14051uniform sampler3D uLightVolume;
14052
14053uniform sampler2D uBlockAtlas;
14054uniform sampler2D uLightMap;
14055
14056uniform vec3 uLightBoxSize;
14057uniform vec3 uLightBoxMin;
14058uniform mat4 uModel;
14059
14060uniform float uTime;
14061uniform mat4 uViewProjection;
14062uniform vec3 uCameraPos;
14063
14064void FLWFinalizeNormal(inout vec3 normal) {
14065 mat3 m;
14066 m[0] = uModel[0].xyz;
14067 m[1] = uModel[1].xyz;
14068 m[2] = uModel[2].xyz;
14069 normal = m * normal;
14070}
14071
14072#if defined(VERTEX_SHADER)
14073
14074out vec3 BoxCoord;
14075
14076void FLWFinalizeWorldPos(inout vec4 worldPos) {
14077 worldPos = uModel * worldPos;
14078
14079 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
14080
14081 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
14082
14083 gl_Position = uViewProjection * worldPos;
14084}
14085
14086#elif defined(FRAGMENT_SHADER)
14087
14088
14089#define ALPHA_DISCARD 0.1
14090// optimize discard usage
14091#if defined(ALPHA_DISCARD)
14092#if defined(GL_ARB_conservative_depth)
14093layout (depth_greater) out float gl_FragDepth;
14094#endif
14095#endif
14096
14097in vec3 BoxCoord;
14098
14099out vec4 FragColor;
14100
14101vec4 FLWBlockTexture(vec2 texCoords) {
14102 return texture(uBlockAtlas, texCoords);
14103}
14104
14105void FLWFinalizeColor(vec4 color) {
14106 float a = color.a;
14107 float fog = clamp(FLWFogFactor(), 0., 1.);
14108
14109 color = mix(uFogColor, color, fog);
14110 color.a = a;
14111
14112 #if defined(ALPHA_DISCARD)
14113 if (color.a < ALPHA_DISCARD) {
14114 discard;
14115 }
14116 #endif
14117
14118 FragColor = color;
14119}
14120
14121vec4 FLWLight(vec2 lightCoords) {
14122 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
14123
14124 return texture(uLightMap, shiftLight(lightCoords));
14125}
14126
14127#endif
14128
14129
14130#define PIOVER2 1.5707963268
14131
14132vec4 quat(vec3 axis, float angle) {
14133 float halfAngle = angle * PIOVER2 / 180.0;
14134 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
14135 return vec4(axis.xyz * cs.y, cs.x);
14136}
14137
14138vec4 quatMult(vec4 q1, vec4 q2) {
14139 // disgustingly vectorized quaternion multiplication
14140 vec4 a = q1.w * q2.xyzw;
14141 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
14142 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
14143 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
14144
14145 return a + b + c + d;
14146}
14147
14148vec3 rotateVertexByQuat(vec3 v, vec4 q) {
14149 vec3 i = q.xyz;
14150 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
14151}
14152
14153vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
14154 return rotateVertexByQuat(v, quat(axis, angle));
14155}
14156
14157float diffuse(vec3 normal) {
14158 vec3 n2 = normal * normal * vec3(.6, .25, .8);
14159 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
14160}
14161struct Vertex {
14162 vec3 pos;
14163 vec2 texCoords;
14164 vec3 normal;
14165};
14166
14167struct BlockFrag {
14168 vec2 texCoords;
14169 vec4 color;
14170 float diffuse;
14171 vec2 light;
14172};
14173
14174#if defined(FRAGMENT_SHADER)
14175void fragment(BlockFrag r) {
14176 vec4 tex = FLWBlockTexture(r.texCoords);
14177
14178 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
14179
14180 FLWFinalizeColor(color);
14181}
14182#endif
14183
14184
14185
14186
14187
14188
14189struct Oriented {
14190 vec2 light;
14191 vec4 color;
14192 vec3 pos;
14193 vec3 pivot;
14194 vec4 rotation;
14195};
14196
14197#if defined(VERTEX_SHADER)
14198BlockFrag vertex(Vertex v, Oriented o) {
14199 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
14200
14201 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
14202
14203 FLWFinalizeWorldPos(worldPos);
14204 FLWFinalizeNormal(norm);
14205
14206 BlockFrag b;
14207 b.diffuse = diffuse(norm);
14208 b.texCoords = v.texCoords;
14209 b.light = o.light;
14210 #if defined(DEBUG_NORMAL)
14211 b.color = vec4(norm, 1.);
14212 #else
14213 b.color = o.color;
14214 #endif
14215 return b;
14216}
14217#endif
14218
14219in vec3 a_v_pos;
14220in vec2 a_v_texCoords;
14221in vec3 a_v_normal;
14222in vec2 a_i_light;
14223in vec4 a_i_color;
14224in vec3 a_i_pos;
14225in vec3 a_i_pivot;
14226in vec4 a_i_rotation;
14227out vec2 v2f_texCoords;
14228out vec4 v2f_color;
14229out float v2f_diffuse;
14230out vec2 v2f_light;
14231void main() {
14232Vertex v;
14233v.pos = a_v_pos;
14234v.texCoords = a_v_texCoords;
14235v.normal = a_v_normal;
14236Oriented i;
14237i.light = a_i_light;
14238i.color = a_i_color;
14239i.pos = a_i_pos;
14240i.pivot = a_i_pivot;
14241i.rotation = a_i_rotation;
14242BlockFrag o = vertex(v, i);
14243v2f_texCoords = o.texCoords;
14244v2f_color = o.color;
14245v2f_diffuse = o.diffuse;
14246v2f_light = o.light;
14247}
14248[17:17:49] [Render thread/ERROR]: Shader compilation log for flywheel:oriented: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
14249
14250[17:17:49] [Render thread/ERROR]: #version 150
14251#extension GL_ARB_conservative_depth : enable
14252#define FRAGMENT_SHADER
14253#define DEBUG_NORMAL
14254#if defined(VERTEX_SHADER)
14255out float FragDistance;
14256#elif defined(FRAGMENT_SHADER)
14257in float FragDistance;
14258#endif
14259uniform vec4 uFogColor;
14260uniform vec2 uFogRange;
14261
14262float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
14263 float distXZ = length(worldPos.xz - cameraPos.xz);
14264 float distY = abs(worldPos.y - cameraPos.y);
14265 return max(distXZ, distY);
14266}
14267
14268float cylindrical_distance(vec3 worldPos) {
14269 float distXZ = length(worldPos.xz);
14270 float distY = abs(worldPos.y);
14271 return max(distXZ, distY);
14272}
14273
14274float FLWFogFactor() {
14275 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
14276}
14277// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
14278vec2 shiftLight(vec2 lm) {
14279 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
14280}
14281
14282
14283uniform sampler3D uLightVolume;
14284
14285uniform sampler2D uBlockAtlas;
14286uniform sampler2D uLightMap;
14287
14288uniform vec3 uLightBoxSize;
14289uniform vec3 uLightBoxMin;
14290uniform mat4 uModel;
14291
14292uniform float uTime;
14293uniform mat4 uViewProjection;
14294uniform vec3 uCameraPos;
14295
14296void FLWFinalizeNormal(inout vec3 normal) {
14297 mat3 m;
14298 m[0] = uModel[0].xyz;
14299 m[1] = uModel[1].xyz;
14300 m[2] = uModel[2].xyz;
14301 normal = m * normal;
14302}
14303
14304#if defined(VERTEX_SHADER)
14305
14306out vec3 BoxCoord;
14307
14308void FLWFinalizeWorldPos(inout vec4 worldPos) {
14309 worldPos = uModel * worldPos;
14310
14311 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
14312
14313 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
14314
14315 gl_Position = uViewProjection * worldPos;
14316}
14317
14318#elif defined(FRAGMENT_SHADER)
14319
14320
14321#define ALPHA_DISCARD 0.1
14322// optimize discard usage
14323#if defined(ALPHA_DISCARD)
14324#if defined(GL_ARB_conservative_depth)
14325layout (depth_greater) out float gl_FragDepth;
14326#endif
14327#endif
14328
14329in vec3 BoxCoord;
14330
14331out vec4 FragColor;
14332
14333vec4 FLWBlockTexture(vec2 texCoords) {
14334 return texture(uBlockAtlas, texCoords);
14335}
14336
14337void FLWFinalizeColor(vec4 color) {
14338 float a = color.a;
14339 float fog = clamp(FLWFogFactor(), 0., 1.);
14340
14341 color = mix(uFogColor, color, fog);
14342 color.a = a;
14343
14344 #if defined(ALPHA_DISCARD)
14345 if (color.a < ALPHA_DISCARD) {
14346 discard;
14347 }
14348 #endif
14349
14350 FragColor = color;
14351}
14352
14353vec4 FLWLight(vec2 lightCoords) {
14354 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
14355
14356 return texture(uLightMap, shiftLight(lightCoords));
14357}
14358
14359#endif
14360
14361
14362#define PIOVER2 1.5707963268
14363
14364vec4 quat(vec3 axis, float angle) {
14365 float halfAngle = angle * PIOVER2 / 180.0;
14366 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
14367 return vec4(axis.xyz * cs.y, cs.x);
14368}
14369
14370vec4 quatMult(vec4 q1, vec4 q2) {
14371 // disgustingly vectorized quaternion multiplication
14372 vec4 a = q1.w * q2.xyzw;
14373 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
14374 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
14375 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
14376
14377 return a + b + c + d;
14378}
14379
14380vec3 rotateVertexByQuat(vec3 v, vec4 q) {
14381 vec3 i = q.xyz;
14382 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
14383}
14384
14385vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
14386 return rotateVertexByQuat(v, quat(axis, angle));
14387}
14388
14389float diffuse(vec3 normal) {
14390 vec3 n2 = normal * normal * vec3(.6, .25, .8);
14391 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
14392}
14393struct Vertex {
14394 vec3 pos;
14395 vec2 texCoords;
14396 vec3 normal;
14397};
14398
14399struct BlockFrag {
14400 vec2 texCoords;
14401 vec4 color;
14402 float diffuse;
14403 vec2 light;
14404};
14405
14406#if defined(FRAGMENT_SHADER)
14407void fragment(BlockFrag r) {
14408 vec4 tex = FLWBlockTexture(r.texCoords);
14409
14410 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
14411
14412 FLWFinalizeColor(color);
14413}
14414#endif
14415
14416
14417
14418
14419
14420
14421struct Oriented {
14422 vec2 light;
14423 vec4 color;
14424 vec3 pos;
14425 vec3 pivot;
14426 vec4 rotation;
14427};
14428
14429#if defined(VERTEX_SHADER)
14430BlockFrag vertex(Vertex v, Oriented o) {
14431 vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
14432
14433 vec3 norm = rotateVertexByQuat(v.normal, o.rotation);
14434
14435 FLWFinalizeWorldPos(worldPos);
14436 FLWFinalizeNormal(norm);
14437
14438 BlockFrag b;
14439 b.diffuse = diffuse(norm);
14440 b.texCoords = v.texCoords;
14441 b.light = o.light;
14442 #if defined(DEBUG_NORMAL)
14443 b.color = vec4(norm, 1.);
14444 #else
14445 b.color = o.color;
14446 #endif
14447 return b;
14448}
14449#endif
14450
14451in vec2 v2f_texCoords;
14452in vec4 v2f_color;
14453in float v2f_diffuse;
14454in vec2 v2f_light;
14455void main() {
14456BlockFrag o;
14457o.texCoords = v2f_texCoords;
14458o.color = v2f_color;
14459o.diffuse = v2f_diffuse;
14460o.light = v2f_light;
14461fragment(o);
14462}
14463[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
14464
14465[17:17:49] [Render thread/ERROR]: #version 150
14466#extension GL_ARB_conservative_depth : enable
14467#define VERTEX_SHADER
14468#if defined(VERTEX_SHADER)
14469out float FragDistance;
14470#elif defined(FRAGMENT_SHADER)
14471in float FragDistance;
14472#endif
14473uniform vec4 uFogColor;
14474uniform vec2 uFogRange;
14475
14476float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
14477 float distXZ = length(worldPos.xz - cameraPos.xz);
14478 float distY = abs(worldPos.y - cameraPos.y);
14479 return max(distXZ, distY);
14480}
14481
14482float cylindrical_distance(vec3 worldPos) {
14483 float distXZ = length(worldPos.xz);
14484 float distY = abs(worldPos.y);
14485 return max(distXZ, distY);
14486}
14487
14488float FLWFogFactor() {
14489 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
14490}
14491// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
14492vec2 shiftLight(vec2 lm) {
14493 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
14494}
14495
14496
14497uniform sampler3D uLightVolume;
14498
14499uniform sampler2D uBlockAtlas;
14500uniform sampler2D uLightMap;
14501
14502uniform vec3 uLightBoxSize;
14503uniform vec3 uLightBoxMin;
14504uniform mat4 uModel;
14505
14506uniform float uTime;
14507uniform mat4 uViewProjection;
14508uniform vec3 uCameraPos;
14509
14510void FLWFinalizeNormal(inout vec3 normal) {
14511 mat3 m;
14512 m[0] = uModel[0].xyz;
14513 m[1] = uModel[1].xyz;
14514 m[2] = uModel[2].xyz;
14515 normal = m * normal;
14516}
14517
14518#if defined(VERTEX_SHADER)
14519
14520out vec3 BoxCoord;
14521
14522void FLWFinalizeWorldPos(inout vec4 worldPos) {
14523 worldPos = uModel * worldPos;
14524
14525 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
14526
14527 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
14528
14529 gl_Position = uViewProjection * worldPos;
14530}
14531
14532#elif defined(FRAGMENT_SHADER)
14533
14534
14535#define ALPHA_DISCARD 0.1
14536// optimize discard usage
14537#if defined(ALPHA_DISCARD)
14538#if defined(GL_ARB_conservative_depth)
14539layout (depth_greater) out float gl_FragDepth;
14540#endif
14541#endif
14542
14543in vec3 BoxCoord;
14544
14545out vec4 FragColor;
14546
14547vec4 FLWBlockTexture(vec2 texCoords) {
14548 return texture(uBlockAtlas, texCoords);
14549}
14550
14551void FLWFinalizeColor(vec4 color) {
14552 float a = color.a;
14553 float fog = clamp(FLWFogFactor(), 0., 1.);
14554
14555 color = mix(uFogColor, color, fog);
14556 color.a = a;
14557
14558 #if defined(ALPHA_DISCARD)
14559 if (color.a < ALPHA_DISCARD) {
14560 discard;
14561 }
14562 #endif
14563
14564 FragColor = color;
14565}
14566
14567vec4 FLWLight(vec2 lightCoords) {
14568 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
14569
14570 return texture(uLightMap, shiftLight(lightCoords));
14571}
14572
14573#endif
14574
14575
14576mat4 rotate(vec3 axis, float angle) {
14577 float s = sin(angle);
14578 float c = cos(angle);
14579 float oc = 1. - c;
14580
14581 vec3 sa = axis * s;
14582
14583 mat4 mr = mat4(1.);
14584 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
14585 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
14586 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
14587
14588 return mr;
14589}
14590
14591mat4 rotation(vec3 rot) {
14592 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
14593}
14594
14595mat3 modelToNormal(mat4 mat) {
14596 // Discard the edges. This won't be accurate for scaled or skewed matrices,
14597 // but we don't have to work with those often.
14598 mat3 m;
14599 m[0] = mat[0].xyz;
14600 m[1] = mat[1].xyz;
14601 m[2] = mat[2].xyz;
14602 return m;
14603}
14604
14605float diffuse(vec3 normal) {
14606 vec3 n2 = normal * normal * vec3(.6, .25, .8);
14607 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
14608}
14609struct Vertex {
14610 vec3 pos;
14611 vec2 texCoords;
14612 vec3 normal;
14613};
14614
14615struct BlockFrag {
14616 vec2 texCoords;
14617 vec4 color;
14618 float diffuse;
14619 vec2 light;
14620};
14621
14622#if defined(FRAGMENT_SHADER)
14623void fragment(BlockFrag r) {
14624 vec4 tex = FLWBlockTexture(r.texCoords);
14625
14626 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
14627
14628 FLWFinalizeColor(color);
14629}
14630#endif
14631#define PI 3.1415926538
14632
14633
14634
14635
14636struct Rotating {
14637 vec2 light;
14638 vec4 color;
14639 vec3 pos;
14640 float speed;
14641 float offset;
14642 vec3 axis;
14643};
14644
14645
14646
14647
14648mat4 kineticRotation(float offset, float speed, vec3 axis) {
14649 float degrees = offset + uTime * speed * 3./10.;
14650 float angle = fract(degrees / 360.) * PI * 2.;
14651
14652 return rotate(axis, angle);
14653}
14654
14655#if defined(VERTEX_SHADER)
14656BlockFrag vertex(Vertex v, Rotating instance) {
14657 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
14658
14659 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
14660 worldPos += vec4(instance.pos + .5, 0.);
14661
14662 vec3 norm = modelToNormal(spin) * v.normal;
14663
14664 FLWFinalizeWorldPos(worldPos);
14665 FLWFinalizeNormal(norm);
14666
14667 BlockFrag b;
14668 b.diffuse = diffuse(norm);
14669 b.texCoords = v.texCoords;
14670 b.light = instance.light;
14671
14672 #if defined(DEBUG_RAINBOW)
14673 b.color = instance.color;
14674 #elif defined(DEBUG_NORMAL)
14675 b.color = vec4(norm, 1.);
14676 #else
14677 b.color = vec4(1.);
14678 #endif
14679
14680 return b;
14681}
14682#endif
14683
14684in vec3 a_v_pos;
14685in vec2 a_v_texCoords;
14686in vec3 a_v_normal;
14687in vec2 a_i_light;
14688in vec4 a_i_color;
14689in vec3 a_i_pos;
14690in float a_i_speed;
14691in float a_i_offset;
14692in vec3 a_i_axis;
14693out vec2 v2f_texCoords;
14694out vec4 v2f_color;
14695out float v2f_diffuse;
14696out vec2 v2f_light;
14697void main() {
14698Vertex v;
14699v.pos = a_v_pos;
14700v.texCoords = a_v_texCoords;
14701v.normal = a_v_normal;
14702Rotating i;
14703i.light = a_i_light;
14704i.color = a_i_color;
14705i.pos = a_i_pos;
14706i.speed = a_i_speed;
14707i.offset = a_i_offset;
14708i.axis = a_i_axis;
14709BlockFrag o = vertex(v, i);
14710v2f_texCoords = o.texCoords;
14711v2f_color = o.color;
14712v2f_diffuse = o.diffuse;
14713v2f_light = o.light;
14714}
14715[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
14716
14717[17:17:49] [Render thread/ERROR]: #version 150
14718#extension GL_ARB_conservative_depth : enable
14719#define FRAGMENT_SHADER
14720#if defined(VERTEX_SHADER)
14721out float FragDistance;
14722#elif defined(FRAGMENT_SHADER)
14723in float FragDistance;
14724#endif
14725uniform vec4 uFogColor;
14726uniform vec2 uFogRange;
14727
14728float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
14729 float distXZ = length(worldPos.xz - cameraPos.xz);
14730 float distY = abs(worldPos.y - cameraPos.y);
14731 return max(distXZ, distY);
14732}
14733
14734float cylindrical_distance(vec3 worldPos) {
14735 float distXZ = length(worldPos.xz);
14736 float distY = abs(worldPos.y);
14737 return max(distXZ, distY);
14738}
14739
14740float FLWFogFactor() {
14741 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
14742}
14743// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
14744vec2 shiftLight(vec2 lm) {
14745 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
14746}
14747
14748
14749uniform sampler3D uLightVolume;
14750
14751uniform sampler2D uBlockAtlas;
14752uniform sampler2D uLightMap;
14753
14754uniform vec3 uLightBoxSize;
14755uniform vec3 uLightBoxMin;
14756uniform mat4 uModel;
14757
14758uniform float uTime;
14759uniform mat4 uViewProjection;
14760uniform vec3 uCameraPos;
14761
14762void FLWFinalizeNormal(inout vec3 normal) {
14763 mat3 m;
14764 m[0] = uModel[0].xyz;
14765 m[1] = uModel[1].xyz;
14766 m[2] = uModel[2].xyz;
14767 normal = m * normal;
14768}
14769
14770#if defined(VERTEX_SHADER)
14771
14772out vec3 BoxCoord;
14773
14774void FLWFinalizeWorldPos(inout vec4 worldPos) {
14775 worldPos = uModel * worldPos;
14776
14777 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
14778
14779 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
14780
14781 gl_Position = uViewProjection * worldPos;
14782}
14783
14784#elif defined(FRAGMENT_SHADER)
14785
14786
14787#define ALPHA_DISCARD 0.1
14788// optimize discard usage
14789#if defined(ALPHA_DISCARD)
14790#if defined(GL_ARB_conservative_depth)
14791layout (depth_greater) out float gl_FragDepth;
14792#endif
14793#endif
14794
14795in vec3 BoxCoord;
14796
14797out vec4 FragColor;
14798
14799vec4 FLWBlockTexture(vec2 texCoords) {
14800 return texture(uBlockAtlas, texCoords);
14801}
14802
14803void FLWFinalizeColor(vec4 color) {
14804 float a = color.a;
14805 float fog = clamp(FLWFogFactor(), 0., 1.);
14806
14807 color = mix(uFogColor, color, fog);
14808 color.a = a;
14809
14810 #if defined(ALPHA_DISCARD)
14811 if (color.a < ALPHA_DISCARD) {
14812 discard;
14813 }
14814 #endif
14815
14816 FragColor = color;
14817}
14818
14819vec4 FLWLight(vec2 lightCoords) {
14820 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
14821
14822 return texture(uLightMap, shiftLight(lightCoords));
14823}
14824
14825#endif
14826
14827
14828mat4 rotate(vec3 axis, float angle) {
14829 float s = sin(angle);
14830 float c = cos(angle);
14831 float oc = 1. - c;
14832
14833 vec3 sa = axis * s;
14834
14835 mat4 mr = mat4(1.);
14836 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
14837 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
14838 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
14839
14840 return mr;
14841}
14842
14843mat4 rotation(vec3 rot) {
14844 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
14845}
14846
14847mat3 modelToNormal(mat4 mat) {
14848 // Discard the edges. This won't be accurate for scaled or skewed matrices,
14849 // but we don't have to work with those often.
14850 mat3 m;
14851 m[0] = mat[0].xyz;
14852 m[1] = mat[1].xyz;
14853 m[2] = mat[2].xyz;
14854 return m;
14855}
14856
14857float diffuse(vec3 normal) {
14858 vec3 n2 = normal * normal * vec3(.6, .25, .8);
14859 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
14860}
14861struct Vertex {
14862 vec3 pos;
14863 vec2 texCoords;
14864 vec3 normal;
14865};
14866
14867struct BlockFrag {
14868 vec2 texCoords;
14869 vec4 color;
14870 float diffuse;
14871 vec2 light;
14872};
14873
14874#if defined(FRAGMENT_SHADER)
14875void fragment(BlockFrag r) {
14876 vec4 tex = FLWBlockTexture(r.texCoords);
14877
14878 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
14879
14880 FLWFinalizeColor(color);
14881}
14882#endif
14883#define PI 3.1415926538
14884
14885
14886
14887
14888struct Rotating {
14889 vec2 light;
14890 vec4 color;
14891 vec3 pos;
14892 float speed;
14893 float offset;
14894 vec3 axis;
14895};
14896
14897
14898
14899
14900mat4 kineticRotation(float offset, float speed, vec3 axis) {
14901 float degrees = offset + uTime * speed * 3./10.;
14902 float angle = fract(degrees / 360.) * PI * 2.;
14903
14904 return rotate(axis, angle);
14905}
14906
14907#if defined(VERTEX_SHADER)
14908BlockFrag vertex(Vertex v, Rotating instance) {
14909 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
14910
14911 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
14912 worldPos += vec4(instance.pos + .5, 0.);
14913
14914 vec3 norm = modelToNormal(spin) * v.normal;
14915
14916 FLWFinalizeWorldPos(worldPos);
14917 FLWFinalizeNormal(norm);
14918
14919 BlockFrag b;
14920 b.diffuse = diffuse(norm);
14921 b.texCoords = v.texCoords;
14922 b.light = instance.light;
14923
14924 #if defined(DEBUG_RAINBOW)
14925 b.color = instance.color;
14926 #elif defined(DEBUG_NORMAL)
14927 b.color = vec4(norm, 1.);
14928 #else
14929 b.color = vec4(1.);
14930 #endif
14931
14932 return b;
14933}
14934#endif
14935
14936in vec2 v2f_texCoords;
14937in vec4 v2f_color;
14938in float v2f_diffuse;
14939in vec2 v2f_light;
14940void main() {
14941BlockFrag o;
14942o.texCoords = v2f_texCoords;
14943o.color = v2f_color;
14944o.diffuse = v2f_diffuse;
14945o.light = v2f_light;
14946fragment(o);
14947}
14948[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
14949
14950[17:17:49] [Render thread/ERROR]: #version 150
14951#extension GL_ARB_conservative_depth : enable
14952#define VERTEX_SHADER
14953#define DEBUG_RAINBOW
14954#if defined(VERTEX_SHADER)
14955out float FragDistance;
14956#elif defined(FRAGMENT_SHADER)
14957in float FragDistance;
14958#endif
14959uniform vec4 uFogColor;
14960uniform vec2 uFogRange;
14961
14962float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
14963 float distXZ = length(worldPos.xz - cameraPos.xz);
14964 float distY = abs(worldPos.y - cameraPos.y);
14965 return max(distXZ, distY);
14966}
14967
14968float cylindrical_distance(vec3 worldPos) {
14969 float distXZ = length(worldPos.xz);
14970 float distY = abs(worldPos.y);
14971 return max(distXZ, distY);
14972}
14973
14974float FLWFogFactor() {
14975 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
14976}
14977// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
14978vec2 shiftLight(vec2 lm) {
14979 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
14980}
14981
14982
14983uniform sampler3D uLightVolume;
14984
14985uniform sampler2D uBlockAtlas;
14986uniform sampler2D uLightMap;
14987
14988uniform vec3 uLightBoxSize;
14989uniform vec3 uLightBoxMin;
14990uniform mat4 uModel;
14991
14992uniform float uTime;
14993uniform mat4 uViewProjection;
14994uniform vec3 uCameraPos;
14995
14996void FLWFinalizeNormal(inout vec3 normal) {
14997 mat3 m;
14998 m[0] = uModel[0].xyz;
14999 m[1] = uModel[1].xyz;
15000 m[2] = uModel[2].xyz;
15001 normal = m * normal;
15002}
15003
15004#if defined(VERTEX_SHADER)
15005
15006out vec3 BoxCoord;
15007
15008void FLWFinalizeWorldPos(inout vec4 worldPos) {
15009 worldPos = uModel * worldPos;
15010
15011 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
15012
15013 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
15014
15015 gl_Position = uViewProjection * worldPos;
15016}
15017
15018#elif defined(FRAGMENT_SHADER)
15019
15020
15021#define ALPHA_DISCARD 0.1
15022// optimize discard usage
15023#if defined(ALPHA_DISCARD)
15024#if defined(GL_ARB_conservative_depth)
15025layout (depth_greater) out float gl_FragDepth;
15026#endif
15027#endif
15028
15029in vec3 BoxCoord;
15030
15031out vec4 FragColor;
15032
15033vec4 FLWBlockTexture(vec2 texCoords) {
15034 return texture(uBlockAtlas, texCoords);
15035}
15036
15037void FLWFinalizeColor(vec4 color) {
15038 float a = color.a;
15039 float fog = clamp(FLWFogFactor(), 0., 1.);
15040
15041 color = mix(uFogColor, color, fog);
15042 color.a = a;
15043
15044 #if defined(ALPHA_DISCARD)
15045 if (color.a < ALPHA_DISCARD) {
15046 discard;
15047 }
15048 #endif
15049
15050 FragColor = color;
15051}
15052
15053vec4 FLWLight(vec2 lightCoords) {
15054 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
15055
15056 return texture(uLightMap, shiftLight(lightCoords));
15057}
15058
15059#endif
15060
15061
15062mat4 rotate(vec3 axis, float angle) {
15063 float s = sin(angle);
15064 float c = cos(angle);
15065 float oc = 1. - c;
15066
15067 vec3 sa = axis * s;
15068
15069 mat4 mr = mat4(1.);
15070 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
15071 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
15072 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
15073
15074 return mr;
15075}
15076
15077mat4 rotation(vec3 rot) {
15078 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
15079}
15080
15081mat3 modelToNormal(mat4 mat) {
15082 // Discard the edges. This won't be accurate for scaled or skewed matrices,
15083 // but we don't have to work with those often.
15084 mat3 m;
15085 m[0] = mat[0].xyz;
15086 m[1] = mat[1].xyz;
15087 m[2] = mat[2].xyz;
15088 return m;
15089}
15090
15091float diffuse(vec3 normal) {
15092 vec3 n2 = normal * normal * vec3(.6, .25, .8);
15093 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
15094}
15095struct Vertex {
15096 vec3 pos;
15097 vec2 texCoords;
15098 vec3 normal;
15099};
15100
15101struct BlockFrag {
15102 vec2 texCoords;
15103 vec4 color;
15104 float diffuse;
15105 vec2 light;
15106};
15107
15108#if defined(FRAGMENT_SHADER)
15109void fragment(BlockFrag r) {
15110 vec4 tex = FLWBlockTexture(r.texCoords);
15111
15112 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
15113
15114 FLWFinalizeColor(color);
15115}
15116#endif
15117#define PI 3.1415926538
15118
15119
15120
15121
15122struct Rotating {
15123 vec2 light;
15124 vec4 color;
15125 vec3 pos;
15126 float speed;
15127 float offset;
15128 vec3 axis;
15129};
15130
15131
15132
15133
15134mat4 kineticRotation(float offset, float speed, vec3 axis) {
15135 float degrees = offset + uTime * speed * 3./10.;
15136 float angle = fract(degrees / 360.) * PI * 2.;
15137
15138 return rotate(axis, angle);
15139}
15140
15141#if defined(VERTEX_SHADER)
15142BlockFrag vertex(Vertex v, Rotating instance) {
15143 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
15144
15145 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
15146 worldPos += vec4(instance.pos + .5, 0.);
15147
15148 vec3 norm = modelToNormal(spin) * v.normal;
15149
15150 FLWFinalizeWorldPos(worldPos);
15151 FLWFinalizeNormal(norm);
15152
15153 BlockFrag b;
15154 b.diffuse = diffuse(norm);
15155 b.texCoords = v.texCoords;
15156 b.light = instance.light;
15157
15158 #if defined(DEBUG_RAINBOW)
15159 b.color = instance.color;
15160 #elif defined(DEBUG_NORMAL)
15161 b.color = vec4(norm, 1.);
15162 #else
15163 b.color = vec4(1.);
15164 #endif
15165
15166 return b;
15167}
15168#endif
15169
15170in vec3 a_v_pos;
15171in vec2 a_v_texCoords;
15172in vec3 a_v_normal;
15173in vec2 a_i_light;
15174in vec4 a_i_color;
15175in vec3 a_i_pos;
15176in float a_i_speed;
15177in float a_i_offset;
15178in vec3 a_i_axis;
15179out vec2 v2f_texCoords;
15180out vec4 v2f_color;
15181out float v2f_diffuse;
15182out vec2 v2f_light;
15183void main() {
15184Vertex v;
15185v.pos = a_v_pos;
15186v.texCoords = a_v_texCoords;
15187v.normal = a_v_normal;
15188Rotating i;
15189i.light = a_i_light;
15190i.color = a_i_color;
15191i.pos = a_i_pos;
15192i.speed = a_i_speed;
15193i.offset = a_i_offset;
15194i.axis = a_i_axis;
15195BlockFrag o = vertex(v, i);
15196v2f_texCoords = o.texCoords;
15197v2f_color = o.color;
15198v2f_diffuse = o.diffuse;
15199v2f_light = o.light;
15200}
15201[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
15202
15203[17:17:49] [Render thread/ERROR]: #version 150
15204#extension GL_ARB_conservative_depth : enable
15205#define FRAGMENT_SHADER
15206#define DEBUG_RAINBOW
15207#if defined(VERTEX_SHADER)
15208out float FragDistance;
15209#elif defined(FRAGMENT_SHADER)
15210in float FragDistance;
15211#endif
15212uniform vec4 uFogColor;
15213uniform vec2 uFogRange;
15214
15215float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
15216 float distXZ = length(worldPos.xz - cameraPos.xz);
15217 float distY = abs(worldPos.y - cameraPos.y);
15218 return max(distXZ, distY);
15219}
15220
15221float cylindrical_distance(vec3 worldPos) {
15222 float distXZ = length(worldPos.xz);
15223 float distY = abs(worldPos.y);
15224 return max(distXZ, distY);
15225}
15226
15227float FLWFogFactor() {
15228 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
15229}
15230// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
15231vec2 shiftLight(vec2 lm) {
15232 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
15233}
15234
15235
15236uniform sampler3D uLightVolume;
15237
15238uniform sampler2D uBlockAtlas;
15239uniform sampler2D uLightMap;
15240
15241uniform vec3 uLightBoxSize;
15242uniform vec3 uLightBoxMin;
15243uniform mat4 uModel;
15244
15245uniform float uTime;
15246uniform mat4 uViewProjection;
15247uniform vec3 uCameraPos;
15248
15249void FLWFinalizeNormal(inout vec3 normal) {
15250 mat3 m;
15251 m[0] = uModel[0].xyz;
15252 m[1] = uModel[1].xyz;
15253 m[2] = uModel[2].xyz;
15254 normal = m * normal;
15255}
15256
15257#if defined(VERTEX_SHADER)
15258
15259out vec3 BoxCoord;
15260
15261void FLWFinalizeWorldPos(inout vec4 worldPos) {
15262 worldPos = uModel * worldPos;
15263
15264 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
15265
15266 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
15267
15268 gl_Position = uViewProjection * worldPos;
15269}
15270
15271#elif defined(FRAGMENT_SHADER)
15272
15273
15274#define ALPHA_DISCARD 0.1
15275// optimize discard usage
15276#if defined(ALPHA_DISCARD)
15277#if defined(GL_ARB_conservative_depth)
15278layout (depth_greater) out float gl_FragDepth;
15279#endif
15280#endif
15281
15282in vec3 BoxCoord;
15283
15284out vec4 FragColor;
15285
15286vec4 FLWBlockTexture(vec2 texCoords) {
15287 return texture(uBlockAtlas, texCoords);
15288}
15289
15290void FLWFinalizeColor(vec4 color) {
15291 float a = color.a;
15292 float fog = clamp(FLWFogFactor(), 0., 1.);
15293
15294 color = mix(uFogColor, color, fog);
15295 color.a = a;
15296
15297 #if defined(ALPHA_DISCARD)
15298 if (color.a < ALPHA_DISCARD) {
15299 discard;
15300 }
15301 #endif
15302
15303 FragColor = color;
15304}
15305
15306vec4 FLWLight(vec2 lightCoords) {
15307 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
15308
15309 return texture(uLightMap, shiftLight(lightCoords));
15310}
15311
15312#endif
15313
15314
15315mat4 rotate(vec3 axis, float angle) {
15316 float s = sin(angle);
15317 float c = cos(angle);
15318 float oc = 1. - c;
15319
15320 vec3 sa = axis * s;
15321
15322 mat4 mr = mat4(1.);
15323 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
15324 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
15325 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
15326
15327 return mr;
15328}
15329
15330mat4 rotation(vec3 rot) {
15331 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
15332}
15333
15334mat3 modelToNormal(mat4 mat) {
15335 // Discard the edges. This won't be accurate for scaled or skewed matrices,
15336 // but we don't have to work with those often.
15337 mat3 m;
15338 m[0] = mat[0].xyz;
15339 m[1] = mat[1].xyz;
15340 m[2] = mat[2].xyz;
15341 return m;
15342}
15343
15344float diffuse(vec3 normal) {
15345 vec3 n2 = normal * normal * vec3(.6, .25, .8);
15346 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
15347}
15348struct Vertex {
15349 vec3 pos;
15350 vec2 texCoords;
15351 vec3 normal;
15352};
15353
15354struct BlockFrag {
15355 vec2 texCoords;
15356 vec4 color;
15357 float diffuse;
15358 vec2 light;
15359};
15360
15361#if defined(FRAGMENT_SHADER)
15362void fragment(BlockFrag r) {
15363 vec4 tex = FLWBlockTexture(r.texCoords);
15364
15365 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
15366
15367 FLWFinalizeColor(color);
15368}
15369#endif
15370#define PI 3.1415926538
15371
15372
15373
15374
15375struct Rotating {
15376 vec2 light;
15377 vec4 color;
15378 vec3 pos;
15379 float speed;
15380 float offset;
15381 vec3 axis;
15382};
15383
15384
15385
15386
15387mat4 kineticRotation(float offset, float speed, vec3 axis) {
15388 float degrees = offset + uTime * speed * 3./10.;
15389 float angle = fract(degrees / 360.) * PI * 2.;
15390
15391 return rotate(axis, angle);
15392}
15393
15394#if defined(VERTEX_SHADER)
15395BlockFrag vertex(Vertex v, Rotating instance) {
15396 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
15397
15398 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
15399 worldPos += vec4(instance.pos + .5, 0.);
15400
15401 vec3 norm = modelToNormal(spin) * v.normal;
15402
15403 FLWFinalizeWorldPos(worldPos);
15404 FLWFinalizeNormal(norm);
15405
15406 BlockFrag b;
15407 b.diffuse = diffuse(norm);
15408 b.texCoords = v.texCoords;
15409 b.light = instance.light;
15410
15411 #if defined(DEBUG_RAINBOW)
15412 b.color = instance.color;
15413 #elif defined(DEBUG_NORMAL)
15414 b.color = vec4(norm, 1.);
15415 #else
15416 b.color = vec4(1.);
15417 #endif
15418
15419 return b;
15420}
15421#endif
15422
15423in vec2 v2f_texCoords;
15424in vec4 v2f_color;
15425in float v2f_diffuse;
15426in vec2 v2f_light;
15427void main() {
15428BlockFrag o;
15429o.texCoords = v2f_texCoords;
15430o.color = v2f_color;
15431o.diffuse = v2f_diffuse;
15432o.light = v2f_light;
15433fragment(o);
15434}
15435[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
15436
15437[17:17:49] [Render thread/ERROR]: #version 150
15438#extension GL_ARB_conservative_depth : enable
15439#define VERTEX_SHADER
15440#define DEBUG_NORMAL
15441#if defined(VERTEX_SHADER)
15442out float FragDistance;
15443#elif defined(FRAGMENT_SHADER)
15444in float FragDistance;
15445#endif
15446uniform vec4 uFogColor;
15447uniform vec2 uFogRange;
15448
15449float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
15450 float distXZ = length(worldPos.xz - cameraPos.xz);
15451 float distY = abs(worldPos.y - cameraPos.y);
15452 return max(distXZ, distY);
15453}
15454
15455float cylindrical_distance(vec3 worldPos) {
15456 float distXZ = length(worldPos.xz);
15457 float distY = abs(worldPos.y);
15458 return max(distXZ, distY);
15459}
15460
15461float FLWFogFactor() {
15462 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
15463}
15464// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
15465vec2 shiftLight(vec2 lm) {
15466 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
15467}
15468
15469
15470uniform sampler3D uLightVolume;
15471
15472uniform sampler2D uBlockAtlas;
15473uniform sampler2D uLightMap;
15474
15475uniform vec3 uLightBoxSize;
15476uniform vec3 uLightBoxMin;
15477uniform mat4 uModel;
15478
15479uniform float uTime;
15480uniform mat4 uViewProjection;
15481uniform vec3 uCameraPos;
15482
15483void FLWFinalizeNormal(inout vec3 normal) {
15484 mat3 m;
15485 m[0] = uModel[0].xyz;
15486 m[1] = uModel[1].xyz;
15487 m[2] = uModel[2].xyz;
15488 normal = m * normal;
15489}
15490
15491#if defined(VERTEX_SHADER)
15492
15493out vec3 BoxCoord;
15494
15495void FLWFinalizeWorldPos(inout vec4 worldPos) {
15496 worldPos = uModel * worldPos;
15497
15498 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
15499
15500 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
15501
15502 gl_Position = uViewProjection * worldPos;
15503}
15504
15505#elif defined(FRAGMENT_SHADER)
15506
15507
15508#define ALPHA_DISCARD 0.1
15509// optimize discard usage
15510#if defined(ALPHA_DISCARD)
15511#if defined(GL_ARB_conservative_depth)
15512layout (depth_greater) out float gl_FragDepth;
15513#endif
15514#endif
15515
15516in vec3 BoxCoord;
15517
15518out vec4 FragColor;
15519
15520vec4 FLWBlockTexture(vec2 texCoords) {
15521 return texture(uBlockAtlas, texCoords);
15522}
15523
15524void FLWFinalizeColor(vec4 color) {
15525 float a = color.a;
15526 float fog = clamp(FLWFogFactor(), 0., 1.);
15527
15528 color = mix(uFogColor, color, fog);
15529 color.a = a;
15530
15531 #if defined(ALPHA_DISCARD)
15532 if (color.a < ALPHA_DISCARD) {
15533 discard;
15534 }
15535 #endif
15536
15537 FragColor = color;
15538}
15539
15540vec4 FLWLight(vec2 lightCoords) {
15541 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
15542
15543 return texture(uLightMap, shiftLight(lightCoords));
15544}
15545
15546#endif
15547
15548
15549mat4 rotate(vec3 axis, float angle) {
15550 float s = sin(angle);
15551 float c = cos(angle);
15552 float oc = 1. - c;
15553
15554 vec3 sa = axis * s;
15555
15556 mat4 mr = mat4(1.);
15557 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
15558 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
15559 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
15560
15561 return mr;
15562}
15563
15564mat4 rotation(vec3 rot) {
15565 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
15566}
15567
15568mat3 modelToNormal(mat4 mat) {
15569 // Discard the edges. This won't be accurate for scaled or skewed matrices,
15570 // but we don't have to work with those often.
15571 mat3 m;
15572 m[0] = mat[0].xyz;
15573 m[1] = mat[1].xyz;
15574 m[2] = mat[2].xyz;
15575 return m;
15576}
15577
15578float diffuse(vec3 normal) {
15579 vec3 n2 = normal * normal * vec3(.6, .25, .8);
15580 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
15581}
15582struct Vertex {
15583 vec3 pos;
15584 vec2 texCoords;
15585 vec3 normal;
15586};
15587
15588struct BlockFrag {
15589 vec2 texCoords;
15590 vec4 color;
15591 float diffuse;
15592 vec2 light;
15593};
15594
15595#if defined(FRAGMENT_SHADER)
15596void fragment(BlockFrag r) {
15597 vec4 tex = FLWBlockTexture(r.texCoords);
15598
15599 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
15600
15601 FLWFinalizeColor(color);
15602}
15603#endif
15604#define PI 3.1415926538
15605
15606
15607
15608
15609struct Rotating {
15610 vec2 light;
15611 vec4 color;
15612 vec3 pos;
15613 float speed;
15614 float offset;
15615 vec3 axis;
15616};
15617
15618
15619
15620
15621mat4 kineticRotation(float offset, float speed, vec3 axis) {
15622 float degrees = offset + uTime * speed * 3./10.;
15623 float angle = fract(degrees / 360.) * PI * 2.;
15624
15625 return rotate(axis, angle);
15626}
15627
15628#if defined(VERTEX_SHADER)
15629BlockFrag vertex(Vertex v, Rotating instance) {
15630 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
15631
15632 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
15633 worldPos += vec4(instance.pos + .5, 0.);
15634
15635 vec3 norm = modelToNormal(spin) * v.normal;
15636
15637 FLWFinalizeWorldPos(worldPos);
15638 FLWFinalizeNormal(norm);
15639
15640 BlockFrag b;
15641 b.diffuse = diffuse(norm);
15642 b.texCoords = v.texCoords;
15643 b.light = instance.light;
15644
15645 #if defined(DEBUG_RAINBOW)
15646 b.color = instance.color;
15647 #elif defined(DEBUG_NORMAL)
15648 b.color = vec4(norm, 1.);
15649 #else
15650 b.color = vec4(1.);
15651 #endif
15652
15653 return b;
15654}
15655#endif
15656
15657in vec3 a_v_pos;
15658in vec2 a_v_texCoords;
15659in vec3 a_v_normal;
15660in vec2 a_i_light;
15661in vec4 a_i_color;
15662in vec3 a_i_pos;
15663in float a_i_speed;
15664in float a_i_offset;
15665in vec3 a_i_axis;
15666out vec2 v2f_texCoords;
15667out vec4 v2f_color;
15668out float v2f_diffuse;
15669out vec2 v2f_light;
15670void main() {
15671Vertex v;
15672v.pos = a_v_pos;
15673v.texCoords = a_v_texCoords;
15674v.normal = a_v_normal;
15675Rotating i;
15676i.light = a_i_light;
15677i.color = a_i_color;
15678i.pos = a_i_pos;
15679i.speed = a_i_speed;
15680i.offset = a_i_offset;
15681i.axis = a_i_axis;
15682BlockFrag o = vertex(v, i);
15683v2f_texCoords = o.texCoords;
15684v2f_color = o.color;
15685v2f_diffuse = o.diffuse;
15686v2f_light = o.light;
15687}
15688[17:17:49] [Render thread/ERROR]: Shader compilation log for create:rotating: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
15689
15690[17:17:49] [Render thread/ERROR]: #version 150
15691#extension GL_ARB_conservative_depth : enable
15692#define FRAGMENT_SHADER
15693#define DEBUG_NORMAL
15694#if defined(VERTEX_SHADER)
15695out float FragDistance;
15696#elif defined(FRAGMENT_SHADER)
15697in float FragDistance;
15698#endif
15699uniform vec4 uFogColor;
15700uniform vec2 uFogRange;
15701
15702float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
15703 float distXZ = length(worldPos.xz - cameraPos.xz);
15704 float distY = abs(worldPos.y - cameraPos.y);
15705 return max(distXZ, distY);
15706}
15707
15708float cylindrical_distance(vec3 worldPos) {
15709 float distXZ = length(worldPos.xz);
15710 float distY = abs(worldPos.y);
15711 return max(distXZ, distY);
15712}
15713
15714float FLWFogFactor() {
15715 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
15716}
15717// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
15718vec2 shiftLight(vec2 lm) {
15719 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
15720}
15721
15722
15723uniform sampler3D uLightVolume;
15724
15725uniform sampler2D uBlockAtlas;
15726uniform sampler2D uLightMap;
15727
15728uniform vec3 uLightBoxSize;
15729uniform vec3 uLightBoxMin;
15730uniform mat4 uModel;
15731
15732uniform float uTime;
15733uniform mat4 uViewProjection;
15734uniform vec3 uCameraPos;
15735
15736void FLWFinalizeNormal(inout vec3 normal) {
15737 mat3 m;
15738 m[0] = uModel[0].xyz;
15739 m[1] = uModel[1].xyz;
15740 m[2] = uModel[2].xyz;
15741 normal = m * normal;
15742}
15743
15744#if defined(VERTEX_SHADER)
15745
15746out vec3 BoxCoord;
15747
15748void FLWFinalizeWorldPos(inout vec4 worldPos) {
15749 worldPos = uModel * worldPos;
15750
15751 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
15752
15753 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
15754
15755 gl_Position = uViewProjection * worldPos;
15756}
15757
15758#elif defined(FRAGMENT_SHADER)
15759
15760
15761#define ALPHA_DISCARD 0.1
15762// optimize discard usage
15763#if defined(ALPHA_DISCARD)
15764#if defined(GL_ARB_conservative_depth)
15765layout (depth_greater) out float gl_FragDepth;
15766#endif
15767#endif
15768
15769in vec3 BoxCoord;
15770
15771out vec4 FragColor;
15772
15773vec4 FLWBlockTexture(vec2 texCoords) {
15774 return texture(uBlockAtlas, texCoords);
15775}
15776
15777void FLWFinalizeColor(vec4 color) {
15778 float a = color.a;
15779 float fog = clamp(FLWFogFactor(), 0., 1.);
15780
15781 color = mix(uFogColor, color, fog);
15782 color.a = a;
15783
15784 #if defined(ALPHA_DISCARD)
15785 if (color.a < ALPHA_DISCARD) {
15786 discard;
15787 }
15788 #endif
15789
15790 FragColor = color;
15791}
15792
15793vec4 FLWLight(vec2 lightCoords) {
15794 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
15795
15796 return texture(uLightMap, shiftLight(lightCoords));
15797}
15798
15799#endif
15800
15801
15802mat4 rotate(vec3 axis, float angle) {
15803 float s = sin(angle);
15804 float c = cos(angle);
15805 float oc = 1. - c;
15806
15807 vec3 sa = axis * s;
15808
15809 mat4 mr = mat4(1.);
15810 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
15811 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
15812 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
15813
15814 return mr;
15815}
15816
15817mat4 rotation(vec3 rot) {
15818 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
15819}
15820
15821mat3 modelToNormal(mat4 mat) {
15822 // Discard the edges. This won't be accurate for scaled or skewed matrices,
15823 // but we don't have to work with those often.
15824 mat3 m;
15825 m[0] = mat[0].xyz;
15826 m[1] = mat[1].xyz;
15827 m[2] = mat[2].xyz;
15828 return m;
15829}
15830
15831float diffuse(vec3 normal) {
15832 vec3 n2 = normal * normal * vec3(.6, .25, .8);
15833 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
15834}
15835struct Vertex {
15836 vec3 pos;
15837 vec2 texCoords;
15838 vec3 normal;
15839};
15840
15841struct BlockFrag {
15842 vec2 texCoords;
15843 vec4 color;
15844 float diffuse;
15845 vec2 light;
15846};
15847
15848#if defined(FRAGMENT_SHADER)
15849void fragment(BlockFrag r) {
15850 vec4 tex = FLWBlockTexture(r.texCoords);
15851
15852 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
15853
15854 FLWFinalizeColor(color);
15855}
15856#endif
15857#define PI 3.1415926538
15858
15859
15860
15861
15862struct Rotating {
15863 vec2 light;
15864 vec4 color;
15865 vec3 pos;
15866 float speed;
15867 float offset;
15868 vec3 axis;
15869};
15870
15871
15872
15873
15874mat4 kineticRotation(float offset, float speed, vec3 axis) {
15875 float degrees = offset + uTime * speed * 3./10.;
15876 float angle = fract(degrees / 360.) * PI * 2.;
15877
15878 return rotate(axis, angle);
15879}
15880
15881#if defined(VERTEX_SHADER)
15882BlockFrag vertex(Vertex v, Rotating instance) {
15883 mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
15884
15885 vec4 worldPos = spin * vec4(v.pos - .5, 1.);
15886 worldPos += vec4(instance.pos + .5, 0.);
15887
15888 vec3 norm = modelToNormal(spin) * v.normal;
15889
15890 FLWFinalizeWorldPos(worldPos);
15891 FLWFinalizeNormal(norm);
15892
15893 BlockFrag b;
15894 b.diffuse = diffuse(norm);
15895 b.texCoords = v.texCoords;
15896 b.light = instance.light;
15897
15898 #if defined(DEBUG_RAINBOW)
15899 b.color = instance.color;
15900 #elif defined(DEBUG_NORMAL)
15901 b.color = vec4(norm, 1.);
15902 #else
15903 b.color = vec4(1.);
15904 #endif
15905
15906 return b;
15907}
15908#endif
15909
15910in vec2 v2f_texCoords;
15911in vec4 v2f_color;
15912in float v2f_diffuse;
15913in vec2 v2f_light;
15914void main() {
15915BlockFrag o;
15916o.texCoords = v2f_texCoords;
15917o.color = v2f_color;
15918o.diffuse = v2f_diffuse;
15919o.light = v2f_light;
15920fragment(o);
15921}
15922[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
15923
15924[17:17:49] [Render thread/ERROR]: #version 150
15925#extension GL_ARB_conservative_depth : enable
15926#define VERTEX_SHADER
15927#if defined(VERTEX_SHADER)
15928out float FragDistance;
15929#elif defined(FRAGMENT_SHADER)
15930in float FragDistance;
15931#endif
15932uniform vec4 uFogColor;
15933uniform vec2 uFogRange;
15934
15935float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
15936 float distXZ = length(worldPos.xz - cameraPos.xz);
15937 float distY = abs(worldPos.y - cameraPos.y);
15938 return max(distXZ, distY);
15939}
15940
15941float cylindrical_distance(vec3 worldPos) {
15942 float distXZ = length(worldPos.xz);
15943 float distY = abs(worldPos.y);
15944 return max(distXZ, distY);
15945}
15946
15947float FLWFogFactor() {
15948 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
15949}
15950// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
15951vec2 shiftLight(vec2 lm) {
15952 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
15953}
15954
15955
15956uniform sampler3D uLightVolume;
15957
15958uniform sampler2D uBlockAtlas;
15959uniform sampler2D uLightMap;
15960
15961uniform vec3 uLightBoxSize;
15962uniform vec3 uLightBoxMin;
15963uniform mat4 uModel;
15964
15965uniform float uTime;
15966uniform mat4 uViewProjection;
15967uniform vec3 uCameraPos;
15968
15969void FLWFinalizeNormal(inout vec3 normal) {
15970 mat3 m;
15971 m[0] = uModel[0].xyz;
15972 m[1] = uModel[1].xyz;
15973 m[2] = uModel[2].xyz;
15974 normal = m * normal;
15975}
15976
15977#if defined(VERTEX_SHADER)
15978
15979out vec3 BoxCoord;
15980
15981void FLWFinalizeWorldPos(inout vec4 worldPos) {
15982 worldPos = uModel * worldPos;
15983
15984 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
15985
15986 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
15987
15988 gl_Position = uViewProjection * worldPos;
15989}
15990
15991#elif defined(FRAGMENT_SHADER)
15992
15993
15994#define ALPHA_DISCARD 0.1
15995// optimize discard usage
15996#if defined(ALPHA_DISCARD)
15997#if defined(GL_ARB_conservative_depth)
15998layout (depth_greater) out float gl_FragDepth;
15999#endif
16000#endif
16001
16002in vec3 BoxCoord;
16003
16004out vec4 FragColor;
16005
16006vec4 FLWBlockTexture(vec2 texCoords) {
16007 return texture(uBlockAtlas, texCoords);
16008}
16009
16010void FLWFinalizeColor(vec4 color) {
16011 float a = color.a;
16012 float fog = clamp(FLWFogFactor(), 0., 1.);
16013
16014 color = mix(uFogColor, color, fog);
16015 color.a = a;
16016
16017 #if defined(ALPHA_DISCARD)
16018 if (color.a < ALPHA_DISCARD) {
16019 discard;
16020 }
16021 #endif
16022
16023 FragColor = color;
16024}
16025
16026vec4 FLWLight(vec2 lightCoords) {
16027 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
16028
16029 return texture(uLightMap, shiftLight(lightCoords));
16030}
16031
16032#endif
16033
16034
16035mat4 rotate(vec3 axis, float angle) {
16036 float s = sin(angle);
16037 float c = cos(angle);
16038 float oc = 1. - c;
16039
16040 vec3 sa = axis * s;
16041
16042 mat4 mr = mat4(1.);
16043 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
16044 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
16045 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
16046
16047 return mr;
16048}
16049
16050mat4 rotation(vec3 rot) {
16051 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
16052}
16053
16054mat3 modelToNormal(mat4 mat) {
16055 // Discard the edges. This won't be accurate for scaled or skewed matrices,
16056 // but we don't have to work with those often.
16057 mat3 m;
16058 m[0] = mat[0].xyz;
16059 m[1] = mat[1].xyz;
16060 m[2] = mat[2].xyz;
16061 return m;
16062}
16063
16064#define PIOVER2 1.5707963268
16065
16066vec4 quat(vec3 axis, float angle) {
16067 float halfAngle = angle * PIOVER2 / 180.0;
16068 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
16069 return vec4(axis.xyz * cs.y, cs.x);
16070}
16071
16072vec4 quatMult(vec4 q1, vec4 q2) {
16073 // disgustingly vectorized quaternion multiplication
16074 vec4 a = q1.w * q2.xyzw;
16075 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
16076 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
16077 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
16078
16079 return a + b + c + d;
16080}
16081
16082vec3 rotateVertexByQuat(vec3 v, vec4 q) {
16083 vec3 i = q.xyz;
16084 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
16085}
16086
16087vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
16088 return rotateVertexByQuat(v, quat(axis, angle));
16089}
16090
16091float diffuse(vec3 normal) {
16092 vec3 n2 = normal * normal * vec3(.6, .25, .8);
16093 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
16094}
16095struct Vertex {
16096 vec3 pos;
16097 vec2 texCoords;
16098 vec3 normal;
16099};
16100
16101struct BlockFrag {
16102 vec2 texCoords;
16103 vec4 color;
16104 float diffuse;
16105 vec2 light;
16106};
16107
16108#if defined(FRAGMENT_SHADER)
16109void fragment(BlockFrag r) {
16110 vec4 tex = FLWBlockTexture(r.texCoords);
16111
16112 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
16113
16114 FLWFinalizeColor(color);
16115}
16116#endif
16117#define PI 3.1415926538
16118
16119
16120
16121
16122
16123struct Actor {
16124 vec3 pos;
16125 vec2 light;
16126 float offset;
16127 vec3 axis;
16128 vec4 rotation;
16129 vec3 rotationCenter;
16130 float speed;
16131};
16132
16133
16134
16135
16136#if defined(VERTEX_SHADER)
16137BlockFrag vertex(Vertex v, Actor instance) {
16138 float degrees = instance.offset + uTime * instance.speed / 20.;
16139 //float angle = fract(degrees / 360.) * PI * 2.;
16140
16141 vec4 kineticRot = quat(instance.axis, degrees);
16142 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
16143
16144 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
16145 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
16146
16147 FLWFinalizeWorldPos(worldPos);
16148 FLWFinalizeNormal(norm);
16149
16150 BlockFrag b;
16151 b.diffuse = diffuse(norm);
16152 b.texCoords = v.texCoords;
16153 b.light = instance.light;
16154
16155 #if defined(DEBUG_NORMAL)
16156 b.color = vec4(norm, 1.);
16157 #else
16158 b.color = vec4(1.);
16159 #endif
16160
16161 return b;
16162}
16163#endif
16164
16165in vec3 a_v_pos;
16166in vec2 a_v_texCoords;
16167in vec3 a_v_normal;
16168in vec3 a_i_pos;
16169in vec2 a_i_light;
16170in float a_i_offset;
16171in vec3 a_i_axis;
16172in vec4 a_i_rotation;
16173in vec3 a_i_rotationCenter;
16174in float a_i_speed;
16175out vec2 v2f_texCoords;
16176out vec4 v2f_color;
16177out float v2f_diffuse;
16178out vec2 v2f_light;
16179void main() {
16180Vertex v;
16181v.pos = a_v_pos;
16182v.texCoords = a_v_texCoords;
16183v.normal = a_v_normal;
16184Actor i;
16185i.pos = a_i_pos;
16186i.light = a_i_light;
16187i.offset = a_i_offset;
16188i.axis = a_i_axis;
16189i.rotation = a_i_rotation;
16190i.rotationCenter = a_i_rotationCenter;
16191i.speed = a_i_speed;
16192BlockFrag o = vertex(v, i);
16193v2f_texCoords = o.texCoords;
16194v2f_color = o.color;
16195v2f_diffuse = o.diffuse;
16196v2f_light = o.light;
16197}
16198[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
16199
16200[17:17:49] [Render thread/ERROR]: #version 150
16201#extension GL_ARB_conservative_depth : enable
16202#define FRAGMENT_SHADER
16203#if defined(VERTEX_SHADER)
16204out float FragDistance;
16205#elif defined(FRAGMENT_SHADER)
16206in float FragDistance;
16207#endif
16208uniform vec4 uFogColor;
16209uniform vec2 uFogRange;
16210
16211float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
16212 float distXZ = length(worldPos.xz - cameraPos.xz);
16213 float distY = abs(worldPos.y - cameraPos.y);
16214 return max(distXZ, distY);
16215}
16216
16217float cylindrical_distance(vec3 worldPos) {
16218 float distXZ = length(worldPos.xz);
16219 float distY = abs(worldPos.y);
16220 return max(distXZ, distY);
16221}
16222
16223float FLWFogFactor() {
16224 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
16225}
16226// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
16227vec2 shiftLight(vec2 lm) {
16228 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
16229}
16230
16231
16232uniform sampler3D uLightVolume;
16233
16234uniform sampler2D uBlockAtlas;
16235uniform sampler2D uLightMap;
16236
16237uniform vec3 uLightBoxSize;
16238uniform vec3 uLightBoxMin;
16239uniform mat4 uModel;
16240
16241uniform float uTime;
16242uniform mat4 uViewProjection;
16243uniform vec3 uCameraPos;
16244
16245void FLWFinalizeNormal(inout vec3 normal) {
16246 mat3 m;
16247 m[0] = uModel[0].xyz;
16248 m[1] = uModel[1].xyz;
16249 m[2] = uModel[2].xyz;
16250 normal = m * normal;
16251}
16252
16253#if defined(VERTEX_SHADER)
16254
16255out vec3 BoxCoord;
16256
16257void FLWFinalizeWorldPos(inout vec4 worldPos) {
16258 worldPos = uModel * worldPos;
16259
16260 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
16261
16262 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
16263
16264 gl_Position = uViewProjection * worldPos;
16265}
16266
16267#elif defined(FRAGMENT_SHADER)
16268
16269
16270#define ALPHA_DISCARD 0.1
16271// optimize discard usage
16272#if defined(ALPHA_DISCARD)
16273#if defined(GL_ARB_conservative_depth)
16274layout (depth_greater) out float gl_FragDepth;
16275#endif
16276#endif
16277
16278in vec3 BoxCoord;
16279
16280out vec4 FragColor;
16281
16282vec4 FLWBlockTexture(vec2 texCoords) {
16283 return texture(uBlockAtlas, texCoords);
16284}
16285
16286void FLWFinalizeColor(vec4 color) {
16287 float a = color.a;
16288 float fog = clamp(FLWFogFactor(), 0., 1.);
16289
16290 color = mix(uFogColor, color, fog);
16291 color.a = a;
16292
16293 #if defined(ALPHA_DISCARD)
16294 if (color.a < ALPHA_DISCARD) {
16295 discard;
16296 }
16297 #endif
16298
16299 FragColor = color;
16300}
16301
16302vec4 FLWLight(vec2 lightCoords) {
16303 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
16304
16305 return texture(uLightMap, shiftLight(lightCoords));
16306}
16307
16308#endif
16309
16310
16311mat4 rotate(vec3 axis, float angle) {
16312 float s = sin(angle);
16313 float c = cos(angle);
16314 float oc = 1. - c;
16315
16316 vec3 sa = axis * s;
16317
16318 mat4 mr = mat4(1.);
16319 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
16320 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
16321 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
16322
16323 return mr;
16324}
16325
16326mat4 rotation(vec3 rot) {
16327 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
16328}
16329
16330mat3 modelToNormal(mat4 mat) {
16331 // Discard the edges. This won't be accurate for scaled or skewed matrices,
16332 // but we don't have to work with those often.
16333 mat3 m;
16334 m[0] = mat[0].xyz;
16335 m[1] = mat[1].xyz;
16336 m[2] = mat[2].xyz;
16337 return m;
16338}
16339
16340#define PIOVER2 1.5707963268
16341
16342vec4 quat(vec3 axis, float angle) {
16343 float halfAngle = angle * PIOVER2 / 180.0;
16344 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
16345 return vec4(axis.xyz * cs.y, cs.x);
16346}
16347
16348vec4 quatMult(vec4 q1, vec4 q2) {
16349 // disgustingly vectorized quaternion multiplication
16350 vec4 a = q1.w * q2.xyzw;
16351 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
16352 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
16353 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
16354
16355 return a + b + c + d;
16356}
16357
16358vec3 rotateVertexByQuat(vec3 v, vec4 q) {
16359 vec3 i = q.xyz;
16360 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
16361}
16362
16363vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
16364 return rotateVertexByQuat(v, quat(axis, angle));
16365}
16366
16367float diffuse(vec3 normal) {
16368 vec3 n2 = normal * normal * vec3(.6, .25, .8);
16369 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
16370}
16371struct Vertex {
16372 vec3 pos;
16373 vec2 texCoords;
16374 vec3 normal;
16375};
16376
16377struct BlockFrag {
16378 vec2 texCoords;
16379 vec4 color;
16380 float diffuse;
16381 vec2 light;
16382};
16383
16384#if defined(FRAGMENT_SHADER)
16385void fragment(BlockFrag r) {
16386 vec4 tex = FLWBlockTexture(r.texCoords);
16387
16388 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
16389
16390 FLWFinalizeColor(color);
16391}
16392#endif
16393#define PI 3.1415926538
16394
16395
16396
16397
16398
16399struct Actor {
16400 vec3 pos;
16401 vec2 light;
16402 float offset;
16403 vec3 axis;
16404 vec4 rotation;
16405 vec3 rotationCenter;
16406 float speed;
16407};
16408
16409
16410
16411
16412#if defined(VERTEX_SHADER)
16413BlockFrag vertex(Vertex v, Actor instance) {
16414 float degrees = instance.offset + uTime * instance.speed / 20.;
16415 //float angle = fract(degrees / 360.) * PI * 2.;
16416
16417 vec4 kineticRot = quat(instance.axis, degrees);
16418 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
16419
16420 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
16421 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
16422
16423 FLWFinalizeWorldPos(worldPos);
16424 FLWFinalizeNormal(norm);
16425
16426 BlockFrag b;
16427 b.diffuse = diffuse(norm);
16428 b.texCoords = v.texCoords;
16429 b.light = instance.light;
16430
16431 #if defined(DEBUG_NORMAL)
16432 b.color = vec4(norm, 1.);
16433 #else
16434 b.color = vec4(1.);
16435 #endif
16436
16437 return b;
16438}
16439#endif
16440
16441in vec2 v2f_texCoords;
16442in vec4 v2f_color;
16443in float v2f_diffuse;
16444in vec2 v2f_light;
16445void main() {
16446BlockFrag o;
16447o.texCoords = v2f_texCoords;
16448o.color = v2f_color;
16449o.diffuse = v2f_diffuse;
16450o.light = v2f_light;
16451fragment(o);
16452}
16453[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
16454
16455[17:17:49] [Render thread/ERROR]: #version 150
16456#extension GL_ARB_conservative_depth : enable
16457#define VERTEX_SHADER
16458#define DEBUG_NORMAL
16459#if defined(VERTEX_SHADER)
16460out float FragDistance;
16461#elif defined(FRAGMENT_SHADER)
16462in float FragDistance;
16463#endif
16464uniform vec4 uFogColor;
16465uniform vec2 uFogRange;
16466
16467float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
16468 float distXZ = length(worldPos.xz - cameraPos.xz);
16469 float distY = abs(worldPos.y - cameraPos.y);
16470 return max(distXZ, distY);
16471}
16472
16473float cylindrical_distance(vec3 worldPos) {
16474 float distXZ = length(worldPos.xz);
16475 float distY = abs(worldPos.y);
16476 return max(distXZ, distY);
16477}
16478
16479float FLWFogFactor() {
16480 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
16481}
16482// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
16483vec2 shiftLight(vec2 lm) {
16484 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
16485}
16486
16487
16488uniform sampler3D uLightVolume;
16489
16490uniform sampler2D uBlockAtlas;
16491uniform sampler2D uLightMap;
16492
16493uniform vec3 uLightBoxSize;
16494uniform vec3 uLightBoxMin;
16495uniform mat4 uModel;
16496
16497uniform float uTime;
16498uniform mat4 uViewProjection;
16499uniform vec3 uCameraPos;
16500
16501void FLWFinalizeNormal(inout vec3 normal) {
16502 mat3 m;
16503 m[0] = uModel[0].xyz;
16504 m[1] = uModel[1].xyz;
16505 m[2] = uModel[2].xyz;
16506 normal = m * normal;
16507}
16508
16509#if defined(VERTEX_SHADER)
16510
16511out vec3 BoxCoord;
16512
16513void FLWFinalizeWorldPos(inout vec4 worldPos) {
16514 worldPos = uModel * worldPos;
16515
16516 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
16517
16518 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
16519
16520 gl_Position = uViewProjection * worldPos;
16521}
16522
16523#elif defined(FRAGMENT_SHADER)
16524
16525
16526#define ALPHA_DISCARD 0.1
16527// optimize discard usage
16528#if defined(ALPHA_DISCARD)
16529#if defined(GL_ARB_conservative_depth)
16530layout (depth_greater) out float gl_FragDepth;
16531#endif
16532#endif
16533
16534in vec3 BoxCoord;
16535
16536out vec4 FragColor;
16537
16538vec4 FLWBlockTexture(vec2 texCoords) {
16539 return texture(uBlockAtlas, texCoords);
16540}
16541
16542void FLWFinalizeColor(vec4 color) {
16543 float a = color.a;
16544 float fog = clamp(FLWFogFactor(), 0., 1.);
16545
16546 color = mix(uFogColor, color, fog);
16547 color.a = a;
16548
16549 #if defined(ALPHA_DISCARD)
16550 if (color.a < ALPHA_DISCARD) {
16551 discard;
16552 }
16553 #endif
16554
16555 FragColor = color;
16556}
16557
16558vec4 FLWLight(vec2 lightCoords) {
16559 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
16560
16561 return texture(uLightMap, shiftLight(lightCoords));
16562}
16563
16564#endif
16565
16566
16567mat4 rotate(vec3 axis, float angle) {
16568 float s = sin(angle);
16569 float c = cos(angle);
16570 float oc = 1. - c;
16571
16572 vec3 sa = axis * s;
16573
16574 mat4 mr = mat4(1.);
16575 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
16576 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
16577 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
16578
16579 return mr;
16580}
16581
16582mat4 rotation(vec3 rot) {
16583 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
16584}
16585
16586mat3 modelToNormal(mat4 mat) {
16587 // Discard the edges. This won't be accurate for scaled or skewed matrices,
16588 // but we don't have to work with those often.
16589 mat3 m;
16590 m[0] = mat[0].xyz;
16591 m[1] = mat[1].xyz;
16592 m[2] = mat[2].xyz;
16593 return m;
16594}
16595
16596#define PIOVER2 1.5707963268
16597
16598vec4 quat(vec3 axis, float angle) {
16599 float halfAngle = angle * PIOVER2 / 180.0;
16600 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
16601 return vec4(axis.xyz * cs.y, cs.x);
16602}
16603
16604vec4 quatMult(vec4 q1, vec4 q2) {
16605 // disgustingly vectorized quaternion multiplication
16606 vec4 a = q1.w * q2.xyzw;
16607 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
16608 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
16609 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
16610
16611 return a + b + c + d;
16612}
16613
16614vec3 rotateVertexByQuat(vec3 v, vec4 q) {
16615 vec3 i = q.xyz;
16616 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
16617}
16618
16619vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
16620 return rotateVertexByQuat(v, quat(axis, angle));
16621}
16622
16623float diffuse(vec3 normal) {
16624 vec3 n2 = normal * normal * vec3(.6, .25, .8);
16625 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
16626}
16627struct Vertex {
16628 vec3 pos;
16629 vec2 texCoords;
16630 vec3 normal;
16631};
16632
16633struct BlockFrag {
16634 vec2 texCoords;
16635 vec4 color;
16636 float diffuse;
16637 vec2 light;
16638};
16639
16640#if defined(FRAGMENT_SHADER)
16641void fragment(BlockFrag r) {
16642 vec4 tex = FLWBlockTexture(r.texCoords);
16643
16644 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
16645
16646 FLWFinalizeColor(color);
16647}
16648#endif
16649#define PI 3.1415926538
16650
16651
16652
16653
16654
16655struct Actor {
16656 vec3 pos;
16657 vec2 light;
16658 float offset;
16659 vec3 axis;
16660 vec4 rotation;
16661 vec3 rotationCenter;
16662 float speed;
16663};
16664
16665
16666
16667
16668#if defined(VERTEX_SHADER)
16669BlockFrag vertex(Vertex v, Actor instance) {
16670 float degrees = instance.offset + uTime * instance.speed / 20.;
16671 //float angle = fract(degrees / 360.) * PI * 2.;
16672
16673 vec4 kineticRot = quat(instance.axis, degrees);
16674 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
16675
16676 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
16677 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
16678
16679 FLWFinalizeWorldPos(worldPos);
16680 FLWFinalizeNormal(norm);
16681
16682 BlockFrag b;
16683 b.diffuse = diffuse(norm);
16684 b.texCoords = v.texCoords;
16685 b.light = instance.light;
16686
16687 #if defined(DEBUG_NORMAL)
16688 b.color = vec4(norm, 1.);
16689 #else
16690 b.color = vec4(1.);
16691 #endif
16692
16693 return b;
16694}
16695#endif
16696
16697in vec3 a_v_pos;
16698in vec2 a_v_texCoords;
16699in vec3 a_v_normal;
16700in vec3 a_i_pos;
16701in vec2 a_i_light;
16702in float a_i_offset;
16703in vec3 a_i_axis;
16704in vec4 a_i_rotation;
16705in vec3 a_i_rotationCenter;
16706in float a_i_speed;
16707out vec2 v2f_texCoords;
16708out vec4 v2f_color;
16709out float v2f_diffuse;
16710out vec2 v2f_light;
16711void main() {
16712Vertex v;
16713v.pos = a_v_pos;
16714v.texCoords = a_v_texCoords;
16715v.normal = a_v_normal;
16716Actor i;
16717i.pos = a_i_pos;
16718i.light = a_i_light;
16719i.offset = a_i_offset;
16720i.axis = a_i_axis;
16721i.rotation = a_i_rotation;
16722i.rotationCenter = a_i_rotationCenter;
16723i.speed = a_i_speed;
16724BlockFrag o = vertex(v, i);
16725v2f_texCoords = o.texCoords;
16726v2f_color = o.color;
16727v2f_diffuse = o.diffuse;
16728v2f_light = o.light;
16729}
16730[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_actor: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
16731
16732[17:17:49] [Render thread/ERROR]: #version 150
16733#extension GL_ARB_conservative_depth : enable
16734#define FRAGMENT_SHADER
16735#define DEBUG_NORMAL
16736#if defined(VERTEX_SHADER)
16737out float FragDistance;
16738#elif defined(FRAGMENT_SHADER)
16739in float FragDistance;
16740#endif
16741uniform vec4 uFogColor;
16742uniform vec2 uFogRange;
16743
16744float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
16745 float distXZ = length(worldPos.xz - cameraPos.xz);
16746 float distY = abs(worldPos.y - cameraPos.y);
16747 return max(distXZ, distY);
16748}
16749
16750float cylindrical_distance(vec3 worldPos) {
16751 float distXZ = length(worldPos.xz);
16752 float distY = abs(worldPos.y);
16753 return max(distXZ, distY);
16754}
16755
16756float FLWFogFactor() {
16757 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
16758}
16759// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
16760vec2 shiftLight(vec2 lm) {
16761 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
16762}
16763
16764
16765uniform sampler3D uLightVolume;
16766
16767uniform sampler2D uBlockAtlas;
16768uniform sampler2D uLightMap;
16769
16770uniform vec3 uLightBoxSize;
16771uniform vec3 uLightBoxMin;
16772uniform mat4 uModel;
16773
16774uniform float uTime;
16775uniform mat4 uViewProjection;
16776uniform vec3 uCameraPos;
16777
16778void FLWFinalizeNormal(inout vec3 normal) {
16779 mat3 m;
16780 m[0] = uModel[0].xyz;
16781 m[1] = uModel[1].xyz;
16782 m[2] = uModel[2].xyz;
16783 normal = m * normal;
16784}
16785
16786#if defined(VERTEX_SHADER)
16787
16788out vec3 BoxCoord;
16789
16790void FLWFinalizeWorldPos(inout vec4 worldPos) {
16791 worldPos = uModel * worldPos;
16792
16793 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
16794
16795 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
16796
16797 gl_Position = uViewProjection * worldPos;
16798}
16799
16800#elif defined(FRAGMENT_SHADER)
16801
16802
16803#define ALPHA_DISCARD 0.1
16804// optimize discard usage
16805#if defined(ALPHA_DISCARD)
16806#if defined(GL_ARB_conservative_depth)
16807layout (depth_greater) out float gl_FragDepth;
16808#endif
16809#endif
16810
16811in vec3 BoxCoord;
16812
16813out vec4 FragColor;
16814
16815vec4 FLWBlockTexture(vec2 texCoords) {
16816 return texture(uBlockAtlas, texCoords);
16817}
16818
16819void FLWFinalizeColor(vec4 color) {
16820 float a = color.a;
16821 float fog = clamp(FLWFogFactor(), 0., 1.);
16822
16823 color = mix(uFogColor, color, fog);
16824 color.a = a;
16825
16826 #if defined(ALPHA_DISCARD)
16827 if (color.a < ALPHA_DISCARD) {
16828 discard;
16829 }
16830 #endif
16831
16832 FragColor = color;
16833}
16834
16835vec4 FLWLight(vec2 lightCoords) {
16836 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
16837
16838 return texture(uLightMap, shiftLight(lightCoords));
16839}
16840
16841#endif
16842
16843
16844mat4 rotate(vec3 axis, float angle) {
16845 float s = sin(angle);
16846 float c = cos(angle);
16847 float oc = 1. - c;
16848
16849 vec3 sa = axis * s;
16850
16851 mat4 mr = mat4(1.);
16852 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
16853 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
16854 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
16855
16856 return mr;
16857}
16858
16859mat4 rotation(vec3 rot) {
16860 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
16861}
16862
16863mat3 modelToNormal(mat4 mat) {
16864 // Discard the edges. This won't be accurate for scaled or skewed matrices,
16865 // but we don't have to work with those often.
16866 mat3 m;
16867 m[0] = mat[0].xyz;
16868 m[1] = mat[1].xyz;
16869 m[2] = mat[2].xyz;
16870 return m;
16871}
16872
16873#define PIOVER2 1.5707963268
16874
16875vec4 quat(vec3 axis, float angle) {
16876 float halfAngle = angle * PIOVER2 / 180.0;
16877 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
16878 return vec4(axis.xyz * cs.y, cs.x);
16879}
16880
16881vec4 quatMult(vec4 q1, vec4 q2) {
16882 // disgustingly vectorized quaternion multiplication
16883 vec4 a = q1.w * q2.xyzw;
16884 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
16885 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
16886 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
16887
16888 return a + b + c + d;
16889}
16890
16891vec3 rotateVertexByQuat(vec3 v, vec4 q) {
16892 vec3 i = q.xyz;
16893 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
16894}
16895
16896vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
16897 return rotateVertexByQuat(v, quat(axis, angle));
16898}
16899
16900float diffuse(vec3 normal) {
16901 vec3 n2 = normal * normal * vec3(.6, .25, .8);
16902 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
16903}
16904struct Vertex {
16905 vec3 pos;
16906 vec2 texCoords;
16907 vec3 normal;
16908};
16909
16910struct BlockFrag {
16911 vec2 texCoords;
16912 vec4 color;
16913 float diffuse;
16914 vec2 light;
16915};
16916
16917#if defined(FRAGMENT_SHADER)
16918void fragment(BlockFrag r) {
16919 vec4 tex = FLWBlockTexture(r.texCoords);
16920
16921 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
16922
16923 FLWFinalizeColor(color);
16924}
16925#endif
16926#define PI 3.1415926538
16927
16928
16929
16930
16931
16932struct Actor {
16933 vec3 pos;
16934 vec2 light;
16935 float offset;
16936 vec3 axis;
16937 vec4 rotation;
16938 vec3 rotationCenter;
16939 float speed;
16940};
16941
16942
16943
16944
16945#if defined(VERTEX_SHADER)
16946BlockFrag vertex(Vertex v, Actor instance) {
16947 float degrees = instance.offset + uTime * instance.speed / 20.;
16948 //float angle = fract(degrees / 360.) * PI * 2.;
16949
16950 vec4 kineticRot = quat(instance.axis, degrees);
16951 vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
16952
16953 vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
16954 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
16955
16956 FLWFinalizeWorldPos(worldPos);
16957 FLWFinalizeNormal(norm);
16958
16959 BlockFrag b;
16960 b.diffuse = diffuse(norm);
16961 b.texCoords = v.texCoords;
16962 b.light = instance.light;
16963
16964 #if defined(DEBUG_NORMAL)
16965 b.color = vec4(norm, 1.);
16966 #else
16967 b.color = vec4(1.);
16968 #endif
16969
16970 return b;
16971}
16972#endif
16973
16974in vec2 v2f_texCoords;
16975in vec4 v2f_color;
16976in float v2f_diffuse;
16977in vec2 v2f_light;
16978void main() {
16979BlockFrag o;
16980o.texCoords = v2f_texCoords;
16981o.color = v2f_color;
16982o.diffuse = v2f_diffuse;
16983o.light = v2f_light;
16984fragment(o);
16985}
16986[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
16987
16988[17:17:49] [Render thread/ERROR]: #version 150
16989#extension GL_ARB_conservative_depth : enable
16990#define VERTEX_SHADER
16991#if defined(VERTEX_SHADER)
16992out float FragDistance;
16993#elif defined(FRAGMENT_SHADER)
16994in float FragDistance;
16995#endif
16996uniform vec4 uFogColor;
16997uniform vec2 uFogRange;
16998
16999float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
17000 float distXZ = length(worldPos.xz - cameraPos.xz);
17001 float distY = abs(worldPos.y - cameraPos.y);
17002 return max(distXZ, distY);
17003}
17004
17005float cylindrical_distance(vec3 worldPos) {
17006 float distXZ = length(worldPos.xz);
17007 float distY = abs(worldPos.y);
17008 return max(distXZ, distY);
17009}
17010
17011float FLWFogFactor() {
17012 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
17013}
17014// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
17015vec2 shiftLight(vec2 lm) {
17016 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
17017}
17018
17019
17020uniform sampler3D uLightVolume;
17021
17022uniform sampler2D uBlockAtlas;
17023uniform sampler2D uLightMap;
17024
17025uniform vec3 uLightBoxSize;
17026uniform vec3 uLightBoxMin;
17027uniform mat4 uModel;
17028
17029uniform float uTime;
17030uniform mat4 uViewProjection;
17031uniform vec3 uCameraPos;
17032
17033void FLWFinalizeNormal(inout vec3 normal) {
17034 mat3 m;
17035 m[0] = uModel[0].xyz;
17036 m[1] = uModel[1].xyz;
17037 m[2] = uModel[2].xyz;
17038 normal = m * normal;
17039}
17040
17041#if defined(VERTEX_SHADER)
17042
17043out vec3 BoxCoord;
17044
17045void FLWFinalizeWorldPos(inout vec4 worldPos) {
17046 worldPos = uModel * worldPos;
17047
17048 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
17049
17050 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
17051
17052 gl_Position = uViewProjection * worldPos;
17053}
17054
17055#elif defined(FRAGMENT_SHADER)
17056
17057
17058#define ALPHA_DISCARD 0.1
17059// optimize discard usage
17060#if defined(ALPHA_DISCARD)
17061#if defined(GL_ARB_conservative_depth)
17062layout (depth_greater) out float gl_FragDepth;
17063#endif
17064#endif
17065
17066in vec3 BoxCoord;
17067
17068out vec4 FragColor;
17069
17070vec4 FLWBlockTexture(vec2 texCoords) {
17071 return texture(uBlockAtlas, texCoords);
17072}
17073
17074void FLWFinalizeColor(vec4 color) {
17075 float a = color.a;
17076 float fog = clamp(FLWFogFactor(), 0., 1.);
17077
17078 color = mix(uFogColor, color, fog);
17079 color.a = a;
17080
17081 #if defined(ALPHA_DISCARD)
17082 if (color.a < ALPHA_DISCARD) {
17083 discard;
17084 }
17085 #endif
17086
17087 FragColor = color;
17088}
17089
17090vec4 FLWLight(vec2 lightCoords) {
17091 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
17092
17093 return texture(uLightMap, shiftLight(lightCoords));
17094}
17095
17096#endif
17097
17098
17099mat4 rotate(vec3 axis, float angle) {
17100 float s = sin(angle);
17101 float c = cos(angle);
17102 float oc = 1. - c;
17103
17104 vec3 sa = axis * s;
17105
17106 mat4 mr = mat4(1.);
17107 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
17108 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
17109 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
17110
17111 return mr;
17112}
17113
17114mat4 rotation(vec3 rot) {
17115 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
17116}
17117
17118mat3 modelToNormal(mat4 mat) {
17119 // Discard the edges. This won't be accurate for scaled or skewed matrices,
17120 // but we don't have to work with those often.
17121 mat3 m;
17122 m[0] = mat[0].xyz;
17123 m[1] = mat[1].xyz;
17124 m[2] = mat[2].xyz;
17125 return m;
17126}
17127
17128#define PIOVER2 1.5707963268
17129
17130vec4 quat(vec3 axis, float angle) {
17131 float halfAngle = angle * PIOVER2 / 180.0;
17132 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
17133 return vec4(axis.xyz * cs.y, cs.x);
17134}
17135
17136vec4 quatMult(vec4 q1, vec4 q2) {
17137 // disgustingly vectorized quaternion multiplication
17138 vec4 a = q1.w * q2.xyzw;
17139 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
17140 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
17141 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
17142
17143 return a + b + c + d;
17144}
17145
17146vec3 rotateVertexByQuat(vec3 v, vec4 q) {
17147 vec3 i = q.xyz;
17148 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
17149}
17150
17151vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
17152 return rotateVertexByQuat(v, quat(axis, angle));
17153}
17154
17155float diffuse(vec3 normal) {
17156 vec3 n2 = normal * normal * vec3(.6, .25, .8);
17157 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
17158}
17159struct Vertex {
17160 vec3 pos;
17161 vec2 texCoords;
17162 vec3 normal;
17163};
17164
17165struct BlockFrag {
17166 vec2 texCoords;
17167 vec4 color;
17168 float diffuse;
17169 vec2 light;
17170};
17171
17172#if defined(FRAGMENT_SHADER)
17173void fragment(BlockFrag r) {
17174 vec4 tex = FLWBlockTexture(r.texCoords);
17175
17176 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
17177
17178 FLWFinalizeColor(color);
17179}
17180#endif
17181#define PI 3.1415926538
17182
17183
17184
17185
17186
17187struct Flap {
17188 vec3 instancePos;
17189 vec2 light;
17190 vec3 segmentOffset;
17191 vec3 pivot;
17192 float horizontalAngle;
17193 float intensity;
17194 float flapScale;
17195 float flapness;
17196};
17197
17198
17199
17200
17201#if defined(VERTEX_SHADER)
17202
17203float toRad(float degrees) {
17204 return fract(degrees / 360.) * PI * 2.;
17205}
17206
17207float getFlapAngle(float flapness, float intensity, float scale) {
17208 float absFlap = abs(flapness);
17209
17210 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
17211
17212 float halfAngle = angle * 0.5;
17213
17214 float which = step(0., flapness); // 0 if negative, 1 if positive
17215 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
17216
17217 return degrees;
17218}
17219
17220BlockFrag vertex(Vertex v, Flap flap) {
17221 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
17222
17223 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
17224 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
17225
17226 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
17227 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
17228
17229 vec4 worldPos = vec4(rotated, 1.);
17230 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
17231
17232 FLWFinalizeWorldPos(worldPos);
17233 FLWFinalizeNormal(norm);
17234
17235 BlockFrag b;
17236 b.diffuse = diffuse(norm);
17237 b.texCoords = v.texCoords;
17238 b.light = flap.light;
17239 #if defined(DEBUG_NORMAL)
17240 b.color = vec4(norm, 1.);
17241 #else
17242 b.color = vec4(1.);
17243 #endif
17244 return b;
17245}
17246#endif
17247
17248in vec3 a_v_pos;
17249in vec2 a_v_texCoords;
17250in vec3 a_v_normal;
17251in vec3 a_i_instancePos;
17252in vec2 a_i_light;
17253in vec3 a_i_segmentOffset;
17254in vec3 a_i_pivot;
17255in float a_i_horizontalAngle;
17256in float a_i_intensity;
17257in float a_i_flapScale;
17258in float a_i_flapness;
17259out vec2 v2f_texCoords;
17260out vec4 v2f_color;
17261out float v2f_diffuse;
17262out vec2 v2f_light;
17263void main() {
17264Vertex v;
17265v.pos = a_v_pos;
17266v.texCoords = a_v_texCoords;
17267v.normal = a_v_normal;
17268Flap i;
17269i.instancePos = a_i_instancePos;
17270i.light = a_i_light;
17271i.segmentOffset = a_i_segmentOffset;
17272i.pivot = a_i_pivot;
17273i.horizontalAngle = a_i_horizontalAngle;
17274i.intensity = a_i_intensity;
17275i.flapScale = a_i_flapScale;
17276i.flapness = a_i_flapness;
17277BlockFrag o = vertex(v, i);
17278v2f_texCoords = o.texCoords;
17279v2f_color = o.color;
17280v2f_diffuse = o.diffuse;
17281v2f_light = o.light;
17282}
17283[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
17284
17285[17:17:49] [Render thread/ERROR]: #version 150
17286#extension GL_ARB_conservative_depth : enable
17287#define FRAGMENT_SHADER
17288#if defined(VERTEX_SHADER)
17289out float FragDistance;
17290#elif defined(FRAGMENT_SHADER)
17291in float FragDistance;
17292#endif
17293uniform vec4 uFogColor;
17294uniform vec2 uFogRange;
17295
17296float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
17297 float distXZ = length(worldPos.xz - cameraPos.xz);
17298 float distY = abs(worldPos.y - cameraPos.y);
17299 return max(distXZ, distY);
17300}
17301
17302float cylindrical_distance(vec3 worldPos) {
17303 float distXZ = length(worldPos.xz);
17304 float distY = abs(worldPos.y);
17305 return max(distXZ, distY);
17306}
17307
17308float FLWFogFactor() {
17309 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
17310}
17311// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
17312vec2 shiftLight(vec2 lm) {
17313 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
17314}
17315
17316
17317uniform sampler3D uLightVolume;
17318
17319uniform sampler2D uBlockAtlas;
17320uniform sampler2D uLightMap;
17321
17322uniform vec3 uLightBoxSize;
17323uniform vec3 uLightBoxMin;
17324uniform mat4 uModel;
17325
17326uniform float uTime;
17327uniform mat4 uViewProjection;
17328uniform vec3 uCameraPos;
17329
17330void FLWFinalizeNormal(inout vec3 normal) {
17331 mat3 m;
17332 m[0] = uModel[0].xyz;
17333 m[1] = uModel[1].xyz;
17334 m[2] = uModel[2].xyz;
17335 normal = m * normal;
17336}
17337
17338#if defined(VERTEX_SHADER)
17339
17340out vec3 BoxCoord;
17341
17342void FLWFinalizeWorldPos(inout vec4 worldPos) {
17343 worldPos = uModel * worldPos;
17344
17345 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
17346
17347 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
17348
17349 gl_Position = uViewProjection * worldPos;
17350}
17351
17352#elif defined(FRAGMENT_SHADER)
17353
17354
17355#define ALPHA_DISCARD 0.1
17356// optimize discard usage
17357#if defined(ALPHA_DISCARD)
17358#if defined(GL_ARB_conservative_depth)
17359layout (depth_greater) out float gl_FragDepth;
17360#endif
17361#endif
17362
17363in vec3 BoxCoord;
17364
17365out vec4 FragColor;
17366
17367vec4 FLWBlockTexture(vec2 texCoords) {
17368 return texture(uBlockAtlas, texCoords);
17369}
17370
17371void FLWFinalizeColor(vec4 color) {
17372 float a = color.a;
17373 float fog = clamp(FLWFogFactor(), 0., 1.);
17374
17375 color = mix(uFogColor, color, fog);
17376 color.a = a;
17377
17378 #if defined(ALPHA_DISCARD)
17379 if (color.a < ALPHA_DISCARD) {
17380 discard;
17381 }
17382 #endif
17383
17384 FragColor = color;
17385}
17386
17387vec4 FLWLight(vec2 lightCoords) {
17388 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
17389
17390 return texture(uLightMap, shiftLight(lightCoords));
17391}
17392
17393#endif
17394
17395
17396mat4 rotate(vec3 axis, float angle) {
17397 float s = sin(angle);
17398 float c = cos(angle);
17399 float oc = 1. - c;
17400
17401 vec3 sa = axis * s;
17402
17403 mat4 mr = mat4(1.);
17404 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
17405 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
17406 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
17407
17408 return mr;
17409}
17410
17411mat4 rotation(vec3 rot) {
17412 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
17413}
17414
17415mat3 modelToNormal(mat4 mat) {
17416 // Discard the edges. This won't be accurate for scaled or skewed matrices,
17417 // but we don't have to work with those often.
17418 mat3 m;
17419 m[0] = mat[0].xyz;
17420 m[1] = mat[1].xyz;
17421 m[2] = mat[2].xyz;
17422 return m;
17423}
17424
17425#define PIOVER2 1.5707963268
17426
17427vec4 quat(vec3 axis, float angle) {
17428 float halfAngle = angle * PIOVER2 / 180.0;
17429 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
17430 return vec4(axis.xyz * cs.y, cs.x);
17431}
17432
17433vec4 quatMult(vec4 q1, vec4 q2) {
17434 // disgustingly vectorized quaternion multiplication
17435 vec4 a = q1.w * q2.xyzw;
17436 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
17437 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
17438 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
17439
17440 return a + b + c + d;
17441}
17442
17443vec3 rotateVertexByQuat(vec3 v, vec4 q) {
17444 vec3 i = q.xyz;
17445 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
17446}
17447
17448vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
17449 return rotateVertexByQuat(v, quat(axis, angle));
17450}
17451
17452float diffuse(vec3 normal) {
17453 vec3 n2 = normal * normal * vec3(.6, .25, .8);
17454 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
17455}
17456struct Vertex {
17457 vec3 pos;
17458 vec2 texCoords;
17459 vec3 normal;
17460};
17461
17462struct BlockFrag {
17463 vec2 texCoords;
17464 vec4 color;
17465 float diffuse;
17466 vec2 light;
17467};
17468
17469#if defined(FRAGMENT_SHADER)
17470void fragment(BlockFrag r) {
17471 vec4 tex = FLWBlockTexture(r.texCoords);
17472
17473 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
17474
17475 FLWFinalizeColor(color);
17476}
17477#endif
17478#define PI 3.1415926538
17479
17480
17481
17482
17483
17484struct Flap {
17485 vec3 instancePos;
17486 vec2 light;
17487 vec3 segmentOffset;
17488 vec3 pivot;
17489 float horizontalAngle;
17490 float intensity;
17491 float flapScale;
17492 float flapness;
17493};
17494
17495
17496
17497
17498#if defined(VERTEX_SHADER)
17499
17500float toRad(float degrees) {
17501 return fract(degrees / 360.) * PI * 2.;
17502}
17503
17504float getFlapAngle(float flapness, float intensity, float scale) {
17505 float absFlap = abs(flapness);
17506
17507 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
17508
17509 float halfAngle = angle * 0.5;
17510
17511 float which = step(0., flapness); // 0 if negative, 1 if positive
17512 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
17513
17514 return degrees;
17515}
17516
17517BlockFrag vertex(Vertex v, Flap flap) {
17518 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
17519
17520 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
17521 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
17522
17523 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
17524 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
17525
17526 vec4 worldPos = vec4(rotated, 1.);
17527 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
17528
17529 FLWFinalizeWorldPos(worldPos);
17530 FLWFinalizeNormal(norm);
17531
17532 BlockFrag b;
17533 b.diffuse = diffuse(norm);
17534 b.texCoords = v.texCoords;
17535 b.light = flap.light;
17536 #if defined(DEBUG_NORMAL)
17537 b.color = vec4(norm, 1.);
17538 #else
17539 b.color = vec4(1.);
17540 #endif
17541 return b;
17542}
17543#endif
17544
17545in vec2 v2f_texCoords;
17546in vec4 v2f_color;
17547in float v2f_diffuse;
17548in vec2 v2f_light;
17549void main() {
17550BlockFrag o;
17551o.texCoords = v2f_texCoords;
17552o.color = v2f_color;
17553o.diffuse = v2f_diffuse;
17554o.light = v2f_light;
17555fragment(o);
17556}
17557[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
17558
17559[17:17:49] [Render thread/ERROR]: #version 150
17560#extension GL_ARB_conservative_depth : enable
17561#define VERTEX_SHADER
17562#define DEBUG_NORMAL
17563#if defined(VERTEX_SHADER)
17564out float FragDistance;
17565#elif defined(FRAGMENT_SHADER)
17566in float FragDistance;
17567#endif
17568uniform vec4 uFogColor;
17569uniform vec2 uFogRange;
17570
17571float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
17572 float distXZ = length(worldPos.xz - cameraPos.xz);
17573 float distY = abs(worldPos.y - cameraPos.y);
17574 return max(distXZ, distY);
17575}
17576
17577float cylindrical_distance(vec3 worldPos) {
17578 float distXZ = length(worldPos.xz);
17579 float distY = abs(worldPos.y);
17580 return max(distXZ, distY);
17581}
17582
17583float FLWFogFactor() {
17584 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
17585}
17586// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
17587vec2 shiftLight(vec2 lm) {
17588 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
17589}
17590
17591
17592uniform sampler3D uLightVolume;
17593
17594uniform sampler2D uBlockAtlas;
17595uniform sampler2D uLightMap;
17596
17597uniform vec3 uLightBoxSize;
17598uniform vec3 uLightBoxMin;
17599uniform mat4 uModel;
17600
17601uniform float uTime;
17602uniform mat4 uViewProjection;
17603uniform vec3 uCameraPos;
17604
17605void FLWFinalizeNormal(inout vec3 normal) {
17606 mat3 m;
17607 m[0] = uModel[0].xyz;
17608 m[1] = uModel[1].xyz;
17609 m[2] = uModel[2].xyz;
17610 normal = m * normal;
17611}
17612
17613#if defined(VERTEX_SHADER)
17614
17615out vec3 BoxCoord;
17616
17617void FLWFinalizeWorldPos(inout vec4 worldPos) {
17618 worldPos = uModel * worldPos;
17619
17620 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
17621
17622 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
17623
17624 gl_Position = uViewProjection * worldPos;
17625}
17626
17627#elif defined(FRAGMENT_SHADER)
17628
17629
17630#define ALPHA_DISCARD 0.1
17631// optimize discard usage
17632#if defined(ALPHA_DISCARD)
17633#if defined(GL_ARB_conservative_depth)
17634layout (depth_greater) out float gl_FragDepth;
17635#endif
17636#endif
17637
17638in vec3 BoxCoord;
17639
17640out vec4 FragColor;
17641
17642vec4 FLWBlockTexture(vec2 texCoords) {
17643 return texture(uBlockAtlas, texCoords);
17644}
17645
17646void FLWFinalizeColor(vec4 color) {
17647 float a = color.a;
17648 float fog = clamp(FLWFogFactor(), 0., 1.);
17649
17650 color = mix(uFogColor, color, fog);
17651 color.a = a;
17652
17653 #if defined(ALPHA_DISCARD)
17654 if (color.a < ALPHA_DISCARD) {
17655 discard;
17656 }
17657 #endif
17658
17659 FragColor = color;
17660}
17661
17662vec4 FLWLight(vec2 lightCoords) {
17663 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
17664
17665 return texture(uLightMap, shiftLight(lightCoords));
17666}
17667
17668#endif
17669
17670
17671mat4 rotate(vec3 axis, float angle) {
17672 float s = sin(angle);
17673 float c = cos(angle);
17674 float oc = 1. - c;
17675
17676 vec3 sa = axis * s;
17677
17678 mat4 mr = mat4(1.);
17679 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
17680 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
17681 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
17682
17683 return mr;
17684}
17685
17686mat4 rotation(vec3 rot) {
17687 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
17688}
17689
17690mat3 modelToNormal(mat4 mat) {
17691 // Discard the edges. This won't be accurate for scaled or skewed matrices,
17692 // but we don't have to work with those often.
17693 mat3 m;
17694 m[0] = mat[0].xyz;
17695 m[1] = mat[1].xyz;
17696 m[2] = mat[2].xyz;
17697 return m;
17698}
17699
17700#define PIOVER2 1.5707963268
17701
17702vec4 quat(vec3 axis, float angle) {
17703 float halfAngle = angle * PIOVER2 / 180.0;
17704 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
17705 return vec4(axis.xyz * cs.y, cs.x);
17706}
17707
17708vec4 quatMult(vec4 q1, vec4 q2) {
17709 // disgustingly vectorized quaternion multiplication
17710 vec4 a = q1.w * q2.xyzw;
17711 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
17712 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
17713 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
17714
17715 return a + b + c + d;
17716}
17717
17718vec3 rotateVertexByQuat(vec3 v, vec4 q) {
17719 vec3 i = q.xyz;
17720 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
17721}
17722
17723vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
17724 return rotateVertexByQuat(v, quat(axis, angle));
17725}
17726
17727float diffuse(vec3 normal) {
17728 vec3 n2 = normal * normal * vec3(.6, .25, .8);
17729 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
17730}
17731struct Vertex {
17732 vec3 pos;
17733 vec2 texCoords;
17734 vec3 normal;
17735};
17736
17737struct BlockFrag {
17738 vec2 texCoords;
17739 vec4 color;
17740 float diffuse;
17741 vec2 light;
17742};
17743
17744#if defined(FRAGMENT_SHADER)
17745void fragment(BlockFrag r) {
17746 vec4 tex = FLWBlockTexture(r.texCoords);
17747
17748 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
17749
17750 FLWFinalizeColor(color);
17751}
17752#endif
17753#define PI 3.1415926538
17754
17755
17756
17757
17758
17759struct Flap {
17760 vec3 instancePos;
17761 vec2 light;
17762 vec3 segmentOffset;
17763 vec3 pivot;
17764 float horizontalAngle;
17765 float intensity;
17766 float flapScale;
17767 float flapness;
17768};
17769
17770
17771
17772
17773#if defined(VERTEX_SHADER)
17774
17775float toRad(float degrees) {
17776 return fract(degrees / 360.) * PI * 2.;
17777}
17778
17779float getFlapAngle(float flapness, float intensity, float scale) {
17780 float absFlap = abs(flapness);
17781
17782 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
17783
17784 float halfAngle = angle * 0.5;
17785
17786 float which = step(0., flapness); // 0 if negative, 1 if positive
17787 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
17788
17789 return degrees;
17790}
17791
17792BlockFrag vertex(Vertex v, Flap flap) {
17793 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
17794
17795 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
17796 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
17797
17798 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
17799 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
17800
17801 vec4 worldPos = vec4(rotated, 1.);
17802 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
17803
17804 FLWFinalizeWorldPos(worldPos);
17805 FLWFinalizeNormal(norm);
17806
17807 BlockFrag b;
17808 b.diffuse = diffuse(norm);
17809 b.texCoords = v.texCoords;
17810 b.light = flap.light;
17811 #if defined(DEBUG_NORMAL)
17812 b.color = vec4(norm, 1.);
17813 #else
17814 b.color = vec4(1.);
17815 #endif
17816 return b;
17817}
17818#endif
17819
17820in vec3 a_v_pos;
17821in vec2 a_v_texCoords;
17822in vec3 a_v_normal;
17823in vec3 a_i_instancePos;
17824in vec2 a_i_light;
17825in vec3 a_i_segmentOffset;
17826in vec3 a_i_pivot;
17827in float a_i_horizontalAngle;
17828in float a_i_intensity;
17829in float a_i_flapScale;
17830in float a_i_flapness;
17831out vec2 v2f_texCoords;
17832out vec4 v2f_color;
17833out float v2f_diffuse;
17834out vec2 v2f_light;
17835void main() {
17836Vertex v;
17837v.pos = a_v_pos;
17838v.texCoords = a_v_texCoords;
17839v.normal = a_v_normal;
17840Flap i;
17841i.instancePos = a_i_instancePos;
17842i.light = a_i_light;
17843i.segmentOffset = a_i_segmentOffset;
17844i.pivot = a_i_pivot;
17845i.horizontalAngle = a_i_horizontalAngle;
17846i.intensity = a_i_intensity;
17847i.flapScale = a_i_flapScale;
17848i.flapness = a_i_flapness;
17849BlockFrag o = vertex(v, i);
17850v2f_texCoords = o.texCoords;
17851v2f_color = o.color;
17852v2f_diffuse = o.diffuse;
17853v2f_light = o.light;
17854}
17855[17:17:49] [Render thread/ERROR]: Shader compilation log for create:flap: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
17856
17857[17:17:49] [Render thread/ERROR]: #version 150
17858#extension GL_ARB_conservative_depth : enable
17859#define FRAGMENT_SHADER
17860#define DEBUG_NORMAL
17861#if defined(VERTEX_SHADER)
17862out float FragDistance;
17863#elif defined(FRAGMENT_SHADER)
17864in float FragDistance;
17865#endif
17866uniform vec4 uFogColor;
17867uniform vec2 uFogRange;
17868
17869float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
17870 float distXZ = length(worldPos.xz - cameraPos.xz);
17871 float distY = abs(worldPos.y - cameraPos.y);
17872 return max(distXZ, distY);
17873}
17874
17875float cylindrical_distance(vec3 worldPos) {
17876 float distXZ = length(worldPos.xz);
17877 float distY = abs(worldPos.y);
17878 return max(distXZ, distY);
17879}
17880
17881float FLWFogFactor() {
17882 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
17883}
17884// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
17885vec2 shiftLight(vec2 lm) {
17886 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
17887}
17888
17889
17890uniform sampler3D uLightVolume;
17891
17892uniform sampler2D uBlockAtlas;
17893uniform sampler2D uLightMap;
17894
17895uniform vec3 uLightBoxSize;
17896uniform vec3 uLightBoxMin;
17897uniform mat4 uModel;
17898
17899uniform float uTime;
17900uniform mat4 uViewProjection;
17901uniform vec3 uCameraPos;
17902
17903void FLWFinalizeNormal(inout vec3 normal) {
17904 mat3 m;
17905 m[0] = uModel[0].xyz;
17906 m[1] = uModel[1].xyz;
17907 m[2] = uModel[2].xyz;
17908 normal = m * normal;
17909}
17910
17911#if defined(VERTEX_SHADER)
17912
17913out vec3 BoxCoord;
17914
17915void FLWFinalizeWorldPos(inout vec4 worldPos) {
17916 worldPos = uModel * worldPos;
17917
17918 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
17919
17920 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
17921
17922 gl_Position = uViewProjection * worldPos;
17923}
17924
17925#elif defined(FRAGMENT_SHADER)
17926
17927
17928#define ALPHA_DISCARD 0.1
17929// optimize discard usage
17930#if defined(ALPHA_DISCARD)
17931#if defined(GL_ARB_conservative_depth)
17932layout (depth_greater) out float gl_FragDepth;
17933#endif
17934#endif
17935
17936in vec3 BoxCoord;
17937
17938out vec4 FragColor;
17939
17940vec4 FLWBlockTexture(vec2 texCoords) {
17941 return texture(uBlockAtlas, texCoords);
17942}
17943
17944void FLWFinalizeColor(vec4 color) {
17945 float a = color.a;
17946 float fog = clamp(FLWFogFactor(), 0., 1.);
17947
17948 color = mix(uFogColor, color, fog);
17949 color.a = a;
17950
17951 #if defined(ALPHA_DISCARD)
17952 if (color.a < ALPHA_DISCARD) {
17953 discard;
17954 }
17955 #endif
17956
17957 FragColor = color;
17958}
17959
17960vec4 FLWLight(vec2 lightCoords) {
17961 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
17962
17963 return texture(uLightMap, shiftLight(lightCoords));
17964}
17965
17966#endif
17967
17968
17969mat4 rotate(vec3 axis, float angle) {
17970 float s = sin(angle);
17971 float c = cos(angle);
17972 float oc = 1. - c;
17973
17974 vec3 sa = axis * s;
17975
17976 mat4 mr = mat4(1.);
17977 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
17978 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
17979 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
17980
17981 return mr;
17982}
17983
17984mat4 rotation(vec3 rot) {
17985 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
17986}
17987
17988mat3 modelToNormal(mat4 mat) {
17989 // Discard the edges. This won't be accurate for scaled or skewed matrices,
17990 // but we don't have to work with those often.
17991 mat3 m;
17992 m[0] = mat[0].xyz;
17993 m[1] = mat[1].xyz;
17994 m[2] = mat[2].xyz;
17995 return m;
17996}
17997
17998#define PIOVER2 1.5707963268
17999
18000vec4 quat(vec3 axis, float angle) {
18001 float halfAngle = angle * PIOVER2 / 180.0;
18002 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
18003 return vec4(axis.xyz * cs.y, cs.x);
18004}
18005
18006vec4 quatMult(vec4 q1, vec4 q2) {
18007 // disgustingly vectorized quaternion multiplication
18008 vec4 a = q1.w * q2.xyzw;
18009 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
18010 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
18011 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
18012
18013 return a + b + c + d;
18014}
18015
18016vec3 rotateVertexByQuat(vec3 v, vec4 q) {
18017 vec3 i = q.xyz;
18018 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
18019}
18020
18021vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
18022 return rotateVertexByQuat(v, quat(axis, angle));
18023}
18024
18025float diffuse(vec3 normal) {
18026 vec3 n2 = normal * normal * vec3(.6, .25, .8);
18027 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
18028}
18029struct Vertex {
18030 vec3 pos;
18031 vec2 texCoords;
18032 vec3 normal;
18033};
18034
18035struct BlockFrag {
18036 vec2 texCoords;
18037 vec4 color;
18038 float diffuse;
18039 vec2 light;
18040};
18041
18042#if defined(FRAGMENT_SHADER)
18043void fragment(BlockFrag r) {
18044 vec4 tex = FLWBlockTexture(r.texCoords);
18045
18046 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
18047
18048 FLWFinalizeColor(color);
18049}
18050#endif
18051#define PI 3.1415926538
18052
18053
18054
18055
18056
18057struct Flap {
18058 vec3 instancePos;
18059 vec2 light;
18060 vec3 segmentOffset;
18061 vec3 pivot;
18062 float horizontalAngle;
18063 float intensity;
18064 float flapScale;
18065 float flapness;
18066};
18067
18068
18069
18070
18071#if defined(VERTEX_SHADER)
18072
18073float toRad(float degrees) {
18074 return fract(degrees / 360.) * PI * 2.;
18075}
18076
18077float getFlapAngle(float flapness, float intensity, float scale) {
18078 float absFlap = abs(flapness);
18079
18080 float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale;
18081
18082 float halfAngle = angle * 0.5;
18083
18084 float which = step(0., flapness); // 0 if negative, 1 if positive
18085 float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply
18086
18087 return degrees;
18088}
18089
18090BlockFrag vertex(Vertex v, Flap flap) {
18091 float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
18092
18093 vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
18094 vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle);
18095
18096 vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
18097 rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
18098
18099 vec4 worldPos = vec4(rotated, 1.);
18100 vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
18101
18102 FLWFinalizeWorldPos(worldPos);
18103 FLWFinalizeNormal(norm);
18104
18105 BlockFrag b;
18106 b.diffuse = diffuse(norm);
18107 b.texCoords = v.texCoords;
18108 b.light = flap.light;
18109 #if defined(DEBUG_NORMAL)
18110 b.color = vec4(norm, 1.);
18111 #else
18112 b.color = vec4(1.);
18113 #endif
18114 return b;
18115}
18116#endif
18117
18118in vec2 v2f_texCoords;
18119in vec4 v2f_color;
18120in float v2f_diffuse;
18121in vec2 v2f_light;
18122void main() {
18123BlockFrag o;
18124o.texCoords = v2f_texCoords;
18125o.color = v2f_color;
18126o.diffuse = v2f_diffuse;
18127o.light = v2f_light;
18128fragment(o);
18129}
18130[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
18131
18132[17:17:49] [Render thread/ERROR]: #version 150
18133#extension GL_ARB_conservative_depth : enable
18134#define VERTEX_SHADER
18135#if defined(VERTEX_SHADER)
18136out float FragDistance;
18137#elif defined(FRAGMENT_SHADER)
18138in float FragDistance;
18139#endif
18140uniform vec4 uFogColor;
18141uniform vec2 uFogRange;
18142
18143float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
18144 float distXZ = length(worldPos.xz - cameraPos.xz);
18145 float distY = abs(worldPos.y - cameraPos.y);
18146 return max(distXZ, distY);
18147}
18148
18149float cylindrical_distance(vec3 worldPos) {
18150 float distXZ = length(worldPos.xz);
18151 float distY = abs(worldPos.y);
18152 return max(distXZ, distY);
18153}
18154
18155float FLWFogFactor() {
18156 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
18157}
18158// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
18159vec2 shiftLight(vec2 lm) {
18160 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
18161}
18162
18163
18164uniform sampler3D uLightVolume;
18165
18166uniform sampler2D uBlockAtlas;
18167uniform sampler2D uLightMap;
18168
18169uniform vec3 uLightBoxSize;
18170uniform vec3 uLightBoxMin;
18171uniform mat4 uModel;
18172
18173uniform float uTime;
18174uniform mat4 uViewProjection;
18175uniform vec3 uCameraPos;
18176
18177void FLWFinalizeNormal(inout vec3 normal) {
18178 mat3 m;
18179 m[0] = uModel[0].xyz;
18180 m[1] = uModel[1].xyz;
18181 m[2] = uModel[2].xyz;
18182 normal = m * normal;
18183}
18184
18185#if defined(VERTEX_SHADER)
18186
18187out vec3 BoxCoord;
18188
18189void FLWFinalizeWorldPos(inout vec4 worldPos) {
18190 worldPos = uModel * worldPos;
18191
18192 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
18193
18194 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
18195
18196 gl_Position = uViewProjection * worldPos;
18197}
18198
18199#elif defined(FRAGMENT_SHADER)
18200
18201
18202#define ALPHA_DISCARD 0.1
18203// optimize discard usage
18204#if defined(ALPHA_DISCARD)
18205#if defined(GL_ARB_conservative_depth)
18206layout (depth_greater) out float gl_FragDepth;
18207#endif
18208#endif
18209
18210in vec3 BoxCoord;
18211
18212out vec4 FragColor;
18213
18214vec4 FLWBlockTexture(vec2 texCoords) {
18215 return texture(uBlockAtlas, texCoords);
18216}
18217
18218void FLWFinalizeColor(vec4 color) {
18219 float a = color.a;
18220 float fog = clamp(FLWFogFactor(), 0., 1.);
18221
18222 color = mix(uFogColor, color, fog);
18223 color.a = a;
18224
18225 #if defined(ALPHA_DISCARD)
18226 if (color.a < ALPHA_DISCARD) {
18227 discard;
18228 }
18229 #endif
18230
18231 FragColor = color;
18232}
18233
18234vec4 FLWLight(vec2 lightCoords) {
18235 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
18236
18237 return texture(uLightMap, shiftLight(lightCoords));
18238}
18239
18240#endif
18241
18242
18243#define PIOVER2 1.5707963268
18244
18245vec4 quat(vec3 axis, float angle) {
18246 float halfAngle = angle * PIOVER2 / 180.0;
18247 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
18248 return vec4(axis.xyz * cs.y, cs.x);
18249}
18250
18251vec4 quatMult(vec4 q1, vec4 q2) {
18252 // disgustingly vectorized quaternion multiplication
18253 vec4 a = q1.w * q2.xyzw;
18254 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
18255 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
18256 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
18257
18258 return a + b + c + d;
18259}
18260
18261vec3 rotateVertexByQuat(vec3 v, vec4 q) {
18262 vec3 i = q.xyz;
18263 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
18264}
18265
18266vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
18267 return rotateVertexByQuat(v, quat(axis, angle));
18268}
18269
18270mat4 rotate(vec3 axis, float angle) {
18271 float s = sin(angle);
18272 float c = cos(angle);
18273 float oc = 1. - c;
18274
18275 vec3 sa = axis * s;
18276
18277 mat4 mr = mat4(1.);
18278 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
18279 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
18280 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
18281
18282 return mr;
18283}
18284
18285mat4 rotation(vec3 rot) {
18286 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
18287}
18288
18289mat3 modelToNormal(mat4 mat) {
18290 // Discard the edges. This won't be accurate for scaled or skewed matrices,
18291 // but we don't have to work with those often.
18292 mat3 m;
18293 m[0] = mat[0].xyz;
18294 m[1] = mat[1].xyz;
18295 m[2] = mat[2].xyz;
18296 return m;
18297}
18298
18299float diffuse(vec3 normal) {
18300 vec3 n2 = normal * normal * vec3(.6, .25, .8);
18301 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
18302}
18303struct Vertex {
18304 vec3 pos;
18305 vec2 texCoords;
18306 vec3 normal;
18307};
18308
18309struct BlockFrag {
18310 vec2 texCoords;
18311 vec4 color;
18312 float diffuse;
18313 vec2 light;
18314};
18315
18316#if defined(FRAGMENT_SHADER)
18317void fragment(BlockFrag r) {
18318 vec4 tex = FLWBlockTexture(r.texCoords);
18319
18320 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
18321
18322 FLWFinalizeColor(color);
18323}
18324#endif
18325#define PI 3.1415926538
18326
18327
18328
18329
18330
18331struct Belt {
18332 vec2 light;
18333 vec4 color;
18334 vec3 pos;
18335 float speed;
18336 float offset;
18337 vec4 rotation;
18338 vec2 sourceTexture;
18339 vec4 scrollTexture;
18340 float scrollMult;
18341};
18342
18343
18344
18345
18346#if defined(VERTEX_SHADER)
18347BlockFrag vertex(Vertex v, Belt instance) {
18348 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
18349
18350 vec4 worldPos = vec4(rotated, 1.);
18351
18352 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
18353
18354 FLWFinalizeWorldPos(worldPos);
18355 FLWFinalizeNormal(norm);
18356
18357 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
18358 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
18359
18360 BlockFrag b;
18361 b.diffuse = diffuse(norm);
18362 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
18363 b.light = instance.light;
18364
18365 #if defined(DEBUG_RAINBOW)
18366 b.color = instance.color;
18367 #elif defined(DEBUG_NORMAL)
18368 b.color = vec4(norm, 1.);
18369 #else
18370 b.color = vec4(1.);
18371 #endif
18372
18373 return b;
18374}
18375#endif
18376
18377in vec3 a_v_pos;
18378in vec2 a_v_texCoords;
18379in vec3 a_v_normal;
18380in vec2 a_i_light;
18381in vec4 a_i_color;
18382in vec3 a_i_pos;
18383in float a_i_speed;
18384in float a_i_offset;
18385in vec4 a_i_rotation;
18386in vec2 a_i_sourceTexture;
18387in vec4 a_i_scrollTexture;
18388in float a_i_scrollMult;
18389out vec2 v2f_texCoords;
18390out vec4 v2f_color;
18391out float v2f_diffuse;
18392out vec2 v2f_light;
18393void main() {
18394Vertex v;
18395v.pos = a_v_pos;
18396v.texCoords = a_v_texCoords;
18397v.normal = a_v_normal;
18398Belt i;
18399i.light = a_i_light;
18400i.color = a_i_color;
18401i.pos = a_i_pos;
18402i.speed = a_i_speed;
18403i.offset = a_i_offset;
18404i.rotation = a_i_rotation;
18405i.sourceTexture = a_i_sourceTexture;
18406i.scrollTexture = a_i_scrollTexture;
18407i.scrollMult = a_i_scrollMult;
18408BlockFrag o = vertex(v, i);
18409v2f_texCoords = o.texCoords;
18410v2f_color = o.color;
18411v2f_diffuse = o.diffuse;
18412v2f_light = o.light;
18413}
18414[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
18415
18416[17:17:49] [Render thread/ERROR]: #version 150
18417#extension GL_ARB_conservative_depth : enable
18418#define FRAGMENT_SHADER
18419#if defined(VERTEX_SHADER)
18420out float FragDistance;
18421#elif defined(FRAGMENT_SHADER)
18422in float FragDistance;
18423#endif
18424uniform vec4 uFogColor;
18425uniform vec2 uFogRange;
18426
18427float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
18428 float distXZ = length(worldPos.xz - cameraPos.xz);
18429 float distY = abs(worldPos.y - cameraPos.y);
18430 return max(distXZ, distY);
18431}
18432
18433float cylindrical_distance(vec3 worldPos) {
18434 float distXZ = length(worldPos.xz);
18435 float distY = abs(worldPos.y);
18436 return max(distXZ, distY);
18437}
18438
18439float FLWFogFactor() {
18440 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
18441}
18442// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
18443vec2 shiftLight(vec2 lm) {
18444 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
18445}
18446
18447
18448uniform sampler3D uLightVolume;
18449
18450uniform sampler2D uBlockAtlas;
18451uniform sampler2D uLightMap;
18452
18453uniform vec3 uLightBoxSize;
18454uniform vec3 uLightBoxMin;
18455uniform mat4 uModel;
18456
18457uniform float uTime;
18458uniform mat4 uViewProjection;
18459uniform vec3 uCameraPos;
18460
18461void FLWFinalizeNormal(inout vec3 normal) {
18462 mat3 m;
18463 m[0] = uModel[0].xyz;
18464 m[1] = uModel[1].xyz;
18465 m[2] = uModel[2].xyz;
18466 normal = m * normal;
18467}
18468
18469#if defined(VERTEX_SHADER)
18470
18471out vec3 BoxCoord;
18472
18473void FLWFinalizeWorldPos(inout vec4 worldPos) {
18474 worldPos = uModel * worldPos;
18475
18476 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
18477
18478 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
18479
18480 gl_Position = uViewProjection * worldPos;
18481}
18482
18483#elif defined(FRAGMENT_SHADER)
18484
18485
18486#define ALPHA_DISCARD 0.1
18487// optimize discard usage
18488#if defined(ALPHA_DISCARD)
18489#if defined(GL_ARB_conservative_depth)
18490layout (depth_greater) out float gl_FragDepth;
18491#endif
18492#endif
18493
18494in vec3 BoxCoord;
18495
18496out vec4 FragColor;
18497
18498vec4 FLWBlockTexture(vec2 texCoords) {
18499 return texture(uBlockAtlas, texCoords);
18500}
18501
18502void FLWFinalizeColor(vec4 color) {
18503 float a = color.a;
18504 float fog = clamp(FLWFogFactor(), 0., 1.);
18505
18506 color = mix(uFogColor, color, fog);
18507 color.a = a;
18508
18509 #if defined(ALPHA_DISCARD)
18510 if (color.a < ALPHA_DISCARD) {
18511 discard;
18512 }
18513 #endif
18514
18515 FragColor = color;
18516}
18517
18518vec4 FLWLight(vec2 lightCoords) {
18519 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
18520
18521 return texture(uLightMap, shiftLight(lightCoords));
18522}
18523
18524#endif
18525
18526
18527#define PIOVER2 1.5707963268
18528
18529vec4 quat(vec3 axis, float angle) {
18530 float halfAngle = angle * PIOVER2 / 180.0;
18531 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
18532 return vec4(axis.xyz * cs.y, cs.x);
18533}
18534
18535vec4 quatMult(vec4 q1, vec4 q2) {
18536 // disgustingly vectorized quaternion multiplication
18537 vec4 a = q1.w * q2.xyzw;
18538 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
18539 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
18540 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
18541
18542 return a + b + c + d;
18543}
18544
18545vec3 rotateVertexByQuat(vec3 v, vec4 q) {
18546 vec3 i = q.xyz;
18547 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
18548}
18549
18550vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
18551 return rotateVertexByQuat(v, quat(axis, angle));
18552}
18553
18554mat4 rotate(vec3 axis, float angle) {
18555 float s = sin(angle);
18556 float c = cos(angle);
18557 float oc = 1. - c;
18558
18559 vec3 sa = axis * s;
18560
18561 mat4 mr = mat4(1.);
18562 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
18563 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
18564 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
18565
18566 return mr;
18567}
18568
18569mat4 rotation(vec3 rot) {
18570 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
18571}
18572
18573mat3 modelToNormal(mat4 mat) {
18574 // Discard the edges. This won't be accurate for scaled or skewed matrices,
18575 // but we don't have to work with those often.
18576 mat3 m;
18577 m[0] = mat[0].xyz;
18578 m[1] = mat[1].xyz;
18579 m[2] = mat[2].xyz;
18580 return m;
18581}
18582
18583float diffuse(vec3 normal) {
18584 vec3 n2 = normal * normal * vec3(.6, .25, .8);
18585 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
18586}
18587struct Vertex {
18588 vec3 pos;
18589 vec2 texCoords;
18590 vec3 normal;
18591};
18592
18593struct BlockFrag {
18594 vec2 texCoords;
18595 vec4 color;
18596 float diffuse;
18597 vec2 light;
18598};
18599
18600#if defined(FRAGMENT_SHADER)
18601void fragment(BlockFrag r) {
18602 vec4 tex = FLWBlockTexture(r.texCoords);
18603
18604 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
18605
18606 FLWFinalizeColor(color);
18607}
18608#endif
18609#define PI 3.1415926538
18610
18611
18612
18613
18614
18615struct Belt {
18616 vec2 light;
18617 vec4 color;
18618 vec3 pos;
18619 float speed;
18620 float offset;
18621 vec4 rotation;
18622 vec2 sourceTexture;
18623 vec4 scrollTexture;
18624 float scrollMult;
18625};
18626
18627
18628
18629
18630#if defined(VERTEX_SHADER)
18631BlockFrag vertex(Vertex v, Belt instance) {
18632 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
18633
18634 vec4 worldPos = vec4(rotated, 1.);
18635
18636 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
18637
18638 FLWFinalizeWorldPos(worldPos);
18639 FLWFinalizeNormal(norm);
18640
18641 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
18642 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
18643
18644 BlockFrag b;
18645 b.diffuse = diffuse(norm);
18646 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
18647 b.light = instance.light;
18648
18649 #if defined(DEBUG_RAINBOW)
18650 b.color = instance.color;
18651 #elif defined(DEBUG_NORMAL)
18652 b.color = vec4(norm, 1.);
18653 #else
18654 b.color = vec4(1.);
18655 #endif
18656
18657 return b;
18658}
18659#endif
18660
18661in vec2 v2f_texCoords;
18662in vec4 v2f_color;
18663in float v2f_diffuse;
18664in vec2 v2f_light;
18665void main() {
18666BlockFrag o;
18667o.texCoords = v2f_texCoords;
18668o.color = v2f_color;
18669o.diffuse = v2f_diffuse;
18670o.light = v2f_light;
18671fragment(o);
18672}
18673[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
18674
18675[17:17:49] [Render thread/ERROR]: #version 150
18676#extension GL_ARB_conservative_depth : enable
18677#define VERTEX_SHADER
18678#define DEBUG_RAINBOW
18679#if defined(VERTEX_SHADER)
18680out float FragDistance;
18681#elif defined(FRAGMENT_SHADER)
18682in float FragDistance;
18683#endif
18684uniform vec4 uFogColor;
18685uniform vec2 uFogRange;
18686
18687float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
18688 float distXZ = length(worldPos.xz - cameraPos.xz);
18689 float distY = abs(worldPos.y - cameraPos.y);
18690 return max(distXZ, distY);
18691}
18692
18693float cylindrical_distance(vec3 worldPos) {
18694 float distXZ = length(worldPos.xz);
18695 float distY = abs(worldPos.y);
18696 return max(distXZ, distY);
18697}
18698
18699float FLWFogFactor() {
18700 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
18701}
18702// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
18703vec2 shiftLight(vec2 lm) {
18704 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
18705}
18706
18707
18708uniform sampler3D uLightVolume;
18709
18710uniform sampler2D uBlockAtlas;
18711uniform sampler2D uLightMap;
18712
18713uniform vec3 uLightBoxSize;
18714uniform vec3 uLightBoxMin;
18715uniform mat4 uModel;
18716
18717uniform float uTime;
18718uniform mat4 uViewProjection;
18719uniform vec3 uCameraPos;
18720
18721void FLWFinalizeNormal(inout vec3 normal) {
18722 mat3 m;
18723 m[0] = uModel[0].xyz;
18724 m[1] = uModel[1].xyz;
18725 m[2] = uModel[2].xyz;
18726 normal = m * normal;
18727}
18728
18729#if defined(VERTEX_SHADER)
18730
18731out vec3 BoxCoord;
18732
18733void FLWFinalizeWorldPos(inout vec4 worldPos) {
18734 worldPos = uModel * worldPos;
18735
18736 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
18737
18738 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
18739
18740 gl_Position = uViewProjection * worldPos;
18741}
18742
18743#elif defined(FRAGMENT_SHADER)
18744
18745
18746#define ALPHA_DISCARD 0.1
18747// optimize discard usage
18748#if defined(ALPHA_DISCARD)
18749#if defined(GL_ARB_conservative_depth)
18750layout (depth_greater) out float gl_FragDepth;
18751#endif
18752#endif
18753
18754in vec3 BoxCoord;
18755
18756out vec4 FragColor;
18757
18758vec4 FLWBlockTexture(vec2 texCoords) {
18759 return texture(uBlockAtlas, texCoords);
18760}
18761
18762void FLWFinalizeColor(vec4 color) {
18763 float a = color.a;
18764 float fog = clamp(FLWFogFactor(), 0., 1.);
18765
18766 color = mix(uFogColor, color, fog);
18767 color.a = a;
18768
18769 #if defined(ALPHA_DISCARD)
18770 if (color.a < ALPHA_DISCARD) {
18771 discard;
18772 }
18773 #endif
18774
18775 FragColor = color;
18776}
18777
18778vec4 FLWLight(vec2 lightCoords) {
18779 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
18780
18781 return texture(uLightMap, shiftLight(lightCoords));
18782}
18783
18784#endif
18785
18786
18787#define PIOVER2 1.5707963268
18788
18789vec4 quat(vec3 axis, float angle) {
18790 float halfAngle = angle * PIOVER2 / 180.0;
18791 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
18792 return vec4(axis.xyz * cs.y, cs.x);
18793}
18794
18795vec4 quatMult(vec4 q1, vec4 q2) {
18796 // disgustingly vectorized quaternion multiplication
18797 vec4 a = q1.w * q2.xyzw;
18798 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
18799 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
18800 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
18801
18802 return a + b + c + d;
18803}
18804
18805vec3 rotateVertexByQuat(vec3 v, vec4 q) {
18806 vec3 i = q.xyz;
18807 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
18808}
18809
18810vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
18811 return rotateVertexByQuat(v, quat(axis, angle));
18812}
18813
18814mat4 rotate(vec3 axis, float angle) {
18815 float s = sin(angle);
18816 float c = cos(angle);
18817 float oc = 1. - c;
18818
18819 vec3 sa = axis * s;
18820
18821 mat4 mr = mat4(1.);
18822 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
18823 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
18824 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
18825
18826 return mr;
18827}
18828
18829mat4 rotation(vec3 rot) {
18830 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
18831}
18832
18833mat3 modelToNormal(mat4 mat) {
18834 // Discard the edges. This won't be accurate for scaled or skewed matrices,
18835 // but we don't have to work with those often.
18836 mat3 m;
18837 m[0] = mat[0].xyz;
18838 m[1] = mat[1].xyz;
18839 m[2] = mat[2].xyz;
18840 return m;
18841}
18842
18843float diffuse(vec3 normal) {
18844 vec3 n2 = normal * normal * vec3(.6, .25, .8);
18845 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
18846}
18847struct Vertex {
18848 vec3 pos;
18849 vec2 texCoords;
18850 vec3 normal;
18851};
18852
18853struct BlockFrag {
18854 vec2 texCoords;
18855 vec4 color;
18856 float diffuse;
18857 vec2 light;
18858};
18859
18860#if defined(FRAGMENT_SHADER)
18861void fragment(BlockFrag r) {
18862 vec4 tex = FLWBlockTexture(r.texCoords);
18863
18864 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
18865
18866 FLWFinalizeColor(color);
18867}
18868#endif
18869#define PI 3.1415926538
18870
18871
18872
18873
18874
18875struct Belt {
18876 vec2 light;
18877 vec4 color;
18878 vec3 pos;
18879 float speed;
18880 float offset;
18881 vec4 rotation;
18882 vec2 sourceTexture;
18883 vec4 scrollTexture;
18884 float scrollMult;
18885};
18886
18887
18888
18889
18890#if defined(VERTEX_SHADER)
18891BlockFrag vertex(Vertex v, Belt instance) {
18892 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
18893
18894 vec4 worldPos = vec4(rotated, 1.);
18895
18896 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
18897
18898 FLWFinalizeWorldPos(worldPos);
18899 FLWFinalizeNormal(norm);
18900
18901 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
18902 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
18903
18904 BlockFrag b;
18905 b.diffuse = diffuse(norm);
18906 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
18907 b.light = instance.light;
18908
18909 #if defined(DEBUG_RAINBOW)
18910 b.color = instance.color;
18911 #elif defined(DEBUG_NORMAL)
18912 b.color = vec4(norm, 1.);
18913 #else
18914 b.color = vec4(1.);
18915 #endif
18916
18917 return b;
18918}
18919#endif
18920
18921in vec3 a_v_pos;
18922in vec2 a_v_texCoords;
18923in vec3 a_v_normal;
18924in vec2 a_i_light;
18925in vec4 a_i_color;
18926in vec3 a_i_pos;
18927in float a_i_speed;
18928in float a_i_offset;
18929in vec4 a_i_rotation;
18930in vec2 a_i_sourceTexture;
18931in vec4 a_i_scrollTexture;
18932in float a_i_scrollMult;
18933out vec2 v2f_texCoords;
18934out vec4 v2f_color;
18935out float v2f_diffuse;
18936out vec2 v2f_light;
18937void main() {
18938Vertex v;
18939v.pos = a_v_pos;
18940v.texCoords = a_v_texCoords;
18941v.normal = a_v_normal;
18942Belt i;
18943i.light = a_i_light;
18944i.color = a_i_color;
18945i.pos = a_i_pos;
18946i.speed = a_i_speed;
18947i.offset = a_i_offset;
18948i.rotation = a_i_rotation;
18949i.sourceTexture = a_i_sourceTexture;
18950i.scrollTexture = a_i_scrollTexture;
18951i.scrollMult = a_i_scrollMult;
18952BlockFrag o = vertex(v, i);
18953v2f_texCoords = o.texCoords;
18954v2f_color = o.color;
18955v2f_diffuse = o.diffuse;
18956v2f_light = o.light;
18957}
18958[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
18959
18960[17:17:49] [Render thread/ERROR]: #version 150
18961#extension GL_ARB_conservative_depth : enable
18962#define FRAGMENT_SHADER
18963#define DEBUG_RAINBOW
18964#if defined(VERTEX_SHADER)
18965out float FragDistance;
18966#elif defined(FRAGMENT_SHADER)
18967in float FragDistance;
18968#endif
18969uniform vec4 uFogColor;
18970uniform vec2 uFogRange;
18971
18972float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
18973 float distXZ = length(worldPos.xz - cameraPos.xz);
18974 float distY = abs(worldPos.y - cameraPos.y);
18975 return max(distXZ, distY);
18976}
18977
18978float cylindrical_distance(vec3 worldPos) {
18979 float distXZ = length(worldPos.xz);
18980 float distY = abs(worldPos.y);
18981 return max(distXZ, distY);
18982}
18983
18984float FLWFogFactor() {
18985 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
18986}
18987// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
18988vec2 shiftLight(vec2 lm) {
18989 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
18990}
18991
18992
18993uniform sampler3D uLightVolume;
18994
18995uniform sampler2D uBlockAtlas;
18996uniform sampler2D uLightMap;
18997
18998uniform vec3 uLightBoxSize;
18999uniform vec3 uLightBoxMin;
19000uniform mat4 uModel;
19001
19002uniform float uTime;
19003uniform mat4 uViewProjection;
19004uniform vec3 uCameraPos;
19005
19006void FLWFinalizeNormal(inout vec3 normal) {
19007 mat3 m;
19008 m[0] = uModel[0].xyz;
19009 m[1] = uModel[1].xyz;
19010 m[2] = uModel[2].xyz;
19011 normal = m * normal;
19012}
19013
19014#if defined(VERTEX_SHADER)
19015
19016out vec3 BoxCoord;
19017
19018void FLWFinalizeWorldPos(inout vec4 worldPos) {
19019 worldPos = uModel * worldPos;
19020
19021 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
19022
19023 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
19024
19025 gl_Position = uViewProjection * worldPos;
19026}
19027
19028#elif defined(FRAGMENT_SHADER)
19029
19030
19031#define ALPHA_DISCARD 0.1
19032// optimize discard usage
19033#if defined(ALPHA_DISCARD)
19034#if defined(GL_ARB_conservative_depth)
19035layout (depth_greater) out float gl_FragDepth;
19036#endif
19037#endif
19038
19039in vec3 BoxCoord;
19040
19041out vec4 FragColor;
19042
19043vec4 FLWBlockTexture(vec2 texCoords) {
19044 return texture(uBlockAtlas, texCoords);
19045}
19046
19047void FLWFinalizeColor(vec4 color) {
19048 float a = color.a;
19049 float fog = clamp(FLWFogFactor(), 0., 1.);
19050
19051 color = mix(uFogColor, color, fog);
19052 color.a = a;
19053
19054 #if defined(ALPHA_DISCARD)
19055 if (color.a < ALPHA_DISCARD) {
19056 discard;
19057 }
19058 #endif
19059
19060 FragColor = color;
19061}
19062
19063vec4 FLWLight(vec2 lightCoords) {
19064 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
19065
19066 return texture(uLightMap, shiftLight(lightCoords));
19067}
19068
19069#endif
19070
19071
19072#define PIOVER2 1.5707963268
19073
19074vec4 quat(vec3 axis, float angle) {
19075 float halfAngle = angle * PIOVER2 / 180.0;
19076 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
19077 return vec4(axis.xyz * cs.y, cs.x);
19078}
19079
19080vec4 quatMult(vec4 q1, vec4 q2) {
19081 // disgustingly vectorized quaternion multiplication
19082 vec4 a = q1.w * q2.xyzw;
19083 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
19084 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
19085 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
19086
19087 return a + b + c + d;
19088}
19089
19090vec3 rotateVertexByQuat(vec3 v, vec4 q) {
19091 vec3 i = q.xyz;
19092 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
19093}
19094
19095vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
19096 return rotateVertexByQuat(v, quat(axis, angle));
19097}
19098
19099mat4 rotate(vec3 axis, float angle) {
19100 float s = sin(angle);
19101 float c = cos(angle);
19102 float oc = 1. - c;
19103
19104 vec3 sa = axis * s;
19105
19106 mat4 mr = mat4(1.);
19107 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
19108 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
19109 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
19110
19111 return mr;
19112}
19113
19114mat4 rotation(vec3 rot) {
19115 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
19116}
19117
19118mat3 modelToNormal(mat4 mat) {
19119 // Discard the edges. This won't be accurate for scaled or skewed matrices,
19120 // but we don't have to work with those often.
19121 mat3 m;
19122 m[0] = mat[0].xyz;
19123 m[1] = mat[1].xyz;
19124 m[2] = mat[2].xyz;
19125 return m;
19126}
19127
19128float diffuse(vec3 normal) {
19129 vec3 n2 = normal * normal * vec3(.6, .25, .8);
19130 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
19131}
19132struct Vertex {
19133 vec3 pos;
19134 vec2 texCoords;
19135 vec3 normal;
19136};
19137
19138struct BlockFrag {
19139 vec2 texCoords;
19140 vec4 color;
19141 float diffuse;
19142 vec2 light;
19143};
19144
19145#if defined(FRAGMENT_SHADER)
19146void fragment(BlockFrag r) {
19147 vec4 tex = FLWBlockTexture(r.texCoords);
19148
19149 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
19150
19151 FLWFinalizeColor(color);
19152}
19153#endif
19154#define PI 3.1415926538
19155
19156
19157
19158
19159
19160struct Belt {
19161 vec2 light;
19162 vec4 color;
19163 vec3 pos;
19164 float speed;
19165 float offset;
19166 vec4 rotation;
19167 vec2 sourceTexture;
19168 vec4 scrollTexture;
19169 float scrollMult;
19170};
19171
19172
19173
19174
19175#if defined(VERTEX_SHADER)
19176BlockFrag vertex(Vertex v, Belt instance) {
19177 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
19178
19179 vec4 worldPos = vec4(rotated, 1.);
19180
19181 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
19182
19183 FLWFinalizeWorldPos(worldPos);
19184 FLWFinalizeNormal(norm);
19185
19186 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
19187 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
19188
19189 BlockFrag b;
19190 b.diffuse = diffuse(norm);
19191 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
19192 b.light = instance.light;
19193
19194 #if defined(DEBUG_RAINBOW)
19195 b.color = instance.color;
19196 #elif defined(DEBUG_NORMAL)
19197 b.color = vec4(norm, 1.);
19198 #else
19199 b.color = vec4(1.);
19200 #endif
19201
19202 return b;
19203}
19204#endif
19205
19206in vec2 v2f_texCoords;
19207in vec4 v2f_color;
19208in float v2f_diffuse;
19209in vec2 v2f_light;
19210void main() {
19211BlockFrag o;
19212o.texCoords = v2f_texCoords;
19213o.color = v2f_color;
19214o.diffuse = v2f_diffuse;
19215o.light = v2f_light;
19216fragment(o);
19217}
19218[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
19219
19220[17:17:49] [Render thread/ERROR]: #version 150
19221#extension GL_ARB_conservative_depth : enable
19222#define VERTEX_SHADER
19223#define DEBUG_NORMAL
19224#if defined(VERTEX_SHADER)
19225out float FragDistance;
19226#elif defined(FRAGMENT_SHADER)
19227in float FragDistance;
19228#endif
19229uniform vec4 uFogColor;
19230uniform vec2 uFogRange;
19231
19232float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
19233 float distXZ = length(worldPos.xz - cameraPos.xz);
19234 float distY = abs(worldPos.y - cameraPos.y);
19235 return max(distXZ, distY);
19236}
19237
19238float cylindrical_distance(vec3 worldPos) {
19239 float distXZ = length(worldPos.xz);
19240 float distY = abs(worldPos.y);
19241 return max(distXZ, distY);
19242}
19243
19244float FLWFogFactor() {
19245 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
19246}
19247// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
19248vec2 shiftLight(vec2 lm) {
19249 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
19250}
19251
19252
19253uniform sampler3D uLightVolume;
19254
19255uniform sampler2D uBlockAtlas;
19256uniform sampler2D uLightMap;
19257
19258uniform vec3 uLightBoxSize;
19259uniform vec3 uLightBoxMin;
19260uniform mat4 uModel;
19261
19262uniform float uTime;
19263uniform mat4 uViewProjection;
19264uniform vec3 uCameraPos;
19265
19266void FLWFinalizeNormal(inout vec3 normal) {
19267 mat3 m;
19268 m[0] = uModel[0].xyz;
19269 m[1] = uModel[1].xyz;
19270 m[2] = uModel[2].xyz;
19271 normal = m * normal;
19272}
19273
19274#if defined(VERTEX_SHADER)
19275
19276out vec3 BoxCoord;
19277
19278void FLWFinalizeWorldPos(inout vec4 worldPos) {
19279 worldPos = uModel * worldPos;
19280
19281 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
19282
19283 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
19284
19285 gl_Position = uViewProjection * worldPos;
19286}
19287
19288#elif defined(FRAGMENT_SHADER)
19289
19290
19291#define ALPHA_DISCARD 0.1
19292// optimize discard usage
19293#if defined(ALPHA_DISCARD)
19294#if defined(GL_ARB_conservative_depth)
19295layout (depth_greater) out float gl_FragDepth;
19296#endif
19297#endif
19298
19299in vec3 BoxCoord;
19300
19301out vec4 FragColor;
19302
19303vec4 FLWBlockTexture(vec2 texCoords) {
19304 return texture(uBlockAtlas, texCoords);
19305}
19306
19307void FLWFinalizeColor(vec4 color) {
19308 float a = color.a;
19309 float fog = clamp(FLWFogFactor(), 0., 1.);
19310
19311 color = mix(uFogColor, color, fog);
19312 color.a = a;
19313
19314 #if defined(ALPHA_DISCARD)
19315 if (color.a < ALPHA_DISCARD) {
19316 discard;
19317 }
19318 #endif
19319
19320 FragColor = color;
19321}
19322
19323vec4 FLWLight(vec2 lightCoords) {
19324 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
19325
19326 return texture(uLightMap, shiftLight(lightCoords));
19327}
19328
19329#endif
19330
19331
19332#define PIOVER2 1.5707963268
19333
19334vec4 quat(vec3 axis, float angle) {
19335 float halfAngle = angle * PIOVER2 / 180.0;
19336 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
19337 return vec4(axis.xyz * cs.y, cs.x);
19338}
19339
19340vec4 quatMult(vec4 q1, vec4 q2) {
19341 // disgustingly vectorized quaternion multiplication
19342 vec4 a = q1.w * q2.xyzw;
19343 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
19344 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
19345 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
19346
19347 return a + b + c + d;
19348}
19349
19350vec3 rotateVertexByQuat(vec3 v, vec4 q) {
19351 vec3 i = q.xyz;
19352 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
19353}
19354
19355vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
19356 return rotateVertexByQuat(v, quat(axis, angle));
19357}
19358
19359mat4 rotate(vec3 axis, float angle) {
19360 float s = sin(angle);
19361 float c = cos(angle);
19362 float oc = 1. - c;
19363
19364 vec3 sa = axis * s;
19365
19366 mat4 mr = mat4(1.);
19367 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
19368 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
19369 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
19370
19371 return mr;
19372}
19373
19374mat4 rotation(vec3 rot) {
19375 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
19376}
19377
19378mat3 modelToNormal(mat4 mat) {
19379 // Discard the edges. This won't be accurate for scaled or skewed matrices,
19380 // but we don't have to work with those often.
19381 mat3 m;
19382 m[0] = mat[0].xyz;
19383 m[1] = mat[1].xyz;
19384 m[2] = mat[2].xyz;
19385 return m;
19386}
19387
19388float diffuse(vec3 normal) {
19389 vec3 n2 = normal * normal * vec3(.6, .25, .8);
19390 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
19391}
19392struct Vertex {
19393 vec3 pos;
19394 vec2 texCoords;
19395 vec3 normal;
19396};
19397
19398struct BlockFrag {
19399 vec2 texCoords;
19400 vec4 color;
19401 float diffuse;
19402 vec2 light;
19403};
19404
19405#if defined(FRAGMENT_SHADER)
19406void fragment(BlockFrag r) {
19407 vec4 tex = FLWBlockTexture(r.texCoords);
19408
19409 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
19410
19411 FLWFinalizeColor(color);
19412}
19413#endif
19414#define PI 3.1415926538
19415
19416
19417
19418
19419
19420struct Belt {
19421 vec2 light;
19422 vec4 color;
19423 vec3 pos;
19424 float speed;
19425 float offset;
19426 vec4 rotation;
19427 vec2 sourceTexture;
19428 vec4 scrollTexture;
19429 float scrollMult;
19430};
19431
19432
19433
19434
19435#if defined(VERTEX_SHADER)
19436BlockFrag vertex(Vertex v, Belt instance) {
19437 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
19438
19439 vec4 worldPos = vec4(rotated, 1.);
19440
19441 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
19442
19443 FLWFinalizeWorldPos(worldPos);
19444 FLWFinalizeNormal(norm);
19445
19446 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
19447 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
19448
19449 BlockFrag b;
19450 b.diffuse = diffuse(norm);
19451 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
19452 b.light = instance.light;
19453
19454 #if defined(DEBUG_RAINBOW)
19455 b.color = instance.color;
19456 #elif defined(DEBUG_NORMAL)
19457 b.color = vec4(norm, 1.);
19458 #else
19459 b.color = vec4(1.);
19460 #endif
19461
19462 return b;
19463}
19464#endif
19465
19466in vec3 a_v_pos;
19467in vec2 a_v_texCoords;
19468in vec3 a_v_normal;
19469in vec2 a_i_light;
19470in vec4 a_i_color;
19471in vec3 a_i_pos;
19472in float a_i_speed;
19473in float a_i_offset;
19474in vec4 a_i_rotation;
19475in vec2 a_i_sourceTexture;
19476in vec4 a_i_scrollTexture;
19477in float a_i_scrollMult;
19478out vec2 v2f_texCoords;
19479out vec4 v2f_color;
19480out float v2f_diffuse;
19481out vec2 v2f_light;
19482void main() {
19483Vertex v;
19484v.pos = a_v_pos;
19485v.texCoords = a_v_texCoords;
19486v.normal = a_v_normal;
19487Belt i;
19488i.light = a_i_light;
19489i.color = a_i_color;
19490i.pos = a_i_pos;
19491i.speed = a_i_speed;
19492i.offset = a_i_offset;
19493i.rotation = a_i_rotation;
19494i.sourceTexture = a_i_sourceTexture;
19495i.scrollTexture = a_i_scrollTexture;
19496i.scrollMult = a_i_scrollMult;
19497BlockFrag o = vertex(v, i);
19498v2f_texCoords = o.texCoords;
19499v2f_color = o.color;
19500v2f_diffuse = o.diffuse;
19501v2f_light = o.light;
19502}
19503[17:17:49] [Render thread/ERROR]: Shader compilation log for create:belt: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
19504
19505[17:17:49] [Render thread/ERROR]: #version 150
19506#extension GL_ARB_conservative_depth : enable
19507#define FRAGMENT_SHADER
19508#define DEBUG_NORMAL
19509#if defined(VERTEX_SHADER)
19510out float FragDistance;
19511#elif defined(FRAGMENT_SHADER)
19512in float FragDistance;
19513#endif
19514uniform vec4 uFogColor;
19515uniform vec2 uFogRange;
19516
19517float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
19518 float distXZ = length(worldPos.xz - cameraPos.xz);
19519 float distY = abs(worldPos.y - cameraPos.y);
19520 return max(distXZ, distY);
19521}
19522
19523float cylindrical_distance(vec3 worldPos) {
19524 float distXZ = length(worldPos.xz);
19525 float distY = abs(worldPos.y);
19526 return max(distXZ, distY);
19527}
19528
19529float FLWFogFactor() {
19530 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
19531}
19532// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
19533vec2 shiftLight(vec2 lm) {
19534 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
19535}
19536
19537
19538uniform sampler3D uLightVolume;
19539
19540uniform sampler2D uBlockAtlas;
19541uniform sampler2D uLightMap;
19542
19543uniform vec3 uLightBoxSize;
19544uniform vec3 uLightBoxMin;
19545uniform mat4 uModel;
19546
19547uniform float uTime;
19548uniform mat4 uViewProjection;
19549uniform vec3 uCameraPos;
19550
19551void FLWFinalizeNormal(inout vec3 normal) {
19552 mat3 m;
19553 m[0] = uModel[0].xyz;
19554 m[1] = uModel[1].xyz;
19555 m[2] = uModel[2].xyz;
19556 normal = m * normal;
19557}
19558
19559#if defined(VERTEX_SHADER)
19560
19561out vec3 BoxCoord;
19562
19563void FLWFinalizeWorldPos(inout vec4 worldPos) {
19564 worldPos = uModel * worldPos;
19565
19566 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
19567
19568 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
19569
19570 gl_Position = uViewProjection * worldPos;
19571}
19572
19573#elif defined(FRAGMENT_SHADER)
19574
19575
19576#define ALPHA_DISCARD 0.1
19577// optimize discard usage
19578#if defined(ALPHA_DISCARD)
19579#if defined(GL_ARB_conservative_depth)
19580layout (depth_greater) out float gl_FragDepth;
19581#endif
19582#endif
19583
19584in vec3 BoxCoord;
19585
19586out vec4 FragColor;
19587
19588vec4 FLWBlockTexture(vec2 texCoords) {
19589 return texture(uBlockAtlas, texCoords);
19590}
19591
19592void FLWFinalizeColor(vec4 color) {
19593 float a = color.a;
19594 float fog = clamp(FLWFogFactor(), 0., 1.);
19595
19596 color = mix(uFogColor, color, fog);
19597 color.a = a;
19598
19599 #if defined(ALPHA_DISCARD)
19600 if (color.a < ALPHA_DISCARD) {
19601 discard;
19602 }
19603 #endif
19604
19605 FragColor = color;
19606}
19607
19608vec4 FLWLight(vec2 lightCoords) {
19609 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
19610
19611 return texture(uLightMap, shiftLight(lightCoords));
19612}
19613
19614#endif
19615
19616
19617#define PIOVER2 1.5707963268
19618
19619vec4 quat(vec3 axis, float angle) {
19620 float halfAngle = angle * PIOVER2 / 180.0;
19621 vec2 cs = sin(vec2(PIOVER2 - halfAngle, halfAngle)); // compute sin and cos in one instruction
19622 return vec4(axis.xyz * cs.y, cs.x);
19623}
19624
19625vec4 quatMult(vec4 q1, vec4 q2) {
19626 // disgustingly vectorized quaternion multiplication
19627 vec4 a = q1.w * q2.xyzw;
19628 vec4 b = q1.x * q2.wzxy * vec4(1., -1., 1., -1.);
19629 vec4 c = q1.y * q2.zwxy * vec4(1., 1., -1., -1.);
19630 vec4 d = q1.z * q2.yxwz * vec4(-1., 1., 1., -1.);
19631
19632 return a + b + c + d;
19633}
19634
19635vec3 rotateVertexByQuat(vec3 v, vec4 q) {
19636 vec3 i = q.xyz;
19637 return v + 2.0 * cross(i, cross(i, v) + q.w * v);
19638}
19639
19640vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
19641 return rotateVertexByQuat(v, quat(axis, angle));
19642}
19643
19644mat4 rotate(vec3 axis, float angle) {
19645 float s = sin(angle);
19646 float c = cos(angle);
19647 float oc = 1. - c;
19648
19649 vec3 sa = axis * s;
19650
19651 mat4 mr = mat4(1.);
19652 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
19653 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
19654 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
19655
19656 return mr;
19657}
19658
19659mat4 rotation(vec3 rot) {
19660 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
19661}
19662
19663mat3 modelToNormal(mat4 mat) {
19664 // Discard the edges. This won't be accurate for scaled or skewed matrices,
19665 // but we don't have to work with those often.
19666 mat3 m;
19667 m[0] = mat[0].xyz;
19668 m[1] = mat[1].xyz;
19669 m[2] = mat[2].xyz;
19670 return m;
19671}
19672
19673float diffuse(vec3 normal) {
19674 vec3 n2 = normal * normal * vec3(.6, .25, .8);
19675 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
19676}
19677struct Vertex {
19678 vec3 pos;
19679 vec2 texCoords;
19680 vec3 normal;
19681};
19682
19683struct BlockFrag {
19684 vec2 texCoords;
19685 vec4 color;
19686 float diffuse;
19687 vec2 light;
19688};
19689
19690#if defined(FRAGMENT_SHADER)
19691void fragment(BlockFrag r) {
19692 vec4 tex = FLWBlockTexture(r.texCoords);
19693
19694 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
19695
19696 FLWFinalizeColor(color);
19697}
19698#endif
19699#define PI 3.1415926538
19700
19701
19702
19703
19704
19705struct Belt {
19706 vec2 light;
19707 vec4 color;
19708 vec3 pos;
19709 float speed;
19710 float offset;
19711 vec4 rotation;
19712 vec2 sourceTexture;
19713 vec4 scrollTexture;
19714 float scrollMult;
19715};
19716
19717
19718
19719
19720#if defined(VERTEX_SHADER)
19721BlockFrag vertex(Vertex v, Belt instance) {
19722 vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
19723
19724 vec4 worldPos = vec4(rotated, 1.);
19725
19726 vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
19727
19728 FLWFinalizeWorldPos(worldPos);
19729 FLWFinalizeNormal(norm);
19730
19731 float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
19732 float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
19733
19734 BlockFrag b;
19735 b.diffuse = diffuse(norm);
19736 b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
19737 b.light = instance.light;
19738
19739 #if defined(DEBUG_RAINBOW)
19740 b.color = instance.color;
19741 #elif defined(DEBUG_NORMAL)
19742 b.color = vec4(norm, 1.);
19743 #else
19744 b.color = vec4(1.);
19745 #endif
19746
19747 return b;
19748}
19749#endif
19750
19751in vec2 v2f_texCoords;
19752in vec4 v2f_color;
19753in float v2f_diffuse;
19754in vec2 v2f_light;
19755void main() {
19756BlockFrag o;
19757o.texCoords = v2f_texCoords;
19758o.color = v2f_color;
19759o.diffuse = v2f_diffuse;
19760o.light = v2f_light;
19761fragment(o);
19762}
19763[17:17:49] [Render thread/INFO]: Loading context 'create:context/contraption'
19764[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_structure: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
19765
19766[17:17:49] [Render thread/ERROR]: #version 150
19767#extension GL_ARB_conservative_depth : enable
19768#define VERTEX_SHADER
19769#if defined(VERTEX_SHADER)
19770out float FragDistance;
19771#elif defined(FRAGMENT_SHADER)
19772in float FragDistance;
19773#endif
19774uniform vec4 uFogColor;
19775uniform vec2 uFogRange;
19776
19777float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
19778 float distXZ = length(worldPos.xz - cameraPos.xz);
19779 float distY = abs(worldPos.y - cameraPos.y);
19780 return max(distXZ, distY);
19781}
19782
19783float cylindrical_distance(vec3 worldPos) {
19784 float distXZ = length(worldPos.xz);
19785 float distY = abs(worldPos.y);
19786 return max(distXZ, distY);
19787}
19788
19789float FLWFogFactor() {
19790 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
19791}
19792// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
19793vec2 shiftLight(vec2 lm) {
19794 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
19795}
19796
19797
19798uniform sampler3D uLightVolume;
19799
19800uniform sampler2D uBlockAtlas;
19801uniform sampler2D uLightMap;
19802
19803uniform vec3 uLightBoxSize;
19804uniform vec3 uLightBoxMin;
19805uniform mat4 uModel;
19806
19807uniform float uTime;
19808uniform mat4 uViewProjection;
19809uniform vec3 uCameraPos;
19810
19811void FLWFinalizeNormal(inout vec3 normal) {
19812 mat3 m;
19813 m[0] = uModel[0].xyz;
19814 m[1] = uModel[1].xyz;
19815 m[2] = uModel[2].xyz;
19816 normal = m * normal;
19817}
19818
19819#if defined(VERTEX_SHADER)
19820
19821out vec3 BoxCoord;
19822
19823void FLWFinalizeWorldPos(inout vec4 worldPos) {
19824 worldPos = uModel * worldPos;
19825
19826 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
19827
19828 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
19829
19830 gl_Position = uViewProjection * worldPos;
19831}
19832
19833#elif defined(FRAGMENT_SHADER)
19834
19835
19836#define ALPHA_DISCARD 0.1
19837// optimize discard usage
19838#if defined(ALPHA_DISCARD)
19839#if defined(GL_ARB_conservative_depth)
19840layout (depth_greater) out float gl_FragDepth;
19841#endif
19842#endif
19843
19844in vec3 BoxCoord;
19845
19846out vec4 FragColor;
19847
19848vec4 FLWBlockTexture(vec2 texCoords) {
19849 return texture(uBlockAtlas, texCoords);
19850}
19851
19852void FLWFinalizeColor(vec4 color) {
19853 float a = color.a;
19854 float fog = clamp(FLWFogFactor(), 0., 1.);
19855
19856 color = mix(uFogColor, color, fog);
19857 color.a = a;
19858
19859 #if defined(ALPHA_DISCARD)
19860 if (color.a < ALPHA_DISCARD) {
19861 discard;
19862 }
19863 #endif
19864
19865 FragColor = color;
19866}
19867
19868vec4 FLWLight(vec2 lightCoords) {
19869 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
19870
19871 return texture(uLightMap, shiftLight(lightCoords));
19872}
19873
19874#endif
19875
19876
19877mat4 rotate(vec3 axis, float angle) {
19878 float s = sin(angle);
19879 float c = cos(angle);
19880 float oc = 1. - c;
19881
19882 vec3 sa = axis * s;
19883
19884 mat4 mr = mat4(1.);
19885 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
19886 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
19887 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
19888
19889 return mr;
19890}
19891
19892mat4 rotation(vec3 rot) {
19893 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
19894}
19895
19896mat3 modelToNormal(mat4 mat) {
19897 // Discard the edges. This won't be accurate for scaled or skewed matrices,
19898 // but we don't have to work with those often.
19899 mat3 m;
19900 m[0] = mat[0].xyz;
19901 m[1] = mat[1].xyz;
19902 m[2] = mat[2].xyz;
19903 return m;
19904}
19905
19906float diffuse(vec3 normal) {
19907 vec3 n2 = normal * normal * vec3(.6, .25, .8);
19908 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
19909}
19910
19911struct BlockFrag {
19912 vec2 texCoords;
19913 vec4 color;
19914 float diffuse;
19915 vec2 light;
19916};
19917
19918#if defined(FRAGMENT_SHADER)
19919void fragment(BlockFrag r) {
19920 vec4 tex = FLWBlockTexture(r.texCoords);
19921
19922 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
19923
19924 FLWFinalizeColor(color);
19925}
19926#endif
19927#define PI 3.1415926538
19928
19929
19930
19931
19932struct Vertex {
19933 vec3 pos;
19934 vec4 color;
19935 vec2 texCoords;
19936 vec2 modelLight;
19937 vec3 normal;
19938};
19939
19940
19941
19942#if defined(VERTEX_SHADER)
19943BlockFrag vertex(Vertex v) {
19944 vec4 worldPos = vec4(v.pos, 1.);
19945 vec3 norm = v.normal;
19946
19947 FLWFinalizeWorldPos(worldPos);
19948 FLWFinalizeNormal(norm);
19949
19950 BlockFrag b;
19951 b.diffuse = diffuse(norm);
19952 b.texCoords = v.texCoords;
19953 b.light = v.modelLight;
19954
19955 #if defined(DEBUG_NORMAL)
19956 b.color = vec4(norm, 1.);
19957 #else
19958 b.color = v.color;
19959 #endif
19960
19961 return b;
19962}
19963#endif
19964
19965in vec3 a_v_pos;
19966in vec4 a_v_color;
19967in vec2 a_v_texCoords;
19968in vec2 a_v_modelLight;
19969in vec3 a_v_normal;
19970out vec2 v2f_texCoords;
19971out vec4 v2f_color;
19972out float v2f_diffuse;
19973out vec2 v2f_light;
19974void main() {
19975Vertex v;
19976v.pos = a_v_pos;
19977v.color = a_v_color;
19978v.texCoords = a_v_texCoords;
19979v.modelLight = a_v_modelLight;
19980v.normal = a_v_normal;
19981BlockFrag o = vertex(v);
19982v2f_texCoords = o.texCoords;
19983v2f_color = o.color;
19984v2f_diffuse = o.diffuse;
19985v2f_light = o.light;
19986}
19987[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_structure: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
19988
19989[17:17:49] [Render thread/ERROR]: #version 150
19990#extension GL_ARB_conservative_depth : enable
19991#define FRAGMENT_SHADER
19992#if defined(VERTEX_SHADER)
19993out float FragDistance;
19994#elif defined(FRAGMENT_SHADER)
19995in float FragDistance;
19996#endif
19997uniform vec4 uFogColor;
19998uniform vec2 uFogRange;
19999
20000float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
20001 float distXZ = length(worldPos.xz - cameraPos.xz);
20002 float distY = abs(worldPos.y - cameraPos.y);
20003 return max(distXZ, distY);
20004}
20005
20006float cylindrical_distance(vec3 worldPos) {
20007 float distXZ = length(worldPos.xz);
20008 float distY = abs(worldPos.y);
20009 return max(distXZ, distY);
20010}
20011
20012float FLWFogFactor() {
20013 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
20014}
20015// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
20016vec2 shiftLight(vec2 lm) {
20017 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
20018}
20019
20020
20021uniform sampler3D uLightVolume;
20022
20023uniform sampler2D uBlockAtlas;
20024uniform sampler2D uLightMap;
20025
20026uniform vec3 uLightBoxSize;
20027uniform vec3 uLightBoxMin;
20028uniform mat4 uModel;
20029
20030uniform float uTime;
20031uniform mat4 uViewProjection;
20032uniform vec3 uCameraPos;
20033
20034void FLWFinalizeNormal(inout vec3 normal) {
20035 mat3 m;
20036 m[0] = uModel[0].xyz;
20037 m[1] = uModel[1].xyz;
20038 m[2] = uModel[2].xyz;
20039 normal = m * normal;
20040}
20041
20042#if defined(VERTEX_SHADER)
20043
20044out vec3 BoxCoord;
20045
20046void FLWFinalizeWorldPos(inout vec4 worldPos) {
20047 worldPos = uModel * worldPos;
20048
20049 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
20050
20051 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
20052
20053 gl_Position = uViewProjection * worldPos;
20054}
20055
20056#elif defined(FRAGMENT_SHADER)
20057
20058
20059#define ALPHA_DISCARD 0.1
20060// optimize discard usage
20061#if defined(ALPHA_DISCARD)
20062#if defined(GL_ARB_conservative_depth)
20063layout (depth_greater) out float gl_FragDepth;
20064#endif
20065#endif
20066
20067in vec3 BoxCoord;
20068
20069out vec4 FragColor;
20070
20071vec4 FLWBlockTexture(vec2 texCoords) {
20072 return texture(uBlockAtlas, texCoords);
20073}
20074
20075void FLWFinalizeColor(vec4 color) {
20076 float a = color.a;
20077 float fog = clamp(FLWFogFactor(), 0., 1.);
20078
20079 color = mix(uFogColor, color, fog);
20080 color.a = a;
20081
20082 #if defined(ALPHA_DISCARD)
20083 if (color.a < ALPHA_DISCARD) {
20084 discard;
20085 }
20086 #endif
20087
20088 FragColor = color;
20089}
20090
20091vec4 FLWLight(vec2 lightCoords) {
20092 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
20093
20094 return texture(uLightMap, shiftLight(lightCoords));
20095}
20096
20097#endif
20098
20099
20100mat4 rotate(vec3 axis, float angle) {
20101 float s = sin(angle);
20102 float c = cos(angle);
20103 float oc = 1. - c;
20104
20105 vec3 sa = axis * s;
20106
20107 mat4 mr = mat4(1.);
20108 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
20109 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
20110 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
20111
20112 return mr;
20113}
20114
20115mat4 rotation(vec3 rot) {
20116 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
20117}
20118
20119mat3 modelToNormal(mat4 mat) {
20120 // Discard the edges. This won't be accurate for scaled or skewed matrices,
20121 // but we don't have to work with those often.
20122 mat3 m;
20123 m[0] = mat[0].xyz;
20124 m[1] = mat[1].xyz;
20125 m[2] = mat[2].xyz;
20126 return m;
20127}
20128
20129float diffuse(vec3 normal) {
20130 vec3 n2 = normal * normal * vec3(.6, .25, .8);
20131 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
20132}
20133
20134struct BlockFrag {
20135 vec2 texCoords;
20136 vec4 color;
20137 float diffuse;
20138 vec2 light;
20139};
20140
20141#if defined(FRAGMENT_SHADER)
20142void fragment(BlockFrag r) {
20143 vec4 tex = FLWBlockTexture(r.texCoords);
20144
20145 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
20146
20147 FLWFinalizeColor(color);
20148}
20149#endif
20150#define PI 3.1415926538
20151
20152
20153
20154
20155struct Vertex {
20156 vec3 pos;
20157 vec4 color;
20158 vec2 texCoords;
20159 vec2 modelLight;
20160 vec3 normal;
20161};
20162
20163
20164
20165#if defined(VERTEX_SHADER)
20166BlockFrag vertex(Vertex v) {
20167 vec4 worldPos = vec4(v.pos, 1.);
20168 vec3 norm = v.normal;
20169
20170 FLWFinalizeWorldPos(worldPos);
20171 FLWFinalizeNormal(norm);
20172
20173 BlockFrag b;
20174 b.diffuse = diffuse(norm);
20175 b.texCoords = v.texCoords;
20176 b.light = v.modelLight;
20177
20178 #if defined(DEBUG_NORMAL)
20179 b.color = vec4(norm, 1.);
20180 #else
20181 b.color = v.color;
20182 #endif
20183
20184 return b;
20185}
20186#endif
20187
20188in vec2 v2f_texCoords;
20189in vec4 v2f_color;
20190in float v2f_diffuse;
20191in vec2 v2f_light;
20192void main() {
20193BlockFrag o;
20194o.texCoords = v2f_texCoords;
20195o.color = v2f_color;
20196o.diffuse = v2f_diffuse;
20197o.light = v2f_light;
20198fragment(o);
20199}
20200[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_structure: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
20201
20202[17:17:49] [Render thread/ERROR]: #version 150
20203#extension GL_ARB_conservative_depth : enable
20204#define VERTEX_SHADER
20205#define DEBUG_NORMAL
20206#if defined(VERTEX_SHADER)
20207out float FragDistance;
20208#elif defined(FRAGMENT_SHADER)
20209in float FragDistance;
20210#endif
20211uniform vec4 uFogColor;
20212uniform vec2 uFogRange;
20213
20214float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
20215 float distXZ = length(worldPos.xz - cameraPos.xz);
20216 float distY = abs(worldPos.y - cameraPos.y);
20217 return max(distXZ, distY);
20218}
20219
20220float cylindrical_distance(vec3 worldPos) {
20221 float distXZ = length(worldPos.xz);
20222 float distY = abs(worldPos.y);
20223 return max(distXZ, distY);
20224}
20225
20226float FLWFogFactor() {
20227 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
20228}
20229// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
20230vec2 shiftLight(vec2 lm) {
20231 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
20232}
20233
20234
20235uniform sampler3D uLightVolume;
20236
20237uniform sampler2D uBlockAtlas;
20238uniform sampler2D uLightMap;
20239
20240uniform vec3 uLightBoxSize;
20241uniform vec3 uLightBoxMin;
20242uniform mat4 uModel;
20243
20244uniform float uTime;
20245uniform mat4 uViewProjection;
20246uniform vec3 uCameraPos;
20247
20248void FLWFinalizeNormal(inout vec3 normal) {
20249 mat3 m;
20250 m[0] = uModel[0].xyz;
20251 m[1] = uModel[1].xyz;
20252 m[2] = uModel[2].xyz;
20253 normal = m * normal;
20254}
20255
20256#if defined(VERTEX_SHADER)
20257
20258out vec3 BoxCoord;
20259
20260void FLWFinalizeWorldPos(inout vec4 worldPos) {
20261 worldPos = uModel * worldPos;
20262
20263 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
20264
20265 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
20266
20267 gl_Position = uViewProjection * worldPos;
20268}
20269
20270#elif defined(FRAGMENT_SHADER)
20271
20272
20273#define ALPHA_DISCARD 0.1
20274// optimize discard usage
20275#if defined(ALPHA_DISCARD)
20276#if defined(GL_ARB_conservative_depth)
20277layout (depth_greater) out float gl_FragDepth;
20278#endif
20279#endif
20280
20281in vec3 BoxCoord;
20282
20283out vec4 FragColor;
20284
20285vec4 FLWBlockTexture(vec2 texCoords) {
20286 return texture(uBlockAtlas, texCoords);
20287}
20288
20289void FLWFinalizeColor(vec4 color) {
20290 float a = color.a;
20291 float fog = clamp(FLWFogFactor(), 0., 1.);
20292
20293 color = mix(uFogColor, color, fog);
20294 color.a = a;
20295
20296 #if defined(ALPHA_DISCARD)
20297 if (color.a < ALPHA_DISCARD) {
20298 discard;
20299 }
20300 #endif
20301
20302 FragColor = color;
20303}
20304
20305vec4 FLWLight(vec2 lightCoords) {
20306 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
20307
20308 return texture(uLightMap, shiftLight(lightCoords));
20309}
20310
20311#endif
20312
20313
20314mat4 rotate(vec3 axis, float angle) {
20315 float s = sin(angle);
20316 float c = cos(angle);
20317 float oc = 1. - c;
20318
20319 vec3 sa = axis * s;
20320
20321 mat4 mr = mat4(1.);
20322 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
20323 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
20324 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
20325
20326 return mr;
20327}
20328
20329mat4 rotation(vec3 rot) {
20330 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
20331}
20332
20333mat3 modelToNormal(mat4 mat) {
20334 // Discard the edges. This won't be accurate for scaled or skewed matrices,
20335 // but we don't have to work with those often.
20336 mat3 m;
20337 m[0] = mat[0].xyz;
20338 m[1] = mat[1].xyz;
20339 m[2] = mat[2].xyz;
20340 return m;
20341}
20342
20343float diffuse(vec3 normal) {
20344 vec3 n2 = normal * normal * vec3(.6, .25, .8);
20345 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
20346}
20347
20348struct BlockFrag {
20349 vec2 texCoords;
20350 vec4 color;
20351 float diffuse;
20352 vec2 light;
20353};
20354
20355#if defined(FRAGMENT_SHADER)
20356void fragment(BlockFrag r) {
20357 vec4 tex = FLWBlockTexture(r.texCoords);
20358
20359 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
20360
20361 FLWFinalizeColor(color);
20362}
20363#endif
20364#define PI 3.1415926538
20365
20366
20367
20368
20369struct Vertex {
20370 vec3 pos;
20371 vec4 color;
20372 vec2 texCoords;
20373 vec2 modelLight;
20374 vec3 normal;
20375};
20376
20377
20378
20379#if defined(VERTEX_SHADER)
20380BlockFrag vertex(Vertex v) {
20381 vec4 worldPos = vec4(v.pos, 1.);
20382 vec3 norm = v.normal;
20383
20384 FLWFinalizeWorldPos(worldPos);
20385 FLWFinalizeNormal(norm);
20386
20387 BlockFrag b;
20388 b.diffuse = diffuse(norm);
20389 b.texCoords = v.texCoords;
20390 b.light = v.modelLight;
20391
20392 #if defined(DEBUG_NORMAL)
20393 b.color = vec4(norm, 1.);
20394 #else
20395 b.color = v.color;
20396 #endif
20397
20398 return b;
20399}
20400#endif
20401
20402in vec3 a_v_pos;
20403in vec4 a_v_color;
20404in vec2 a_v_texCoords;
20405in vec2 a_v_modelLight;
20406in vec3 a_v_normal;
20407out vec2 v2f_texCoords;
20408out vec4 v2f_color;
20409out float v2f_diffuse;
20410out vec2 v2f_light;
20411void main() {
20412Vertex v;
20413v.pos = a_v_pos;
20414v.color = a_v_color;
20415v.texCoords = a_v_texCoords;
20416v.modelLight = a_v_modelLight;
20417v.normal = a_v_normal;
20418BlockFrag o = vertex(v);
20419v2f_texCoords = o.texCoords;
20420v2f_color = o.color;
20421v2f_diffuse = o.diffuse;
20422v2f_light = o.light;
20423}
20424[17:17:49] [Render thread/ERROR]: Shader compilation log for create:contraption_structure: WARNING: 0:2: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_conservative_depth" is not supported
20425
20426[17:17:49] [Render thread/ERROR]: #version 150
20427#extension GL_ARB_conservative_depth : enable
20428#define FRAGMENT_SHADER
20429#define DEBUG_NORMAL
20430#if defined(VERTEX_SHADER)
20431out float FragDistance;
20432#elif defined(FRAGMENT_SHADER)
20433in float FragDistance;
20434#endif
20435uniform vec4 uFogColor;
20436uniform vec2 uFogRange;
20437
20438float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
20439 float distXZ = length(worldPos.xz - cameraPos.xz);
20440 float distY = abs(worldPos.y - cameraPos.y);
20441 return max(distXZ, distY);
20442}
20443
20444float cylindrical_distance(vec3 worldPos) {
20445 float distXZ = length(worldPos.xz);
20446 float distY = abs(worldPos.y);
20447 return max(distXZ, distY);
20448}
20449
20450float FLWFogFactor() {
20451 return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
20452}
20453// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap
20454vec2 shiftLight(vec2 lm) {
20455 return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
20456}
20457
20458
20459uniform sampler3D uLightVolume;
20460
20461uniform sampler2D uBlockAtlas;
20462uniform sampler2D uLightMap;
20463
20464uniform vec3 uLightBoxSize;
20465uniform vec3 uLightBoxMin;
20466uniform mat4 uModel;
20467
20468uniform float uTime;
20469uniform mat4 uViewProjection;
20470uniform vec3 uCameraPos;
20471
20472void FLWFinalizeNormal(inout vec3 normal) {
20473 mat3 m;
20474 m[0] = uModel[0].xyz;
20475 m[1] = uModel[1].xyz;
20476 m[2] = uModel[2].xyz;
20477 normal = m * normal;
20478}
20479
20480#if defined(VERTEX_SHADER)
20481
20482out vec3 BoxCoord;
20483
20484void FLWFinalizeWorldPos(inout vec4 worldPos) {
20485 worldPos = uModel * worldPos;
20486
20487 BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
20488
20489 FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
20490
20491 gl_Position = uViewProjection * worldPos;
20492}
20493
20494#elif defined(FRAGMENT_SHADER)
20495
20496
20497#define ALPHA_DISCARD 0.1
20498// optimize discard usage
20499#if defined(ALPHA_DISCARD)
20500#if defined(GL_ARB_conservative_depth)
20501layout (depth_greater) out float gl_FragDepth;
20502#endif
20503#endif
20504
20505in vec3 BoxCoord;
20506
20507out vec4 FragColor;
20508
20509vec4 FLWBlockTexture(vec2 texCoords) {
20510 return texture(uBlockAtlas, texCoords);
20511}
20512
20513void FLWFinalizeColor(vec4 color) {
20514 float a = color.a;
20515 float fog = clamp(FLWFogFactor(), 0., 1.);
20516
20517 color = mix(uFogColor, color, fog);
20518 color.a = a;
20519
20520 #if defined(ALPHA_DISCARD)
20521 if (color.a < ALPHA_DISCARD) {
20522 discard;
20523 }
20524 #endif
20525
20526 FragColor = color;
20527}
20528
20529vec4 FLWLight(vec2 lightCoords) {
20530 lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
20531
20532 return texture(uLightMap, shiftLight(lightCoords));
20533}
20534
20535#endif
20536
20537
20538mat4 rotate(vec3 axis, float angle) {
20539 float s = sin(angle);
20540 float c = cos(angle);
20541 float oc = 1. - c;
20542
20543 vec3 sa = axis * s;
20544
20545 mat4 mr = mat4(1.);
20546 mr[0].xyz = oc * axis.xxz * axis.xyx + vec3(c, sa.z, -sa.y);
20547 mr[1].xyz = oc * axis.xyy * axis.yyz + vec3(-sa.z, c, sa.x);
20548 mr[2].xyz = oc * axis.zyz * axis.xzz + vec3(sa.y, -sa.x, c);
20549
20550 return mr;
20551}
20552
20553mat4 rotation(vec3 rot) {
20554 return rotate(vec3(0., 1., 0.), rot.y) * rotate(vec3(0., 0., 1.), rot.z) * rotate(vec3(1., 0., 0.), rot.x);
20555}
20556
20557mat3 modelToNormal(mat4 mat) {
20558 // Discard the edges. This won't be accurate for scaled or skewed matrices,
20559 // but we don't have to work with those often.
20560 mat3 m;
20561 m[0] = mat[0].xyz;
20562 m[1] = mat[1].xyz;
20563 m[2] = mat[2].xyz;
20564 return m;
20565}
20566
20567float diffuse(vec3 normal) {
20568 vec3 n2 = normal * normal * vec3(.6, .25, .8);
20569 return min(n2.x + n2.y * (3. + normal.y) + n2.z, 1.);
20570}
20571
20572struct BlockFrag {
20573 vec2 texCoords;
20574 vec4 color;
20575 float diffuse;
20576 vec2 light;
20577};
20578
20579#if defined(FRAGMENT_SHADER)
20580void fragment(BlockFrag r) {
20581 vec4 tex = FLWBlockTexture(r.texCoords);
20582
20583 vec4 color = vec4(tex.rgb * FLWLight(r.light).rgb * r.diffuse, tex.a) * r.color;
20584
20585 FLWFinalizeColor(color);
20586}
20587#endif
20588#define PI 3.1415926538
20589
20590
20591
20592
20593struct Vertex {
20594 vec3 pos;
20595 vec4 color;
20596 vec2 texCoords;
20597 vec2 modelLight;
20598 vec3 normal;
20599};
20600
20601
20602
20603#if defined(VERTEX_SHADER)
20604BlockFrag vertex(Vertex v) {
20605 vec4 worldPos = vec4(v.pos, 1.);
20606 vec3 norm = v.normal;
20607
20608 FLWFinalizeWorldPos(worldPos);
20609 FLWFinalizeNormal(norm);
20610
20611 BlockFrag b;
20612 b.diffuse = diffuse(norm);
20613 b.texCoords = v.texCoords;
20614 b.light = v.modelLight;
20615
20616 #if defined(DEBUG_NORMAL)
20617 b.color = vec4(norm, 1.);
20618 #else
20619 b.color = v.color;
20620 #endif
20621
20622 return b;
20623}
20624#endif
20625
20626in vec2 v2f_texCoords;
20627in vec4 v2f_color;
20628in float v2f_diffuse;
20629in vec2 v2f_light;
20630void main() {
20631BlockFrag o;
20632o.texCoords = v2f_texCoords;
20633o.color = v2f_color;
20634o.diffuse = v2f_diffuse;
20635o.light = v2f_light;
20636fragment(o);
20637}
20638[17:17:49] [Render thread/INFO]: Loaded all shader programs.
20639[17:17:52] [Render thread/INFO]: OpenAL initialized on device OpenAL Soft on Headset Earphone (HyperX Virtual Surround Sound)
20640[17:17:52] [Render thread/INFO]: Sound engine started
20641[17:17:52] [Render thread/INFO]: Created: 2048x1024x4 minecraft:textures/atlas/blocks.png-atlas
20642[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 56
20643[17:17:53] [Render thread/INFO]: Created: 256x128x4 minecraft:textures/atlas/signs.png-atlas
20644[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20645[17:17:53] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas
20646[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20647[17:17:53] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas
20648[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20649[17:17:53] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas
20650[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20651[17:17:53] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas
20652[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20653[17:17:53] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas
20654[17:17:53] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20655[17:17:55] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/particles.png-atlas
20656[17:17:56] [Render thread/INFO]: [OptiFine] Animated sprites: 1
20657[17:17:56] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/paintings.png-atlas
20658[17:17:56] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20659[17:17:56] [Render thread/INFO]: Created: 128x128x0 minecraft:textures/atlas/mob_effects.png-atlas
20660[17:17:56] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20661[17:17:56] [Render thread/INFO]: Created: 128x256x0 jei:textures/atlas/gui.png-atlas
20662[17:17:56] [Render thread/INFO]: [OptiFine] Animated sprites: 0
20663[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/config_button
20664[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/config_button
20665[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/config_button_cheat
20666[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/config_button_cheat
20667[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/arrow_previous
20668[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/arrow_previous
20669[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/arrow_next
20670[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/arrow_next
20671[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: minecraft:missingno
20672[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: minecraft:missingno
20673[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/info
20674[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/info
20675[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/recipe_transfer
20676[17:17:56] [Render thread/WARN]: [OptiFine] Invalid grid V: 16, icon: jei:gui/icons/recipe_transfer
20677[17:17:56] [Render thread/INFO]: [OptiFine] *** Reloading custom textures ***
20678[17:17:56] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20679[17:17:56] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20680[17:17:56] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20681[17:18:06] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20682[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: creeper, name: armor
20683[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: minecart, name: dirt
20684[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: chest_minecart, name: dirt
20685[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: command_block_minecart, name: dirt
20686[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: furnace_minecart, name: dirt
20687[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: hopper_minecart, name: dirt
20688[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: tnt_minecart, name: dirt
20689[17:18:06] [Render thread/WARN]: [OptiFine] Model renderer not found, model: spawner_minecart, name: dirt
20690[17:18:07] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20691[17:18:07] [Render thread/WARN]: [OptiFine] Unknown resource pack file: mod_resources
20692[17:18:07] [Render thread/INFO]: [OptiFine] Disable Forge light pipeline
20693[17:18:07] [Render thread/INFO]: [OptiFine] Set ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled=false
20694[17:18:14] [Render thread/INFO]: Connecting to Femboiihooters.aternos.me, 25565
20695[17:18:14] [Netty Client IO #2/INFO]: Connected to a vanilla server. Catching up missing behaviour.
20696[11Jan2022 17:18:15.585] [Render thread/INFO] [com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService/]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
20697[17:19:01] [Render thread/INFO]: Stopping!
This log will be saved for 90 days from their last view.
Report abuse