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)
|
151 | out float FragDistance;
|
152 | #elif defined(FRAGMENT_SHADER)
|
153 | in float FragDistance;
|
154 | #endif
|
155 | uniform vec4 uFogColor;
|
156 | uniform vec2 uFogRange;
|
157 |
|
158 | float 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 |
|
164 | float cylindrical_distance(vec3 worldPos) {
|
165 | float distXZ = length(worldPos.xz);
|
166 | float distY = abs(worldPos.y);
|
167 | return max(distXZ, distY);
|
168 | }
|
169 |
|
170 | float FLWFogFactor() {
|
171 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
172 | }
|
173 |
|
174 |
|
175 | uniform float uTime;
|
176 | uniform mat4 uViewProjection;
|
177 | uniform vec3 uCameraPos;
|
178 |
|
179 | uniform vec2 uTextureScale;
|
180 | uniform sampler2D uBlockAtlas;
|
181 | uniform sampler2D uLightMap;
|
182 | uniform sampler2D uCrumbling;
|
183 |
|
184 | uniform vec2 uWindowSize;
|
185 |
|
186 | void FLWFinalizeNormal(inout vec3 normal) {
|
187 | // noop
|
188 | }
|
189 |
|
190 | #if defined(VERTEX_SHADER)
|
191 | void 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 |
|
201 | out vec4 fragColor;
|
202 |
|
203 | vec4 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 |
|
210 | void 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 |
|
226 | vec4 FLWLight(vec2 lightCoords) {
|
227 | return vec4(1.);
|
228 | }
|
229 | #endif
|
230 |
|
231 |
|
232 | float 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 | }
|
236 | struct Vertex {
|
237 | vec3 pos;
|
238 | vec2 texCoords;
|
239 | vec3 normal;
|
240 | };
|
241 |
|
242 | struct BlockFrag {
|
243 | vec2 texCoords;
|
244 | vec4 color;
|
245 | float diffuse;
|
246 | vec2 light;
|
247 | };
|
248 |
|
249 | #if defined(FRAGMENT_SHADER)
|
250 | void 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 |
|
262 | struct Instance {
|
263 | vec2 light;
|
264 | vec4 color;
|
265 | mat4 transform;
|
266 | mat3 normalMat;
|
267 | };
|
268 |
|
269 | #if defined(VERTEX_SHADER)
|
270 | BlockFrag 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 |
|
293 | in vec3 a_v_pos;
|
294 | in vec2 a_v_texCoords;
|
295 | in vec3 a_v_normal;
|
296 | in vec2 a_i_light;
|
297 | in vec4 a_i_color;
|
298 | in mat4 a_i_transform;
|
299 | in mat3 a_i_normalMat;
|
300 | out vec2 v2f_texCoords;
|
301 | out vec4 v2f_color;
|
302 | out float v2f_diffuse;
|
303 | out vec2 v2f_light;
|
304 | void main() {
|
305 | Vertex v;
|
306 | v.pos = a_v_pos;
|
307 | v.texCoords = a_v_texCoords;
|
308 | v.normal = a_v_normal;
|
309 | Instance i;
|
310 | i.light = a_i_light;
|
311 | i.color = a_i_color;
|
312 | i.transform = a_i_transform;
|
313 | i.normalMat = a_i_normalMat;
|
314 | BlockFrag o = vertex(v, i);
|
315 | v2f_texCoords = o.texCoords;
|
316 | v2f_color = o.color;
|
317 | v2f_diffuse = o.diffuse;
|
318 | v2f_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)
|
326 | out float FragDistance;
|
327 | #elif defined(FRAGMENT_SHADER)
|
328 | in float FragDistance;
|
329 | #endif
|
330 | uniform vec4 uFogColor;
|
331 | uniform vec2 uFogRange;
|
332 |
|
333 | float 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 |
|
339 | float cylindrical_distance(vec3 worldPos) {
|
340 | float distXZ = length(worldPos.xz);
|
341 | float distY = abs(worldPos.y);
|
342 | return max(distXZ, distY);
|
343 | }
|
344 |
|
345 | float FLWFogFactor() {
|
346 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
347 | }
|
348 |
|
349 |
|
350 | uniform float uTime;
|
351 | uniform mat4 uViewProjection;
|
352 | uniform vec3 uCameraPos;
|
353 |
|
354 | uniform vec2 uTextureScale;
|
355 | uniform sampler2D uBlockAtlas;
|
356 | uniform sampler2D uLightMap;
|
357 | uniform sampler2D uCrumbling;
|
358 |
|
359 | uniform vec2 uWindowSize;
|
360 |
|
361 | void FLWFinalizeNormal(inout vec3 normal) {
|
362 | // noop
|
363 | }
|
364 |
|
365 | #if defined(VERTEX_SHADER)
|
366 | void 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 |
|
376 | out vec4 fragColor;
|
377 |
|
378 | vec4 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 |
|
385 | void 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 |
|
401 | vec4 FLWLight(vec2 lightCoords) {
|
402 | return vec4(1.);
|
403 | }
|
404 | #endif
|
405 |
|
406 |
|
407 | float 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 | }
|
411 | struct Vertex {
|
412 | vec3 pos;
|
413 | vec2 texCoords;
|
414 | vec3 normal;
|
415 | };
|
416 |
|
417 | struct BlockFrag {
|
418 | vec2 texCoords;
|
419 | vec4 color;
|
420 | float diffuse;
|
421 | vec2 light;
|
422 | };
|
423 |
|
424 | #if defined(FRAGMENT_SHADER)
|
425 | void 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 |
|
437 | struct Instance {
|
438 | vec2 light;
|
439 | vec4 color;
|
440 | mat4 transform;
|
441 | mat3 normalMat;
|
442 | };
|
443 |
|
444 | #if defined(VERTEX_SHADER)
|
445 | BlockFrag 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 |
|
468 | in vec2 v2f_texCoords;
|
469 | in vec4 v2f_color;
|
470 | in float v2f_diffuse;
|
471 | in vec2 v2f_light;
|
472 | void main() {
|
473 | BlockFrag o;
|
474 | o.texCoords = v2f_texCoords;
|
475 | o.color = v2f_color;
|
476 | o.diffuse = v2f_diffuse;
|
477 | o.light = v2f_light;
|
478 | fragment(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)
|
487 | out float FragDistance;
|
488 | #elif defined(FRAGMENT_SHADER)
|
489 | in float FragDistance;
|
490 | #endif
|
491 | uniform vec4 uFogColor;
|
492 | uniform vec2 uFogRange;
|
493 |
|
494 | float 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 |
|
500 | float cylindrical_distance(vec3 worldPos) {
|
501 | float distXZ = length(worldPos.xz);
|
502 | float distY = abs(worldPos.y);
|
503 | return max(distXZ, distY);
|
504 | }
|
505 |
|
506 | float FLWFogFactor() {
|
507 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
508 | }
|
509 |
|
510 |
|
511 | uniform float uTime;
|
512 | uniform mat4 uViewProjection;
|
513 | uniform vec3 uCameraPos;
|
514 |
|
515 | uniform vec2 uTextureScale;
|
516 | uniform sampler2D uBlockAtlas;
|
517 | uniform sampler2D uLightMap;
|
518 | uniform sampler2D uCrumbling;
|
519 |
|
520 | uniform vec2 uWindowSize;
|
521 |
|
522 | void FLWFinalizeNormal(inout vec3 normal) {
|
523 | // noop
|
524 | }
|
525 |
|
526 | #if defined(VERTEX_SHADER)
|
527 | void 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 |
|
537 | out vec4 fragColor;
|
538 |
|
539 | vec4 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 |
|
546 | void 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 |
|
562 | vec4 FLWLight(vec2 lightCoords) {
|
563 | return vec4(1.);
|
564 | }
|
565 | #endif
|
566 |
|
567 |
|
568 | float 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 | }
|
572 | struct Vertex {
|
573 | vec3 pos;
|
574 | vec2 texCoords;
|
575 | vec3 normal;
|
576 | };
|
577 |
|
578 | struct BlockFrag {
|
579 | vec2 texCoords;
|
580 | vec4 color;
|
581 | float diffuse;
|
582 | vec2 light;
|
583 | };
|
584 |
|
585 | #if defined(FRAGMENT_SHADER)
|
586 | void 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 |
|
598 | struct Instance {
|
599 | vec2 light;
|
600 | vec4 color;
|
601 | mat4 transform;
|
602 | mat3 normalMat;
|
603 | };
|
604 |
|
605 | #if defined(VERTEX_SHADER)
|
606 | BlockFrag 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 |
|
629 | in vec3 a_v_pos;
|
630 | in vec2 a_v_texCoords;
|
631 | in vec3 a_v_normal;
|
632 | in vec2 a_i_light;
|
633 | in vec4 a_i_color;
|
634 | in mat4 a_i_transform;
|
635 | in mat3 a_i_normalMat;
|
636 | out vec2 v2f_texCoords;
|
637 | out vec4 v2f_color;
|
638 | out float v2f_diffuse;
|
639 | out vec2 v2f_light;
|
640 | void main() {
|
641 | Vertex v;
|
642 | v.pos = a_v_pos;
|
643 | v.texCoords = a_v_texCoords;
|
644 | v.normal = a_v_normal;
|
645 | Instance i;
|
646 | i.light = a_i_light;
|
647 | i.color = a_i_color;
|
648 | i.transform = a_i_transform;
|
649 | i.normalMat = a_i_normalMat;
|
650 | BlockFrag o = vertex(v, i);
|
651 | v2f_texCoords = o.texCoords;
|
652 | v2f_color = o.color;
|
653 | v2f_diffuse = o.diffuse;
|
654 | v2f_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)
|
663 | out float FragDistance;
|
664 | #elif defined(FRAGMENT_SHADER)
|
665 | in float FragDistance;
|
666 | #endif
|
667 | uniform vec4 uFogColor;
|
668 | uniform vec2 uFogRange;
|
669 |
|
670 | float 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 |
|
676 | float cylindrical_distance(vec3 worldPos) {
|
677 | float distXZ = length(worldPos.xz);
|
678 | float distY = abs(worldPos.y);
|
679 | return max(distXZ, distY);
|
680 | }
|
681 |
|
682 | float FLWFogFactor() {
|
683 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
684 | }
|
685 |
|
686 |
|
687 | uniform float uTime;
|
688 | uniform mat4 uViewProjection;
|
689 | uniform vec3 uCameraPos;
|
690 |
|
691 | uniform vec2 uTextureScale;
|
692 | uniform sampler2D uBlockAtlas;
|
693 | uniform sampler2D uLightMap;
|
694 | uniform sampler2D uCrumbling;
|
695 |
|
696 | uniform vec2 uWindowSize;
|
697 |
|
698 | void FLWFinalizeNormal(inout vec3 normal) {
|
699 | // noop
|
700 | }
|
701 |
|
702 | #if defined(VERTEX_SHADER)
|
703 | void 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 |
|
713 | out vec4 fragColor;
|
714 |
|
715 | vec4 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 |
|
722 | void 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 |
|
738 | vec4 FLWLight(vec2 lightCoords) {
|
739 | return vec4(1.);
|
740 | }
|
741 | #endif
|
742 |
|
743 |
|
744 | float 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 | }
|
748 | struct Vertex {
|
749 | vec3 pos;
|
750 | vec2 texCoords;
|
751 | vec3 normal;
|
752 | };
|
753 |
|
754 | struct BlockFrag {
|
755 | vec2 texCoords;
|
756 | vec4 color;
|
757 | float diffuse;
|
758 | vec2 light;
|
759 | };
|
760 |
|
761 | #if defined(FRAGMENT_SHADER)
|
762 | void 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 |
|
774 | struct Instance {
|
775 | vec2 light;
|
776 | vec4 color;
|
777 | mat4 transform;
|
778 | mat3 normalMat;
|
779 | };
|
780 |
|
781 | #if defined(VERTEX_SHADER)
|
782 | BlockFrag 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 |
|
805 | in vec2 v2f_texCoords;
|
806 | in vec4 v2f_color;
|
807 | in float v2f_diffuse;
|
808 | in vec2 v2f_light;
|
809 | void main() {
|
810 | BlockFrag o;
|
811 | o.texCoords = v2f_texCoords;
|
812 | o.color = v2f_color;
|
813 | o.diffuse = v2f_diffuse;
|
814 | o.light = v2f_light;
|
815 | fragment(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)
|
823 | out float FragDistance;
|
824 | #elif defined(FRAGMENT_SHADER)
|
825 | in float FragDistance;
|
826 | #endif
|
827 | uniform vec4 uFogColor;
|
828 | uniform vec2 uFogRange;
|
829 |
|
830 | float 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 |
|
836 | float cylindrical_distance(vec3 worldPos) {
|
837 | float distXZ = length(worldPos.xz);
|
838 | float distY = abs(worldPos.y);
|
839 | return max(distXZ, distY);
|
840 | }
|
841 |
|
842 | float FLWFogFactor() {
|
843 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
844 | }
|
845 |
|
846 |
|
847 | uniform float uTime;
|
848 | uniform mat4 uViewProjection;
|
849 | uniform vec3 uCameraPos;
|
850 |
|
851 | uniform vec2 uTextureScale;
|
852 | uniform sampler2D uBlockAtlas;
|
853 | uniform sampler2D uLightMap;
|
854 | uniform sampler2D uCrumbling;
|
855 |
|
856 | uniform vec2 uWindowSize;
|
857 |
|
858 | void FLWFinalizeNormal(inout vec3 normal) {
|
859 | // noop
|
860 | }
|
861 |
|
862 | #if defined(VERTEX_SHADER)
|
863 | void 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 |
|
873 | out vec4 fragColor;
|
874 |
|
875 | vec4 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 |
|
882 | void 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 |
|
898 | vec4 FLWLight(vec2 lightCoords) {
|
899 | return vec4(1.);
|
900 | }
|
901 | #endif
|
902 |
|
903 |
|
904 | #define PIOVER2 1.5707963268
|
905 |
|
906 | vec4 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 |
|
912 | vec4 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 |
|
922 | vec3 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 |
|
927 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
928 | return rotateVertexByQuat(v, quat(axis, angle));
|
929 | }
|
930 |
|
931 | float 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 | }
|
935 | struct Vertex {
|
936 | vec3 pos;
|
937 | vec2 texCoords;
|
938 | vec3 normal;
|
939 | };
|
940 |
|
941 | struct BlockFrag {
|
942 | vec2 texCoords;
|
943 | vec4 color;
|
944 | float diffuse;
|
945 | vec2 light;
|
946 | };
|
947 |
|
948 | #if defined(FRAGMENT_SHADER)
|
949 | void 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 |
|
963 | struct Oriented {
|
964 | vec2 light;
|
965 | vec4 color;
|
966 | vec3 pos;
|
967 | vec3 pivot;
|
968 | vec4 rotation;
|
969 | };
|
970 |
|
971 | #if defined(VERTEX_SHADER)
|
972 | BlockFrag 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 |
|
993 | in vec3 a_v_pos;
|
994 | in vec2 a_v_texCoords;
|
995 | in vec3 a_v_normal;
|
996 | in vec2 a_i_light;
|
997 | in vec4 a_i_color;
|
998 | in vec3 a_i_pos;
|
999 | in vec3 a_i_pivot;
|
1000 | in vec4 a_i_rotation;
|
1001 | out vec2 v2f_texCoords;
|
1002 | out vec4 v2f_color;
|
1003 | out float v2f_diffuse;
|
1004 | out vec2 v2f_light;
|
1005 | void main() {
|
1006 | Vertex v;
|
1007 | v.pos = a_v_pos;
|
1008 | v.texCoords = a_v_texCoords;
|
1009 | v.normal = a_v_normal;
|
1010 | Oriented i;
|
1011 | i.light = a_i_light;
|
1012 | i.color = a_i_color;
|
1013 | i.pos = a_i_pos;
|
1014 | i.pivot = a_i_pivot;
|
1015 | i.rotation = a_i_rotation;
|
1016 | BlockFrag o = vertex(v, i);
|
1017 | v2f_texCoords = o.texCoords;
|
1018 | v2f_color = o.color;
|
1019 | v2f_diffuse = o.diffuse;
|
1020 | v2f_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)
|
1028 | out float FragDistance;
|
1029 | #elif defined(FRAGMENT_SHADER)
|
1030 | in float FragDistance;
|
1031 | #endif
|
1032 | uniform vec4 uFogColor;
|
1033 | uniform vec2 uFogRange;
|
1034 |
|
1035 | float 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 |
|
1041 | float cylindrical_distance(vec3 worldPos) {
|
1042 | float distXZ = length(worldPos.xz);
|
1043 | float distY = abs(worldPos.y);
|
1044 | return max(distXZ, distY);
|
1045 | }
|
1046 |
|
1047 | float FLWFogFactor() {
|
1048 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
1049 | }
|
1050 |
|
1051 |
|
1052 | uniform float uTime;
|
1053 | uniform mat4 uViewProjection;
|
1054 | uniform vec3 uCameraPos;
|
1055 |
|
1056 | uniform vec2 uTextureScale;
|
1057 | uniform sampler2D uBlockAtlas;
|
1058 | uniform sampler2D uLightMap;
|
1059 | uniform sampler2D uCrumbling;
|
1060 |
|
1061 | uniform vec2 uWindowSize;
|
1062 |
|
1063 | void FLWFinalizeNormal(inout vec3 normal) {
|
1064 | // noop
|
1065 | }
|
1066 |
|
1067 | #if defined(VERTEX_SHADER)
|
1068 | void 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 |
|
1078 | out vec4 fragColor;
|
1079 |
|
1080 | vec4 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 |
|
1087 | void 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 |
|
1103 | vec4 FLWLight(vec2 lightCoords) {
|
1104 | return vec4(1.);
|
1105 | }
|
1106 | #endif
|
1107 |
|
1108 |
|
1109 | #define PIOVER2 1.5707963268
|
1110 |
|
1111 | vec4 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 |
|
1117 | vec4 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 |
|
1127 | vec3 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 |
|
1132 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
1133 | return rotateVertexByQuat(v, quat(axis, angle));
|
1134 | }
|
1135 |
|
1136 | float 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 | }
|
1140 | struct Vertex {
|
1141 | vec3 pos;
|
1142 | vec2 texCoords;
|
1143 | vec3 normal;
|
1144 | };
|
1145 |
|
1146 | struct BlockFrag {
|
1147 | vec2 texCoords;
|
1148 | vec4 color;
|
1149 | float diffuse;
|
1150 | vec2 light;
|
1151 | };
|
1152 |
|
1153 | #if defined(FRAGMENT_SHADER)
|
1154 | void 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 |
|
1168 | struct Oriented {
|
1169 | vec2 light;
|
1170 | vec4 color;
|
1171 | vec3 pos;
|
1172 | vec3 pivot;
|
1173 | vec4 rotation;
|
1174 | };
|
1175 |
|
1176 | #if defined(VERTEX_SHADER)
|
1177 | BlockFrag 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 |
|
1198 | in vec2 v2f_texCoords;
|
1199 | in vec4 v2f_color;
|
1200 | in float v2f_diffuse;
|
1201 | in vec2 v2f_light;
|
1202 | void main() {
|
1203 | BlockFrag o;
|
1204 | o.texCoords = v2f_texCoords;
|
1205 | o.color = v2f_color;
|
1206 | o.diffuse = v2f_diffuse;
|
1207 | o.light = v2f_light;
|
1208 | fragment(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)
|
1217 | out float FragDistance;
|
1218 | #elif defined(FRAGMENT_SHADER)
|
1219 | in float FragDistance;
|
1220 | #endif
|
1221 | uniform vec4 uFogColor;
|
1222 | uniform vec2 uFogRange;
|
1223 |
|
1224 | float 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 |
|
1230 | float cylindrical_distance(vec3 worldPos) {
|
1231 | float distXZ = length(worldPos.xz);
|
1232 | float distY = abs(worldPos.y);
|
1233 | return max(distXZ, distY);
|
1234 | }
|
1235 |
|
1236 | float FLWFogFactor() {
|
1237 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
1238 | }
|
1239 |
|
1240 |
|
1241 | uniform float uTime;
|
1242 | uniform mat4 uViewProjection;
|
1243 | uniform vec3 uCameraPos;
|
1244 |
|
1245 | uniform vec2 uTextureScale;
|
1246 | uniform sampler2D uBlockAtlas;
|
1247 | uniform sampler2D uLightMap;
|
1248 | uniform sampler2D uCrumbling;
|
1249 |
|
1250 | uniform vec2 uWindowSize;
|
1251 |
|
1252 | void FLWFinalizeNormal(inout vec3 normal) {
|
1253 | // noop
|
1254 | }
|
1255 |
|
1256 | #if defined(VERTEX_SHADER)
|
1257 | void 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 |
|
1267 | out vec4 fragColor;
|
1268 |
|
1269 | vec4 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 |
|
1276 | void 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 |
|
1292 | vec4 FLWLight(vec2 lightCoords) {
|
1293 | return vec4(1.);
|
1294 | }
|
1295 | #endif
|
1296 |
|
1297 |
|
1298 | #define PIOVER2 1.5707963268
|
1299 |
|
1300 | vec4 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 |
|
1306 | vec4 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 |
|
1316 | vec3 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 |
|
1321 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
1322 | return rotateVertexByQuat(v, quat(axis, angle));
|
1323 | }
|
1324 |
|
1325 | float 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 | }
|
1329 | struct Vertex {
|
1330 | vec3 pos;
|
1331 | vec2 texCoords;
|
1332 | vec3 normal;
|
1333 | };
|
1334 |
|
1335 | struct BlockFrag {
|
1336 | vec2 texCoords;
|
1337 | vec4 color;
|
1338 | float diffuse;
|
1339 | vec2 light;
|
1340 | };
|
1341 |
|
1342 | #if defined(FRAGMENT_SHADER)
|
1343 | void 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 |
|
1357 | struct Oriented {
|
1358 | vec2 light;
|
1359 | vec4 color;
|
1360 | vec3 pos;
|
1361 | vec3 pivot;
|
1362 | vec4 rotation;
|
1363 | };
|
1364 |
|
1365 | #if defined(VERTEX_SHADER)
|
1366 | BlockFrag 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 |
|
1387 | in vec3 a_v_pos;
|
1388 | in vec2 a_v_texCoords;
|
1389 | in vec3 a_v_normal;
|
1390 | in vec2 a_i_light;
|
1391 | in vec4 a_i_color;
|
1392 | in vec3 a_i_pos;
|
1393 | in vec3 a_i_pivot;
|
1394 | in vec4 a_i_rotation;
|
1395 | out vec2 v2f_texCoords;
|
1396 | out vec4 v2f_color;
|
1397 | out float v2f_diffuse;
|
1398 | out vec2 v2f_light;
|
1399 | void main() {
|
1400 | Vertex v;
|
1401 | v.pos = a_v_pos;
|
1402 | v.texCoords = a_v_texCoords;
|
1403 | v.normal = a_v_normal;
|
1404 | Oriented i;
|
1405 | i.light = a_i_light;
|
1406 | i.color = a_i_color;
|
1407 | i.pos = a_i_pos;
|
1408 | i.pivot = a_i_pivot;
|
1409 | i.rotation = a_i_rotation;
|
1410 | BlockFrag o = vertex(v, i);
|
1411 | v2f_texCoords = o.texCoords;
|
1412 | v2f_color = o.color;
|
1413 | v2f_diffuse = o.diffuse;
|
1414 | v2f_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)
|
1423 | out float FragDistance;
|
1424 | #elif defined(FRAGMENT_SHADER)
|
1425 | in float FragDistance;
|
1426 | #endif
|
1427 | uniform vec4 uFogColor;
|
1428 | uniform vec2 uFogRange;
|
1429 |
|
1430 | float 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 |
|
1436 | float cylindrical_distance(vec3 worldPos) {
|
1437 | float distXZ = length(worldPos.xz);
|
1438 | float distY = abs(worldPos.y);
|
1439 | return max(distXZ, distY);
|
1440 | }
|
1441 |
|
1442 | float FLWFogFactor() {
|
1443 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
1444 | }
|
1445 |
|
1446 |
|
1447 | uniform float uTime;
|
1448 | uniform mat4 uViewProjection;
|
1449 | uniform vec3 uCameraPos;
|
1450 |
|
1451 | uniform vec2 uTextureScale;
|
1452 | uniform sampler2D uBlockAtlas;
|
1453 | uniform sampler2D uLightMap;
|
1454 | uniform sampler2D uCrumbling;
|
1455 |
|
1456 | uniform vec2 uWindowSize;
|
1457 |
|
1458 | void FLWFinalizeNormal(inout vec3 normal) {
|
1459 | // noop
|
1460 | }
|
1461 |
|
1462 | #if defined(VERTEX_SHADER)
|
1463 | void 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 |
|
1473 | out vec4 fragColor;
|
1474 |
|
1475 | vec4 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 |
|
1482 | void 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 |
|
1498 | vec4 FLWLight(vec2 lightCoords) {
|
1499 | return vec4(1.);
|
1500 | }
|
1501 | #endif
|
1502 |
|
1503 |
|
1504 | #define PIOVER2 1.5707963268
|
1505 |
|
1506 | vec4 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 |
|
1512 | vec4 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 |
|
1522 | vec3 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 |
|
1527 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
1528 | return rotateVertexByQuat(v, quat(axis, angle));
|
1529 | }
|
1530 |
|
1531 | float 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 | }
|
1535 | struct Vertex {
|
1536 | vec3 pos;
|
1537 | vec2 texCoords;
|
1538 | vec3 normal;
|
1539 | };
|
1540 |
|
1541 | struct BlockFrag {
|
1542 | vec2 texCoords;
|
1543 | vec4 color;
|
1544 | float diffuse;
|
1545 | vec2 light;
|
1546 | };
|
1547 |
|
1548 | #if defined(FRAGMENT_SHADER)
|
1549 | void 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 |
|
1563 | struct Oriented {
|
1564 | vec2 light;
|
1565 | vec4 color;
|
1566 | vec3 pos;
|
1567 | vec3 pivot;
|
1568 | vec4 rotation;
|
1569 | };
|
1570 |
|
1571 | #if defined(VERTEX_SHADER)
|
1572 | BlockFrag 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 |
|
1593 | in vec2 v2f_texCoords;
|
1594 | in vec4 v2f_color;
|
1595 | in float v2f_diffuse;
|
1596 | in vec2 v2f_light;
|
1597 | void main() {
|
1598 | BlockFrag o;
|
1599 | o.texCoords = v2f_texCoords;
|
1600 | o.color = v2f_color;
|
1601 | o.diffuse = v2f_diffuse;
|
1602 | o.light = v2f_light;
|
1603 | fragment(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)
|
1611 | out float FragDistance;
|
1612 | #elif defined(FRAGMENT_SHADER)
|
1613 | in float FragDistance;
|
1614 | #endif
|
1615 | uniform vec4 uFogColor;
|
1616 | uniform vec2 uFogRange;
|
1617 |
|
1618 | float 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 |
|
1624 | float cylindrical_distance(vec3 worldPos) {
|
1625 | float distXZ = length(worldPos.xz);
|
1626 | float distY = abs(worldPos.y);
|
1627 | return max(distXZ, distY);
|
1628 | }
|
1629 |
|
1630 | float FLWFogFactor() {
|
1631 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
1632 | }
|
1633 |
|
1634 |
|
1635 | uniform float uTime;
|
1636 | uniform mat4 uViewProjection;
|
1637 | uniform vec3 uCameraPos;
|
1638 |
|
1639 | uniform vec2 uTextureScale;
|
1640 | uniform sampler2D uBlockAtlas;
|
1641 | uniform sampler2D uLightMap;
|
1642 | uniform sampler2D uCrumbling;
|
1643 |
|
1644 | uniform vec2 uWindowSize;
|
1645 |
|
1646 | void FLWFinalizeNormal(inout vec3 normal) {
|
1647 | // noop
|
1648 | }
|
1649 |
|
1650 | #if defined(VERTEX_SHADER)
|
1651 | void 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 |
|
1661 | out vec4 fragColor;
|
1662 |
|
1663 | vec4 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 |
|
1670 | void 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 |
|
1686 | vec4 FLWLight(vec2 lightCoords) {
|
1687 | return vec4(1.);
|
1688 | }
|
1689 | #endif
|
1690 |
|
1691 |
|
1692 | mat4 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 |
|
1707 | mat4 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 |
|
1711 | mat3 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 |
|
1721 | float 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 | }
|
1725 | struct Vertex {
|
1726 | vec3 pos;
|
1727 | vec2 texCoords;
|
1728 | vec3 normal;
|
1729 | };
|
1730 |
|
1731 | struct BlockFrag {
|
1732 | vec2 texCoords;
|
1733 | vec4 color;
|
1734 | float diffuse;
|
1735 | vec2 light;
|
1736 | };
|
1737 |
|
1738 | #if defined(FRAGMENT_SHADER)
|
1739 | void 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 |
|
1752 | struct Rotating {
|
1753 | vec2 light;
|
1754 | vec4 color;
|
1755 | vec3 pos;
|
1756 | float speed;
|
1757 | float offset;
|
1758 | vec3 axis;
|
1759 | };
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 | mat4 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)
|
1772 | BlockFrag 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 |
|
1800 | in vec3 a_v_pos;
|
1801 | in vec2 a_v_texCoords;
|
1802 | in vec3 a_v_normal;
|
1803 | in vec2 a_i_light;
|
1804 | in vec4 a_i_color;
|
1805 | in vec3 a_i_pos;
|
1806 | in float a_i_speed;
|
1807 | in float a_i_offset;
|
1808 | in vec3 a_i_axis;
|
1809 | out vec2 v2f_texCoords;
|
1810 | out vec4 v2f_color;
|
1811 | out float v2f_diffuse;
|
1812 | out vec2 v2f_light;
|
1813 | void main() {
|
1814 | Vertex v;
|
1815 | v.pos = a_v_pos;
|
1816 | v.texCoords = a_v_texCoords;
|
1817 | v.normal = a_v_normal;
|
1818 | Rotating i;
|
1819 | i.light = a_i_light;
|
1820 | i.color = a_i_color;
|
1821 | i.pos = a_i_pos;
|
1822 | i.speed = a_i_speed;
|
1823 | i.offset = a_i_offset;
|
1824 | i.axis = a_i_axis;
|
1825 | BlockFrag o = vertex(v, i);
|
1826 | v2f_texCoords = o.texCoords;
|
1827 | v2f_color = o.color;
|
1828 | v2f_diffuse = o.diffuse;
|
1829 | v2f_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)
|
1837 | out float FragDistance;
|
1838 | #elif defined(FRAGMENT_SHADER)
|
1839 | in float FragDistance;
|
1840 | #endif
|
1841 | uniform vec4 uFogColor;
|
1842 | uniform vec2 uFogRange;
|
1843 |
|
1844 | float 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 |
|
1850 | float cylindrical_distance(vec3 worldPos) {
|
1851 | float distXZ = length(worldPos.xz);
|
1852 | float distY = abs(worldPos.y);
|
1853 | return max(distXZ, distY);
|
1854 | }
|
1855 |
|
1856 | float FLWFogFactor() {
|
1857 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
1858 | }
|
1859 |
|
1860 |
|
1861 | uniform float uTime;
|
1862 | uniform mat4 uViewProjection;
|
1863 | uniform vec3 uCameraPos;
|
1864 |
|
1865 | uniform vec2 uTextureScale;
|
1866 | uniform sampler2D uBlockAtlas;
|
1867 | uniform sampler2D uLightMap;
|
1868 | uniform sampler2D uCrumbling;
|
1869 |
|
1870 | uniform vec2 uWindowSize;
|
1871 |
|
1872 | void FLWFinalizeNormal(inout vec3 normal) {
|
1873 | // noop
|
1874 | }
|
1875 |
|
1876 | #if defined(VERTEX_SHADER)
|
1877 | void 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 |
|
1887 | out vec4 fragColor;
|
1888 |
|
1889 | vec4 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 |
|
1896 | void 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 |
|
1912 | vec4 FLWLight(vec2 lightCoords) {
|
1913 | return vec4(1.);
|
1914 | }
|
1915 | #endif
|
1916 |
|
1917 |
|
1918 | mat4 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 |
|
1933 | mat4 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 |
|
1937 | mat3 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 |
|
1947 | float 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 | }
|
1951 | struct Vertex {
|
1952 | vec3 pos;
|
1953 | vec2 texCoords;
|
1954 | vec3 normal;
|
1955 | };
|
1956 |
|
1957 | struct BlockFrag {
|
1958 | vec2 texCoords;
|
1959 | vec4 color;
|
1960 | float diffuse;
|
1961 | vec2 light;
|
1962 | };
|
1963 |
|
1964 | #if defined(FRAGMENT_SHADER)
|
1965 | void 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 |
|
1978 | struct Rotating {
|
1979 | vec2 light;
|
1980 | vec4 color;
|
1981 | vec3 pos;
|
1982 | float speed;
|
1983 | float offset;
|
1984 | vec3 axis;
|
1985 | };
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 | mat4 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)
|
1998 | BlockFrag 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 |
|
2026 | in vec2 v2f_texCoords;
|
2027 | in vec4 v2f_color;
|
2028 | in float v2f_diffuse;
|
2029 | in vec2 v2f_light;
|
2030 | void main() {
|
2031 | BlockFrag o;
|
2032 | o.texCoords = v2f_texCoords;
|
2033 | o.color = v2f_color;
|
2034 | o.diffuse = v2f_diffuse;
|
2035 | o.light = v2f_light;
|
2036 | fragment(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)
|
2045 | out float FragDistance;
|
2046 | #elif defined(FRAGMENT_SHADER)
|
2047 | in float FragDistance;
|
2048 | #endif
|
2049 | uniform vec4 uFogColor;
|
2050 | uniform vec2 uFogRange;
|
2051 |
|
2052 | float 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 |
|
2058 | float cylindrical_distance(vec3 worldPos) {
|
2059 | float distXZ = length(worldPos.xz);
|
2060 | float distY = abs(worldPos.y);
|
2061 | return max(distXZ, distY);
|
2062 | }
|
2063 |
|
2064 | float FLWFogFactor() {
|
2065 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
2066 | }
|
2067 |
|
2068 |
|
2069 | uniform float uTime;
|
2070 | uniform mat4 uViewProjection;
|
2071 | uniform vec3 uCameraPos;
|
2072 |
|
2073 | uniform vec2 uTextureScale;
|
2074 | uniform sampler2D uBlockAtlas;
|
2075 | uniform sampler2D uLightMap;
|
2076 | uniform sampler2D uCrumbling;
|
2077 |
|
2078 | uniform vec2 uWindowSize;
|
2079 |
|
2080 | void FLWFinalizeNormal(inout vec3 normal) {
|
2081 | // noop
|
2082 | }
|
2083 |
|
2084 | #if defined(VERTEX_SHADER)
|
2085 | void 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 |
|
2095 | out vec4 fragColor;
|
2096 |
|
2097 | vec4 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 |
|
2104 | void 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 |
|
2120 | vec4 FLWLight(vec2 lightCoords) {
|
2121 | return vec4(1.);
|
2122 | }
|
2123 | #endif
|
2124 |
|
2125 |
|
2126 | mat4 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 |
|
2141 | mat4 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 |
|
2145 | mat3 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 |
|
2155 | float 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 | }
|
2159 | struct Vertex {
|
2160 | vec3 pos;
|
2161 | vec2 texCoords;
|
2162 | vec3 normal;
|
2163 | };
|
2164 |
|
2165 | struct BlockFrag {
|
2166 | vec2 texCoords;
|
2167 | vec4 color;
|
2168 | float diffuse;
|
2169 | vec2 light;
|
2170 | };
|
2171 |
|
2172 | #if defined(FRAGMENT_SHADER)
|
2173 | void 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 |
|
2186 | struct Rotating {
|
2187 | vec2 light;
|
2188 | vec4 color;
|
2189 | vec3 pos;
|
2190 | float speed;
|
2191 | float offset;
|
2192 | vec3 axis;
|
2193 | };
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 | mat4 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)
|
2206 | BlockFrag 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 |
|
2234 | in vec3 a_v_pos;
|
2235 | in vec2 a_v_texCoords;
|
2236 | in vec3 a_v_normal;
|
2237 | in vec2 a_i_light;
|
2238 | in vec4 a_i_color;
|
2239 | in vec3 a_i_pos;
|
2240 | in float a_i_speed;
|
2241 | in float a_i_offset;
|
2242 | in vec3 a_i_axis;
|
2243 | out vec2 v2f_texCoords;
|
2244 | out vec4 v2f_color;
|
2245 | out float v2f_diffuse;
|
2246 | out vec2 v2f_light;
|
2247 | void main() {
|
2248 | Vertex v;
|
2249 | v.pos = a_v_pos;
|
2250 | v.texCoords = a_v_texCoords;
|
2251 | v.normal = a_v_normal;
|
2252 | Rotating i;
|
2253 | i.light = a_i_light;
|
2254 | i.color = a_i_color;
|
2255 | i.pos = a_i_pos;
|
2256 | i.speed = a_i_speed;
|
2257 | i.offset = a_i_offset;
|
2258 | i.axis = a_i_axis;
|
2259 | BlockFrag o = vertex(v, i);
|
2260 | v2f_texCoords = o.texCoords;
|
2261 | v2f_color = o.color;
|
2262 | v2f_diffuse = o.diffuse;
|
2263 | v2f_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)
|
2272 | out float FragDistance;
|
2273 | #elif defined(FRAGMENT_SHADER)
|
2274 | in float FragDistance;
|
2275 | #endif
|
2276 | uniform vec4 uFogColor;
|
2277 | uniform vec2 uFogRange;
|
2278 |
|
2279 | float 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 |
|
2285 | float cylindrical_distance(vec3 worldPos) {
|
2286 | float distXZ = length(worldPos.xz);
|
2287 | float distY = abs(worldPos.y);
|
2288 | return max(distXZ, distY);
|
2289 | }
|
2290 |
|
2291 | float FLWFogFactor() {
|
2292 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
2293 | }
|
2294 |
|
2295 |
|
2296 | uniform float uTime;
|
2297 | uniform mat4 uViewProjection;
|
2298 | uniform vec3 uCameraPos;
|
2299 |
|
2300 | uniform vec2 uTextureScale;
|
2301 | uniform sampler2D uBlockAtlas;
|
2302 | uniform sampler2D uLightMap;
|
2303 | uniform sampler2D uCrumbling;
|
2304 |
|
2305 | uniform vec2 uWindowSize;
|
2306 |
|
2307 | void FLWFinalizeNormal(inout vec3 normal) {
|
2308 | // noop
|
2309 | }
|
2310 |
|
2311 | #if defined(VERTEX_SHADER)
|
2312 | void 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 |
|
2322 | out vec4 fragColor;
|
2323 |
|
2324 | vec4 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 |
|
2331 | void 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 |
|
2347 | vec4 FLWLight(vec2 lightCoords) {
|
2348 | return vec4(1.);
|
2349 | }
|
2350 | #endif
|
2351 |
|
2352 |
|
2353 | mat4 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 |
|
2368 | mat4 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 |
|
2372 | mat3 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 |
|
2382 | float 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 | }
|
2386 | struct Vertex {
|
2387 | vec3 pos;
|
2388 | vec2 texCoords;
|
2389 | vec3 normal;
|
2390 | };
|
2391 |
|
2392 | struct BlockFrag {
|
2393 | vec2 texCoords;
|
2394 | vec4 color;
|
2395 | float diffuse;
|
2396 | vec2 light;
|
2397 | };
|
2398 |
|
2399 | #if defined(FRAGMENT_SHADER)
|
2400 | void 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 |
|
2413 | struct Rotating {
|
2414 | vec2 light;
|
2415 | vec4 color;
|
2416 | vec3 pos;
|
2417 | float speed;
|
2418 | float offset;
|
2419 | vec3 axis;
|
2420 | };
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 | mat4 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)
|
2433 | BlockFrag 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 |
|
2461 | in vec2 v2f_texCoords;
|
2462 | in vec4 v2f_color;
|
2463 | in float v2f_diffuse;
|
2464 | in vec2 v2f_light;
|
2465 | void main() {
|
2466 | BlockFrag o;
|
2467 | o.texCoords = v2f_texCoords;
|
2468 | o.color = v2f_color;
|
2469 | o.diffuse = v2f_diffuse;
|
2470 | o.light = v2f_light;
|
2471 | fragment(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)
|
2480 | out float FragDistance;
|
2481 | #elif defined(FRAGMENT_SHADER)
|
2482 | in float FragDistance;
|
2483 | #endif
|
2484 | uniform vec4 uFogColor;
|
2485 | uniform vec2 uFogRange;
|
2486 |
|
2487 | float 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 |
|
2493 | float cylindrical_distance(vec3 worldPos) {
|
2494 | float distXZ = length(worldPos.xz);
|
2495 | float distY = abs(worldPos.y);
|
2496 | return max(distXZ, distY);
|
2497 | }
|
2498 |
|
2499 | float FLWFogFactor() {
|
2500 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
2501 | }
|
2502 |
|
2503 |
|
2504 | uniform float uTime;
|
2505 | uniform mat4 uViewProjection;
|
2506 | uniform vec3 uCameraPos;
|
2507 |
|
2508 | uniform vec2 uTextureScale;
|
2509 | uniform sampler2D uBlockAtlas;
|
2510 | uniform sampler2D uLightMap;
|
2511 | uniform sampler2D uCrumbling;
|
2512 |
|
2513 | uniform vec2 uWindowSize;
|
2514 |
|
2515 | void FLWFinalizeNormal(inout vec3 normal) {
|
2516 | // noop
|
2517 | }
|
2518 |
|
2519 | #if defined(VERTEX_SHADER)
|
2520 | void 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 |
|
2530 | out vec4 fragColor;
|
2531 |
|
2532 | vec4 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 |
|
2539 | void 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 |
|
2555 | vec4 FLWLight(vec2 lightCoords) {
|
2556 | return vec4(1.);
|
2557 | }
|
2558 | #endif
|
2559 |
|
2560 |
|
2561 | mat4 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 |
|
2576 | mat4 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 |
|
2580 | mat3 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 |
|
2590 | float 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 | }
|
2594 | struct Vertex {
|
2595 | vec3 pos;
|
2596 | vec2 texCoords;
|
2597 | vec3 normal;
|
2598 | };
|
2599 |
|
2600 | struct BlockFrag {
|
2601 | vec2 texCoords;
|
2602 | vec4 color;
|
2603 | float diffuse;
|
2604 | vec2 light;
|
2605 | };
|
2606 |
|
2607 | #if defined(FRAGMENT_SHADER)
|
2608 | void 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 |
|
2621 | struct Rotating {
|
2622 | vec2 light;
|
2623 | vec4 color;
|
2624 | vec3 pos;
|
2625 | float speed;
|
2626 | float offset;
|
2627 | vec3 axis;
|
2628 | };
|
2629 |
|
2630 |
|
2631 |
|
2632 |
|
2633 | mat4 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)
|
2641 | BlockFrag 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 |
|
2669 | in vec3 a_v_pos;
|
2670 | in vec2 a_v_texCoords;
|
2671 | in vec3 a_v_normal;
|
2672 | in vec2 a_i_light;
|
2673 | in vec4 a_i_color;
|
2674 | in vec3 a_i_pos;
|
2675 | in float a_i_speed;
|
2676 | in float a_i_offset;
|
2677 | in vec3 a_i_axis;
|
2678 | out vec2 v2f_texCoords;
|
2679 | out vec4 v2f_color;
|
2680 | out float v2f_diffuse;
|
2681 | out vec2 v2f_light;
|
2682 | void main() {
|
2683 | Vertex v;
|
2684 | v.pos = a_v_pos;
|
2685 | v.texCoords = a_v_texCoords;
|
2686 | v.normal = a_v_normal;
|
2687 | Rotating i;
|
2688 | i.light = a_i_light;
|
2689 | i.color = a_i_color;
|
2690 | i.pos = a_i_pos;
|
2691 | i.speed = a_i_speed;
|
2692 | i.offset = a_i_offset;
|
2693 | i.axis = a_i_axis;
|
2694 | BlockFrag o = vertex(v, i);
|
2695 | v2f_texCoords = o.texCoords;
|
2696 | v2f_color = o.color;
|
2697 | v2f_diffuse = o.diffuse;
|
2698 | v2f_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)
|
2707 | out float FragDistance;
|
2708 | #elif defined(FRAGMENT_SHADER)
|
2709 | in float FragDistance;
|
2710 | #endif
|
2711 | uniform vec4 uFogColor;
|
2712 | uniform vec2 uFogRange;
|
2713 |
|
2714 | float 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 |
|
2720 | float cylindrical_distance(vec3 worldPos) {
|
2721 | float distXZ = length(worldPos.xz);
|
2722 | float distY = abs(worldPos.y);
|
2723 | return max(distXZ, distY);
|
2724 | }
|
2725 |
|
2726 | float FLWFogFactor() {
|
2727 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
2728 | }
|
2729 |
|
2730 |
|
2731 | uniform float uTime;
|
2732 | uniform mat4 uViewProjection;
|
2733 | uniform vec3 uCameraPos;
|
2734 |
|
2735 | uniform vec2 uTextureScale;
|
2736 | uniform sampler2D uBlockAtlas;
|
2737 | uniform sampler2D uLightMap;
|
2738 | uniform sampler2D uCrumbling;
|
2739 |
|
2740 | uniform vec2 uWindowSize;
|
2741 |
|
2742 | void FLWFinalizeNormal(inout vec3 normal) {
|
2743 | // noop
|
2744 | }
|
2745 |
|
2746 | #if defined(VERTEX_SHADER)
|
2747 | void 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 |
|
2757 | out vec4 fragColor;
|
2758 |
|
2759 | vec4 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 |
|
2766 | void 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 |
|
2782 | vec4 FLWLight(vec2 lightCoords) {
|
2783 | return vec4(1.);
|
2784 | }
|
2785 | #endif
|
2786 |
|
2787 |
|
2788 | mat4 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 |
|
2803 | mat4 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 |
|
2807 | mat3 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 |
|
2817 | float 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 | }
|
2821 | struct Vertex {
|
2822 | vec3 pos;
|
2823 | vec2 texCoords;
|
2824 | vec3 normal;
|
2825 | };
|
2826 |
|
2827 | struct BlockFrag {
|
2828 | vec2 texCoords;
|
2829 | vec4 color;
|
2830 | float diffuse;
|
2831 | vec2 light;
|
2832 | };
|
2833 |
|
2834 | #if defined(FRAGMENT_SHADER)
|
2835 | void 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 |
|
2848 | struct Rotating {
|
2849 | vec2 light;
|
2850 | vec4 color;
|
2851 | vec3 pos;
|
2852 | float speed;
|
2853 | float offset;
|
2854 | vec3 axis;
|
2855 | };
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 | mat4 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)
|
2868 | BlockFrag 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 |
|
2896 | in vec2 v2f_texCoords;
|
2897 | in vec4 v2f_color;
|
2898 | in float v2f_diffuse;
|
2899 | in vec2 v2f_light;
|
2900 | void main() {
|
2901 | BlockFrag o;
|
2902 | o.texCoords = v2f_texCoords;
|
2903 | o.color = v2f_color;
|
2904 | o.diffuse = v2f_diffuse;
|
2905 | o.light = v2f_light;
|
2906 | fragment(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)
|
2914 | out float FragDistance;
|
2915 | #elif defined(FRAGMENT_SHADER)
|
2916 | in float FragDistance;
|
2917 | #endif
|
2918 | uniform vec4 uFogColor;
|
2919 | uniform vec2 uFogRange;
|
2920 |
|
2921 | float 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 |
|
2927 | float cylindrical_distance(vec3 worldPos) {
|
2928 | float distXZ = length(worldPos.xz);
|
2929 | float distY = abs(worldPos.y);
|
2930 | return max(distXZ, distY);
|
2931 | }
|
2932 |
|
2933 | float FLWFogFactor() {
|
2934 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
2935 | }
|
2936 |
|
2937 |
|
2938 | uniform float uTime;
|
2939 | uniform mat4 uViewProjection;
|
2940 | uniform vec3 uCameraPos;
|
2941 |
|
2942 | uniform vec2 uTextureScale;
|
2943 | uniform sampler2D uBlockAtlas;
|
2944 | uniform sampler2D uLightMap;
|
2945 | uniform sampler2D uCrumbling;
|
2946 |
|
2947 | uniform vec2 uWindowSize;
|
2948 |
|
2949 | void FLWFinalizeNormal(inout vec3 normal) {
|
2950 | // noop
|
2951 | }
|
2952 |
|
2953 | #if defined(VERTEX_SHADER)
|
2954 | void 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 |
|
2964 | out vec4 fragColor;
|
2965 |
|
2966 | vec4 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 |
|
2973 | void 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 |
|
2989 | vec4 FLWLight(vec2 lightCoords) {
|
2990 | return vec4(1.);
|
2991 | }
|
2992 | #endif
|
2993 |
|
2994 |
|
2995 | mat4 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 |
|
3010 | mat4 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 |
|
3014 | mat3 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 |
|
3026 | vec4 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 |
|
3032 | vec4 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 |
|
3042 | vec3 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 |
|
3047 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
3048 | return rotateVertexByQuat(v, quat(axis, angle));
|
3049 | }
|
3050 |
|
3051 | float 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 | }
|
3055 | struct Vertex {
|
3056 | vec3 pos;
|
3057 | vec2 texCoords;
|
3058 | vec3 normal;
|
3059 | };
|
3060 |
|
3061 | struct BlockFrag {
|
3062 | vec2 texCoords;
|
3063 | vec4 color;
|
3064 | float diffuse;
|
3065 | vec2 light;
|
3066 | };
|
3067 |
|
3068 | #if defined(FRAGMENT_SHADER)
|
3069 | void 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 |
|
3083 | struct 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)
|
3097 | BlockFrag 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 |
|
3125 | in vec3 a_v_pos;
|
3126 | in vec2 a_v_texCoords;
|
3127 | in vec3 a_v_normal;
|
3128 | in vec3 a_i_pos;
|
3129 | in vec2 a_i_light;
|
3130 | in float a_i_offset;
|
3131 | in vec3 a_i_axis;
|
3132 | in vec4 a_i_rotation;
|
3133 | in vec3 a_i_rotationCenter;
|
3134 | in float a_i_speed;
|
3135 | out vec2 v2f_texCoords;
|
3136 | out vec4 v2f_color;
|
3137 | out float v2f_diffuse;
|
3138 | out vec2 v2f_light;
|
3139 | void main() {
|
3140 | Vertex v;
|
3141 | v.pos = a_v_pos;
|
3142 | v.texCoords = a_v_texCoords;
|
3143 | v.normal = a_v_normal;
|
3144 | Actor i;
|
3145 | i.pos = a_i_pos;
|
3146 | i.light = a_i_light;
|
3147 | i.offset = a_i_offset;
|
3148 | i.axis = a_i_axis;
|
3149 | i.rotation = a_i_rotation;
|
3150 | i.rotationCenter = a_i_rotationCenter;
|
3151 | i.speed = a_i_speed;
|
3152 | BlockFrag o = vertex(v, i);
|
3153 | v2f_texCoords = o.texCoords;
|
3154 | v2f_color = o.color;
|
3155 | v2f_diffuse = o.diffuse;
|
3156 | v2f_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)
|
3164 | out float FragDistance;
|
3165 | #elif defined(FRAGMENT_SHADER)
|
3166 | in float FragDistance;
|
3167 | #endif
|
3168 | uniform vec4 uFogColor;
|
3169 | uniform vec2 uFogRange;
|
3170 |
|
3171 | float 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 |
|
3177 | float cylindrical_distance(vec3 worldPos) {
|
3178 | float distXZ = length(worldPos.xz);
|
3179 | float distY = abs(worldPos.y);
|
3180 | return max(distXZ, distY);
|
3181 | }
|
3182 |
|
3183 | float FLWFogFactor() {
|
3184 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
3185 | }
|
3186 |
|
3187 |
|
3188 | uniform float uTime;
|
3189 | uniform mat4 uViewProjection;
|
3190 | uniform vec3 uCameraPos;
|
3191 |
|
3192 | uniform vec2 uTextureScale;
|
3193 | uniform sampler2D uBlockAtlas;
|
3194 | uniform sampler2D uLightMap;
|
3195 | uniform sampler2D uCrumbling;
|
3196 |
|
3197 | uniform vec2 uWindowSize;
|
3198 |
|
3199 | void FLWFinalizeNormal(inout vec3 normal) {
|
3200 | // noop
|
3201 | }
|
3202 |
|
3203 | #if defined(VERTEX_SHADER)
|
3204 | void 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 |
|
3214 | out vec4 fragColor;
|
3215 |
|
3216 | vec4 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 |
|
3223 | void 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 |
|
3239 | vec4 FLWLight(vec2 lightCoords) {
|
3240 | return vec4(1.);
|
3241 | }
|
3242 | #endif
|
3243 |
|
3244 |
|
3245 | mat4 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 |
|
3260 | mat4 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 |
|
3264 | mat3 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 |
|
3276 | vec4 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 |
|
3282 | vec4 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 |
|
3292 | vec3 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 |
|
3297 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
3298 | return rotateVertexByQuat(v, quat(axis, angle));
|
3299 | }
|
3300 |
|
3301 | float 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 | }
|
3305 | struct Vertex {
|
3306 | vec3 pos;
|
3307 | vec2 texCoords;
|
3308 | vec3 normal;
|
3309 | };
|
3310 |
|
3311 | struct BlockFrag {
|
3312 | vec2 texCoords;
|
3313 | vec4 color;
|
3314 | float diffuse;
|
3315 | vec2 light;
|
3316 | };
|
3317 |
|
3318 | #if defined(FRAGMENT_SHADER)
|
3319 | void 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 |
|
3333 | struct 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)
|
3347 | BlockFrag 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 |
|
3375 | in vec2 v2f_texCoords;
|
3376 | in vec4 v2f_color;
|
3377 | in float v2f_diffuse;
|
3378 | in vec2 v2f_light;
|
3379 | void main() {
|
3380 | BlockFrag o;
|
3381 | o.texCoords = v2f_texCoords;
|
3382 | o.color = v2f_color;
|
3383 | o.diffuse = v2f_diffuse;
|
3384 | o.light = v2f_light;
|
3385 | fragment(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)
|
3394 | out float FragDistance;
|
3395 | #elif defined(FRAGMENT_SHADER)
|
3396 | in float FragDistance;
|
3397 | #endif
|
3398 | uniform vec4 uFogColor;
|
3399 | uniform vec2 uFogRange;
|
3400 |
|
3401 | float 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 |
|
3407 | float cylindrical_distance(vec3 worldPos) {
|
3408 | float distXZ = length(worldPos.xz);
|
3409 | float distY = abs(worldPos.y);
|
3410 | return max(distXZ, distY);
|
3411 | }
|
3412 |
|
3413 | float FLWFogFactor() {
|
3414 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
3415 | }
|
3416 |
|
3417 |
|
3418 | uniform float uTime;
|
3419 | uniform mat4 uViewProjection;
|
3420 | uniform vec3 uCameraPos;
|
3421 |
|
3422 | uniform vec2 uTextureScale;
|
3423 | uniform sampler2D uBlockAtlas;
|
3424 | uniform sampler2D uLightMap;
|
3425 | uniform sampler2D uCrumbling;
|
3426 |
|
3427 | uniform vec2 uWindowSize;
|
3428 |
|
3429 | void FLWFinalizeNormal(inout vec3 normal) {
|
3430 | // noop
|
3431 | }
|
3432 |
|
3433 | #if defined(VERTEX_SHADER)
|
3434 | void 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 |
|
3444 | out vec4 fragColor;
|
3445 |
|
3446 | vec4 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 |
|
3453 | void 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 |
|
3469 | vec4 FLWLight(vec2 lightCoords) {
|
3470 | return vec4(1.);
|
3471 | }
|
3472 | #endif
|
3473 |
|
3474 |
|
3475 | mat4 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 |
|
3490 | mat4 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 |
|
3494 | mat3 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 |
|
3506 | vec4 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 |
|
3512 | vec4 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 |
|
3522 | vec3 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 |
|
3527 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
3528 | return rotateVertexByQuat(v, quat(axis, angle));
|
3529 | }
|
3530 |
|
3531 | float 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 | }
|
3535 | struct Vertex {
|
3536 | vec3 pos;
|
3537 | vec2 texCoords;
|
3538 | vec3 normal;
|
3539 | };
|
3540 |
|
3541 | struct BlockFrag {
|
3542 | vec2 texCoords;
|
3543 | vec4 color;
|
3544 | float diffuse;
|
3545 | vec2 light;
|
3546 | };
|
3547 |
|
3548 | #if defined(FRAGMENT_SHADER)
|
3549 | void 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 |
|
3563 | struct 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)
|
3577 | BlockFrag 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 |
|
3605 | in vec3 a_v_pos;
|
3606 | in vec2 a_v_texCoords;
|
3607 | in vec3 a_v_normal;
|
3608 | in vec3 a_i_pos;
|
3609 | in vec2 a_i_light;
|
3610 | in float a_i_offset;
|
3611 | in vec3 a_i_axis;
|
3612 | in vec4 a_i_rotation;
|
3613 | in vec3 a_i_rotationCenter;
|
3614 | in float a_i_speed;
|
3615 | out vec2 v2f_texCoords;
|
3616 | out vec4 v2f_color;
|
3617 | out float v2f_diffuse;
|
3618 | out vec2 v2f_light;
|
3619 | void main() {
|
3620 | Vertex v;
|
3621 | v.pos = a_v_pos;
|
3622 | v.texCoords = a_v_texCoords;
|
3623 | v.normal = a_v_normal;
|
3624 | Actor i;
|
3625 | i.pos = a_i_pos;
|
3626 | i.light = a_i_light;
|
3627 | i.offset = a_i_offset;
|
3628 | i.axis = a_i_axis;
|
3629 | i.rotation = a_i_rotation;
|
3630 | i.rotationCenter = a_i_rotationCenter;
|
3631 | i.speed = a_i_speed;
|
3632 | BlockFrag o = vertex(v, i);
|
3633 | v2f_texCoords = o.texCoords;
|
3634 | v2f_color = o.color;
|
3635 | v2f_diffuse = o.diffuse;
|
3636 | v2f_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)
|
3645 | out float FragDistance;
|
3646 | #elif defined(FRAGMENT_SHADER)
|
3647 | in float FragDistance;
|
3648 | #endif
|
3649 | uniform vec4 uFogColor;
|
3650 | uniform vec2 uFogRange;
|
3651 |
|
3652 | float 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 |
|
3658 | float cylindrical_distance(vec3 worldPos) {
|
3659 | float distXZ = length(worldPos.xz);
|
3660 | float distY = abs(worldPos.y);
|
3661 | return max(distXZ, distY);
|
3662 | }
|
3663 |
|
3664 | float FLWFogFactor() {
|
3665 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
3666 | }
|
3667 |
|
3668 |
|
3669 | uniform float uTime;
|
3670 | uniform mat4 uViewProjection;
|
3671 | uniform vec3 uCameraPos;
|
3672 |
|
3673 | uniform vec2 uTextureScale;
|
3674 | uniform sampler2D uBlockAtlas;
|
3675 | uniform sampler2D uLightMap;
|
3676 | uniform sampler2D uCrumbling;
|
3677 |
|
3678 | uniform vec2 uWindowSize;
|
3679 |
|
3680 | void FLWFinalizeNormal(inout vec3 normal) {
|
3681 | // noop
|
3682 | }
|
3683 |
|
3684 | #if defined(VERTEX_SHADER)
|
3685 | void 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 |
|
3695 | out vec4 fragColor;
|
3696 |
|
3697 | vec4 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 |
|
3704 | void 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 |
|
3720 | vec4 FLWLight(vec2 lightCoords) {
|
3721 | return vec4(1.);
|
3722 | }
|
3723 | #endif
|
3724 |
|
3725 |
|
3726 | mat4 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 |
|
3741 | mat4 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 |
|
3745 | mat3 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 |
|
3757 | vec4 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 |
|
3763 | vec4 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 |
|
3773 | vec3 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 |
|
3778 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
3779 | return rotateVertexByQuat(v, quat(axis, angle));
|
3780 | }
|
3781 |
|
3782 | float 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 | }
|
3786 | struct Vertex {
|
3787 | vec3 pos;
|
3788 | vec2 texCoords;
|
3789 | vec3 normal;
|
3790 | };
|
3791 |
|
3792 | struct BlockFrag {
|
3793 | vec2 texCoords;
|
3794 | vec4 color;
|
3795 | float diffuse;
|
3796 | vec2 light;
|
3797 | };
|
3798 |
|
3799 | #if defined(FRAGMENT_SHADER)
|
3800 | void 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 |
|
3814 | struct 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)
|
3828 | BlockFrag 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 |
|
3856 | in vec2 v2f_texCoords;
|
3857 | in vec4 v2f_color;
|
3858 | in float v2f_diffuse;
|
3859 | in vec2 v2f_light;
|
3860 | void main() {
|
3861 | BlockFrag o;
|
3862 | o.texCoords = v2f_texCoords;
|
3863 | o.color = v2f_color;
|
3864 | o.diffuse = v2f_diffuse;
|
3865 | o.light = v2f_light;
|
3866 | fragment(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)
|
3874 | out float FragDistance;
|
3875 | #elif defined(FRAGMENT_SHADER)
|
3876 | in float FragDistance;
|
3877 | #endif
|
3878 | uniform vec4 uFogColor;
|
3879 | uniform vec2 uFogRange;
|
3880 |
|
3881 | float 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 |
|
3887 | float cylindrical_distance(vec3 worldPos) {
|
3888 | float distXZ = length(worldPos.xz);
|
3889 | float distY = abs(worldPos.y);
|
3890 | return max(distXZ, distY);
|
3891 | }
|
3892 |
|
3893 | float FLWFogFactor() {
|
3894 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
3895 | }
|
3896 |
|
3897 |
|
3898 | uniform float uTime;
|
3899 | uniform mat4 uViewProjection;
|
3900 | uniform vec3 uCameraPos;
|
3901 |
|
3902 | uniform vec2 uTextureScale;
|
3903 | uniform sampler2D uBlockAtlas;
|
3904 | uniform sampler2D uLightMap;
|
3905 | uniform sampler2D uCrumbling;
|
3906 |
|
3907 | uniform vec2 uWindowSize;
|
3908 |
|
3909 | void FLWFinalizeNormal(inout vec3 normal) {
|
3910 | // noop
|
3911 | }
|
3912 |
|
3913 | #if defined(VERTEX_SHADER)
|
3914 | void 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 |
|
3924 | out vec4 fragColor;
|
3925 |
|
3926 | vec4 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 |
|
3933 | void 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 |
|
3949 | vec4 FLWLight(vec2 lightCoords) {
|
3950 | return vec4(1.);
|
3951 | }
|
3952 | #endif
|
3953 |
|
3954 |
|
3955 | mat4 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 |
|
3970 | mat4 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 |
|
3974 | mat3 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 |
|
3986 | vec4 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 |
|
3992 | vec4 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 |
|
4002 | vec3 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 |
|
4007 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
4008 | return rotateVertexByQuat(v, quat(axis, angle));
|
4009 | }
|
4010 |
|
4011 | float 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 | }
|
4015 | struct Vertex {
|
4016 | vec3 pos;
|
4017 | vec2 texCoords;
|
4018 | vec3 normal;
|
4019 | };
|
4020 |
|
4021 | struct BlockFrag {
|
4022 | vec2 texCoords;
|
4023 | vec4 color;
|
4024 | float diffuse;
|
4025 | vec2 light;
|
4026 | };
|
4027 |
|
4028 | #if defined(FRAGMENT_SHADER)
|
4029 | void 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 |
|
4043 | struct 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 |
|
4059 | float toRad(float degrees) {
|
4060 | return fract(degrees / 360.) * PI * 2.;
|
4061 | }
|
4062 |
|
4063 | float 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 |
|
4076 | BlockFrag 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 |
|
4104 | in vec3 a_v_pos;
|
4105 | in vec2 a_v_texCoords;
|
4106 | in vec3 a_v_normal;
|
4107 | in vec3 a_i_instancePos;
|
4108 | in vec2 a_i_light;
|
4109 | in vec3 a_i_segmentOffset;
|
4110 | in vec3 a_i_pivot;
|
4111 | in float a_i_horizontalAngle;
|
4112 | in float a_i_intensity;
|
4113 | in float a_i_flapScale;
|
4114 | in float a_i_flapness;
|
4115 | out vec2 v2f_texCoords;
|
4116 | out vec4 v2f_color;
|
4117 | out float v2f_diffuse;
|
4118 | out vec2 v2f_light;
|
4119 | void main() {
|
4120 | Vertex v;
|
4121 | v.pos = a_v_pos;
|
4122 | v.texCoords = a_v_texCoords;
|
4123 | v.normal = a_v_normal;
|
4124 | Flap i;
|
4125 | i.instancePos = a_i_instancePos;
|
4126 | i.light = a_i_light;
|
4127 | i.segmentOffset = a_i_segmentOffset;
|
4128 | i.pivot = a_i_pivot;
|
4129 | i.horizontalAngle = a_i_horizontalAngle;
|
4130 | i.intensity = a_i_intensity;
|
4131 | i.flapScale = a_i_flapScale;
|
4132 | i.flapness = a_i_flapness;
|
4133 | BlockFrag o = vertex(v, i);
|
4134 | v2f_texCoords = o.texCoords;
|
4135 | v2f_color = o.color;
|
4136 | v2f_diffuse = o.diffuse;
|
4137 | v2f_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)
|
4145 | out float FragDistance;
|
4146 | #elif defined(FRAGMENT_SHADER)
|
4147 | in float FragDistance;
|
4148 | #endif
|
4149 | uniform vec4 uFogColor;
|
4150 | uniform vec2 uFogRange;
|
4151 |
|
4152 | float 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 |
|
4158 | float cylindrical_distance(vec3 worldPos) {
|
4159 | float distXZ = length(worldPos.xz);
|
4160 | float distY = abs(worldPos.y);
|
4161 | return max(distXZ, distY);
|
4162 | }
|
4163 |
|
4164 | float FLWFogFactor() {
|
4165 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
4166 | }
|
4167 |
|
4168 |
|
4169 | uniform float uTime;
|
4170 | uniform mat4 uViewProjection;
|
4171 | uniform vec3 uCameraPos;
|
4172 |
|
4173 | uniform vec2 uTextureScale;
|
4174 | uniform sampler2D uBlockAtlas;
|
4175 | uniform sampler2D uLightMap;
|
4176 | uniform sampler2D uCrumbling;
|
4177 |
|
4178 | uniform vec2 uWindowSize;
|
4179 |
|
4180 | void FLWFinalizeNormal(inout vec3 normal) {
|
4181 | // noop
|
4182 | }
|
4183 |
|
4184 | #if defined(VERTEX_SHADER)
|
4185 | void 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 |
|
4195 | out vec4 fragColor;
|
4196 |
|
4197 | vec4 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 |
|
4204 | void 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 |
|
4220 | vec4 FLWLight(vec2 lightCoords) {
|
4221 | return vec4(1.);
|
4222 | }
|
4223 | #endif
|
4224 |
|
4225 |
|
4226 | mat4 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 |
|
4241 | mat4 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 |
|
4245 | mat3 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 |
|
4257 | vec4 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 |
|
4263 | vec4 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 |
|
4273 | vec3 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 |
|
4278 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
4279 | return rotateVertexByQuat(v, quat(axis, angle));
|
4280 | }
|
4281 |
|
4282 | float 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 | }
|
4286 | struct Vertex {
|
4287 | vec3 pos;
|
4288 | vec2 texCoords;
|
4289 | vec3 normal;
|
4290 | };
|
4291 |
|
4292 | struct BlockFrag {
|
4293 | vec2 texCoords;
|
4294 | vec4 color;
|
4295 | float diffuse;
|
4296 | vec2 light;
|
4297 | };
|
4298 |
|
4299 | #if defined(FRAGMENT_SHADER)
|
4300 | void 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 |
|
4314 | struct 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 |
|
4330 | float toRad(float degrees) {
|
4331 | return fract(degrees / 360.) * PI * 2.;
|
4332 | }
|
4333 |
|
4334 | float 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 |
|
4347 | BlockFrag 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 |
|
4375 | in vec2 v2f_texCoords;
|
4376 | in vec4 v2f_color;
|
4377 | in float v2f_diffuse;
|
4378 | in vec2 v2f_light;
|
4379 | void main() {
|
4380 | BlockFrag o;
|
4381 | o.texCoords = v2f_texCoords;
|
4382 | o.color = v2f_color;
|
4383 | o.diffuse = v2f_diffuse;
|
4384 | o.light = v2f_light;
|
4385 | fragment(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)
|
4394 | out float FragDistance;
|
4395 | #elif defined(FRAGMENT_SHADER)
|
4396 | in float FragDistance;
|
4397 | #endif
|
4398 | uniform vec4 uFogColor;
|
4399 | uniform vec2 uFogRange;
|
4400 |
|
4401 | float 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 |
|
4407 | float cylindrical_distance(vec3 worldPos) {
|
4408 | float distXZ = length(worldPos.xz);
|
4409 | float distY = abs(worldPos.y);
|
4410 | return max(distXZ, distY);
|
4411 | }
|
4412 |
|
4413 | float FLWFogFactor() {
|
4414 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
4415 | }
|
4416 |
|
4417 |
|
4418 | uniform float uTime;
|
4419 | uniform mat4 uViewProjection;
|
4420 | uniform vec3 uCameraPos;
|
4421 |
|
4422 | uniform vec2 uTextureScale;
|
4423 | uniform sampler2D uBlockAtlas;
|
4424 | uniform sampler2D uLightMap;
|
4425 | uniform sampler2D uCrumbling;
|
4426 |
|
4427 | uniform vec2 uWindowSize;
|
4428 |
|
4429 | void FLWFinalizeNormal(inout vec3 normal) {
|
4430 | // noop
|
4431 | }
|
4432 |
|
4433 | #if defined(VERTEX_SHADER)
|
4434 | void 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 |
|
4444 | out vec4 fragColor;
|
4445 |
|
4446 | vec4 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 |
|
4453 | void 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 |
|
4469 | vec4 FLWLight(vec2 lightCoords) {
|
4470 | return vec4(1.);
|
4471 | }
|
4472 | #endif
|
4473 |
|
4474 |
|
4475 | mat4 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 |
|
4490 | mat4 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 |
|
4494 | mat3 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 |
|
4506 | vec4 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 |
|
4512 | vec4 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 |
|
4522 | vec3 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 |
|
4527 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
4528 | return rotateVertexByQuat(v, quat(axis, angle));
|
4529 | }
|
4530 |
|
4531 | float 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 | }
|
4535 | struct Vertex {
|
4536 | vec3 pos;
|
4537 | vec2 texCoords;
|
4538 | vec3 normal;
|
4539 | };
|
4540 |
|
4541 | struct BlockFrag {
|
4542 | vec2 texCoords;
|
4543 | vec4 color;
|
4544 | float diffuse;
|
4545 | vec2 light;
|
4546 | };
|
4547 |
|
4548 | #if defined(FRAGMENT_SHADER)
|
4549 | void 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 |
|
4563 | struct 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 |
|
4579 | float toRad(float degrees) {
|
4580 | return fract(degrees / 360.) * PI * 2.;
|
4581 | }
|
4582 |
|
4583 | float 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 |
|
4596 | BlockFrag 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 |
|
4624 | in vec3 a_v_pos;
|
4625 | in vec2 a_v_texCoords;
|
4626 | in vec3 a_v_normal;
|
4627 | in vec3 a_i_instancePos;
|
4628 | in vec2 a_i_light;
|
4629 | in vec3 a_i_segmentOffset;
|
4630 | in vec3 a_i_pivot;
|
4631 | in float a_i_horizontalAngle;
|
4632 | in float a_i_intensity;
|
4633 | in float a_i_flapScale;
|
4634 | in float a_i_flapness;
|
4635 | out vec2 v2f_texCoords;
|
4636 | out vec4 v2f_color;
|
4637 | out float v2f_diffuse;
|
4638 | out vec2 v2f_light;
|
4639 | void main() {
|
4640 | Vertex v;
|
4641 | v.pos = a_v_pos;
|
4642 | v.texCoords = a_v_texCoords;
|
4643 | v.normal = a_v_normal;
|
4644 | Flap i;
|
4645 | i.instancePos = a_i_instancePos;
|
4646 | i.light = a_i_light;
|
4647 | i.segmentOffset = a_i_segmentOffset;
|
4648 | i.pivot = a_i_pivot;
|
4649 | i.horizontalAngle = a_i_horizontalAngle;
|
4650 | i.intensity = a_i_intensity;
|
4651 | i.flapScale = a_i_flapScale;
|
4652 | i.flapness = a_i_flapness;
|
4653 | BlockFrag o = vertex(v, i);
|
4654 | v2f_texCoords = o.texCoords;
|
4655 | v2f_color = o.color;
|
4656 | v2f_diffuse = o.diffuse;
|
4657 | v2f_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)
|
4666 | out float FragDistance;
|
4667 | #elif defined(FRAGMENT_SHADER)
|
4668 | in float FragDistance;
|
4669 | #endif
|
4670 | uniform vec4 uFogColor;
|
4671 | uniform vec2 uFogRange;
|
4672 |
|
4673 | float 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 |
|
4679 | float cylindrical_distance(vec3 worldPos) {
|
4680 | float distXZ = length(worldPos.xz);
|
4681 | float distY = abs(worldPos.y);
|
4682 | return max(distXZ, distY);
|
4683 | }
|
4684 |
|
4685 | float FLWFogFactor() {
|
4686 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
4687 | }
|
4688 |
|
4689 |
|
4690 | uniform float uTime;
|
4691 | uniform mat4 uViewProjection;
|
4692 | uniform vec3 uCameraPos;
|
4693 |
|
4694 | uniform vec2 uTextureScale;
|
4695 | uniform sampler2D uBlockAtlas;
|
4696 | uniform sampler2D uLightMap;
|
4697 | uniform sampler2D uCrumbling;
|
4698 |
|
4699 | uniform vec2 uWindowSize;
|
4700 |
|
4701 | void FLWFinalizeNormal(inout vec3 normal) {
|
4702 | // noop
|
4703 | }
|
4704 |
|
4705 | #if defined(VERTEX_SHADER)
|
4706 | void 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 |
|
4716 | out vec4 fragColor;
|
4717 |
|
4718 | vec4 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 |
|
4725 | void 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 |
|
4741 | vec4 FLWLight(vec2 lightCoords) {
|
4742 | return vec4(1.);
|
4743 | }
|
4744 | #endif
|
4745 |
|
4746 |
|
4747 | mat4 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 |
|
4762 | mat4 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 |
|
4766 | mat3 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 |
|
4778 | vec4 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 |
|
4784 | vec4 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 |
|
4794 | vec3 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 |
|
4799 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
4800 | return rotateVertexByQuat(v, quat(axis, angle));
|
4801 | }
|
4802 |
|
4803 | float 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 | }
|
4807 | struct Vertex {
|
4808 | vec3 pos;
|
4809 | vec2 texCoords;
|
4810 | vec3 normal;
|
4811 | };
|
4812 |
|
4813 | struct BlockFrag {
|
4814 | vec2 texCoords;
|
4815 | vec4 color;
|
4816 | float diffuse;
|
4817 | vec2 light;
|
4818 | };
|
4819 |
|
4820 | #if defined(FRAGMENT_SHADER)
|
4821 | void 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 |
|
4835 | struct 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 |
|
4851 | float toRad(float degrees) {
|
4852 | return fract(degrees / 360.) * PI * 2.;
|
4853 | }
|
4854 |
|
4855 | float 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 |
|
4868 | BlockFrag 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 |
|
4896 | in vec2 v2f_texCoords;
|
4897 | in vec4 v2f_color;
|
4898 | in float v2f_diffuse;
|
4899 | in vec2 v2f_light;
|
4900 | void main() {
|
4901 | BlockFrag o;
|
4902 | o.texCoords = v2f_texCoords;
|
4903 | o.color = v2f_color;
|
4904 | o.diffuse = v2f_diffuse;
|
4905 | o.light = v2f_light;
|
4906 | fragment(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)
|
4914 | out float FragDistance;
|
4915 | #elif defined(FRAGMENT_SHADER)
|
4916 | in float FragDistance;
|
4917 | #endif
|
4918 | uniform vec4 uFogColor;
|
4919 | uniform vec2 uFogRange;
|
4920 |
|
4921 | float 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 |
|
4927 | float cylindrical_distance(vec3 worldPos) {
|
4928 | float distXZ = length(worldPos.xz);
|
4929 | float distY = abs(worldPos.y);
|
4930 | return max(distXZ, distY);
|
4931 | }
|
4932 |
|
4933 | float FLWFogFactor() {
|
4934 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
4935 | }
|
4936 |
|
4937 |
|
4938 | uniform float uTime;
|
4939 | uniform mat4 uViewProjection;
|
4940 | uniform vec3 uCameraPos;
|
4941 |
|
4942 | uniform vec2 uTextureScale;
|
4943 | uniform sampler2D uBlockAtlas;
|
4944 | uniform sampler2D uLightMap;
|
4945 | uniform sampler2D uCrumbling;
|
4946 |
|
4947 | uniform vec2 uWindowSize;
|
4948 |
|
4949 | void FLWFinalizeNormal(inout vec3 normal) {
|
4950 | // noop
|
4951 | }
|
4952 |
|
4953 | #if defined(VERTEX_SHADER)
|
4954 | void 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 |
|
4964 | out vec4 fragColor;
|
4965 |
|
4966 | vec4 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 |
|
4973 | void 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 |
|
4989 | vec4 FLWLight(vec2 lightCoords) {
|
4990 | return vec4(1.);
|
4991 | }
|
4992 | #endif
|
4993 |
|
4994 |
|
4995 | #define PIOVER2 1.5707963268
|
4996 |
|
4997 | vec4 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 |
|
5003 | vec4 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 |
|
5013 | vec3 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 |
|
5018 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
5019 | return rotateVertexByQuat(v, quat(axis, angle));
|
5020 | }
|
5021 |
|
5022 | mat4 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 |
|
5037 | mat4 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 |
|
5041 | mat3 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 |
|
5051 | float 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 | }
|
5055 | struct Vertex {
|
5056 | vec3 pos;
|
5057 | vec2 texCoords;
|
5058 | vec3 normal;
|
5059 | };
|
5060 |
|
5061 | struct BlockFrag {
|
5062 | vec2 texCoords;
|
5063 | vec4 color;
|
5064 | float diffuse;
|
5065 | vec2 light;
|
5066 | };
|
5067 |
|
5068 | #if defined(FRAGMENT_SHADER)
|
5069 | void 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 |
|
5083 | struct 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)
|
5099 | BlockFrag 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 |
|
5129 | in vec3 a_v_pos;
|
5130 | in vec2 a_v_texCoords;
|
5131 | in vec3 a_v_normal;
|
5132 | in vec2 a_i_light;
|
5133 | in vec4 a_i_color;
|
5134 | in vec3 a_i_pos;
|
5135 | in float a_i_speed;
|
5136 | in float a_i_offset;
|
5137 | in vec4 a_i_rotation;
|
5138 | in vec2 a_i_sourceTexture;
|
5139 | in vec4 a_i_scrollTexture;
|
5140 | in float a_i_scrollMult;
|
5141 | out vec2 v2f_texCoords;
|
5142 | out vec4 v2f_color;
|
5143 | out float v2f_diffuse;
|
5144 | out vec2 v2f_light;
|
5145 | void main() {
|
5146 | Vertex v;
|
5147 | v.pos = a_v_pos;
|
5148 | v.texCoords = a_v_texCoords;
|
5149 | v.normal = a_v_normal;
|
5150 | Belt i;
|
5151 | i.light = a_i_light;
|
5152 | i.color = a_i_color;
|
5153 | i.pos = a_i_pos;
|
5154 | i.speed = a_i_speed;
|
5155 | i.offset = a_i_offset;
|
5156 | i.rotation = a_i_rotation;
|
5157 | i.sourceTexture = a_i_sourceTexture;
|
5158 | i.scrollTexture = a_i_scrollTexture;
|
5159 | i.scrollMult = a_i_scrollMult;
|
5160 | BlockFrag o = vertex(v, i);
|
5161 | v2f_texCoords = o.texCoords;
|
5162 | v2f_color = o.color;
|
5163 | v2f_diffuse = o.diffuse;
|
5164 | v2f_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)
|
5172 | out float FragDistance;
|
5173 | #elif defined(FRAGMENT_SHADER)
|
5174 | in float FragDistance;
|
5175 | #endif
|
5176 | uniform vec4 uFogColor;
|
5177 | uniform vec2 uFogRange;
|
5178 |
|
5179 | float 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 |
|
5185 | float cylindrical_distance(vec3 worldPos) {
|
5186 | float distXZ = length(worldPos.xz);
|
5187 | float distY = abs(worldPos.y);
|
5188 | return max(distXZ, distY);
|
5189 | }
|
5190 |
|
5191 | float FLWFogFactor() {
|
5192 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
5193 | }
|
5194 |
|
5195 |
|
5196 | uniform float uTime;
|
5197 | uniform mat4 uViewProjection;
|
5198 | uniform vec3 uCameraPos;
|
5199 |
|
5200 | uniform vec2 uTextureScale;
|
5201 | uniform sampler2D uBlockAtlas;
|
5202 | uniform sampler2D uLightMap;
|
5203 | uniform sampler2D uCrumbling;
|
5204 |
|
5205 | uniform vec2 uWindowSize;
|
5206 |
|
5207 | void FLWFinalizeNormal(inout vec3 normal) {
|
5208 | // noop
|
5209 | }
|
5210 |
|
5211 | #if defined(VERTEX_SHADER)
|
5212 | void 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 |
|
5222 | out vec4 fragColor;
|
5223 |
|
5224 | vec4 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 |
|
5231 | void 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 |
|
5247 | vec4 FLWLight(vec2 lightCoords) {
|
5248 | return vec4(1.);
|
5249 | }
|
5250 | #endif
|
5251 |
|
5252 |
|
5253 | #define PIOVER2 1.5707963268
|
5254 |
|
5255 | vec4 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 |
|
5261 | vec4 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 |
|
5271 | vec3 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 |
|
5276 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
5277 | return rotateVertexByQuat(v, quat(axis, angle));
|
5278 | }
|
5279 |
|
5280 | mat4 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 |
|
5295 | mat4 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 |
|
5299 | mat3 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 |
|
5309 | float 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 | }
|
5313 | struct Vertex {
|
5314 | vec3 pos;
|
5315 | vec2 texCoords;
|
5316 | vec3 normal;
|
5317 | };
|
5318 |
|
5319 | struct BlockFrag {
|
5320 | vec2 texCoords;
|
5321 | vec4 color;
|
5322 | float diffuse;
|
5323 | vec2 light;
|
5324 | };
|
5325 |
|
5326 | #if defined(FRAGMENT_SHADER)
|
5327 | void 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 |
|
5341 | struct 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)
|
5357 | BlockFrag 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 |
|
5387 | in vec2 v2f_texCoords;
|
5388 | in vec4 v2f_color;
|
5389 | in float v2f_diffuse;
|
5390 | in vec2 v2f_light;
|
5391 | void main() {
|
5392 | BlockFrag o;
|
5393 | o.texCoords = v2f_texCoords;
|
5394 | o.color = v2f_color;
|
5395 | o.diffuse = v2f_diffuse;
|
5396 | o.light = v2f_light;
|
5397 | fragment(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)
|
5406 | out float FragDistance;
|
5407 | #elif defined(FRAGMENT_SHADER)
|
5408 | in float FragDistance;
|
5409 | #endif
|
5410 | uniform vec4 uFogColor;
|
5411 | uniform vec2 uFogRange;
|
5412 |
|
5413 | float 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 |
|
5419 | float cylindrical_distance(vec3 worldPos) {
|
5420 | float distXZ = length(worldPos.xz);
|
5421 | float distY = abs(worldPos.y);
|
5422 | return max(distXZ, distY);
|
5423 | }
|
5424 |
|
5425 | float FLWFogFactor() {
|
5426 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
5427 | }
|
5428 |
|
5429 |
|
5430 | uniform float uTime;
|
5431 | uniform mat4 uViewProjection;
|
5432 | uniform vec3 uCameraPos;
|
5433 |
|
5434 | uniform vec2 uTextureScale;
|
5435 | uniform sampler2D uBlockAtlas;
|
5436 | uniform sampler2D uLightMap;
|
5437 | uniform sampler2D uCrumbling;
|
5438 |
|
5439 | uniform vec2 uWindowSize;
|
5440 |
|
5441 | void FLWFinalizeNormal(inout vec3 normal) {
|
5442 | // noop
|
5443 | }
|
5444 |
|
5445 | #if defined(VERTEX_SHADER)
|
5446 | void 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 |
|
5456 | out vec4 fragColor;
|
5457 |
|
5458 | vec4 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 |
|
5465 | void 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 |
|
5481 | vec4 FLWLight(vec2 lightCoords) {
|
5482 | return vec4(1.);
|
5483 | }
|
5484 | #endif
|
5485 |
|
5486 |
|
5487 | #define PIOVER2 1.5707963268
|
5488 |
|
5489 | vec4 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 |
|
5495 | vec4 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 |
|
5505 | vec3 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 |
|
5510 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
5511 | return rotateVertexByQuat(v, quat(axis, angle));
|
5512 | }
|
5513 |
|
5514 | mat4 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 |
|
5529 | mat4 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 |
|
5533 | mat3 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 |
|
5543 | float 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 | }
|
5547 | struct Vertex {
|
5548 | vec3 pos;
|
5549 | vec2 texCoords;
|
5550 | vec3 normal;
|
5551 | };
|
5552 |
|
5553 | struct BlockFrag {
|
5554 | vec2 texCoords;
|
5555 | vec4 color;
|
5556 | float diffuse;
|
5557 | vec2 light;
|
5558 | };
|
5559 |
|
5560 | #if defined(FRAGMENT_SHADER)
|
5561 | void 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 |
|
5575 | struct 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)
|
5591 | BlockFrag 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 |
|
5621 | in vec3 a_v_pos;
|
5622 | in vec2 a_v_texCoords;
|
5623 | in vec3 a_v_normal;
|
5624 | in vec2 a_i_light;
|
5625 | in vec4 a_i_color;
|
5626 | in vec3 a_i_pos;
|
5627 | in float a_i_speed;
|
5628 | in float a_i_offset;
|
5629 | in vec4 a_i_rotation;
|
5630 | in vec2 a_i_sourceTexture;
|
5631 | in vec4 a_i_scrollTexture;
|
5632 | in float a_i_scrollMult;
|
5633 | out vec2 v2f_texCoords;
|
5634 | out vec4 v2f_color;
|
5635 | out float v2f_diffuse;
|
5636 | out vec2 v2f_light;
|
5637 | void main() {
|
5638 | Vertex v;
|
5639 | v.pos = a_v_pos;
|
5640 | v.texCoords = a_v_texCoords;
|
5641 | v.normal = a_v_normal;
|
5642 | Belt i;
|
5643 | i.light = a_i_light;
|
5644 | i.color = a_i_color;
|
5645 | i.pos = a_i_pos;
|
5646 | i.speed = a_i_speed;
|
5647 | i.offset = a_i_offset;
|
5648 | i.rotation = a_i_rotation;
|
5649 | i.sourceTexture = a_i_sourceTexture;
|
5650 | i.scrollTexture = a_i_scrollTexture;
|
5651 | i.scrollMult = a_i_scrollMult;
|
5652 | BlockFrag o = vertex(v, i);
|
5653 | v2f_texCoords = o.texCoords;
|
5654 | v2f_color = o.color;
|
5655 | v2f_diffuse = o.diffuse;
|
5656 | v2f_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)
|
5665 | out float FragDistance;
|
5666 | #elif defined(FRAGMENT_SHADER)
|
5667 | in float FragDistance;
|
5668 | #endif
|
5669 | uniform vec4 uFogColor;
|
5670 | uniform vec2 uFogRange;
|
5671 |
|
5672 | float 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 |
|
5678 | float cylindrical_distance(vec3 worldPos) {
|
5679 | float distXZ = length(worldPos.xz);
|
5680 | float distY = abs(worldPos.y);
|
5681 | return max(distXZ, distY);
|
5682 | }
|
5683 |
|
5684 | float FLWFogFactor() {
|
5685 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
5686 | }
|
5687 |
|
5688 |
|
5689 | uniform float uTime;
|
5690 | uniform mat4 uViewProjection;
|
5691 | uniform vec3 uCameraPos;
|
5692 |
|
5693 | uniform vec2 uTextureScale;
|
5694 | uniform sampler2D uBlockAtlas;
|
5695 | uniform sampler2D uLightMap;
|
5696 | uniform sampler2D uCrumbling;
|
5697 |
|
5698 | uniform vec2 uWindowSize;
|
5699 |
|
5700 | void FLWFinalizeNormal(inout vec3 normal) {
|
5701 | // noop
|
5702 | }
|
5703 |
|
5704 | #if defined(VERTEX_SHADER)
|
5705 | void 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 |
|
5715 | out vec4 fragColor;
|
5716 |
|
5717 | vec4 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 |
|
5724 | void 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 |
|
5740 | vec4 FLWLight(vec2 lightCoords) {
|
5741 | return vec4(1.);
|
5742 | }
|
5743 | #endif
|
5744 |
|
5745 |
|
5746 | #define PIOVER2 1.5707963268
|
5747 |
|
5748 | vec4 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 |
|
5754 | vec4 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 |
|
5764 | vec3 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 |
|
5769 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
5770 | return rotateVertexByQuat(v, quat(axis, angle));
|
5771 | }
|
5772 |
|
5773 | mat4 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 |
|
5788 | mat4 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 |
|
5792 | mat3 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 |
|
5802 | float 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 | }
|
5806 | struct Vertex {
|
5807 | vec3 pos;
|
5808 | vec2 texCoords;
|
5809 | vec3 normal;
|
5810 | };
|
5811 |
|
5812 | struct BlockFrag {
|
5813 | vec2 texCoords;
|
5814 | vec4 color;
|
5815 | float diffuse;
|
5816 | vec2 light;
|
5817 | };
|
5818 |
|
5819 | #if defined(FRAGMENT_SHADER)
|
5820 | void 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 |
|
5834 | struct 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)
|
5850 | BlockFrag 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 |
|
5880 | in vec2 v2f_texCoords;
|
5881 | in vec4 v2f_color;
|
5882 | in float v2f_diffuse;
|
5883 | in vec2 v2f_light;
|
5884 | void main() {
|
5885 | BlockFrag o;
|
5886 | o.texCoords = v2f_texCoords;
|
5887 | o.color = v2f_color;
|
5888 | o.diffuse = v2f_diffuse;
|
5889 | o.light = v2f_light;
|
5890 | fragment(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)
|
5899 | out float FragDistance;
|
5900 | #elif defined(FRAGMENT_SHADER)
|
5901 | in float FragDistance;
|
5902 | #endif
|
5903 | uniform vec4 uFogColor;
|
5904 | uniform vec2 uFogRange;
|
5905 |
|
5906 | float 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 |
|
5912 | float cylindrical_distance(vec3 worldPos) {
|
5913 | float distXZ = length(worldPos.xz);
|
5914 | float distY = abs(worldPos.y);
|
5915 | return max(distXZ, distY);
|
5916 | }
|
5917 |
|
5918 | float FLWFogFactor() {
|
5919 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
5920 | }
|
5921 |
|
5922 |
|
5923 | uniform float uTime;
|
5924 | uniform mat4 uViewProjection;
|
5925 | uniform vec3 uCameraPos;
|
5926 |
|
5927 | uniform vec2 uTextureScale;
|
5928 | uniform sampler2D uBlockAtlas;
|
5929 | uniform sampler2D uLightMap;
|
5930 | uniform sampler2D uCrumbling;
|
5931 |
|
5932 | uniform vec2 uWindowSize;
|
5933 |
|
5934 | void FLWFinalizeNormal(inout vec3 normal) {
|
5935 | // noop
|
5936 | }
|
5937 |
|
5938 | #if defined(VERTEX_SHADER)
|
5939 | void 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 |
|
5949 | out vec4 fragColor;
|
5950 |
|
5951 | vec4 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 |
|
5958 | void 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 |
|
5974 | vec4 FLWLight(vec2 lightCoords) {
|
5975 | return vec4(1.);
|
5976 | }
|
5977 | #endif
|
5978 |
|
5979 |
|
5980 | #define PIOVER2 1.5707963268
|
5981 |
|
5982 | vec4 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 |
|
5988 | vec4 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 |
|
5998 | vec3 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 |
|
6003 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
6004 | return rotateVertexByQuat(v, quat(axis, angle));
|
6005 | }
|
6006 |
|
6007 | mat4 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 |
|
6022 | mat4 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 |
|
6026 | mat3 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 |
|
6036 | float 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 | }
|
6040 | struct Vertex {
|
6041 | vec3 pos;
|
6042 | vec2 texCoords;
|
6043 | vec3 normal;
|
6044 | };
|
6045 |
|
6046 | struct BlockFrag {
|
6047 | vec2 texCoords;
|
6048 | vec4 color;
|
6049 | float diffuse;
|
6050 | vec2 light;
|
6051 | };
|
6052 |
|
6053 | #if defined(FRAGMENT_SHADER)
|
6054 | void 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 |
|
6068 | struct 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)
|
6084 | BlockFrag 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 |
|
6114 | in vec3 a_v_pos;
|
6115 | in vec2 a_v_texCoords;
|
6116 | in vec3 a_v_normal;
|
6117 | in vec2 a_i_light;
|
6118 | in vec4 a_i_color;
|
6119 | in vec3 a_i_pos;
|
6120 | in float a_i_speed;
|
6121 | in float a_i_offset;
|
6122 | in vec4 a_i_rotation;
|
6123 | in vec2 a_i_sourceTexture;
|
6124 | in vec4 a_i_scrollTexture;
|
6125 | in float a_i_scrollMult;
|
6126 | out vec2 v2f_texCoords;
|
6127 | out vec4 v2f_color;
|
6128 | out float v2f_diffuse;
|
6129 | out vec2 v2f_light;
|
6130 | void main() {
|
6131 | Vertex v;
|
6132 | v.pos = a_v_pos;
|
6133 | v.texCoords = a_v_texCoords;
|
6134 | v.normal = a_v_normal;
|
6135 | Belt i;
|
6136 | i.light = a_i_light;
|
6137 | i.color = a_i_color;
|
6138 | i.pos = a_i_pos;
|
6139 | i.speed = a_i_speed;
|
6140 | i.offset = a_i_offset;
|
6141 | i.rotation = a_i_rotation;
|
6142 | i.sourceTexture = a_i_sourceTexture;
|
6143 | i.scrollTexture = a_i_scrollTexture;
|
6144 | i.scrollMult = a_i_scrollMult;
|
6145 | BlockFrag o = vertex(v, i);
|
6146 | v2f_texCoords = o.texCoords;
|
6147 | v2f_color = o.color;
|
6148 | v2f_diffuse = o.diffuse;
|
6149 | v2f_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)
|
6158 | out float FragDistance;
|
6159 | #elif defined(FRAGMENT_SHADER)
|
6160 | in float FragDistance;
|
6161 | #endif
|
6162 | uniform vec4 uFogColor;
|
6163 | uniform vec2 uFogRange;
|
6164 |
|
6165 | float 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 |
|
6171 | float cylindrical_distance(vec3 worldPos) {
|
6172 | float distXZ = length(worldPos.xz);
|
6173 | float distY = abs(worldPos.y);
|
6174 | return max(distXZ, distY);
|
6175 | }
|
6176 |
|
6177 | float FLWFogFactor() {
|
6178 | return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
6179 | }
|
6180 |
|
6181 |
|
6182 | uniform float uTime;
|
6183 | uniform mat4 uViewProjection;
|
6184 | uniform vec3 uCameraPos;
|
6185 |
|
6186 | uniform vec2 uTextureScale;
|
6187 | uniform sampler2D uBlockAtlas;
|
6188 | uniform sampler2D uLightMap;
|
6189 | uniform sampler2D uCrumbling;
|
6190 |
|
6191 | uniform vec2 uWindowSize;
|
6192 |
|
6193 | void FLWFinalizeNormal(inout vec3 normal) {
|
6194 | // noop
|
6195 | }
|
6196 |
|
6197 | #if defined(VERTEX_SHADER)
|
6198 | void 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 |
|
6208 | out vec4 fragColor;
|
6209 |
|
6210 | vec4 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 |
|
6217 | void 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 |
|
6233 | vec4 FLWLight(vec2 lightCoords) {
|
6234 | return vec4(1.);
|
6235 | }
|
6236 | #endif
|
6237 |
|
6238 |
|
6239 | #define PIOVER2 1.5707963268
|
6240 |
|
6241 | vec4 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 |
|
6247 | vec4 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 |
|
6257 | vec3 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 |
|
6262 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
6263 | return rotateVertexByQuat(v, quat(axis, angle));
|
6264 | }
|
6265 |
|
6266 | mat4 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 |
|
6281 | mat4 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 |
|
6285 | mat3 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 |
|
6295 | float 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 | }
|
6299 | struct Vertex {
|
6300 | vec3 pos;
|
6301 | vec2 texCoords;
|
6302 | vec3 normal;
|
6303 | };
|
6304 |
|
6305 | struct BlockFrag {
|
6306 | vec2 texCoords;
|
6307 | vec4 color;
|
6308 | float diffuse;
|
6309 | vec2 light;
|
6310 | };
|
6311 |
|
6312 | #if defined(FRAGMENT_SHADER)
|
6313 | void 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 |
|
6327 | struct 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)
|
6343 | BlockFrag 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 |
|
6373 | in vec2 v2f_texCoords;
|
6374 | in vec4 v2f_color;
|
6375 | in float v2f_diffuse;
|
6376 | in vec2 v2f_light;
|
6377 | void main() {
|
6378 | BlockFrag o;
|
6379 | o.texCoords = v2f_texCoords;
|
6380 | o.color = v2f_color;
|
6381 | o.diffuse = v2f_diffuse;
|
6382 | o.light = v2f_light;
|
6383 | fragment(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)
|
6392 | out float FragDistance;
|
6393 | #elif defined(FRAGMENT_SHADER)
|
6394 | in float FragDistance;
|
6395 | #endif
|
6396 | uniform vec4 uFogColor;
|
6397 | uniform vec2 uFogRange;
|
6398 |
|
6399 | float 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 |
|
6405 | float cylindrical_distance(vec3 worldPos) {
|
6406 | float distXZ = length(worldPos.xz);
|
6407 | float distY = abs(worldPos.y);
|
6408 | return max(distXZ, distY);
|
6409 | }
|
6410 |
|
6411 | float 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
|
6415 | vec2 shiftLight(vec2 lm) {
|
6416 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
6417 | }
|
6418 |
|
6419 |
|
6420 | uniform float uTime;
|
6421 | uniform mat4 uViewProjection;
|
6422 | uniform vec3 uCameraPos;
|
6423 |
|
6424 | uniform vec2 uTextureScale;
|
6425 | uniform sampler2D uBlockAtlas;
|
6426 | uniform sampler2D uLightMap;
|
6427 |
|
6428 | uniform vec2 uWindowSize;
|
6429 |
|
6430 | void FLWFinalizeNormal(inout vec3 normal) {
|
6431 | // noop
|
6432 | }
|
6433 |
|
6434 | #if defined(VERTEX_SHADER)
|
6435 | void 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)
|
6448 | layout (depth_greater) out float gl_FragDepth;
|
6449 | #endif
|
6450 | #endif
|
6451 | out vec4 fragColor;
|
6452 |
|
6453 | vec4 FLWBlockTexture(vec2 texCoords) {
|
6454 | return texture(uBlockAtlas, texCoords);
|
6455 | }
|
6456 |
|
6457 | void 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 |
|
6473 | vec4 FLWLight(vec2 lightCoords) {
|
6474 | return texture(uLightMap, shiftLight(lightCoords));
|
6475 | }
|
6476 | #endif
|
6477 |
|
6478 |
|
6479 | float 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 | }
|
6483 | struct Vertex {
|
6484 | vec3 pos;
|
6485 | vec2 texCoords;
|
6486 | vec3 normal;
|
6487 | };
|
6488 |
|
6489 | struct BlockFrag {
|
6490 | vec2 texCoords;
|
6491 | vec4 color;
|
6492 | float diffuse;
|
6493 | vec2 light;
|
6494 | };
|
6495 |
|
6496 | #if defined(FRAGMENT_SHADER)
|
6497 | void 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 |
|
6509 | struct Instance {
|
6510 | vec2 light;
|
6511 | vec4 color;
|
6512 | mat4 transform;
|
6513 | mat3 normalMat;
|
6514 | };
|
6515 |
|
6516 | #if defined(VERTEX_SHADER)
|
6517 | BlockFrag 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 |
|
6540 | in vec3 a_v_pos;
|
6541 | in vec2 a_v_texCoords;
|
6542 | in vec3 a_v_normal;
|
6543 | in vec2 a_i_light;
|
6544 | in vec4 a_i_color;
|
6545 | in mat4 a_i_transform;
|
6546 | in mat3 a_i_normalMat;
|
6547 | out vec2 v2f_texCoords;
|
6548 | out vec4 v2f_color;
|
6549 | out float v2f_diffuse;
|
6550 | out vec2 v2f_light;
|
6551 | void main() {
|
6552 | Vertex v;
|
6553 | v.pos = a_v_pos;
|
6554 | v.texCoords = a_v_texCoords;
|
6555 | v.normal = a_v_normal;
|
6556 | Instance i;
|
6557 | i.light = a_i_light;
|
6558 | i.color = a_i_color;
|
6559 | i.transform = a_i_transform;
|
6560 | i.normalMat = a_i_normalMat;
|
6561 | BlockFrag o = vertex(v, i);
|
6562 | v2f_texCoords = o.texCoords;
|
6563 | v2f_color = o.color;
|
6564 | v2f_diffuse = o.diffuse;
|
6565 | v2f_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)
|
6573 | out float FragDistance;
|
6574 | #elif defined(FRAGMENT_SHADER)
|
6575 | in float FragDistance;
|
6576 | #endif
|
6577 | uniform vec4 uFogColor;
|
6578 | uniform vec2 uFogRange;
|
6579 |
|
6580 | float 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 |
|
6586 | float cylindrical_distance(vec3 worldPos) {
|
6587 | float distXZ = length(worldPos.xz);
|
6588 | float distY = abs(worldPos.y);
|
6589 | return max(distXZ, distY);
|
6590 | }
|
6591 |
|
6592 | float 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
|
6596 | vec2 shiftLight(vec2 lm) {
|
6597 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
6598 | }
|
6599 |
|
6600 |
|
6601 | uniform float uTime;
|
6602 | uniform mat4 uViewProjection;
|
6603 | uniform vec3 uCameraPos;
|
6604 |
|
6605 | uniform vec2 uTextureScale;
|
6606 | uniform sampler2D uBlockAtlas;
|
6607 | uniform sampler2D uLightMap;
|
6608 |
|
6609 | uniform vec2 uWindowSize;
|
6610 |
|
6611 | void FLWFinalizeNormal(inout vec3 normal) {
|
6612 | // noop
|
6613 | }
|
6614 |
|
6615 | #if defined(VERTEX_SHADER)
|
6616 | void 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)
|
6629 | layout (depth_greater) out float gl_FragDepth;
|
6630 | #endif
|
6631 | #endif
|
6632 | out vec4 fragColor;
|
6633 |
|
6634 | vec4 FLWBlockTexture(vec2 texCoords) {
|
6635 | return texture(uBlockAtlas, texCoords);
|
6636 | }
|
6637 |
|
6638 | void 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 |
|
6654 | vec4 FLWLight(vec2 lightCoords) {
|
6655 | return texture(uLightMap, shiftLight(lightCoords));
|
6656 | }
|
6657 | #endif
|
6658 |
|
6659 |
|
6660 | float 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 | }
|
6664 | struct Vertex {
|
6665 | vec3 pos;
|
6666 | vec2 texCoords;
|
6667 | vec3 normal;
|
6668 | };
|
6669 |
|
6670 | struct BlockFrag {
|
6671 | vec2 texCoords;
|
6672 | vec4 color;
|
6673 | float diffuse;
|
6674 | vec2 light;
|
6675 | };
|
6676 |
|
6677 | #if defined(FRAGMENT_SHADER)
|
6678 | void 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 |
|
6690 | struct Instance {
|
6691 | vec2 light;
|
6692 | vec4 color;
|
6693 | mat4 transform;
|
6694 | mat3 normalMat;
|
6695 | };
|
6696 |
|
6697 | #if defined(VERTEX_SHADER)
|
6698 | BlockFrag 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 |
|
6721 | in vec2 v2f_texCoords;
|
6722 | in vec4 v2f_color;
|
6723 | in float v2f_diffuse;
|
6724 | in vec2 v2f_light;
|
6725 | void main() {
|
6726 | BlockFrag o;
|
6727 | o.texCoords = v2f_texCoords;
|
6728 | o.color = v2f_color;
|
6729 | o.diffuse = v2f_diffuse;
|
6730 | o.light = v2f_light;
|
6731 | fragment(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)
|
6740 | out float FragDistance;
|
6741 | #elif defined(FRAGMENT_SHADER)
|
6742 | in float FragDistance;
|
6743 | #endif
|
6744 | uniform vec4 uFogColor;
|
6745 | uniform vec2 uFogRange;
|
6746 |
|
6747 | float 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 |
|
6753 | float cylindrical_distance(vec3 worldPos) {
|
6754 | float distXZ = length(worldPos.xz);
|
6755 | float distY = abs(worldPos.y);
|
6756 | return max(distXZ, distY);
|
6757 | }
|
6758 |
|
6759 | float 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
|
6763 | vec2 shiftLight(vec2 lm) {
|
6764 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
6765 | }
|
6766 |
|
6767 |
|
6768 | uniform float uTime;
|
6769 | uniform mat4 uViewProjection;
|
6770 | uniform vec3 uCameraPos;
|
6771 |
|
6772 | uniform vec2 uTextureScale;
|
6773 | uniform sampler2D uBlockAtlas;
|
6774 | uniform sampler2D uLightMap;
|
6775 |
|
6776 | uniform vec2 uWindowSize;
|
6777 |
|
6778 | void FLWFinalizeNormal(inout vec3 normal) {
|
6779 | // noop
|
6780 | }
|
6781 |
|
6782 | #if defined(VERTEX_SHADER)
|
6783 | void 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)
|
6796 | layout (depth_greater) out float gl_FragDepth;
|
6797 | #endif
|
6798 | #endif
|
6799 | out vec4 fragColor;
|
6800 |
|
6801 | vec4 FLWBlockTexture(vec2 texCoords) {
|
6802 | return texture(uBlockAtlas, texCoords);
|
6803 | }
|
6804 |
|
6805 | void 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 |
|
6821 | vec4 FLWLight(vec2 lightCoords) {
|
6822 | return texture(uLightMap, shiftLight(lightCoords));
|
6823 | }
|
6824 | #endif
|
6825 |
|
6826 |
|
6827 | float 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 | }
|
6831 | struct Vertex {
|
6832 | vec3 pos;
|
6833 | vec2 texCoords;
|
6834 | vec3 normal;
|
6835 | };
|
6836 |
|
6837 | struct BlockFrag {
|
6838 | vec2 texCoords;
|
6839 | vec4 color;
|
6840 | float diffuse;
|
6841 | vec2 light;
|
6842 | };
|
6843 |
|
6844 | #if defined(FRAGMENT_SHADER)
|
6845 | void 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 |
|
6857 | struct Instance {
|
6858 | vec2 light;
|
6859 | vec4 color;
|
6860 | mat4 transform;
|
6861 | mat3 normalMat;
|
6862 | };
|
6863 |
|
6864 | #if defined(VERTEX_SHADER)
|
6865 | BlockFrag 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 |
|
6888 | in vec3 a_v_pos;
|
6889 | in vec2 a_v_texCoords;
|
6890 | in vec3 a_v_normal;
|
6891 | in vec2 a_i_light;
|
6892 | in vec4 a_i_color;
|
6893 | in mat4 a_i_transform;
|
6894 | in mat3 a_i_normalMat;
|
6895 | out vec2 v2f_texCoords;
|
6896 | out vec4 v2f_color;
|
6897 | out float v2f_diffuse;
|
6898 | out vec2 v2f_light;
|
6899 | void main() {
|
6900 | Vertex v;
|
6901 | v.pos = a_v_pos;
|
6902 | v.texCoords = a_v_texCoords;
|
6903 | v.normal = a_v_normal;
|
6904 | Instance i;
|
6905 | i.light = a_i_light;
|
6906 | i.color = a_i_color;
|
6907 | i.transform = a_i_transform;
|
6908 | i.normalMat = a_i_normalMat;
|
6909 | BlockFrag o = vertex(v, i);
|
6910 | v2f_texCoords = o.texCoords;
|
6911 | v2f_color = o.color;
|
6912 | v2f_diffuse = o.diffuse;
|
6913 | v2f_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)
|
6922 | out float FragDistance;
|
6923 | #elif defined(FRAGMENT_SHADER)
|
6924 | in float FragDistance;
|
6925 | #endif
|
6926 | uniform vec4 uFogColor;
|
6927 | uniform vec2 uFogRange;
|
6928 |
|
6929 | float 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 |
|
6935 | float cylindrical_distance(vec3 worldPos) {
|
6936 | float distXZ = length(worldPos.xz);
|
6937 | float distY = abs(worldPos.y);
|
6938 | return max(distXZ, distY);
|
6939 | }
|
6940 |
|
6941 | float 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
|
6945 | vec2 shiftLight(vec2 lm) {
|
6946 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
6947 | }
|
6948 |
|
6949 |
|
6950 | uniform float uTime;
|
6951 | uniform mat4 uViewProjection;
|
6952 | uniform vec3 uCameraPos;
|
6953 |
|
6954 | uniform vec2 uTextureScale;
|
6955 | uniform sampler2D uBlockAtlas;
|
6956 | uniform sampler2D uLightMap;
|
6957 |
|
6958 | uniform vec2 uWindowSize;
|
6959 |
|
6960 | void FLWFinalizeNormal(inout vec3 normal) {
|
6961 | // noop
|
6962 | }
|
6963 |
|
6964 | #if defined(VERTEX_SHADER)
|
6965 | void 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)
|
6978 | layout (depth_greater) out float gl_FragDepth;
|
6979 | #endif
|
6980 | #endif
|
6981 | out vec4 fragColor;
|
6982 |
|
6983 | vec4 FLWBlockTexture(vec2 texCoords) {
|
6984 | return texture(uBlockAtlas, texCoords);
|
6985 | }
|
6986 |
|
6987 | void 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 |
|
7003 | vec4 FLWLight(vec2 lightCoords) {
|
7004 | return texture(uLightMap, shiftLight(lightCoords));
|
7005 | }
|
7006 | #endif
|
7007 |
|
7008 |
|
7009 | float 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 | }
|
7013 | struct Vertex {
|
7014 | vec3 pos;
|
7015 | vec2 texCoords;
|
7016 | vec3 normal;
|
7017 | };
|
7018 |
|
7019 | struct BlockFrag {
|
7020 | vec2 texCoords;
|
7021 | vec4 color;
|
7022 | float diffuse;
|
7023 | vec2 light;
|
7024 | };
|
7025 |
|
7026 | #if defined(FRAGMENT_SHADER)
|
7027 | void 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 |
|
7039 | struct Instance {
|
7040 | vec2 light;
|
7041 | vec4 color;
|
7042 | mat4 transform;
|
7043 | mat3 normalMat;
|
7044 | };
|
7045 |
|
7046 | #if defined(VERTEX_SHADER)
|
7047 | BlockFrag 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 |
|
7070 | in vec2 v2f_texCoords;
|
7071 | in vec4 v2f_color;
|
7072 | in float v2f_diffuse;
|
7073 | in vec2 v2f_light;
|
7074 | void main() {
|
7075 | BlockFrag o;
|
7076 | o.texCoords = v2f_texCoords;
|
7077 | o.color = v2f_color;
|
7078 | o.diffuse = v2f_diffuse;
|
7079 | o.light = v2f_light;
|
7080 | fragment(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)
|
7088 | out float FragDistance;
|
7089 | #elif defined(FRAGMENT_SHADER)
|
7090 | in float FragDistance;
|
7091 | #endif
|
7092 | uniform vec4 uFogColor;
|
7093 | uniform vec2 uFogRange;
|
7094 |
|
7095 | float 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 |
|
7101 | float cylindrical_distance(vec3 worldPos) {
|
7102 | float distXZ = length(worldPos.xz);
|
7103 | float distY = abs(worldPos.y);
|
7104 | return max(distXZ, distY);
|
7105 | }
|
7106 |
|
7107 | float 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
|
7111 | vec2 shiftLight(vec2 lm) {
|
7112 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
7113 | }
|
7114 |
|
7115 |
|
7116 | uniform float uTime;
|
7117 | uniform mat4 uViewProjection;
|
7118 | uniform vec3 uCameraPos;
|
7119 |
|
7120 | uniform vec2 uTextureScale;
|
7121 | uniform sampler2D uBlockAtlas;
|
7122 | uniform sampler2D uLightMap;
|
7123 |
|
7124 | uniform vec2 uWindowSize;
|
7125 |
|
7126 | void FLWFinalizeNormal(inout vec3 normal) {
|
7127 | // noop
|
7128 | }
|
7129 |
|
7130 | #if defined(VERTEX_SHADER)
|
7131 | void 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)
|
7144 | layout (depth_greater) out float gl_FragDepth;
|
7145 | #endif
|
7146 | #endif
|
7147 | out vec4 fragColor;
|
7148 |
|
7149 | vec4 FLWBlockTexture(vec2 texCoords) {
|
7150 | return texture(uBlockAtlas, texCoords);
|
7151 | }
|
7152 |
|
7153 | void 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 |
|
7169 | vec4 FLWLight(vec2 lightCoords) {
|
7170 | return texture(uLightMap, shiftLight(lightCoords));
|
7171 | }
|
7172 | #endif
|
7173 |
|
7174 |
|
7175 | #define PIOVER2 1.5707963268
|
7176 |
|
7177 | vec4 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 |
|
7183 | vec4 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 |
|
7193 | vec3 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 |
|
7198 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
7199 | return rotateVertexByQuat(v, quat(axis, angle));
|
7200 | }
|
7201 |
|
7202 | float 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 | }
|
7206 | struct Vertex {
|
7207 | vec3 pos;
|
7208 | vec2 texCoords;
|
7209 | vec3 normal;
|
7210 | };
|
7211 |
|
7212 | struct BlockFrag {
|
7213 | vec2 texCoords;
|
7214 | vec4 color;
|
7215 | float diffuse;
|
7216 | vec2 light;
|
7217 | };
|
7218 |
|
7219 | #if defined(FRAGMENT_SHADER)
|
7220 | void 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 |
|
7234 | struct Oriented {
|
7235 | vec2 light;
|
7236 | vec4 color;
|
7237 | vec3 pos;
|
7238 | vec3 pivot;
|
7239 | vec4 rotation;
|
7240 | };
|
7241 |
|
7242 | #if defined(VERTEX_SHADER)
|
7243 | BlockFrag 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 |
|
7264 | in vec3 a_v_pos;
|
7265 | in vec2 a_v_texCoords;
|
7266 | in vec3 a_v_normal;
|
7267 | in vec2 a_i_light;
|
7268 | in vec4 a_i_color;
|
7269 | in vec3 a_i_pos;
|
7270 | in vec3 a_i_pivot;
|
7271 | in vec4 a_i_rotation;
|
7272 | out vec2 v2f_texCoords;
|
7273 | out vec4 v2f_color;
|
7274 | out float v2f_diffuse;
|
7275 | out vec2 v2f_light;
|
7276 | void main() {
|
7277 | Vertex v;
|
7278 | v.pos = a_v_pos;
|
7279 | v.texCoords = a_v_texCoords;
|
7280 | v.normal = a_v_normal;
|
7281 | Oriented i;
|
7282 | i.light = a_i_light;
|
7283 | i.color = a_i_color;
|
7284 | i.pos = a_i_pos;
|
7285 | i.pivot = a_i_pivot;
|
7286 | i.rotation = a_i_rotation;
|
7287 | BlockFrag o = vertex(v, i);
|
7288 | v2f_texCoords = o.texCoords;
|
7289 | v2f_color = o.color;
|
7290 | v2f_diffuse = o.diffuse;
|
7291 | v2f_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)
|
7299 | out float FragDistance;
|
7300 | #elif defined(FRAGMENT_SHADER)
|
7301 | in float FragDistance;
|
7302 | #endif
|
7303 | uniform vec4 uFogColor;
|
7304 | uniform vec2 uFogRange;
|
7305 |
|
7306 | float 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 |
|
7312 | float cylindrical_distance(vec3 worldPos) {
|
7313 | float distXZ = length(worldPos.xz);
|
7314 | float distY = abs(worldPos.y);
|
7315 | return max(distXZ, distY);
|
7316 | }
|
7317 |
|
7318 | float 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
|
7322 | vec2 shiftLight(vec2 lm) {
|
7323 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
7324 | }
|
7325 |
|
7326 |
|
7327 | uniform float uTime;
|
7328 | uniform mat4 uViewProjection;
|
7329 | uniform vec3 uCameraPos;
|
7330 |
|
7331 | uniform vec2 uTextureScale;
|
7332 | uniform sampler2D uBlockAtlas;
|
7333 | uniform sampler2D uLightMap;
|
7334 |
|
7335 | uniform vec2 uWindowSize;
|
7336 |
|
7337 | void FLWFinalizeNormal(inout vec3 normal) {
|
7338 | // noop
|
7339 | }
|
7340 |
|
7341 | #if defined(VERTEX_SHADER)
|
7342 | void 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)
|
7355 | layout (depth_greater) out float gl_FragDepth;
|
7356 | #endif
|
7357 | #endif
|
7358 | out vec4 fragColor;
|
7359 |
|
7360 | vec4 FLWBlockTexture(vec2 texCoords) {
|
7361 | return texture(uBlockAtlas, texCoords);
|
7362 | }
|
7363 |
|
7364 | void 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 |
|
7380 | vec4 FLWLight(vec2 lightCoords) {
|
7381 | return texture(uLightMap, shiftLight(lightCoords));
|
7382 | }
|
7383 | #endif
|
7384 |
|
7385 |
|
7386 | #define PIOVER2 1.5707963268
|
7387 |
|
7388 | vec4 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 |
|
7394 | vec4 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 |
|
7404 | vec3 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 |
|
7409 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
7410 | return rotateVertexByQuat(v, quat(axis, angle));
|
7411 | }
|
7412 |
|
7413 | float 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 | }
|
7417 | struct Vertex {
|
7418 | vec3 pos;
|
7419 | vec2 texCoords;
|
7420 | vec3 normal;
|
7421 | };
|
7422 |
|
7423 | struct BlockFrag {
|
7424 | vec2 texCoords;
|
7425 | vec4 color;
|
7426 | float diffuse;
|
7427 | vec2 light;
|
7428 | };
|
7429 |
|
7430 | #if defined(FRAGMENT_SHADER)
|
7431 | void 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 |
|
7445 | struct Oriented {
|
7446 | vec2 light;
|
7447 | vec4 color;
|
7448 | vec3 pos;
|
7449 | vec3 pivot;
|
7450 | vec4 rotation;
|
7451 | };
|
7452 |
|
7453 | #if defined(VERTEX_SHADER)
|
7454 | BlockFrag 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 |
|
7475 | in vec2 v2f_texCoords;
|
7476 | in vec4 v2f_color;
|
7477 | in float v2f_diffuse;
|
7478 | in vec2 v2f_light;
|
7479 | void main() {
|
7480 | BlockFrag o;
|
7481 | o.texCoords = v2f_texCoords;
|
7482 | o.color = v2f_color;
|
7483 | o.diffuse = v2f_diffuse;
|
7484 | o.light = v2f_light;
|
7485 | fragment(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)
|
7494 | out float FragDistance;
|
7495 | #elif defined(FRAGMENT_SHADER)
|
7496 | in float FragDistance;
|
7497 | #endif
|
7498 | uniform vec4 uFogColor;
|
7499 | uniform vec2 uFogRange;
|
7500 |
|
7501 | float 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 |
|
7507 | float cylindrical_distance(vec3 worldPos) {
|
7508 | float distXZ = length(worldPos.xz);
|
7509 | float distY = abs(worldPos.y);
|
7510 | return max(distXZ, distY);
|
7511 | }
|
7512 |
|
7513 | float 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
|
7517 | vec2 shiftLight(vec2 lm) {
|
7518 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
7519 | }
|
7520 |
|
7521 |
|
7522 | uniform float uTime;
|
7523 | uniform mat4 uViewProjection;
|
7524 | uniform vec3 uCameraPos;
|
7525 |
|
7526 | uniform vec2 uTextureScale;
|
7527 | uniform sampler2D uBlockAtlas;
|
7528 | uniform sampler2D uLightMap;
|
7529 |
|
7530 | uniform vec2 uWindowSize;
|
7531 |
|
7532 | void FLWFinalizeNormal(inout vec3 normal) {
|
7533 | // noop
|
7534 | }
|
7535 |
|
7536 | #if defined(VERTEX_SHADER)
|
7537 | void 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)
|
7550 | layout (depth_greater) out float gl_FragDepth;
|
7551 | #endif
|
7552 | #endif
|
7553 | out vec4 fragColor;
|
7554 |
|
7555 | vec4 FLWBlockTexture(vec2 texCoords) {
|
7556 | return texture(uBlockAtlas, texCoords);
|
7557 | }
|
7558 |
|
7559 | void 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 |
|
7575 | vec4 FLWLight(vec2 lightCoords) {
|
7576 | return texture(uLightMap, shiftLight(lightCoords));
|
7577 | }
|
7578 | #endif
|
7579 |
|
7580 |
|
7581 | #define PIOVER2 1.5707963268
|
7582 |
|
7583 | vec4 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 |
|
7589 | vec4 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 |
|
7599 | vec3 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 |
|
7604 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
7605 | return rotateVertexByQuat(v, quat(axis, angle));
|
7606 | }
|
7607 |
|
7608 | float 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 | }
|
7612 | struct Vertex {
|
7613 | vec3 pos;
|
7614 | vec2 texCoords;
|
7615 | vec3 normal;
|
7616 | };
|
7617 |
|
7618 | struct BlockFrag {
|
7619 | vec2 texCoords;
|
7620 | vec4 color;
|
7621 | float diffuse;
|
7622 | vec2 light;
|
7623 | };
|
7624 |
|
7625 | #if defined(FRAGMENT_SHADER)
|
7626 | void 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 |
|
7640 | struct Oriented {
|
7641 | vec2 light;
|
7642 | vec4 color;
|
7643 | vec3 pos;
|
7644 | vec3 pivot;
|
7645 | vec4 rotation;
|
7646 | };
|
7647 |
|
7648 | #if defined(VERTEX_SHADER)
|
7649 | BlockFrag 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 |
|
7670 | in vec3 a_v_pos;
|
7671 | in vec2 a_v_texCoords;
|
7672 | in vec3 a_v_normal;
|
7673 | in vec2 a_i_light;
|
7674 | in vec4 a_i_color;
|
7675 | in vec3 a_i_pos;
|
7676 | in vec3 a_i_pivot;
|
7677 | in vec4 a_i_rotation;
|
7678 | out vec2 v2f_texCoords;
|
7679 | out vec4 v2f_color;
|
7680 | out float v2f_diffuse;
|
7681 | out vec2 v2f_light;
|
7682 | void main() {
|
7683 | Vertex v;
|
7684 | v.pos = a_v_pos;
|
7685 | v.texCoords = a_v_texCoords;
|
7686 | v.normal = a_v_normal;
|
7687 | Oriented i;
|
7688 | i.light = a_i_light;
|
7689 | i.color = a_i_color;
|
7690 | i.pos = a_i_pos;
|
7691 | i.pivot = a_i_pivot;
|
7692 | i.rotation = a_i_rotation;
|
7693 | BlockFrag o = vertex(v, i);
|
7694 | v2f_texCoords = o.texCoords;
|
7695 | v2f_color = o.color;
|
7696 | v2f_diffuse = o.diffuse;
|
7697 | v2f_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)
|
7706 | out float FragDistance;
|
7707 | #elif defined(FRAGMENT_SHADER)
|
7708 | in float FragDistance;
|
7709 | #endif
|
7710 | uniform vec4 uFogColor;
|
7711 | uniform vec2 uFogRange;
|
7712 |
|
7713 | float 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 |
|
7719 | float cylindrical_distance(vec3 worldPos) {
|
7720 | float distXZ = length(worldPos.xz);
|
7721 | float distY = abs(worldPos.y);
|
7722 | return max(distXZ, distY);
|
7723 | }
|
7724 |
|
7725 | float 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
|
7729 | vec2 shiftLight(vec2 lm) {
|
7730 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
7731 | }
|
7732 |
|
7733 |
|
7734 | uniform float uTime;
|
7735 | uniform mat4 uViewProjection;
|
7736 | uniform vec3 uCameraPos;
|
7737 |
|
7738 | uniform vec2 uTextureScale;
|
7739 | uniform sampler2D uBlockAtlas;
|
7740 | uniform sampler2D uLightMap;
|
7741 |
|
7742 | uniform vec2 uWindowSize;
|
7743 |
|
7744 | void FLWFinalizeNormal(inout vec3 normal) {
|
7745 | // noop
|
7746 | }
|
7747 |
|
7748 | #if defined(VERTEX_SHADER)
|
7749 | void 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)
|
7762 | layout (depth_greater) out float gl_FragDepth;
|
7763 | #endif
|
7764 | #endif
|
7765 | out vec4 fragColor;
|
7766 |
|
7767 | vec4 FLWBlockTexture(vec2 texCoords) {
|
7768 | return texture(uBlockAtlas, texCoords);
|
7769 | }
|
7770 |
|
7771 | void 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 |
|
7787 | vec4 FLWLight(vec2 lightCoords) {
|
7788 | return texture(uLightMap, shiftLight(lightCoords));
|
7789 | }
|
7790 | #endif
|
7791 |
|
7792 |
|
7793 | #define PIOVER2 1.5707963268
|
7794 |
|
7795 | vec4 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 |
|
7801 | vec4 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 |
|
7811 | vec3 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 |
|
7816 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
7817 | return rotateVertexByQuat(v, quat(axis, angle));
|
7818 | }
|
7819 |
|
7820 | float 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 | }
|
7824 | struct Vertex {
|
7825 | vec3 pos;
|
7826 | vec2 texCoords;
|
7827 | vec3 normal;
|
7828 | };
|
7829 |
|
7830 | struct BlockFrag {
|
7831 | vec2 texCoords;
|
7832 | vec4 color;
|
7833 | float diffuse;
|
7834 | vec2 light;
|
7835 | };
|
7836 |
|
7837 | #if defined(FRAGMENT_SHADER)
|
7838 | void 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 |
|
7852 | struct Oriented {
|
7853 | vec2 light;
|
7854 | vec4 color;
|
7855 | vec3 pos;
|
7856 | vec3 pivot;
|
7857 | vec4 rotation;
|
7858 | };
|
7859 |
|
7860 | #if defined(VERTEX_SHADER)
|
7861 | BlockFrag 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 |
|
7882 | in vec2 v2f_texCoords;
|
7883 | in vec4 v2f_color;
|
7884 | in float v2f_diffuse;
|
7885 | in vec2 v2f_light;
|
7886 | void main() {
|
7887 | BlockFrag o;
|
7888 | o.texCoords = v2f_texCoords;
|
7889 | o.color = v2f_color;
|
7890 | o.diffuse = v2f_diffuse;
|
7891 | o.light = v2f_light;
|
7892 | fragment(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)
|
7900 | out float FragDistance;
|
7901 | #elif defined(FRAGMENT_SHADER)
|
7902 | in float FragDistance;
|
7903 | #endif
|
7904 | uniform vec4 uFogColor;
|
7905 | uniform vec2 uFogRange;
|
7906 |
|
7907 | float 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 |
|
7913 | float cylindrical_distance(vec3 worldPos) {
|
7914 | float distXZ = length(worldPos.xz);
|
7915 | float distY = abs(worldPos.y);
|
7916 | return max(distXZ, distY);
|
7917 | }
|
7918 |
|
7919 | float 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
|
7923 | vec2 shiftLight(vec2 lm) {
|
7924 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
7925 | }
|
7926 |
|
7927 |
|
7928 | uniform float uTime;
|
7929 | uniform mat4 uViewProjection;
|
7930 | uniform vec3 uCameraPos;
|
7931 |
|
7932 | uniform vec2 uTextureScale;
|
7933 | uniform sampler2D uBlockAtlas;
|
7934 | uniform sampler2D uLightMap;
|
7935 |
|
7936 | uniform vec2 uWindowSize;
|
7937 |
|
7938 | void FLWFinalizeNormal(inout vec3 normal) {
|
7939 | // noop
|
7940 | }
|
7941 |
|
7942 | #if defined(VERTEX_SHADER)
|
7943 | void 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)
|
7956 | layout (depth_greater) out float gl_FragDepth;
|
7957 | #endif
|
7958 | #endif
|
7959 | out vec4 fragColor;
|
7960 |
|
7961 | vec4 FLWBlockTexture(vec2 texCoords) {
|
7962 | return texture(uBlockAtlas, texCoords);
|
7963 | }
|
7964 |
|
7965 | void 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 |
|
7981 | vec4 FLWLight(vec2 lightCoords) {
|
7982 | return texture(uLightMap, shiftLight(lightCoords));
|
7983 | }
|
7984 | #endif
|
7985 |
|
7986 |
|
7987 | mat4 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 |
|
8002 | mat4 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 |
|
8006 | mat3 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 |
|
8016 | float 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 | }
|
8020 | struct Vertex {
|
8021 | vec3 pos;
|
8022 | vec2 texCoords;
|
8023 | vec3 normal;
|
8024 | };
|
8025 |
|
8026 | struct BlockFrag {
|
8027 | vec2 texCoords;
|
8028 | vec4 color;
|
8029 | float diffuse;
|
8030 | vec2 light;
|
8031 | };
|
8032 |
|
8033 | #if defined(FRAGMENT_SHADER)
|
8034 | void 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 |
|
8047 | struct Rotating {
|
8048 | vec2 light;
|
8049 | vec4 color;
|
8050 | vec3 pos;
|
8051 | float speed;
|
8052 | float offset;
|
8053 | vec3 axis;
|
8054 | };
|
8055 |
|
8056 |
|
8057 |
|
8058 |
|
8059 | mat4 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)
|
8067 | BlockFrag 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 |
|
8095 | in vec3 a_v_pos;
|
8096 | in vec2 a_v_texCoords;
|
8097 | in vec3 a_v_normal;
|
8098 | in vec2 a_i_light;
|
8099 | in vec4 a_i_color;
|
8100 | in vec3 a_i_pos;
|
8101 | in float a_i_speed;
|
8102 | in float a_i_offset;
|
8103 | in vec3 a_i_axis;
|
8104 | out vec2 v2f_texCoords;
|
8105 | out vec4 v2f_color;
|
8106 | out float v2f_diffuse;
|
8107 | out vec2 v2f_light;
|
8108 | void main() {
|
8109 | Vertex v;
|
8110 | v.pos = a_v_pos;
|
8111 | v.texCoords = a_v_texCoords;
|
8112 | v.normal = a_v_normal;
|
8113 | Rotating i;
|
8114 | i.light = a_i_light;
|
8115 | i.color = a_i_color;
|
8116 | i.pos = a_i_pos;
|
8117 | i.speed = a_i_speed;
|
8118 | i.offset = a_i_offset;
|
8119 | i.axis = a_i_axis;
|
8120 | BlockFrag o = vertex(v, i);
|
8121 | v2f_texCoords = o.texCoords;
|
8122 | v2f_color = o.color;
|
8123 | v2f_diffuse = o.diffuse;
|
8124 | v2f_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)
|
8132 | out float FragDistance;
|
8133 | #elif defined(FRAGMENT_SHADER)
|
8134 | in float FragDistance;
|
8135 | #endif
|
8136 | uniform vec4 uFogColor;
|
8137 | uniform vec2 uFogRange;
|
8138 |
|
8139 | float 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 |
|
8145 | float cylindrical_distance(vec3 worldPos) {
|
8146 | float distXZ = length(worldPos.xz);
|
8147 | float distY = abs(worldPos.y);
|
8148 | return max(distXZ, distY);
|
8149 | }
|
8150 |
|
8151 | float 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
|
8155 | vec2 shiftLight(vec2 lm) {
|
8156 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
8157 | }
|
8158 |
|
8159 |
|
8160 | uniform float uTime;
|
8161 | uniform mat4 uViewProjection;
|
8162 | uniform vec3 uCameraPos;
|
8163 |
|
8164 | uniform vec2 uTextureScale;
|
8165 | uniform sampler2D uBlockAtlas;
|
8166 | uniform sampler2D uLightMap;
|
8167 |
|
8168 | uniform vec2 uWindowSize;
|
8169 |
|
8170 | void FLWFinalizeNormal(inout vec3 normal) {
|
8171 | // noop
|
8172 | }
|
8173 |
|
8174 | #if defined(VERTEX_SHADER)
|
8175 | void 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)
|
8188 | layout (depth_greater) out float gl_FragDepth;
|
8189 | #endif
|
8190 | #endif
|
8191 | out vec4 fragColor;
|
8192 |
|
8193 | vec4 FLWBlockTexture(vec2 texCoords) {
|
8194 | return texture(uBlockAtlas, texCoords);
|
8195 | }
|
8196 |
|
8197 | void 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 |
|
8213 | vec4 FLWLight(vec2 lightCoords) {
|
8214 | return texture(uLightMap, shiftLight(lightCoords));
|
8215 | }
|
8216 | #endif
|
8217 |
|
8218 |
|
8219 | mat4 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 |
|
8234 | mat4 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 |
|
8238 | mat3 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 |
|
8248 | float 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 | }
|
8252 | struct Vertex {
|
8253 | vec3 pos;
|
8254 | vec2 texCoords;
|
8255 | vec3 normal;
|
8256 | };
|
8257 |
|
8258 | struct BlockFrag {
|
8259 | vec2 texCoords;
|
8260 | vec4 color;
|
8261 | float diffuse;
|
8262 | vec2 light;
|
8263 | };
|
8264 |
|
8265 | #if defined(FRAGMENT_SHADER)
|
8266 | void 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 |
|
8279 | struct Rotating {
|
8280 | vec2 light;
|
8281 | vec4 color;
|
8282 | vec3 pos;
|
8283 | float speed;
|
8284 | float offset;
|
8285 | vec3 axis;
|
8286 | };
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 | mat4 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)
|
8299 | BlockFrag 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 |
|
8327 | in vec2 v2f_texCoords;
|
8328 | in vec4 v2f_color;
|
8329 | in float v2f_diffuse;
|
8330 | in vec2 v2f_light;
|
8331 | void main() {
|
8332 | BlockFrag o;
|
8333 | o.texCoords = v2f_texCoords;
|
8334 | o.color = v2f_color;
|
8335 | o.diffuse = v2f_diffuse;
|
8336 | o.light = v2f_light;
|
8337 | fragment(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)
|
8346 | out float FragDistance;
|
8347 | #elif defined(FRAGMENT_SHADER)
|
8348 | in float FragDistance;
|
8349 | #endif
|
8350 | uniform vec4 uFogColor;
|
8351 | uniform vec2 uFogRange;
|
8352 |
|
8353 | float 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 |
|
8359 | float cylindrical_distance(vec3 worldPos) {
|
8360 | float distXZ = length(worldPos.xz);
|
8361 | float distY = abs(worldPos.y);
|
8362 | return max(distXZ, distY);
|
8363 | }
|
8364 |
|
8365 | float 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
|
8369 | vec2 shiftLight(vec2 lm) {
|
8370 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
8371 | }
|
8372 |
|
8373 |
|
8374 | uniform float uTime;
|
8375 | uniform mat4 uViewProjection;
|
8376 | uniform vec3 uCameraPos;
|
8377 |
|
8378 | uniform vec2 uTextureScale;
|
8379 | uniform sampler2D uBlockAtlas;
|
8380 | uniform sampler2D uLightMap;
|
8381 |
|
8382 | uniform vec2 uWindowSize;
|
8383 |
|
8384 | void FLWFinalizeNormal(inout vec3 normal) {
|
8385 | // noop
|
8386 | }
|
8387 |
|
8388 | #if defined(VERTEX_SHADER)
|
8389 | void 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)
|
8402 | layout (depth_greater) out float gl_FragDepth;
|
8403 | #endif
|
8404 | #endif
|
8405 | out vec4 fragColor;
|
8406 |
|
8407 | vec4 FLWBlockTexture(vec2 texCoords) {
|
8408 | return texture(uBlockAtlas, texCoords);
|
8409 | }
|
8410 |
|
8411 | void 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 |
|
8427 | vec4 FLWLight(vec2 lightCoords) {
|
8428 | return texture(uLightMap, shiftLight(lightCoords));
|
8429 | }
|
8430 | #endif
|
8431 |
|
8432 |
|
8433 | mat4 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 |
|
8448 | mat4 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 |
|
8452 | mat3 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 |
|
8462 | float 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 | }
|
8466 | struct Vertex {
|
8467 | vec3 pos;
|
8468 | vec2 texCoords;
|
8469 | vec3 normal;
|
8470 | };
|
8471 |
|
8472 | struct BlockFrag {
|
8473 | vec2 texCoords;
|
8474 | vec4 color;
|
8475 | float diffuse;
|
8476 | vec2 light;
|
8477 | };
|
8478 |
|
8479 | #if defined(FRAGMENT_SHADER)
|
8480 | void 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 |
|
8493 | struct Rotating {
|
8494 | vec2 light;
|
8495 | vec4 color;
|
8496 | vec3 pos;
|
8497 | float speed;
|
8498 | float offset;
|
8499 | vec3 axis;
|
8500 | };
|
8501 |
|
8502 |
|
8503 |
|
8504 |
|
8505 | mat4 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)
|
8513 | BlockFrag 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 |
|
8541 | in vec3 a_v_pos;
|
8542 | in vec2 a_v_texCoords;
|
8543 | in vec3 a_v_normal;
|
8544 | in vec2 a_i_light;
|
8545 | in vec4 a_i_color;
|
8546 | in vec3 a_i_pos;
|
8547 | in float a_i_speed;
|
8548 | in float a_i_offset;
|
8549 | in vec3 a_i_axis;
|
8550 | out vec2 v2f_texCoords;
|
8551 | out vec4 v2f_color;
|
8552 | out float v2f_diffuse;
|
8553 | out vec2 v2f_light;
|
8554 | void main() {
|
8555 | Vertex v;
|
8556 | v.pos = a_v_pos;
|
8557 | v.texCoords = a_v_texCoords;
|
8558 | v.normal = a_v_normal;
|
8559 | Rotating i;
|
8560 | i.light = a_i_light;
|
8561 | i.color = a_i_color;
|
8562 | i.pos = a_i_pos;
|
8563 | i.speed = a_i_speed;
|
8564 | i.offset = a_i_offset;
|
8565 | i.axis = a_i_axis;
|
8566 | BlockFrag o = vertex(v, i);
|
8567 | v2f_texCoords = o.texCoords;
|
8568 | v2f_color = o.color;
|
8569 | v2f_diffuse = o.diffuse;
|
8570 | v2f_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)
|
8579 | out float FragDistance;
|
8580 | #elif defined(FRAGMENT_SHADER)
|
8581 | in float FragDistance;
|
8582 | #endif
|
8583 | uniform vec4 uFogColor;
|
8584 | uniform vec2 uFogRange;
|
8585 |
|
8586 | float 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 |
|
8592 | float cylindrical_distance(vec3 worldPos) {
|
8593 | float distXZ = length(worldPos.xz);
|
8594 | float distY = abs(worldPos.y);
|
8595 | return max(distXZ, distY);
|
8596 | }
|
8597 |
|
8598 | float 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
|
8602 | vec2 shiftLight(vec2 lm) {
|
8603 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
8604 | }
|
8605 |
|
8606 |
|
8607 | uniform float uTime;
|
8608 | uniform mat4 uViewProjection;
|
8609 | uniform vec3 uCameraPos;
|
8610 |
|
8611 | uniform vec2 uTextureScale;
|
8612 | uniform sampler2D uBlockAtlas;
|
8613 | uniform sampler2D uLightMap;
|
8614 |
|
8615 | uniform vec2 uWindowSize;
|
8616 |
|
8617 | void FLWFinalizeNormal(inout vec3 normal) {
|
8618 | // noop
|
8619 | }
|
8620 |
|
8621 | #if defined(VERTEX_SHADER)
|
8622 | void 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)
|
8635 | layout (depth_greater) out float gl_FragDepth;
|
8636 | #endif
|
8637 | #endif
|
8638 | out vec4 fragColor;
|
8639 |
|
8640 | vec4 FLWBlockTexture(vec2 texCoords) {
|
8641 | return texture(uBlockAtlas, texCoords);
|
8642 | }
|
8643 |
|
8644 | void 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 |
|
8660 | vec4 FLWLight(vec2 lightCoords) {
|
8661 | return texture(uLightMap, shiftLight(lightCoords));
|
8662 | }
|
8663 | #endif
|
8664 |
|
8665 |
|
8666 | mat4 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 |
|
8681 | mat4 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 |
|
8685 | mat3 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 |
|
8695 | float 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 | }
|
8699 | struct Vertex {
|
8700 | vec3 pos;
|
8701 | vec2 texCoords;
|
8702 | vec3 normal;
|
8703 | };
|
8704 |
|
8705 | struct BlockFrag {
|
8706 | vec2 texCoords;
|
8707 | vec4 color;
|
8708 | float diffuse;
|
8709 | vec2 light;
|
8710 | };
|
8711 |
|
8712 | #if defined(FRAGMENT_SHADER)
|
8713 | void 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 |
|
8726 | struct Rotating {
|
8727 | vec2 light;
|
8728 | vec4 color;
|
8729 | vec3 pos;
|
8730 | float speed;
|
8731 | float offset;
|
8732 | vec3 axis;
|
8733 | };
|
8734 |
|
8735 |
|
8736 |
|
8737 |
|
8738 | mat4 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)
|
8746 | BlockFrag 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 |
|
8774 | in vec2 v2f_texCoords;
|
8775 | in vec4 v2f_color;
|
8776 | in float v2f_diffuse;
|
8777 | in vec2 v2f_light;
|
8778 | void main() {
|
8779 | BlockFrag o;
|
8780 | o.texCoords = v2f_texCoords;
|
8781 | o.color = v2f_color;
|
8782 | o.diffuse = v2f_diffuse;
|
8783 | o.light = v2f_light;
|
8784 | fragment(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)
|
8793 | out float FragDistance;
|
8794 | #elif defined(FRAGMENT_SHADER)
|
8795 | in float FragDistance;
|
8796 | #endif
|
8797 | uniform vec4 uFogColor;
|
8798 | uniform vec2 uFogRange;
|
8799 |
|
8800 | float 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 |
|
8806 | float cylindrical_distance(vec3 worldPos) {
|
8807 | float distXZ = length(worldPos.xz);
|
8808 | float distY = abs(worldPos.y);
|
8809 | return max(distXZ, distY);
|
8810 | }
|
8811 |
|
8812 | float 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
|
8816 | vec2 shiftLight(vec2 lm) {
|
8817 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
8818 | }
|
8819 |
|
8820 |
|
8821 | uniform float uTime;
|
8822 | uniform mat4 uViewProjection;
|
8823 | uniform vec3 uCameraPos;
|
8824 |
|
8825 | uniform vec2 uTextureScale;
|
8826 | uniform sampler2D uBlockAtlas;
|
8827 | uniform sampler2D uLightMap;
|
8828 |
|
8829 | uniform vec2 uWindowSize;
|
8830 |
|
8831 | void FLWFinalizeNormal(inout vec3 normal) {
|
8832 | // noop
|
8833 | }
|
8834 |
|
8835 | #if defined(VERTEX_SHADER)
|
8836 | void 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)
|
8849 | layout (depth_greater) out float gl_FragDepth;
|
8850 | #endif
|
8851 | #endif
|
8852 | out vec4 fragColor;
|
8853 |
|
8854 | vec4 FLWBlockTexture(vec2 texCoords) {
|
8855 | return texture(uBlockAtlas, texCoords);
|
8856 | }
|
8857 |
|
8858 | void 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 |
|
8874 | vec4 FLWLight(vec2 lightCoords) {
|
8875 | return texture(uLightMap, shiftLight(lightCoords));
|
8876 | }
|
8877 | #endif
|
8878 |
|
8879 |
|
8880 | mat4 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 |
|
8895 | mat4 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 |
|
8899 | mat3 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 |
|
8909 | float 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 | }
|
8913 | struct Vertex {
|
8914 | vec3 pos;
|
8915 | vec2 texCoords;
|
8916 | vec3 normal;
|
8917 | };
|
8918 |
|
8919 | struct BlockFrag {
|
8920 | vec2 texCoords;
|
8921 | vec4 color;
|
8922 | float diffuse;
|
8923 | vec2 light;
|
8924 | };
|
8925 |
|
8926 | #if defined(FRAGMENT_SHADER)
|
8927 | void 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 |
|
8940 | struct Rotating {
|
8941 | vec2 light;
|
8942 | vec4 color;
|
8943 | vec3 pos;
|
8944 | float speed;
|
8945 | float offset;
|
8946 | vec3 axis;
|
8947 | };
|
8948 |
|
8949 |
|
8950 |
|
8951 |
|
8952 | mat4 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)
|
8960 | BlockFrag 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 |
|
8988 | in vec3 a_v_pos;
|
8989 | in vec2 a_v_texCoords;
|
8990 | in vec3 a_v_normal;
|
8991 | in vec2 a_i_light;
|
8992 | in vec4 a_i_color;
|
8993 | in vec3 a_i_pos;
|
8994 | in float a_i_speed;
|
8995 | in float a_i_offset;
|
8996 | in vec3 a_i_axis;
|
8997 | out vec2 v2f_texCoords;
|
8998 | out vec4 v2f_color;
|
8999 | out float v2f_diffuse;
|
9000 | out vec2 v2f_light;
|
9001 | void main() {
|
9002 | Vertex v;
|
9003 | v.pos = a_v_pos;
|
9004 | v.texCoords = a_v_texCoords;
|
9005 | v.normal = a_v_normal;
|
9006 | Rotating i;
|
9007 | i.light = a_i_light;
|
9008 | i.color = a_i_color;
|
9009 | i.pos = a_i_pos;
|
9010 | i.speed = a_i_speed;
|
9011 | i.offset = a_i_offset;
|
9012 | i.axis = a_i_axis;
|
9013 | BlockFrag o = vertex(v, i);
|
9014 | v2f_texCoords = o.texCoords;
|
9015 | v2f_color = o.color;
|
9016 | v2f_diffuse = o.diffuse;
|
9017 | v2f_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)
|
9026 | out float FragDistance;
|
9027 | #elif defined(FRAGMENT_SHADER)
|
9028 | in float FragDistance;
|
9029 | #endif
|
9030 | uniform vec4 uFogColor;
|
9031 | uniform vec2 uFogRange;
|
9032 |
|
9033 | float 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 |
|
9039 | float cylindrical_distance(vec3 worldPos) {
|
9040 | float distXZ = length(worldPos.xz);
|
9041 | float distY = abs(worldPos.y);
|
9042 | return max(distXZ, distY);
|
9043 | }
|
9044 |
|
9045 | float 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
|
9049 | vec2 shiftLight(vec2 lm) {
|
9050 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
9051 | }
|
9052 |
|
9053 |
|
9054 | uniform float uTime;
|
9055 | uniform mat4 uViewProjection;
|
9056 | uniform vec3 uCameraPos;
|
9057 |
|
9058 | uniform vec2 uTextureScale;
|
9059 | uniform sampler2D uBlockAtlas;
|
9060 | uniform sampler2D uLightMap;
|
9061 |
|
9062 | uniform vec2 uWindowSize;
|
9063 |
|
9064 | void FLWFinalizeNormal(inout vec3 normal) {
|
9065 | // noop
|
9066 | }
|
9067 |
|
9068 | #if defined(VERTEX_SHADER)
|
9069 | void 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)
|
9082 | layout (depth_greater) out float gl_FragDepth;
|
9083 | #endif
|
9084 | #endif
|
9085 | out vec4 fragColor;
|
9086 |
|
9087 | vec4 FLWBlockTexture(vec2 texCoords) {
|
9088 | return texture(uBlockAtlas, texCoords);
|
9089 | }
|
9090 |
|
9091 | void 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 |
|
9107 | vec4 FLWLight(vec2 lightCoords) {
|
9108 | return texture(uLightMap, shiftLight(lightCoords));
|
9109 | }
|
9110 | #endif
|
9111 |
|
9112 |
|
9113 | mat4 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 |
|
9128 | mat4 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 |
|
9132 | mat3 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 |
|
9142 | float 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 | }
|
9146 | struct Vertex {
|
9147 | vec3 pos;
|
9148 | vec2 texCoords;
|
9149 | vec3 normal;
|
9150 | };
|
9151 |
|
9152 | struct BlockFrag {
|
9153 | vec2 texCoords;
|
9154 | vec4 color;
|
9155 | float diffuse;
|
9156 | vec2 light;
|
9157 | };
|
9158 |
|
9159 | #if defined(FRAGMENT_SHADER)
|
9160 | void 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 |
|
9173 | struct Rotating {
|
9174 | vec2 light;
|
9175 | vec4 color;
|
9176 | vec3 pos;
|
9177 | float speed;
|
9178 | float offset;
|
9179 | vec3 axis;
|
9180 | };
|
9181 |
|
9182 |
|
9183 |
|
9184 |
|
9185 | mat4 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)
|
9193 | BlockFrag 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 |
|
9221 | in vec2 v2f_texCoords;
|
9222 | in vec4 v2f_color;
|
9223 | in float v2f_diffuse;
|
9224 | in vec2 v2f_light;
|
9225 | void main() {
|
9226 | BlockFrag o;
|
9227 | o.texCoords = v2f_texCoords;
|
9228 | o.color = v2f_color;
|
9229 | o.diffuse = v2f_diffuse;
|
9230 | o.light = v2f_light;
|
9231 | fragment(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)
|
9239 | out float FragDistance;
|
9240 | #elif defined(FRAGMENT_SHADER)
|
9241 | in float FragDistance;
|
9242 | #endif
|
9243 | uniform vec4 uFogColor;
|
9244 | uniform vec2 uFogRange;
|
9245 |
|
9246 | float 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 |
|
9252 | float cylindrical_distance(vec3 worldPos) {
|
9253 | float distXZ = length(worldPos.xz);
|
9254 | float distY = abs(worldPos.y);
|
9255 | return max(distXZ, distY);
|
9256 | }
|
9257 |
|
9258 | float 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
|
9262 | vec2 shiftLight(vec2 lm) {
|
9263 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
9264 | }
|
9265 |
|
9266 |
|
9267 | uniform float uTime;
|
9268 | uniform mat4 uViewProjection;
|
9269 | uniform vec3 uCameraPos;
|
9270 |
|
9271 | uniform vec2 uTextureScale;
|
9272 | uniform sampler2D uBlockAtlas;
|
9273 | uniform sampler2D uLightMap;
|
9274 |
|
9275 | uniform vec2 uWindowSize;
|
9276 |
|
9277 | void FLWFinalizeNormal(inout vec3 normal) {
|
9278 | // noop
|
9279 | }
|
9280 |
|
9281 | #if defined(VERTEX_SHADER)
|
9282 | void 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)
|
9295 | layout (depth_greater) out float gl_FragDepth;
|
9296 | #endif
|
9297 | #endif
|
9298 | out vec4 fragColor;
|
9299 |
|
9300 | vec4 FLWBlockTexture(vec2 texCoords) {
|
9301 | return texture(uBlockAtlas, texCoords);
|
9302 | }
|
9303 |
|
9304 | void 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 |
|
9320 | vec4 FLWLight(vec2 lightCoords) {
|
9321 | return texture(uLightMap, shiftLight(lightCoords));
|
9322 | }
|
9323 | #endif
|
9324 |
|
9325 |
|
9326 | mat4 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 |
|
9341 | mat4 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 |
|
9345 | mat3 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 |
|
9357 | vec4 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 |
|
9363 | vec4 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 |
|
9373 | vec3 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 |
|
9378 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
9379 | return rotateVertexByQuat(v, quat(axis, angle));
|
9380 | }
|
9381 |
|
9382 | float 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 | }
|
9386 | struct Vertex {
|
9387 | vec3 pos;
|
9388 | vec2 texCoords;
|
9389 | vec3 normal;
|
9390 | };
|
9391 |
|
9392 | struct BlockFrag {
|
9393 | vec2 texCoords;
|
9394 | vec4 color;
|
9395 | float diffuse;
|
9396 | vec2 light;
|
9397 | };
|
9398 |
|
9399 | #if defined(FRAGMENT_SHADER)
|
9400 | void 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 |
|
9414 | struct 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)
|
9428 | BlockFrag 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 |
|
9456 | in vec3 a_v_pos;
|
9457 | in vec2 a_v_texCoords;
|
9458 | in vec3 a_v_normal;
|
9459 | in vec3 a_i_pos;
|
9460 | in vec2 a_i_light;
|
9461 | in float a_i_offset;
|
9462 | in vec3 a_i_axis;
|
9463 | in vec4 a_i_rotation;
|
9464 | in vec3 a_i_rotationCenter;
|
9465 | in float a_i_speed;
|
9466 | out vec2 v2f_texCoords;
|
9467 | out vec4 v2f_color;
|
9468 | out float v2f_diffuse;
|
9469 | out vec2 v2f_light;
|
9470 | void main() {
|
9471 | Vertex v;
|
9472 | v.pos = a_v_pos;
|
9473 | v.texCoords = a_v_texCoords;
|
9474 | v.normal = a_v_normal;
|
9475 | Actor i;
|
9476 | i.pos = a_i_pos;
|
9477 | i.light = a_i_light;
|
9478 | i.offset = a_i_offset;
|
9479 | i.axis = a_i_axis;
|
9480 | i.rotation = a_i_rotation;
|
9481 | i.rotationCenter = a_i_rotationCenter;
|
9482 | i.speed = a_i_speed;
|
9483 | BlockFrag o = vertex(v, i);
|
9484 | v2f_texCoords = o.texCoords;
|
9485 | v2f_color = o.color;
|
9486 | v2f_diffuse = o.diffuse;
|
9487 | v2f_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)
|
9495 | out float FragDistance;
|
9496 | #elif defined(FRAGMENT_SHADER)
|
9497 | in float FragDistance;
|
9498 | #endif
|
9499 | uniform vec4 uFogColor;
|
9500 | uniform vec2 uFogRange;
|
9501 |
|
9502 | float 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 |
|
9508 | float cylindrical_distance(vec3 worldPos) {
|
9509 | float distXZ = length(worldPos.xz);
|
9510 | float distY = abs(worldPos.y);
|
9511 | return max(distXZ, distY);
|
9512 | }
|
9513 |
|
9514 | float 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
|
9518 | vec2 shiftLight(vec2 lm) {
|
9519 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
9520 | }
|
9521 |
|
9522 |
|
9523 | uniform float uTime;
|
9524 | uniform mat4 uViewProjection;
|
9525 | uniform vec3 uCameraPos;
|
9526 |
|
9527 | uniform vec2 uTextureScale;
|
9528 | uniform sampler2D uBlockAtlas;
|
9529 | uniform sampler2D uLightMap;
|
9530 |
|
9531 | uniform vec2 uWindowSize;
|
9532 |
|
9533 | void FLWFinalizeNormal(inout vec3 normal) {
|
9534 | // noop
|
9535 | }
|
9536 |
|
9537 | #if defined(VERTEX_SHADER)
|
9538 | void 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)
|
9551 | layout (depth_greater) out float gl_FragDepth;
|
9552 | #endif
|
9553 | #endif
|
9554 | out vec4 fragColor;
|
9555 |
|
9556 | vec4 FLWBlockTexture(vec2 texCoords) {
|
9557 | return texture(uBlockAtlas, texCoords);
|
9558 | }
|
9559 |
|
9560 | void 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 |
|
9576 | vec4 FLWLight(vec2 lightCoords) {
|
9577 | return texture(uLightMap, shiftLight(lightCoords));
|
9578 | }
|
9579 | #endif
|
9580 |
|
9581 |
|
9582 | mat4 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 |
|
9597 | mat4 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 |
|
9601 | mat3 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 |
|
9613 | vec4 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 |
|
9619 | vec4 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 |
|
9629 | vec3 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 |
|
9634 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
9635 | return rotateVertexByQuat(v, quat(axis, angle));
|
9636 | }
|
9637 |
|
9638 | float 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 | }
|
9642 | struct Vertex {
|
9643 | vec3 pos;
|
9644 | vec2 texCoords;
|
9645 | vec3 normal;
|
9646 | };
|
9647 |
|
9648 | struct BlockFrag {
|
9649 | vec2 texCoords;
|
9650 | vec4 color;
|
9651 | float diffuse;
|
9652 | vec2 light;
|
9653 | };
|
9654 |
|
9655 | #if defined(FRAGMENT_SHADER)
|
9656 | void 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 |
|
9670 | struct 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)
|
9684 | BlockFrag 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 |
|
9712 | in vec2 v2f_texCoords;
|
9713 | in vec4 v2f_color;
|
9714 | in float v2f_diffuse;
|
9715 | in vec2 v2f_light;
|
9716 | void main() {
|
9717 | BlockFrag o;
|
9718 | o.texCoords = v2f_texCoords;
|
9719 | o.color = v2f_color;
|
9720 | o.diffuse = v2f_diffuse;
|
9721 | o.light = v2f_light;
|
9722 | fragment(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)
|
9731 | out float FragDistance;
|
9732 | #elif defined(FRAGMENT_SHADER)
|
9733 | in float FragDistance;
|
9734 | #endif
|
9735 | uniform vec4 uFogColor;
|
9736 | uniform vec2 uFogRange;
|
9737 |
|
9738 | float 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 |
|
9744 | float cylindrical_distance(vec3 worldPos) {
|
9745 | float distXZ = length(worldPos.xz);
|
9746 | float distY = abs(worldPos.y);
|
9747 | return max(distXZ, distY);
|
9748 | }
|
9749 |
|
9750 | float 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
|
9754 | vec2 shiftLight(vec2 lm) {
|
9755 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
9756 | }
|
9757 |
|
9758 |
|
9759 | uniform float uTime;
|
9760 | uniform mat4 uViewProjection;
|
9761 | uniform vec3 uCameraPos;
|
9762 |
|
9763 | uniform vec2 uTextureScale;
|
9764 | uniform sampler2D uBlockAtlas;
|
9765 | uniform sampler2D uLightMap;
|
9766 |
|
9767 | uniform vec2 uWindowSize;
|
9768 |
|
9769 | void FLWFinalizeNormal(inout vec3 normal) {
|
9770 | // noop
|
9771 | }
|
9772 |
|
9773 | #if defined(VERTEX_SHADER)
|
9774 | void 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)
|
9787 | layout (depth_greater) out float gl_FragDepth;
|
9788 | #endif
|
9789 | #endif
|
9790 | out vec4 fragColor;
|
9791 |
|
9792 | vec4 FLWBlockTexture(vec2 texCoords) {
|
9793 | return texture(uBlockAtlas, texCoords);
|
9794 | }
|
9795 |
|
9796 | void 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 |
|
9812 | vec4 FLWLight(vec2 lightCoords) {
|
9813 | return texture(uLightMap, shiftLight(lightCoords));
|
9814 | }
|
9815 | #endif
|
9816 |
|
9817 |
|
9818 | mat4 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 |
|
9833 | mat4 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 |
|
9837 | mat3 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 |
|
9849 | vec4 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 |
|
9855 | vec4 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 |
|
9865 | vec3 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 |
|
9870 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
9871 | return rotateVertexByQuat(v, quat(axis, angle));
|
9872 | }
|
9873 |
|
9874 | float 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 | }
|
9878 | struct Vertex {
|
9879 | vec3 pos;
|
9880 | vec2 texCoords;
|
9881 | vec3 normal;
|
9882 | };
|
9883 |
|
9884 | struct BlockFrag {
|
9885 | vec2 texCoords;
|
9886 | vec4 color;
|
9887 | float diffuse;
|
9888 | vec2 light;
|
9889 | };
|
9890 |
|
9891 | #if defined(FRAGMENT_SHADER)
|
9892 | void 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 |
|
9906 | struct 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)
|
9920 | BlockFrag 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 |
|
9948 | in vec3 a_v_pos;
|
9949 | in vec2 a_v_texCoords;
|
9950 | in vec3 a_v_normal;
|
9951 | in vec3 a_i_pos;
|
9952 | in vec2 a_i_light;
|
9953 | in float a_i_offset;
|
9954 | in vec3 a_i_axis;
|
9955 | in vec4 a_i_rotation;
|
9956 | in vec3 a_i_rotationCenter;
|
9957 | in float a_i_speed;
|
9958 | out vec2 v2f_texCoords;
|
9959 | out vec4 v2f_color;
|
9960 | out float v2f_diffuse;
|
9961 | out vec2 v2f_light;
|
9962 | void main() {
|
9963 | Vertex v;
|
9964 | v.pos = a_v_pos;
|
9965 | v.texCoords = a_v_texCoords;
|
9966 | v.normal = a_v_normal;
|
9967 | Actor i;
|
9968 | i.pos = a_i_pos;
|
9969 | i.light = a_i_light;
|
9970 | i.offset = a_i_offset;
|
9971 | i.axis = a_i_axis;
|
9972 | i.rotation = a_i_rotation;
|
9973 | i.rotationCenter = a_i_rotationCenter;
|
9974 | i.speed = a_i_speed;
|
9975 | BlockFrag o = vertex(v, i);
|
9976 | v2f_texCoords = o.texCoords;
|
9977 | v2f_color = o.color;
|
9978 | v2f_diffuse = o.diffuse;
|
9979 | v2f_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)
|
9988 | out float FragDistance;
|
9989 | #elif defined(FRAGMENT_SHADER)
|
9990 | in float FragDistance;
|
9991 | #endif
|
9992 | uniform vec4 uFogColor;
|
9993 | uniform vec2 uFogRange;
|
9994 |
|
9995 | float 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 |
|
10001 | float cylindrical_distance(vec3 worldPos) {
|
10002 | float distXZ = length(worldPos.xz);
|
10003 | float distY = abs(worldPos.y);
|
10004 | return max(distXZ, distY);
|
10005 | }
|
10006 |
|
10007 | float 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
|
10011 | vec2 shiftLight(vec2 lm) {
|
10012 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
10013 | }
|
10014 |
|
10015 |
|
10016 | uniform float uTime;
|
10017 | uniform mat4 uViewProjection;
|
10018 | uniform vec3 uCameraPos;
|
10019 |
|
10020 | uniform vec2 uTextureScale;
|
10021 | uniform sampler2D uBlockAtlas;
|
10022 | uniform sampler2D uLightMap;
|
10023 |
|
10024 | uniform vec2 uWindowSize;
|
10025 |
|
10026 | void FLWFinalizeNormal(inout vec3 normal) {
|
10027 | // noop
|
10028 | }
|
10029 |
|
10030 | #if defined(VERTEX_SHADER)
|
10031 | void 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)
|
10044 | layout (depth_greater) out float gl_FragDepth;
|
10045 | #endif
|
10046 | #endif
|
10047 | out vec4 fragColor;
|
10048 |
|
10049 | vec4 FLWBlockTexture(vec2 texCoords) {
|
10050 | return texture(uBlockAtlas, texCoords);
|
10051 | }
|
10052 |
|
10053 | void 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 |
|
10069 | vec4 FLWLight(vec2 lightCoords) {
|
10070 | return texture(uLightMap, shiftLight(lightCoords));
|
10071 | }
|
10072 | #endif
|
10073 |
|
10074 |
|
10075 | mat4 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 |
|
10090 | mat4 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 |
|
10094 | mat3 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 |
|
10106 | vec4 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 |
|
10112 | vec4 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 |
|
10122 | vec3 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 |
|
10127 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
10128 | return rotateVertexByQuat(v, quat(axis, angle));
|
10129 | }
|
10130 |
|
10131 | float 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 | }
|
10135 | struct Vertex {
|
10136 | vec3 pos;
|
10137 | vec2 texCoords;
|
10138 | vec3 normal;
|
10139 | };
|
10140 |
|
10141 | struct BlockFrag {
|
10142 | vec2 texCoords;
|
10143 | vec4 color;
|
10144 | float diffuse;
|
10145 | vec2 light;
|
10146 | };
|
10147 |
|
10148 | #if defined(FRAGMENT_SHADER)
|
10149 | void 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 |
|
10163 | struct 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)
|
10177 | BlockFrag 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 |
|
10205 | in vec2 v2f_texCoords;
|
10206 | in vec4 v2f_color;
|
10207 | in float v2f_diffuse;
|
10208 | in vec2 v2f_light;
|
10209 | void main() {
|
10210 | BlockFrag o;
|
10211 | o.texCoords = v2f_texCoords;
|
10212 | o.color = v2f_color;
|
10213 | o.diffuse = v2f_diffuse;
|
10214 | o.light = v2f_light;
|
10215 | fragment(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)
|
10223 | out float FragDistance;
|
10224 | #elif defined(FRAGMENT_SHADER)
|
10225 | in float FragDistance;
|
10226 | #endif
|
10227 | uniform vec4 uFogColor;
|
10228 | uniform vec2 uFogRange;
|
10229 |
|
10230 | float 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 |
|
10236 | float cylindrical_distance(vec3 worldPos) {
|
10237 | float distXZ = length(worldPos.xz);
|
10238 | float distY = abs(worldPos.y);
|
10239 | return max(distXZ, distY);
|
10240 | }
|
10241 |
|
10242 | float 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
|
10246 | vec2 shiftLight(vec2 lm) {
|
10247 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
10248 | }
|
10249 |
|
10250 |
|
10251 | uniform float uTime;
|
10252 | uniform mat4 uViewProjection;
|
10253 | uniform vec3 uCameraPos;
|
10254 |
|
10255 | uniform vec2 uTextureScale;
|
10256 | uniform sampler2D uBlockAtlas;
|
10257 | uniform sampler2D uLightMap;
|
10258 |
|
10259 | uniform vec2 uWindowSize;
|
10260 |
|
10261 | void FLWFinalizeNormal(inout vec3 normal) {
|
10262 | // noop
|
10263 | }
|
10264 |
|
10265 | #if defined(VERTEX_SHADER)
|
10266 | void 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)
|
10279 | layout (depth_greater) out float gl_FragDepth;
|
10280 | #endif
|
10281 | #endif
|
10282 | out vec4 fragColor;
|
10283 |
|
10284 | vec4 FLWBlockTexture(vec2 texCoords) {
|
10285 | return texture(uBlockAtlas, texCoords);
|
10286 | }
|
10287 |
|
10288 | void 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 |
|
10304 | vec4 FLWLight(vec2 lightCoords) {
|
10305 | return texture(uLightMap, shiftLight(lightCoords));
|
10306 | }
|
10307 | #endif
|
10308 |
|
10309 |
|
10310 | mat4 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 |
|
10325 | mat4 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 |
|
10329 | mat3 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 |
|
10341 | vec4 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 |
|
10347 | vec4 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 |
|
10357 | vec3 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 |
|
10362 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
10363 | return rotateVertexByQuat(v, quat(axis, angle));
|
10364 | }
|
10365 |
|
10366 | float 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 | }
|
10370 | struct Vertex {
|
10371 | vec3 pos;
|
10372 | vec2 texCoords;
|
10373 | vec3 normal;
|
10374 | };
|
10375 |
|
10376 | struct BlockFrag {
|
10377 | vec2 texCoords;
|
10378 | vec4 color;
|
10379 | float diffuse;
|
10380 | vec2 light;
|
10381 | };
|
10382 |
|
10383 | #if defined(FRAGMENT_SHADER)
|
10384 | void 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 |
|
10398 | struct 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 |
|
10414 | float toRad(float degrees) {
|
10415 | return fract(degrees / 360.) * PI * 2.;
|
10416 | }
|
10417 |
|
10418 | float 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 |
|
10431 | BlockFrag 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 |
|
10459 | in vec3 a_v_pos;
|
10460 | in vec2 a_v_texCoords;
|
10461 | in vec3 a_v_normal;
|
10462 | in vec3 a_i_instancePos;
|
10463 | in vec2 a_i_light;
|
10464 | in vec3 a_i_segmentOffset;
|
10465 | in vec3 a_i_pivot;
|
10466 | in float a_i_horizontalAngle;
|
10467 | in float a_i_intensity;
|
10468 | in float a_i_flapScale;
|
10469 | in float a_i_flapness;
|
10470 | out vec2 v2f_texCoords;
|
10471 | out vec4 v2f_color;
|
10472 | out float v2f_diffuse;
|
10473 | out vec2 v2f_light;
|
10474 | void main() {
|
10475 | Vertex v;
|
10476 | v.pos = a_v_pos;
|
10477 | v.texCoords = a_v_texCoords;
|
10478 | v.normal = a_v_normal;
|
10479 | Flap i;
|
10480 | i.instancePos = a_i_instancePos;
|
10481 | i.light = a_i_light;
|
10482 | i.segmentOffset = a_i_segmentOffset;
|
10483 | i.pivot = a_i_pivot;
|
10484 | i.horizontalAngle = a_i_horizontalAngle;
|
10485 | i.intensity = a_i_intensity;
|
10486 | i.flapScale = a_i_flapScale;
|
10487 | i.flapness = a_i_flapness;
|
10488 | BlockFrag o = vertex(v, i);
|
10489 | v2f_texCoords = o.texCoords;
|
10490 | v2f_color = o.color;
|
10491 | v2f_diffuse = o.diffuse;
|
10492 | v2f_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)
|
10500 | out float FragDistance;
|
10501 | #elif defined(FRAGMENT_SHADER)
|
10502 | in float FragDistance;
|
10503 | #endif
|
10504 | uniform vec4 uFogColor;
|
10505 | uniform vec2 uFogRange;
|
10506 |
|
10507 | float 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 |
|
10513 | float cylindrical_distance(vec3 worldPos) {
|
10514 | float distXZ = length(worldPos.xz);
|
10515 | float distY = abs(worldPos.y);
|
10516 | return max(distXZ, distY);
|
10517 | }
|
10518 |
|
10519 | float 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
|
10523 | vec2 shiftLight(vec2 lm) {
|
10524 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
10525 | }
|
10526 |
|
10527 |
|
10528 | uniform float uTime;
|
10529 | uniform mat4 uViewProjection;
|
10530 | uniform vec3 uCameraPos;
|
10531 |
|
10532 | uniform vec2 uTextureScale;
|
10533 | uniform sampler2D uBlockAtlas;
|
10534 | uniform sampler2D uLightMap;
|
10535 |
|
10536 | uniform vec2 uWindowSize;
|
10537 |
|
10538 | void FLWFinalizeNormal(inout vec3 normal) {
|
10539 | // noop
|
10540 | }
|
10541 |
|
10542 | #if defined(VERTEX_SHADER)
|
10543 | void 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)
|
10556 | layout (depth_greater) out float gl_FragDepth;
|
10557 | #endif
|
10558 | #endif
|
10559 | out vec4 fragColor;
|
10560 |
|
10561 | vec4 FLWBlockTexture(vec2 texCoords) {
|
10562 | return texture(uBlockAtlas, texCoords);
|
10563 | }
|
10564 |
|
10565 | void 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 |
|
10581 | vec4 FLWLight(vec2 lightCoords) {
|
10582 | return texture(uLightMap, shiftLight(lightCoords));
|
10583 | }
|
10584 | #endif
|
10585 |
|
10586 |
|
10587 | mat4 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 |
|
10602 | mat4 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 |
|
10606 | mat3 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 |
|
10618 | vec4 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 |
|
10624 | vec4 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 |
|
10634 | vec3 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 |
|
10639 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
10640 | return rotateVertexByQuat(v, quat(axis, angle));
|
10641 | }
|
10642 |
|
10643 | float 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 | }
|
10647 | struct Vertex {
|
10648 | vec3 pos;
|
10649 | vec2 texCoords;
|
10650 | vec3 normal;
|
10651 | };
|
10652 |
|
10653 | struct BlockFrag {
|
10654 | vec2 texCoords;
|
10655 | vec4 color;
|
10656 | float diffuse;
|
10657 | vec2 light;
|
10658 | };
|
10659 |
|
10660 | #if defined(FRAGMENT_SHADER)
|
10661 | void 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 |
|
10675 | struct 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 |
|
10691 | float toRad(float degrees) {
|
10692 | return fract(degrees / 360.) * PI * 2.;
|
10693 | }
|
10694 |
|
10695 | float 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 |
|
10708 | BlockFrag 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 |
|
10736 | in vec2 v2f_texCoords;
|
10737 | in vec4 v2f_color;
|
10738 | in float v2f_diffuse;
|
10739 | in vec2 v2f_light;
|
10740 | void main() {
|
10741 | BlockFrag o;
|
10742 | o.texCoords = v2f_texCoords;
|
10743 | o.color = v2f_color;
|
10744 | o.diffuse = v2f_diffuse;
|
10745 | o.light = v2f_light;
|
10746 | fragment(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)
|
10755 | out float FragDistance;
|
10756 | #elif defined(FRAGMENT_SHADER)
|
10757 | in float FragDistance;
|
10758 | #endif
|
10759 | uniform vec4 uFogColor;
|
10760 | uniform vec2 uFogRange;
|
10761 |
|
10762 | float 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 |
|
10768 | float cylindrical_distance(vec3 worldPos) {
|
10769 | float distXZ = length(worldPos.xz);
|
10770 | float distY = abs(worldPos.y);
|
10771 | return max(distXZ, distY);
|
10772 | }
|
10773 |
|
10774 | float 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
|
10778 | vec2 shiftLight(vec2 lm) {
|
10779 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
10780 | }
|
10781 |
|
10782 |
|
10783 | uniform float uTime;
|
10784 | uniform mat4 uViewProjection;
|
10785 | uniform vec3 uCameraPos;
|
10786 |
|
10787 | uniform vec2 uTextureScale;
|
10788 | uniform sampler2D uBlockAtlas;
|
10789 | uniform sampler2D uLightMap;
|
10790 |
|
10791 | uniform vec2 uWindowSize;
|
10792 |
|
10793 | void FLWFinalizeNormal(inout vec3 normal) {
|
10794 | // noop
|
10795 | }
|
10796 |
|
10797 | #if defined(VERTEX_SHADER)
|
10798 | void 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)
|
10811 | layout (depth_greater) out float gl_FragDepth;
|
10812 | #endif
|
10813 | #endif
|
10814 | out vec4 fragColor;
|
10815 |
|
10816 | vec4 FLWBlockTexture(vec2 texCoords) {
|
10817 | return texture(uBlockAtlas, texCoords);
|
10818 | }
|
10819 |
|
10820 | void 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 |
|
10836 | vec4 FLWLight(vec2 lightCoords) {
|
10837 | return texture(uLightMap, shiftLight(lightCoords));
|
10838 | }
|
10839 | #endif
|
10840 |
|
10841 |
|
10842 | mat4 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 |
|
10857 | mat4 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 |
|
10861 | mat3 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 |
|
10873 | vec4 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 |
|
10879 | vec4 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 |
|
10889 | vec3 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 |
|
10894 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
10895 | return rotateVertexByQuat(v, quat(axis, angle));
|
10896 | }
|
10897 |
|
10898 | float 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 | }
|
10902 | struct Vertex {
|
10903 | vec3 pos;
|
10904 | vec2 texCoords;
|
10905 | vec3 normal;
|
10906 | };
|
10907 |
|
10908 | struct BlockFrag {
|
10909 | vec2 texCoords;
|
10910 | vec4 color;
|
10911 | float diffuse;
|
10912 | vec2 light;
|
10913 | };
|
10914 |
|
10915 | #if defined(FRAGMENT_SHADER)
|
10916 | void 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 |
|
10930 | struct 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 |
|
10946 | float toRad(float degrees) {
|
10947 | return fract(degrees / 360.) * PI * 2.;
|
10948 | }
|
10949 |
|
10950 | float 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 |
|
10963 | BlockFrag 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 |
|
10991 | in vec3 a_v_pos;
|
10992 | in vec2 a_v_texCoords;
|
10993 | in vec3 a_v_normal;
|
10994 | in vec3 a_i_instancePos;
|
10995 | in vec2 a_i_light;
|
10996 | in vec3 a_i_segmentOffset;
|
10997 | in vec3 a_i_pivot;
|
10998 | in float a_i_horizontalAngle;
|
10999 | in float a_i_intensity;
|
11000 | in float a_i_flapScale;
|
11001 | in float a_i_flapness;
|
11002 | out vec2 v2f_texCoords;
|
11003 | out vec4 v2f_color;
|
11004 | out float v2f_diffuse;
|
11005 | out vec2 v2f_light;
|
11006 | void main() {
|
11007 | Vertex v;
|
11008 | v.pos = a_v_pos;
|
11009 | v.texCoords = a_v_texCoords;
|
11010 | v.normal = a_v_normal;
|
11011 | Flap i;
|
11012 | i.instancePos = a_i_instancePos;
|
11013 | i.light = a_i_light;
|
11014 | i.segmentOffset = a_i_segmentOffset;
|
11015 | i.pivot = a_i_pivot;
|
11016 | i.horizontalAngle = a_i_horizontalAngle;
|
11017 | i.intensity = a_i_intensity;
|
11018 | i.flapScale = a_i_flapScale;
|
11019 | i.flapness = a_i_flapness;
|
11020 | BlockFrag o = vertex(v, i);
|
11021 | v2f_texCoords = o.texCoords;
|
11022 | v2f_color = o.color;
|
11023 | v2f_diffuse = o.diffuse;
|
11024 | v2f_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)
|
11033 | out float FragDistance;
|
11034 | #elif defined(FRAGMENT_SHADER)
|
11035 | in float FragDistance;
|
11036 | #endif
|
11037 | uniform vec4 uFogColor;
|
11038 | uniform vec2 uFogRange;
|
11039 |
|
11040 | float 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 |
|
11046 | float cylindrical_distance(vec3 worldPos) {
|
11047 | float distXZ = length(worldPos.xz);
|
11048 | float distY = abs(worldPos.y);
|
11049 | return max(distXZ, distY);
|
11050 | }
|
11051 |
|
11052 | float 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
|
11056 | vec2 shiftLight(vec2 lm) {
|
11057 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
11058 | }
|
11059 |
|
11060 |
|
11061 | uniform float uTime;
|
11062 | uniform mat4 uViewProjection;
|
11063 | uniform vec3 uCameraPos;
|
11064 |
|
11065 | uniform vec2 uTextureScale;
|
11066 | uniform sampler2D uBlockAtlas;
|
11067 | uniform sampler2D uLightMap;
|
11068 |
|
11069 | uniform vec2 uWindowSize;
|
11070 |
|
11071 | void FLWFinalizeNormal(inout vec3 normal) {
|
11072 | // noop
|
11073 | }
|
11074 |
|
11075 | #if defined(VERTEX_SHADER)
|
11076 | void 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)
|
11089 | layout (depth_greater) out float gl_FragDepth;
|
11090 | #endif
|
11091 | #endif
|
11092 | out vec4 fragColor;
|
11093 |
|
11094 | vec4 FLWBlockTexture(vec2 texCoords) {
|
11095 | return texture(uBlockAtlas, texCoords);
|
11096 | }
|
11097 |
|
11098 | void 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 |
|
11114 | vec4 FLWLight(vec2 lightCoords) {
|
11115 | return texture(uLightMap, shiftLight(lightCoords));
|
11116 | }
|
11117 | #endif
|
11118 |
|
11119 |
|
11120 | mat4 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 |
|
11135 | mat4 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 |
|
11139 | mat3 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 |
|
11151 | vec4 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 |
|
11157 | vec4 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 |
|
11167 | vec3 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 |
|
11172 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
11173 | return rotateVertexByQuat(v, quat(axis, angle));
|
11174 | }
|
11175 |
|
11176 | float 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 | }
|
11180 | struct Vertex {
|
11181 | vec3 pos;
|
11182 | vec2 texCoords;
|
11183 | vec3 normal;
|
11184 | };
|
11185 |
|
11186 | struct BlockFrag {
|
11187 | vec2 texCoords;
|
11188 | vec4 color;
|
11189 | float diffuse;
|
11190 | vec2 light;
|
11191 | };
|
11192 |
|
11193 | #if defined(FRAGMENT_SHADER)
|
11194 | void 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 |
|
11208 | struct 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 |
|
11224 | float toRad(float degrees) {
|
11225 | return fract(degrees / 360.) * PI * 2.;
|
11226 | }
|
11227 |
|
11228 | float 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 |
|
11241 | BlockFrag 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 |
|
11269 | in vec2 v2f_texCoords;
|
11270 | in vec4 v2f_color;
|
11271 | in float v2f_diffuse;
|
11272 | in vec2 v2f_light;
|
11273 | void main() {
|
11274 | BlockFrag o;
|
11275 | o.texCoords = v2f_texCoords;
|
11276 | o.color = v2f_color;
|
11277 | o.diffuse = v2f_diffuse;
|
11278 | o.light = v2f_light;
|
11279 | fragment(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)
|
11287 | out float FragDistance;
|
11288 | #elif defined(FRAGMENT_SHADER)
|
11289 | in float FragDistance;
|
11290 | #endif
|
11291 | uniform vec4 uFogColor;
|
11292 | uniform vec2 uFogRange;
|
11293 |
|
11294 | float 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 |
|
11300 | float cylindrical_distance(vec3 worldPos) {
|
11301 | float distXZ = length(worldPos.xz);
|
11302 | float distY = abs(worldPos.y);
|
11303 | return max(distXZ, distY);
|
11304 | }
|
11305 |
|
11306 | float 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
|
11310 | vec2 shiftLight(vec2 lm) {
|
11311 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
11312 | }
|
11313 |
|
11314 |
|
11315 | uniform float uTime;
|
11316 | uniform mat4 uViewProjection;
|
11317 | uniform vec3 uCameraPos;
|
11318 |
|
11319 | uniform vec2 uTextureScale;
|
11320 | uniform sampler2D uBlockAtlas;
|
11321 | uniform sampler2D uLightMap;
|
11322 |
|
11323 | uniform vec2 uWindowSize;
|
11324 |
|
11325 | void FLWFinalizeNormal(inout vec3 normal) {
|
11326 | // noop
|
11327 | }
|
11328 |
|
11329 | #if defined(VERTEX_SHADER)
|
11330 | void 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)
|
11343 | layout (depth_greater) out float gl_FragDepth;
|
11344 | #endif
|
11345 | #endif
|
11346 | out vec4 fragColor;
|
11347 |
|
11348 | vec4 FLWBlockTexture(vec2 texCoords) {
|
11349 | return texture(uBlockAtlas, texCoords);
|
11350 | }
|
11351 |
|
11352 | void 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 |
|
11368 | vec4 FLWLight(vec2 lightCoords) {
|
11369 | return texture(uLightMap, shiftLight(lightCoords));
|
11370 | }
|
11371 | #endif
|
11372 |
|
11373 |
|
11374 | #define PIOVER2 1.5707963268
|
11375 |
|
11376 | vec4 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 |
|
11382 | vec4 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 |
|
11392 | vec3 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 |
|
11397 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
11398 | return rotateVertexByQuat(v, quat(axis, angle));
|
11399 | }
|
11400 |
|
11401 | mat4 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 |
|
11416 | mat4 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 |
|
11420 | mat3 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 |
|
11430 | float 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 | }
|
11434 | struct Vertex {
|
11435 | vec3 pos;
|
11436 | vec2 texCoords;
|
11437 | vec3 normal;
|
11438 | };
|
11439 |
|
11440 | struct BlockFrag {
|
11441 | vec2 texCoords;
|
11442 | vec4 color;
|
11443 | float diffuse;
|
11444 | vec2 light;
|
11445 | };
|
11446 |
|
11447 | #if defined(FRAGMENT_SHADER)
|
11448 | void 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 |
|
11462 | struct 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)
|
11478 | BlockFrag 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 |
|
11508 | in vec3 a_v_pos;
|
11509 | in vec2 a_v_texCoords;
|
11510 | in vec3 a_v_normal;
|
11511 | in vec2 a_i_light;
|
11512 | in vec4 a_i_color;
|
11513 | in vec3 a_i_pos;
|
11514 | in float a_i_speed;
|
11515 | in float a_i_offset;
|
11516 | in vec4 a_i_rotation;
|
11517 | in vec2 a_i_sourceTexture;
|
11518 | in vec4 a_i_scrollTexture;
|
11519 | in float a_i_scrollMult;
|
11520 | out vec2 v2f_texCoords;
|
11521 | out vec4 v2f_color;
|
11522 | out float v2f_diffuse;
|
11523 | out vec2 v2f_light;
|
11524 | void main() {
|
11525 | Vertex v;
|
11526 | v.pos = a_v_pos;
|
11527 | v.texCoords = a_v_texCoords;
|
11528 | v.normal = a_v_normal;
|
11529 | Belt i;
|
11530 | i.light = a_i_light;
|
11531 | i.color = a_i_color;
|
11532 | i.pos = a_i_pos;
|
11533 | i.speed = a_i_speed;
|
11534 | i.offset = a_i_offset;
|
11535 | i.rotation = a_i_rotation;
|
11536 | i.sourceTexture = a_i_sourceTexture;
|
11537 | i.scrollTexture = a_i_scrollTexture;
|
11538 | i.scrollMult = a_i_scrollMult;
|
11539 | BlockFrag o = vertex(v, i);
|
11540 | v2f_texCoords = o.texCoords;
|
11541 | v2f_color = o.color;
|
11542 | v2f_diffuse = o.diffuse;
|
11543 | v2f_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)
|
11551 | out float FragDistance;
|
11552 | #elif defined(FRAGMENT_SHADER)
|
11553 | in float FragDistance;
|
11554 | #endif
|
11555 | uniform vec4 uFogColor;
|
11556 | uniform vec2 uFogRange;
|
11557 |
|
11558 | float 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 |
|
11564 | float cylindrical_distance(vec3 worldPos) {
|
11565 | float distXZ = length(worldPos.xz);
|
11566 | float distY = abs(worldPos.y);
|
11567 | return max(distXZ, distY);
|
11568 | }
|
11569 |
|
11570 | float 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
|
11574 | vec2 shiftLight(vec2 lm) {
|
11575 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
11576 | }
|
11577 |
|
11578 |
|
11579 | uniform float uTime;
|
11580 | uniform mat4 uViewProjection;
|
11581 | uniform vec3 uCameraPos;
|
11582 |
|
11583 | uniform vec2 uTextureScale;
|
11584 | uniform sampler2D uBlockAtlas;
|
11585 | uniform sampler2D uLightMap;
|
11586 |
|
11587 | uniform vec2 uWindowSize;
|
11588 |
|
11589 | void FLWFinalizeNormal(inout vec3 normal) {
|
11590 | // noop
|
11591 | }
|
11592 |
|
11593 | #if defined(VERTEX_SHADER)
|
11594 | void 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)
|
11607 | layout (depth_greater) out float gl_FragDepth;
|
11608 | #endif
|
11609 | #endif
|
11610 | out vec4 fragColor;
|
11611 |
|
11612 | vec4 FLWBlockTexture(vec2 texCoords) {
|
11613 | return texture(uBlockAtlas, texCoords);
|
11614 | }
|
11615 |
|
11616 | void 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 |
|
11632 | vec4 FLWLight(vec2 lightCoords) {
|
11633 | return texture(uLightMap, shiftLight(lightCoords));
|
11634 | }
|
11635 | #endif
|
11636 |
|
11637 |
|
11638 | #define PIOVER2 1.5707963268
|
11639 |
|
11640 | vec4 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 |
|
11646 | vec4 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 |
|
11656 | vec3 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 |
|
11661 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
11662 | return rotateVertexByQuat(v, quat(axis, angle));
|
11663 | }
|
11664 |
|
11665 | mat4 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 |
|
11680 | mat4 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 |
|
11684 | mat3 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 |
|
11694 | float 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 | }
|
11698 | struct Vertex {
|
11699 | vec3 pos;
|
11700 | vec2 texCoords;
|
11701 | vec3 normal;
|
11702 | };
|
11703 |
|
11704 | struct BlockFrag {
|
11705 | vec2 texCoords;
|
11706 | vec4 color;
|
11707 | float diffuse;
|
11708 | vec2 light;
|
11709 | };
|
11710 |
|
11711 | #if defined(FRAGMENT_SHADER)
|
11712 | void 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 |
|
11726 | struct 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)
|
11742 | BlockFrag 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 |
|
11772 | in vec2 v2f_texCoords;
|
11773 | in vec4 v2f_color;
|
11774 | in float v2f_diffuse;
|
11775 | in vec2 v2f_light;
|
11776 | void main() {
|
11777 | BlockFrag o;
|
11778 | o.texCoords = v2f_texCoords;
|
11779 | o.color = v2f_color;
|
11780 | o.diffuse = v2f_diffuse;
|
11781 | o.light = v2f_light;
|
11782 | fragment(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)
|
11791 | out float FragDistance;
|
11792 | #elif defined(FRAGMENT_SHADER)
|
11793 | in float FragDistance;
|
11794 | #endif
|
11795 | uniform vec4 uFogColor;
|
11796 | uniform vec2 uFogRange;
|
11797 |
|
11798 | float 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 |
|
11804 | float cylindrical_distance(vec3 worldPos) {
|
11805 | float distXZ = length(worldPos.xz);
|
11806 | float distY = abs(worldPos.y);
|
11807 | return max(distXZ, distY);
|
11808 | }
|
11809 |
|
11810 | float 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
|
11814 | vec2 shiftLight(vec2 lm) {
|
11815 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
11816 | }
|
11817 |
|
11818 |
|
11819 | uniform float uTime;
|
11820 | uniform mat4 uViewProjection;
|
11821 | uniform vec3 uCameraPos;
|
11822 |
|
11823 | uniform vec2 uTextureScale;
|
11824 | uniform sampler2D uBlockAtlas;
|
11825 | uniform sampler2D uLightMap;
|
11826 |
|
11827 | uniform vec2 uWindowSize;
|
11828 |
|
11829 | void FLWFinalizeNormal(inout vec3 normal) {
|
11830 | // noop
|
11831 | }
|
11832 |
|
11833 | #if defined(VERTEX_SHADER)
|
11834 | void 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)
|
11847 | layout (depth_greater) out float gl_FragDepth;
|
11848 | #endif
|
11849 | #endif
|
11850 | out vec4 fragColor;
|
11851 |
|
11852 | vec4 FLWBlockTexture(vec2 texCoords) {
|
11853 | return texture(uBlockAtlas, texCoords);
|
11854 | }
|
11855 |
|
11856 | void 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 |
|
11872 | vec4 FLWLight(vec2 lightCoords) {
|
11873 | return texture(uLightMap, shiftLight(lightCoords));
|
11874 | }
|
11875 | #endif
|
11876 |
|
11877 |
|
11878 | #define PIOVER2 1.5707963268
|
11879 |
|
11880 | vec4 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 |
|
11886 | vec4 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 |
|
11896 | vec3 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 |
|
11901 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
11902 | return rotateVertexByQuat(v, quat(axis, angle));
|
11903 | }
|
11904 |
|
11905 | mat4 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 |
|
11920 | mat4 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 |
|
11924 | mat3 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 |
|
11934 | float 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 | }
|
11938 | struct Vertex {
|
11939 | vec3 pos;
|
11940 | vec2 texCoords;
|
11941 | vec3 normal;
|
11942 | };
|
11943 |
|
11944 | struct BlockFrag {
|
11945 | vec2 texCoords;
|
11946 | vec4 color;
|
11947 | float diffuse;
|
11948 | vec2 light;
|
11949 | };
|
11950 |
|
11951 | #if defined(FRAGMENT_SHADER)
|
11952 | void 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 |
|
11966 | struct 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)
|
11982 | BlockFrag 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 |
|
12012 | in vec3 a_v_pos;
|
12013 | in vec2 a_v_texCoords;
|
12014 | in vec3 a_v_normal;
|
12015 | in vec2 a_i_light;
|
12016 | in vec4 a_i_color;
|
12017 | in vec3 a_i_pos;
|
12018 | in float a_i_speed;
|
12019 | in float a_i_offset;
|
12020 | in vec4 a_i_rotation;
|
12021 | in vec2 a_i_sourceTexture;
|
12022 | in vec4 a_i_scrollTexture;
|
12023 | in float a_i_scrollMult;
|
12024 | out vec2 v2f_texCoords;
|
12025 | out vec4 v2f_color;
|
12026 | out float v2f_diffuse;
|
12027 | out vec2 v2f_light;
|
12028 | void main() {
|
12029 | Vertex v;
|
12030 | v.pos = a_v_pos;
|
12031 | v.texCoords = a_v_texCoords;
|
12032 | v.normal = a_v_normal;
|
12033 | Belt i;
|
12034 | i.light = a_i_light;
|
12035 | i.color = a_i_color;
|
12036 | i.pos = a_i_pos;
|
12037 | i.speed = a_i_speed;
|
12038 | i.offset = a_i_offset;
|
12039 | i.rotation = a_i_rotation;
|
12040 | i.sourceTexture = a_i_sourceTexture;
|
12041 | i.scrollTexture = a_i_scrollTexture;
|
12042 | i.scrollMult = a_i_scrollMult;
|
12043 | BlockFrag o = vertex(v, i);
|
12044 | v2f_texCoords = o.texCoords;
|
12045 | v2f_color = o.color;
|
12046 | v2f_diffuse = o.diffuse;
|
12047 | v2f_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)
|
12056 | out float FragDistance;
|
12057 | #elif defined(FRAGMENT_SHADER)
|
12058 | in float FragDistance;
|
12059 | #endif
|
12060 | uniform vec4 uFogColor;
|
12061 | uniform vec2 uFogRange;
|
12062 |
|
12063 | float 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 |
|
12069 | float cylindrical_distance(vec3 worldPos) {
|
12070 | float distXZ = length(worldPos.xz);
|
12071 | float distY = abs(worldPos.y);
|
12072 | return max(distXZ, distY);
|
12073 | }
|
12074 |
|
12075 | float 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
|
12079 | vec2 shiftLight(vec2 lm) {
|
12080 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
12081 | }
|
12082 |
|
12083 |
|
12084 | uniform float uTime;
|
12085 | uniform mat4 uViewProjection;
|
12086 | uniform vec3 uCameraPos;
|
12087 |
|
12088 | uniform vec2 uTextureScale;
|
12089 | uniform sampler2D uBlockAtlas;
|
12090 | uniform sampler2D uLightMap;
|
12091 |
|
12092 | uniform vec2 uWindowSize;
|
12093 |
|
12094 | void FLWFinalizeNormal(inout vec3 normal) {
|
12095 | // noop
|
12096 | }
|
12097 |
|
12098 | #if defined(VERTEX_SHADER)
|
12099 | void 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)
|
12112 | layout (depth_greater) out float gl_FragDepth;
|
12113 | #endif
|
12114 | #endif
|
12115 | out vec4 fragColor;
|
12116 |
|
12117 | vec4 FLWBlockTexture(vec2 texCoords) {
|
12118 | return texture(uBlockAtlas, texCoords);
|
12119 | }
|
12120 |
|
12121 | void 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 |
|
12137 | vec4 FLWLight(vec2 lightCoords) {
|
12138 | return texture(uLightMap, shiftLight(lightCoords));
|
12139 | }
|
12140 | #endif
|
12141 |
|
12142 |
|
12143 | #define PIOVER2 1.5707963268
|
12144 |
|
12145 | vec4 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 |
|
12151 | vec4 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 |
|
12161 | vec3 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 |
|
12166 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
12167 | return rotateVertexByQuat(v, quat(axis, angle));
|
12168 | }
|
12169 |
|
12170 | mat4 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 |
|
12185 | mat4 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 |
|
12189 | mat3 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 |
|
12199 | float 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 | }
|
12203 | struct Vertex {
|
12204 | vec3 pos;
|
12205 | vec2 texCoords;
|
12206 | vec3 normal;
|
12207 | };
|
12208 |
|
12209 | struct BlockFrag {
|
12210 | vec2 texCoords;
|
12211 | vec4 color;
|
12212 | float diffuse;
|
12213 | vec2 light;
|
12214 | };
|
12215 |
|
12216 | #if defined(FRAGMENT_SHADER)
|
12217 | void 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 |
|
12231 | struct 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)
|
12247 | BlockFrag 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 |
|
12277 | in vec2 v2f_texCoords;
|
12278 | in vec4 v2f_color;
|
12279 | in float v2f_diffuse;
|
12280 | in vec2 v2f_light;
|
12281 | void main() {
|
12282 | BlockFrag o;
|
12283 | o.texCoords = v2f_texCoords;
|
12284 | o.color = v2f_color;
|
12285 | o.diffuse = v2f_diffuse;
|
12286 | o.light = v2f_light;
|
12287 | fragment(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)
|
12296 | out float FragDistance;
|
12297 | #elif defined(FRAGMENT_SHADER)
|
12298 | in float FragDistance;
|
12299 | #endif
|
12300 | uniform vec4 uFogColor;
|
12301 | uniform vec2 uFogRange;
|
12302 |
|
12303 | float 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 |
|
12309 | float cylindrical_distance(vec3 worldPos) {
|
12310 | float distXZ = length(worldPos.xz);
|
12311 | float distY = abs(worldPos.y);
|
12312 | return max(distXZ, distY);
|
12313 | }
|
12314 |
|
12315 | float 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
|
12319 | vec2 shiftLight(vec2 lm) {
|
12320 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
12321 | }
|
12322 |
|
12323 |
|
12324 | uniform float uTime;
|
12325 | uniform mat4 uViewProjection;
|
12326 | uniform vec3 uCameraPos;
|
12327 |
|
12328 | uniform vec2 uTextureScale;
|
12329 | uniform sampler2D uBlockAtlas;
|
12330 | uniform sampler2D uLightMap;
|
12331 |
|
12332 | uniform vec2 uWindowSize;
|
12333 |
|
12334 | void FLWFinalizeNormal(inout vec3 normal) {
|
12335 | // noop
|
12336 | }
|
12337 |
|
12338 | #if defined(VERTEX_SHADER)
|
12339 | void 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)
|
12352 | layout (depth_greater) out float gl_FragDepth;
|
12353 | #endif
|
12354 | #endif
|
12355 | out vec4 fragColor;
|
12356 |
|
12357 | vec4 FLWBlockTexture(vec2 texCoords) {
|
12358 | return texture(uBlockAtlas, texCoords);
|
12359 | }
|
12360 |
|
12361 | void 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 |
|
12377 | vec4 FLWLight(vec2 lightCoords) {
|
12378 | return texture(uLightMap, shiftLight(lightCoords));
|
12379 | }
|
12380 | #endif
|
12381 |
|
12382 |
|
12383 | #define PIOVER2 1.5707963268
|
12384 |
|
12385 | vec4 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 |
|
12391 | vec4 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 |
|
12401 | vec3 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 |
|
12406 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
12407 | return rotateVertexByQuat(v, quat(axis, angle));
|
12408 | }
|
12409 |
|
12410 | mat4 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 |
|
12425 | mat4 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 |
|
12429 | mat3 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 |
|
12439 | float 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 | }
|
12443 | struct Vertex {
|
12444 | vec3 pos;
|
12445 | vec2 texCoords;
|
12446 | vec3 normal;
|
12447 | };
|
12448 |
|
12449 | struct BlockFrag {
|
12450 | vec2 texCoords;
|
12451 | vec4 color;
|
12452 | float diffuse;
|
12453 | vec2 light;
|
12454 | };
|
12455 |
|
12456 | #if defined(FRAGMENT_SHADER)
|
12457 | void 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 |
|
12471 | struct 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)
|
12487 | BlockFrag 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 |
|
12517 | in vec3 a_v_pos;
|
12518 | in vec2 a_v_texCoords;
|
12519 | in vec3 a_v_normal;
|
12520 | in vec2 a_i_light;
|
12521 | in vec4 a_i_color;
|
12522 | in vec3 a_i_pos;
|
12523 | in float a_i_speed;
|
12524 | in float a_i_offset;
|
12525 | in vec4 a_i_rotation;
|
12526 | in vec2 a_i_sourceTexture;
|
12527 | in vec4 a_i_scrollTexture;
|
12528 | in float a_i_scrollMult;
|
12529 | out vec2 v2f_texCoords;
|
12530 | out vec4 v2f_color;
|
12531 | out float v2f_diffuse;
|
12532 | out vec2 v2f_light;
|
12533 | void main() {
|
12534 | Vertex v;
|
12535 | v.pos = a_v_pos;
|
12536 | v.texCoords = a_v_texCoords;
|
12537 | v.normal = a_v_normal;
|
12538 | Belt i;
|
12539 | i.light = a_i_light;
|
12540 | i.color = a_i_color;
|
12541 | i.pos = a_i_pos;
|
12542 | i.speed = a_i_speed;
|
12543 | i.offset = a_i_offset;
|
12544 | i.rotation = a_i_rotation;
|
12545 | i.sourceTexture = a_i_sourceTexture;
|
12546 | i.scrollTexture = a_i_scrollTexture;
|
12547 | i.scrollMult = a_i_scrollMult;
|
12548 | BlockFrag o = vertex(v, i);
|
12549 | v2f_texCoords = o.texCoords;
|
12550 | v2f_color = o.color;
|
12551 | v2f_diffuse = o.diffuse;
|
12552 | v2f_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)
|
12561 | out float FragDistance;
|
12562 | #elif defined(FRAGMENT_SHADER)
|
12563 | in float FragDistance;
|
12564 | #endif
|
12565 | uniform vec4 uFogColor;
|
12566 | uniform vec2 uFogRange;
|
12567 |
|
12568 | float 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 |
|
12574 | float cylindrical_distance(vec3 worldPos) {
|
12575 | float distXZ = length(worldPos.xz);
|
12576 | float distY = abs(worldPos.y);
|
12577 | return max(distXZ, distY);
|
12578 | }
|
12579 |
|
12580 | float 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
|
12584 | vec2 shiftLight(vec2 lm) {
|
12585 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
12586 | }
|
12587 |
|
12588 |
|
12589 | uniform float uTime;
|
12590 | uniform mat4 uViewProjection;
|
12591 | uniform vec3 uCameraPos;
|
12592 |
|
12593 | uniform vec2 uTextureScale;
|
12594 | uniform sampler2D uBlockAtlas;
|
12595 | uniform sampler2D uLightMap;
|
12596 |
|
12597 | uniform vec2 uWindowSize;
|
12598 |
|
12599 | void FLWFinalizeNormal(inout vec3 normal) {
|
12600 | // noop
|
12601 | }
|
12602 |
|
12603 | #if defined(VERTEX_SHADER)
|
12604 | void 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)
|
12617 | layout (depth_greater) out float gl_FragDepth;
|
12618 | #endif
|
12619 | #endif
|
12620 | out vec4 fragColor;
|
12621 |
|
12622 | vec4 FLWBlockTexture(vec2 texCoords) {
|
12623 | return texture(uBlockAtlas, texCoords);
|
12624 | }
|
12625 |
|
12626 | void 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 |
|
12642 | vec4 FLWLight(vec2 lightCoords) {
|
12643 | return texture(uLightMap, shiftLight(lightCoords));
|
12644 | }
|
12645 | #endif
|
12646 |
|
12647 |
|
12648 | #define PIOVER2 1.5707963268
|
12649 |
|
12650 | vec4 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 |
|
12656 | vec4 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 |
|
12666 | vec3 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 |
|
12671 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
12672 | return rotateVertexByQuat(v, quat(axis, angle));
|
12673 | }
|
12674 |
|
12675 | mat4 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 |
|
12690 | mat4 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 |
|
12694 | mat3 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 |
|
12704 | float 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 | }
|
12708 | struct Vertex {
|
12709 | vec3 pos;
|
12710 | vec2 texCoords;
|
12711 | vec3 normal;
|
12712 | };
|
12713 |
|
12714 | struct BlockFrag {
|
12715 | vec2 texCoords;
|
12716 | vec4 color;
|
12717 | float diffuse;
|
12718 | vec2 light;
|
12719 | };
|
12720 |
|
12721 | #if defined(FRAGMENT_SHADER)
|
12722 | void 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 |
|
12736 | struct 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)
|
12752 | BlockFrag 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 |
|
12782 | in vec2 v2f_texCoords;
|
12783 | in vec4 v2f_color;
|
12784 | in float v2f_diffuse;
|
12785 | in vec2 v2f_light;
|
12786 | void main() {
|
12787 | BlockFrag o;
|
12788 | o.texCoords = v2f_texCoords;
|
12789 | o.color = v2f_color;
|
12790 | o.diffuse = v2f_diffuse;
|
12791 | o.light = v2f_light;
|
12792 | fragment(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)
|
12801 | out float FragDistance;
|
12802 | #elif defined(FRAGMENT_SHADER)
|
12803 | in float FragDistance;
|
12804 | #endif
|
12805 | uniform vec4 uFogColor;
|
12806 | uniform vec2 uFogRange;
|
12807 |
|
12808 | float 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 |
|
12814 | float cylindrical_distance(vec3 worldPos) {
|
12815 | float distXZ = length(worldPos.xz);
|
12816 | float distY = abs(worldPos.y);
|
12817 | return max(distXZ, distY);
|
12818 | }
|
12819 |
|
12820 | float 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
|
12824 | vec2 shiftLight(vec2 lm) {
|
12825 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
12826 | }
|
12827 |
|
12828 |
|
12829 | uniform sampler3D uLightVolume;
|
12830 |
|
12831 | uniform sampler2D uBlockAtlas;
|
12832 | uniform sampler2D uLightMap;
|
12833 |
|
12834 | uniform vec3 uLightBoxSize;
|
12835 | uniform vec3 uLightBoxMin;
|
12836 | uniform mat4 uModel;
|
12837 |
|
12838 | uniform float uTime;
|
12839 | uniform mat4 uViewProjection;
|
12840 | uniform vec3 uCameraPos;
|
12841 |
|
12842 | void 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 |
|
12852 | out vec3 BoxCoord;
|
12853 |
|
12854 | void 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)
|
12871 | layout (depth_greater) out float gl_FragDepth;
|
12872 | #endif
|
12873 | #endif
|
12874 |
|
12875 | in vec3 BoxCoord;
|
12876 |
|
12877 | out vec4 FragColor;
|
12878 |
|
12879 | vec4 FLWBlockTexture(vec2 texCoords) {
|
12880 | return texture(uBlockAtlas, texCoords);
|
12881 | }
|
12882 |
|
12883 | void 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 |
|
12899 | vec4 FLWLight(vec2 lightCoords) {
|
12900 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
12901 |
|
12902 | return texture(uLightMap, shiftLight(lightCoords));
|
12903 | }
|
12904 |
|
12905 | #endif
|
12906 |
|
12907 |
|
12908 | float 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 | }
|
12912 | struct Vertex {
|
12913 | vec3 pos;
|
12914 | vec2 texCoords;
|
12915 | vec3 normal;
|
12916 | };
|
12917 |
|
12918 | struct BlockFrag {
|
12919 | vec2 texCoords;
|
12920 | vec4 color;
|
12921 | float diffuse;
|
12922 | vec2 light;
|
12923 | };
|
12924 |
|
12925 | #if defined(FRAGMENT_SHADER)
|
12926 | void 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 |
|
12938 | struct Instance {
|
12939 | vec2 light;
|
12940 | vec4 color;
|
12941 | mat4 transform;
|
12942 | mat3 normalMat;
|
12943 | };
|
12944 |
|
12945 | #if defined(VERTEX_SHADER)
|
12946 | BlockFrag 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 |
|
12969 | in vec3 a_v_pos;
|
12970 | in vec2 a_v_texCoords;
|
12971 | in vec3 a_v_normal;
|
12972 | in vec2 a_i_light;
|
12973 | in vec4 a_i_color;
|
12974 | in mat4 a_i_transform;
|
12975 | in mat3 a_i_normalMat;
|
12976 | out vec2 v2f_texCoords;
|
12977 | out vec4 v2f_color;
|
12978 | out float v2f_diffuse;
|
12979 | out vec2 v2f_light;
|
12980 | void main() {
|
12981 | Vertex v;
|
12982 | v.pos = a_v_pos;
|
12983 | v.texCoords = a_v_texCoords;
|
12984 | v.normal = a_v_normal;
|
12985 | Instance i;
|
12986 | i.light = a_i_light;
|
12987 | i.color = a_i_color;
|
12988 | i.transform = a_i_transform;
|
12989 | i.normalMat = a_i_normalMat;
|
12990 | BlockFrag o = vertex(v, i);
|
12991 | v2f_texCoords = o.texCoords;
|
12992 | v2f_color = o.color;
|
12993 | v2f_diffuse = o.diffuse;
|
12994 | v2f_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)
|
13002 | out float FragDistance;
|
13003 | #elif defined(FRAGMENT_SHADER)
|
13004 | in float FragDistance;
|
13005 | #endif
|
13006 | uniform vec4 uFogColor;
|
13007 | uniform vec2 uFogRange;
|
13008 |
|
13009 | float 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 |
|
13015 | float cylindrical_distance(vec3 worldPos) {
|
13016 | float distXZ = length(worldPos.xz);
|
13017 | float distY = abs(worldPos.y);
|
13018 | return max(distXZ, distY);
|
13019 | }
|
13020 |
|
13021 | float 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
|
13025 | vec2 shiftLight(vec2 lm) {
|
13026 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
13027 | }
|
13028 |
|
13029 |
|
13030 | uniform sampler3D uLightVolume;
|
13031 |
|
13032 | uniform sampler2D uBlockAtlas;
|
13033 | uniform sampler2D uLightMap;
|
13034 |
|
13035 | uniform vec3 uLightBoxSize;
|
13036 | uniform vec3 uLightBoxMin;
|
13037 | uniform mat4 uModel;
|
13038 |
|
13039 | uniform float uTime;
|
13040 | uniform mat4 uViewProjection;
|
13041 | uniform vec3 uCameraPos;
|
13042 |
|
13043 | void 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 |
|
13053 | out vec3 BoxCoord;
|
13054 |
|
13055 | void 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)
|
13072 | layout (depth_greater) out float gl_FragDepth;
|
13073 | #endif
|
13074 | #endif
|
13075 |
|
13076 | in vec3 BoxCoord;
|
13077 |
|
13078 | out vec4 FragColor;
|
13079 |
|
13080 | vec4 FLWBlockTexture(vec2 texCoords) {
|
13081 | return texture(uBlockAtlas, texCoords);
|
13082 | }
|
13083 |
|
13084 | void 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 |
|
13100 | vec4 FLWLight(vec2 lightCoords) {
|
13101 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
13102 |
|
13103 | return texture(uLightMap, shiftLight(lightCoords));
|
13104 | }
|
13105 |
|
13106 | #endif
|
13107 |
|
13108 |
|
13109 | float 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 | }
|
13113 | struct Vertex {
|
13114 | vec3 pos;
|
13115 | vec2 texCoords;
|
13116 | vec3 normal;
|
13117 | };
|
13118 |
|
13119 | struct BlockFrag {
|
13120 | vec2 texCoords;
|
13121 | vec4 color;
|
13122 | float diffuse;
|
13123 | vec2 light;
|
13124 | };
|
13125 |
|
13126 | #if defined(FRAGMENT_SHADER)
|
13127 | void 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 |
|
13139 | struct Instance {
|
13140 | vec2 light;
|
13141 | vec4 color;
|
13142 | mat4 transform;
|
13143 | mat3 normalMat;
|
13144 | };
|
13145 |
|
13146 | #if defined(VERTEX_SHADER)
|
13147 | BlockFrag 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 |
|
13170 | in vec2 v2f_texCoords;
|
13171 | in vec4 v2f_color;
|
13172 | in float v2f_diffuse;
|
13173 | in vec2 v2f_light;
|
13174 | void main() {
|
13175 | BlockFrag o;
|
13176 | o.texCoords = v2f_texCoords;
|
13177 | o.color = v2f_color;
|
13178 | o.diffuse = v2f_diffuse;
|
13179 | o.light = v2f_light;
|
13180 | fragment(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)
|
13189 | out float FragDistance;
|
13190 | #elif defined(FRAGMENT_SHADER)
|
13191 | in float FragDistance;
|
13192 | #endif
|
13193 | uniform vec4 uFogColor;
|
13194 | uniform vec2 uFogRange;
|
13195 |
|
13196 | float 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 |
|
13202 | float cylindrical_distance(vec3 worldPos) {
|
13203 | float distXZ = length(worldPos.xz);
|
13204 | float distY = abs(worldPos.y);
|
13205 | return max(distXZ, distY);
|
13206 | }
|
13207 |
|
13208 | float 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
|
13212 | vec2 shiftLight(vec2 lm) {
|
13213 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
13214 | }
|
13215 |
|
13216 |
|
13217 | uniform sampler3D uLightVolume;
|
13218 |
|
13219 | uniform sampler2D uBlockAtlas;
|
13220 | uniform sampler2D uLightMap;
|
13221 |
|
13222 | uniform vec3 uLightBoxSize;
|
13223 | uniform vec3 uLightBoxMin;
|
13224 | uniform mat4 uModel;
|
13225 |
|
13226 | uniform float uTime;
|
13227 | uniform mat4 uViewProjection;
|
13228 | uniform vec3 uCameraPos;
|
13229 |
|
13230 | void 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 |
|
13240 | out vec3 BoxCoord;
|
13241 |
|
13242 | void 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)
|
13259 | layout (depth_greater) out float gl_FragDepth;
|
13260 | #endif
|
13261 | #endif
|
13262 |
|
13263 | in vec3 BoxCoord;
|
13264 |
|
13265 | out vec4 FragColor;
|
13266 |
|
13267 | vec4 FLWBlockTexture(vec2 texCoords) {
|
13268 | return texture(uBlockAtlas, texCoords);
|
13269 | }
|
13270 |
|
13271 | void 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 |
|
13287 | vec4 FLWLight(vec2 lightCoords) {
|
13288 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
13289 |
|
13290 | return texture(uLightMap, shiftLight(lightCoords));
|
13291 | }
|
13292 |
|
13293 | #endif
|
13294 |
|
13295 |
|
13296 | float 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 | }
|
13300 | struct Vertex {
|
13301 | vec3 pos;
|
13302 | vec2 texCoords;
|
13303 | vec3 normal;
|
13304 | };
|
13305 |
|
13306 | struct BlockFrag {
|
13307 | vec2 texCoords;
|
13308 | vec4 color;
|
13309 | float diffuse;
|
13310 | vec2 light;
|
13311 | };
|
13312 |
|
13313 | #if defined(FRAGMENT_SHADER)
|
13314 | void 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 |
|
13326 | struct Instance {
|
13327 | vec2 light;
|
13328 | vec4 color;
|
13329 | mat4 transform;
|
13330 | mat3 normalMat;
|
13331 | };
|
13332 |
|
13333 | #if defined(VERTEX_SHADER)
|
13334 | BlockFrag 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 |
|
13357 | in vec3 a_v_pos;
|
13358 | in vec2 a_v_texCoords;
|
13359 | in vec3 a_v_normal;
|
13360 | in vec2 a_i_light;
|
13361 | in vec4 a_i_color;
|
13362 | in mat4 a_i_transform;
|
13363 | in mat3 a_i_normalMat;
|
13364 | out vec2 v2f_texCoords;
|
13365 | out vec4 v2f_color;
|
13366 | out float v2f_diffuse;
|
13367 | out vec2 v2f_light;
|
13368 | void main() {
|
13369 | Vertex v;
|
13370 | v.pos = a_v_pos;
|
13371 | v.texCoords = a_v_texCoords;
|
13372 | v.normal = a_v_normal;
|
13373 | Instance i;
|
13374 | i.light = a_i_light;
|
13375 | i.color = a_i_color;
|
13376 | i.transform = a_i_transform;
|
13377 | i.normalMat = a_i_normalMat;
|
13378 | BlockFrag o = vertex(v, i);
|
13379 | v2f_texCoords = o.texCoords;
|
13380 | v2f_color = o.color;
|
13381 | v2f_diffuse = o.diffuse;
|
13382 | v2f_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)
|
13391 | out float FragDistance;
|
13392 | #elif defined(FRAGMENT_SHADER)
|
13393 | in float FragDistance;
|
13394 | #endif
|
13395 | uniform vec4 uFogColor;
|
13396 | uniform vec2 uFogRange;
|
13397 |
|
13398 | float 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 |
|
13404 | float cylindrical_distance(vec3 worldPos) {
|
13405 | float distXZ = length(worldPos.xz);
|
13406 | float distY = abs(worldPos.y);
|
13407 | return max(distXZ, distY);
|
13408 | }
|
13409 |
|
13410 | float 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
|
13414 | vec2 shiftLight(vec2 lm) {
|
13415 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
13416 | }
|
13417 |
|
13418 |
|
13419 | uniform sampler3D uLightVolume;
|
13420 |
|
13421 | uniform sampler2D uBlockAtlas;
|
13422 | uniform sampler2D uLightMap;
|
13423 |
|
13424 | uniform vec3 uLightBoxSize;
|
13425 | uniform vec3 uLightBoxMin;
|
13426 | uniform mat4 uModel;
|
13427 |
|
13428 | uniform float uTime;
|
13429 | uniform mat4 uViewProjection;
|
13430 | uniform vec3 uCameraPos;
|
13431 |
|
13432 | void 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 |
|
13442 | out vec3 BoxCoord;
|
13443 |
|
13444 | void 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)
|
13461 | layout (depth_greater) out float gl_FragDepth;
|
13462 | #endif
|
13463 | #endif
|
13464 |
|
13465 | in vec3 BoxCoord;
|
13466 |
|
13467 | out vec4 FragColor;
|
13468 |
|
13469 | vec4 FLWBlockTexture(vec2 texCoords) {
|
13470 | return texture(uBlockAtlas, texCoords);
|
13471 | }
|
13472 |
|
13473 | void 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 |
|
13489 | vec4 FLWLight(vec2 lightCoords) {
|
13490 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
13491 |
|
13492 | return texture(uLightMap, shiftLight(lightCoords));
|
13493 | }
|
13494 |
|
13495 | #endif
|
13496 |
|
13497 |
|
13498 | float 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 | }
|
13502 | struct Vertex {
|
13503 | vec3 pos;
|
13504 | vec2 texCoords;
|
13505 | vec3 normal;
|
13506 | };
|
13507 |
|
13508 | struct BlockFrag {
|
13509 | vec2 texCoords;
|
13510 | vec4 color;
|
13511 | float diffuse;
|
13512 | vec2 light;
|
13513 | };
|
13514 |
|
13515 | #if defined(FRAGMENT_SHADER)
|
13516 | void 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 |
|
13528 | struct Instance {
|
13529 | vec2 light;
|
13530 | vec4 color;
|
13531 | mat4 transform;
|
13532 | mat3 normalMat;
|
13533 | };
|
13534 |
|
13535 | #if defined(VERTEX_SHADER)
|
13536 | BlockFrag 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 |
|
13559 | in vec2 v2f_texCoords;
|
13560 | in vec4 v2f_color;
|
13561 | in float v2f_diffuse;
|
13562 | in vec2 v2f_light;
|
13563 | void main() {
|
13564 | BlockFrag o;
|
13565 | o.texCoords = v2f_texCoords;
|
13566 | o.color = v2f_color;
|
13567 | o.diffuse = v2f_diffuse;
|
13568 | o.light = v2f_light;
|
13569 | fragment(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)
|
13577 | out float FragDistance;
|
13578 | #elif defined(FRAGMENT_SHADER)
|
13579 | in float FragDistance;
|
13580 | #endif
|
13581 | uniform vec4 uFogColor;
|
13582 | uniform vec2 uFogRange;
|
13583 |
|
13584 | float 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 |
|
13590 | float cylindrical_distance(vec3 worldPos) {
|
13591 | float distXZ = length(worldPos.xz);
|
13592 | float distY = abs(worldPos.y);
|
13593 | return max(distXZ, distY);
|
13594 | }
|
13595 |
|
13596 | float 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
|
13600 | vec2 shiftLight(vec2 lm) {
|
13601 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
13602 | }
|
13603 |
|
13604 |
|
13605 | uniform sampler3D uLightVolume;
|
13606 |
|
13607 | uniform sampler2D uBlockAtlas;
|
13608 | uniform sampler2D uLightMap;
|
13609 |
|
13610 | uniform vec3 uLightBoxSize;
|
13611 | uniform vec3 uLightBoxMin;
|
13612 | uniform mat4 uModel;
|
13613 |
|
13614 | uniform float uTime;
|
13615 | uniform mat4 uViewProjection;
|
13616 | uniform vec3 uCameraPos;
|
13617 |
|
13618 | void 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 |
|
13628 | out vec3 BoxCoord;
|
13629 |
|
13630 | void 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)
|
13647 | layout (depth_greater) out float gl_FragDepth;
|
13648 | #endif
|
13649 | #endif
|
13650 |
|
13651 | in vec3 BoxCoord;
|
13652 |
|
13653 | out vec4 FragColor;
|
13654 |
|
13655 | vec4 FLWBlockTexture(vec2 texCoords) {
|
13656 | return texture(uBlockAtlas, texCoords);
|
13657 | }
|
13658 |
|
13659 | void 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 |
|
13675 | vec4 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 |
|
13686 | vec4 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 |
|
13692 | vec4 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 |
|
13702 | vec3 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 |
|
13707 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
13708 | return rotateVertexByQuat(v, quat(axis, angle));
|
13709 | }
|
13710 |
|
13711 | float 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 | }
|
13715 | struct Vertex {
|
13716 | vec3 pos;
|
13717 | vec2 texCoords;
|
13718 | vec3 normal;
|
13719 | };
|
13720 |
|
13721 | struct BlockFrag {
|
13722 | vec2 texCoords;
|
13723 | vec4 color;
|
13724 | float diffuse;
|
13725 | vec2 light;
|
13726 | };
|
13727 |
|
13728 | #if defined(FRAGMENT_SHADER)
|
13729 | void 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 |
|
13743 | struct Oriented {
|
13744 | vec2 light;
|
13745 | vec4 color;
|
13746 | vec3 pos;
|
13747 | vec3 pivot;
|
13748 | vec4 rotation;
|
13749 | };
|
13750 |
|
13751 | #if defined(VERTEX_SHADER)
|
13752 | BlockFrag 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 |
|
13773 | in vec3 a_v_pos;
|
13774 | in vec2 a_v_texCoords;
|
13775 | in vec3 a_v_normal;
|
13776 | in vec2 a_i_light;
|
13777 | in vec4 a_i_color;
|
13778 | in vec3 a_i_pos;
|
13779 | in vec3 a_i_pivot;
|
13780 | in vec4 a_i_rotation;
|
13781 | out vec2 v2f_texCoords;
|
13782 | out vec4 v2f_color;
|
13783 | out float v2f_diffuse;
|
13784 | out vec2 v2f_light;
|
13785 | void main() {
|
13786 | Vertex v;
|
13787 | v.pos = a_v_pos;
|
13788 | v.texCoords = a_v_texCoords;
|
13789 | v.normal = a_v_normal;
|
13790 | Oriented i;
|
13791 | i.light = a_i_light;
|
13792 | i.color = a_i_color;
|
13793 | i.pos = a_i_pos;
|
13794 | i.pivot = a_i_pivot;
|
13795 | i.rotation = a_i_rotation;
|
13796 | BlockFrag o = vertex(v, i);
|
13797 | v2f_texCoords = o.texCoords;
|
13798 | v2f_color = o.color;
|
13799 | v2f_diffuse = o.diffuse;
|
13800 | v2f_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)
|
13808 | out float FragDistance;
|
13809 | #elif defined(FRAGMENT_SHADER)
|
13810 | in float FragDistance;
|
13811 | #endif
|
13812 | uniform vec4 uFogColor;
|
13813 | uniform vec2 uFogRange;
|
13814 |
|
13815 | float 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 |
|
13821 | float cylindrical_distance(vec3 worldPos) {
|
13822 | float distXZ = length(worldPos.xz);
|
13823 | float distY = abs(worldPos.y);
|
13824 | return max(distXZ, distY);
|
13825 | }
|
13826 |
|
13827 | float 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
|
13831 | vec2 shiftLight(vec2 lm) {
|
13832 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
13833 | }
|
13834 |
|
13835 |
|
13836 | uniform sampler3D uLightVolume;
|
13837 |
|
13838 | uniform sampler2D uBlockAtlas;
|
13839 | uniform sampler2D uLightMap;
|
13840 |
|
13841 | uniform vec3 uLightBoxSize;
|
13842 | uniform vec3 uLightBoxMin;
|
13843 | uniform mat4 uModel;
|
13844 |
|
13845 | uniform float uTime;
|
13846 | uniform mat4 uViewProjection;
|
13847 | uniform vec3 uCameraPos;
|
13848 |
|
13849 | void 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 |
|
13859 | out vec3 BoxCoord;
|
13860 |
|
13861 | void 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)
|
13878 | layout (depth_greater) out float gl_FragDepth;
|
13879 | #endif
|
13880 | #endif
|
13881 |
|
13882 | in vec3 BoxCoord;
|
13883 |
|
13884 | out vec4 FragColor;
|
13885 |
|
13886 | vec4 FLWBlockTexture(vec2 texCoords) {
|
13887 | return texture(uBlockAtlas, texCoords);
|
13888 | }
|
13889 |
|
13890 | void 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 |
|
13906 | vec4 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 |
|
13917 | vec4 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 |
|
13923 | vec4 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 |
|
13933 | vec3 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 |
|
13938 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
13939 | return rotateVertexByQuat(v, quat(axis, angle));
|
13940 | }
|
13941 |
|
13942 | float 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 | }
|
13946 | struct Vertex {
|
13947 | vec3 pos;
|
13948 | vec2 texCoords;
|
13949 | vec3 normal;
|
13950 | };
|
13951 |
|
13952 | struct BlockFrag {
|
13953 | vec2 texCoords;
|
13954 | vec4 color;
|
13955 | float diffuse;
|
13956 | vec2 light;
|
13957 | };
|
13958 |
|
13959 | #if defined(FRAGMENT_SHADER)
|
13960 | void 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 |
|
13974 | struct Oriented {
|
13975 | vec2 light;
|
13976 | vec4 color;
|
13977 | vec3 pos;
|
13978 | vec3 pivot;
|
13979 | vec4 rotation;
|
13980 | };
|
13981 |
|
13982 | #if defined(VERTEX_SHADER)
|
13983 | BlockFrag 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 |
|
14004 | in vec2 v2f_texCoords;
|
14005 | in vec4 v2f_color;
|
14006 | in float v2f_diffuse;
|
14007 | in vec2 v2f_light;
|
14008 | void main() {
|
14009 | BlockFrag o;
|
14010 | o.texCoords = v2f_texCoords;
|
14011 | o.color = v2f_color;
|
14012 | o.diffuse = v2f_diffuse;
|
14013 | o.light = v2f_light;
|
14014 | fragment(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)
|
14023 | out float FragDistance;
|
14024 | #elif defined(FRAGMENT_SHADER)
|
14025 | in float FragDistance;
|
14026 | #endif
|
14027 | uniform vec4 uFogColor;
|
14028 | uniform vec2 uFogRange;
|
14029 |
|
14030 | float 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 |
|
14036 | float cylindrical_distance(vec3 worldPos) {
|
14037 | float distXZ = length(worldPos.xz);
|
14038 | float distY = abs(worldPos.y);
|
14039 | return max(distXZ, distY);
|
14040 | }
|
14041 |
|
14042 | float 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
|
14046 | vec2 shiftLight(vec2 lm) {
|
14047 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
14048 | }
|
14049 |
|
14050 |
|
14051 | uniform sampler3D uLightVolume;
|
14052 |
|
14053 | uniform sampler2D uBlockAtlas;
|
14054 | uniform sampler2D uLightMap;
|
14055 |
|
14056 | uniform vec3 uLightBoxSize;
|
14057 | uniform vec3 uLightBoxMin;
|
14058 | uniform mat4 uModel;
|
14059 |
|
14060 | uniform float uTime;
|
14061 | uniform mat4 uViewProjection;
|
14062 | uniform vec3 uCameraPos;
|
14063 |
|
14064 | void 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 |
|
14074 | out vec3 BoxCoord;
|
14075 |
|
14076 | void 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)
|
14093 | layout (depth_greater) out float gl_FragDepth;
|
14094 | #endif
|
14095 | #endif
|
14096 |
|
14097 | in vec3 BoxCoord;
|
14098 |
|
14099 | out vec4 FragColor;
|
14100 |
|
14101 | vec4 FLWBlockTexture(vec2 texCoords) {
|
14102 | return texture(uBlockAtlas, texCoords);
|
14103 | }
|
14104 |
|
14105 | void 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 |
|
14121 | vec4 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 |
|
14132 | vec4 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 |
|
14138 | vec4 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 |
|
14148 | vec3 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 |
|
14153 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
14154 | return rotateVertexByQuat(v, quat(axis, angle));
|
14155 | }
|
14156 |
|
14157 | float 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 | }
|
14161 | struct Vertex {
|
14162 | vec3 pos;
|
14163 | vec2 texCoords;
|
14164 | vec3 normal;
|
14165 | };
|
14166 |
|
14167 | struct BlockFrag {
|
14168 | vec2 texCoords;
|
14169 | vec4 color;
|
14170 | float diffuse;
|
14171 | vec2 light;
|
14172 | };
|
14173 |
|
14174 | #if defined(FRAGMENT_SHADER)
|
14175 | void 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 |
|
14189 | struct Oriented {
|
14190 | vec2 light;
|
14191 | vec4 color;
|
14192 | vec3 pos;
|
14193 | vec3 pivot;
|
14194 | vec4 rotation;
|
14195 | };
|
14196 |
|
14197 | #if defined(VERTEX_SHADER)
|
14198 | BlockFrag 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 |
|
14219 | in vec3 a_v_pos;
|
14220 | in vec2 a_v_texCoords;
|
14221 | in vec3 a_v_normal;
|
14222 | in vec2 a_i_light;
|
14223 | in vec4 a_i_color;
|
14224 | in vec3 a_i_pos;
|
14225 | in vec3 a_i_pivot;
|
14226 | in vec4 a_i_rotation;
|
14227 | out vec2 v2f_texCoords;
|
14228 | out vec4 v2f_color;
|
14229 | out float v2f_diffuse;
|
14230 | out vec2 v2f_light;
|
14231 | void main() {
|
14232 | Vertex v;
|
14233 | v.pos = a_v_pos;
|
14234 | v.texCoords = a_v_texCoords;
|
14235 | v.normal = a_v_normal;
|
14236 | Oriented i;
|
14237 | i.light = a_i_light;
|
14238 | i.color = a_i_color;
|
14239 | i.pos = a_i_pos;
|
14240 | i.pivot = a_i_pivot;
|
14241 | i.rotation = a_i_rotation;
|
14242 | BlockFrag o = vertex(v, i);
|
14243 | v2f_texCoords = o.texCoords;
|
14244 | v2f_color = o.color;
|
14245 | v2f_diffuse = o.diffuse;
|
14246 | v2f_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)
|
14255 | out float FragDistance;
|
14256 | #elif defined(FRAGMENT_SHADER)
|
14257 | in float FragDistance;
|
14258 | #endif
|
14259 | uniform vec4 uFogColor;
|
14260 | uniform vec2 uFogRange;
|
14261 |
|
14262 | float 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 |
|
14268 | float cylindrical_distance(vec3 worldPos) {
|
14269 | float distXZ = length(worldPos.xz);
|
14270 | float distY = abs(worldPos.y);
|
14271 | return max(distXZ, distY);
|
14272 | }
|
14273 |
|
14274 | float 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
|
14278 | vec2 shiftLight(vec2 lm) {
|
14279 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
14280 | }
|
14281 |
|
14282 |
|
14283 | uniform sampler3D uLightVolume;
|
14284 |
|
14285 | uniform sampler2D uBlockAtlas;
|
14286 | uniform sampler2D uLightMap;
|
14287 |
|
14288 | uniform vec3 uLightBoxSize;
|
14289 | uniform vec3 uLightBoxMin;
|
14290 | uniform mat4 uModel;
|
14291 |
|
14292 | uniform float uTime;
|
14293 | uniform mat4 uViewProjection;
|
14294 | uniform vec3 uCameraPos;
|
14295 |
|
14296 | void 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 |
|
14306 | out vec3 BoxCoord;
|
14307 |
|
14308 | void 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)
|
14325 | layout (depth_greater) out float gl_FragDepth;
|
14326 | #endif
|
14327 | #endif
|
14328 |
|
14329 | in vec3 BoxCoord;
|
14330 |
|
14331 | out vec4 FragColor;
|
14332 |
|
14333 | vec4 FLWBlockTexture(vec2 texCoords) {
|
14334 | return texture(uBlockAtlas, texCoords);
|
14335 | }
|
14336 |
|
14337 | void 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 |
|
14353 | vec4 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 |
|
14364 | vec4 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 |
|
14370 | vec4 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 |
|
14380 | vec3 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 |
|
14385 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
14386 | return rotateVertexByQuat(v, quat(axis, angle));
|
14387 | }
|
14388 |
|
14389 | float 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 | }
|
14393 | struct Vertex {
|
14394 | vec3 pos;
|
14395 | vec2 texCoords;
|
14396 | vec3 normal;
|
14397 | };
|
14398 |
|
14399 | struct BlockFrag {
|
14400 | vec2 texCoords;
|
14401 | vec4 color;
|
14402 | float diffuse;
|
14403 | vec2 light;
|
14404 | };
|
14405 |
|
14406 | #if defined(FRAGMENT_SHADER)
|
14407 | void 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 |
|
14421 | struct Oriented {
|
14422 | vec2 light;
|
14423 | vec4 color;
|
14424 | vec3 pos;
|
14425 | vec3 pivot;
|
14426 | vec4 rotation;
|
14427 | };
|
14428 |
|
14429 | #if defined(VERTEX_SHADER)
|
14430 | BlockFrag 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 |
|
14451 | in vec2 v2f_texCoords;
|
14452 | in vec4 v2f_color;
|
14453 | in float v2f_diffuse;
|
14454 | in vec2 v2f_light;
|
14455 | void main() {
|
14456 | BlockFrag o;
|
14457 | o.texCoords = v2f_texCoords;
|
14458 | o.color = v2f_color;
|
14459 | o.diffuse = v2f_diffuse;
|
14460 | o.light = v2f_light;
|
14461 | fragment(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)
|
14469 | out float FragDistance;
|
14470 | #elif defined(FRAGMENT_SHADER)
|
14471 | in float FragDistance;
|
14472 | #endif
|
14473 | uniform vec4 uFogColor;
|
14474 | uniform vec2 uFogRange;
|
14475 |
|
14476 | float 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 |
|
14482 | float cylindrical_distance(vec3 worldPos) {
|
14483 | float distXZ = length(worldPos.xz);
|
14484 | float distY = abs(worldPos.y);
|
14485 | return max(distXZ, distY);
|
14486 | }
|
14487 |
|
14488 | float 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
|
14492 | vec2 shiftLight(vec2 lm) {
|
14493 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
14494 | }
|
14495 |
|
14496 |
|
14497 | uniform sampler3D uLightVolume;
|
14498 |
|
14499 | uniform sampler2D uBlockAtlas;
|
14500 | uniform sampler2D uLightMap;
|
14501 |
|
14502 | uniform vec3 uLightBoxSize;
|
14503 | uniform vec3 uLightBoxMin;
|
14504 | uniform mat4 uModel;
|
14505 |
|
14506 | uniform float uTime;
|
14507 | uniform mat4 uViewProjection;
|
14508 | uniform vec3 uCameraPos;
|
14509 |
|
14510 | void 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 |
|
14520 | out vec3 BoxCoord;
|
14521 |
|
14522 | void 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)
|
14539 | layout (depth_greater) out float gl_FragDepth;
|
14540 | #endif
|
14541 | #endif
|
14542 |
|
14543 | in vec3 BoxCoord;
|
14544 |
|
14545 | out vec4 FragColor;
|
14546 |
|
14547 | vec4 FLWBlockTexture(vec2 texCoords) {
|
14548 | return texture(uBlockAtlas, texCoords);
|
14549 | }
|
14550 |
|
14551 | void 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 |
|
14567 | vec4 FLWLight(vec2 lightCoords) {
|
14568 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
14569 |
|
14570 | return texture(uLightMap, shiftLight(lightCoords));
|
14571 | }
|
14572 |
|
14573 | #endif
|
14574 |
|
14575 |
|
14576 | mat4 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 |
|
14591 | mat4 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 |
|
14595 | mat3 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 |
|
14605 | float 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 | }
|
14609 | struct Vertex {
|
14610 | vec3 pos;
|
14611 | vec2 texCoords;
|
14612 | vec3 normal;
|
14613 | };
|
14614 |
|
14615 | struct BlockFrag {
|
14616 | vec2 texCoords;
|
14617 | vec4 color;
|
14618 | float diffuse;
|
14619 | vec2 light;
|
14620 | };
|
14621 |
|
14622 | #if defined(FRAGMENT_SHADER)
|
14623 | void 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 |
|
14636 | struct Rotating {
|
14637 | vec2 light;
|
14638 | vec4 color;
|
14639 | vec3 pos;
|
14640 | float speed;
|
14641 | float offset;
|
14642 | vec3 axis;
|
14643 | };
|
14644 |
|
14645 |
|
14646 |
|
14647 |
|
14648 | mat4 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)
|
14656 | BlockFrag 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 |
|
14684 | in vec3 a_v_pos;
|
14685 | in vec2 a_v_texCoords;
|
14686 | in vec3 a_v_normal;
|
14687 | in vec2 a_i_light;
|
14688 | in vec4 a_i_color;
|
14689 | in vec3 a_i_pos;
|
14690 | in float a_i_speed;
|
14691 | in float a_i_offset;
|
14692 | in vec3 a_i_axis;
|
14693 | out vec2 v2f_texCoords;
|
14694 | out vec4 v2f_color;
|
14695 | out float v2f_diffuse;
|
14696 | out vec2 v2f_light;
|
14697 | void main() {
|
14698 | Vertex v;
|
14699 | v.pos = a_v_pos;
|
14700 | v.texCoords = a_v_texCoords;
|
14701 | v.normal = a_v_normal;
|
14702 | Rotating i;
|
14703 | i.light = a_i_light;
|
14704 | i.color = a_i_color;
|
14705 | i.pos = a_i_pos;
|
14706 | i.speed = a_i_speed;
|
14707 | i.offset = a_i_offset;
|
14708 | i.axis = a_i_axis;
|
14709 | BlockFrag o = vertex(v, i);
|
14710 | v2f_texCoords = o.texCoords;
|
14711 | v2f_color = o.color;
|
14712 | v2f_diffuse = o.diffuse;
|
14713 | v2f_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)
|
14721 | out float FragDistance;
|
14722 | #elif defined(FRAGMENT_SHADER)
|
14723 | in float FragDistance;
|
14724 | #endif
|
14725 | uniform vec4 uFogColor;
|
14726 | uniform vec2 uFogRange;
|
14727 |
|
14728 | float 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 |
|
14734 | float cylindrical_distance(vec3 worldPos) {
|
14735 | float distXZ = length(worldPos.xz);
|
14736 | float distY = abs(worldPos.y);
|
14737 | return max(distXZ, distY);
|
14738 | }
|
14739 |
|
14740 | float 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
|
14744 | vec2 shiftLight(vec2 lm) {
|
14745 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
14746 | }
|
14747 |
|
14748 |
|
14749 | uniform sampler3D uLightVolume;
|
14750 |
|
14751 | uniform sampler2D uBlockAtlas;
|
14752 | uniform sampler2D uLightMap;
|
14753 |
|
14754 | uniform vec3 uLightBoxSize;
|
14755 | uniform vec3 uLightBoxMin;
|
14756 | uniform mat4 uModel;
|
14757 |
|
14758 | uniform float uTime;
|
14759 | uniform mat4 uViewProjection;
|
14760 | uniform vec3 uCameraPos;
|
14761 |
|
14762 | void 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 |
|
14772 | out vec3 BoxCoord;
|
14773 |
|
14774 | void 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)
|
14791 | layout (depth_greater) out float gl_FragDepth;
|
14792 | #endif
|
14793 | #endif
|
14794 |
|
14795 | in vec3 BoxCoord;
|
14796 |
|
14797 | out vec4 FragColor;
|
14798 |
|
14799 | vec4 FLWBlockTexture(vec2 texCoords) {
|
14800 | return texture(uBlockAtlas, texCoords);
|
14801 | }
|
14802 |
|
14803 | void 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 |
|
14819 | vec4 FLWLight(vec2 lightCoords) {
|
14820 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
14821 |
|
14822 | return texture(uLightMap, shiftLight(lightCoords));
|
14823 | }
|
14824 |
|
14825 | #endif
|
14826 |
|
14827 |
|
14828 | mat4 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 |
|
14843 | mat4 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 |
|
14847 | mat3 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 |
|
14857 | float 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 | }
|
14861 | struct Vertex {
|
14862 | vec3 pos;
|
14863 | vec2 texCoords;
|
14864 | vec3 normal;
|
14865 | };
|
14866 |
|
14867 | struct BlockFrag {
|
14868 | vec2 texCoords;
|
14869 | vec4 color;
|
14870 | float diffuse;
|
14871 | vec2 light;
|
14872 | };
|
14873 |
|
14874 | #if defined(FRAGMENT_SHADER)
|
14875 | void 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 |
|
14888 | struct Rotating {
|
14889 | vec2 light;
|
14890 | vec4 color;
|
14891 | vec3 pos;
|
14892 | float speed;
|
14893 | float offset;
|
14894 | vec3 axis;
|
14895 | };
|
14896 |
|
14897 |
|
14898 |
|
14899 |
|
14900 | mat4 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)
|
14908 | BlockFrag 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 |
|
14936 | in vec2 v2f_texCoords;
|
14937 | in vec4 v2f_color;
|
14938 | in float v2f_diffuse;
|
14939 | in vec2 v2f_light;
|
14940 | void main() {
|
14941 | BlockFrag o;
|
14942 | o.texCoords = v2f_texCoords;
|
14943 | o.color = v2f_color;
|
14944 | o.diffuse = v2f_diffuse;
|
14945 | o.light = v2f_light;
|
14946 | fragment(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)
|
14955 | out float FragDistance;
|
14956 | #elif defined(FRAGMENT_SHADER)
|
14957 | in float FragDistance;
|
14958 | #endif
|
14959 | uniform vec4 uFogColor;
|
14960 | uniform vec2 uFogRange;
|
14961 |
|
14962 | float 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 |
|
14968 | float cylindrical_distance(vec3 worldPos) {
|
14969 | float distXZ = length(worldPos.xz);
|
14970 | float distY = abs(worldPos.y);
|
14971 | return max(distXZ, distY);
|
14972 | }
|
14973 |
|
14974 | float 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
|
14978 | vec2 shiftLight(vec2 lm) {
|
14979 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
14980 | }
|
14981 |
|
14982 |
|
14983 | uniform sampler3D uLightVolume;
|
14984 |
|
14985 | uniform sampler2D uBlockAtlas;
|
14986 | uniform sampler2D uLightMap;
|
14987 |
|
14988 | uniform vec3 uLightBoxSize;
|
14989 | uniform vec3 uLightBoxMin;
|
14990 | uniform mat4 uModel;
|
14991 |
|
14992 | uniform float uTime;
|
14993 | uniform mat4 uViewProjection;
|
14994 | uniform vec3 uCameraPos;
|
14995 |
|
14996 | void 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 |
|
15006 | out vec3 BoxCoord;
|
15007 |
|
15008 | void 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)
|
15025 | layout (depth_greater) out float gl_FragDepth;
|
15026 | #endif
|
15027 | #endif
|
15028 |
|
15029 | in vec3 BoxCoord;
|
15030 |
|
15031 | out vec4 FragColor;
|
15032 |
|
15033 | vec4 FLWBlockTexture(vec2 texCoords) {
|
15034 | return texture(uBlockAtlas, texCoords);
|
15035 | }
|
15036 |
|
15037 | void 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 |
|
15053 | vec4 FLWLight(vec2 lightCoords) {
|
15054 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
15055 |
|
15056 | return texture(uLightMap, shiftLight(lightCoords));
|
15057 | }
|
15058 |
|
15059 | #endif
|
15060 |
|
15061 |
|
15062 | mat4 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 |
|
15077 | mat4 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 |
|
15081 | mat3 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 |
|
15091 | float 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 | }
|
15095 | struct Vertex {
|
15096 | vec3 pos;
|
15097 | vec2 texCoords;
|
15098 | vec3 normal;
|
15099 | };
|
15100 |
|
15101 | struct BlockFrag {
|
15102 | vec2 texCoords;
|
15103 | vec4 color;
|
15104 | float diffuse;
|
15105 | vec2 light;
|
15106 | };
|
15107 |
|
15108 | #if defined(FRAGMENT_SHADER)
|
15109 | void 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 |
|
15122 | struct Rotating {
|
15123 | vec2 light;
|
15124 | vec4 color;
|
15125 | vec3 pos;
|
15126 | float speed;
|
15127 | float offset;
|
15128 | vec3 axis;
|
15129 | };
|
15130 |
|
15131 |
|
15132 |
|
15133 |
|
15134 | mat4 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)
|
15142 | BlockFrag 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 |
|
15170 | in vec3 a_v_pos;
|
15171 | in vec2 a_v_texCoords;
|
15172 | in vec3 a_v_normal;
|
15173 | in vec2 a_i_light;
|
15174 | in vec4 a_i_color;
|
15175 | in vec3 a_i_pos;
|
15176 | in float a_i_speed;
|
15177 | in float a_i_offset;
|
15178 | in vec3 a_i_axis;
|
15179 | out vec2 v2f_texCoords;
|
15180 | out vec4 v2f_color;
|
15181 | out float v2f_diffuse;
|
15182 | out vec2 v2f_light;
|
15183 | void main() {
|
15184 | Vertex v;
|
15185 | v.pos = a_v_pos;
|
15186 | v.texCoords = a_v_texCoords;
|
15187 | v.normal = a_v_normal;
|
15188 | Rotating i;
|
15189 | i.light = a_i_light;
|
15190 | i.color = a_i_color;
|
15191 | i.pos = a_i_pos;
|
15192 | i.speed = a_i_speed;
|
15193 | i.offset = a_i_offset;
|
15194 | i.axis = a_i_axis;
|
15195 | BlockFrag o = vertex(v, i);
|
15196 | v2f_texCoords = o.texCoords;
|
15197 | v2f_color = o.color;
|
15198 | v2f_diffuse = o.diffuse;
|
15199 | v2f_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)
|
15208 | out float FragDistance;
|
15209 | #elif defined(FRAGMENT_SHADER)
|
15210 | in float FragDistance;
|
15211 | #endif
|
15212 | uniform vec4 uFogColor;
|
15213 | uniform vec2 uFogRange;
|
15214 |
|
15215 | float 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 |
|
15221 | float cylindrical_distance(vec3 worldPos) {
|
15222 | float distXZ = length(worldPos.xz);
|
15223 | float distY = abs(worldPos.y);
|
15224 | return max(distXZ, distY);
|
15225 | }
|
15226 |
|
15227 | float 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
|
15231 | vec2 shiftLight(vec2 lm) {
|
15232 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
15233 | }
|
15234 |
|
15235 |
|
15236 | uniform sampler3D uLightVolume;
|
15237 |
|
15238 | uniform sampler2D uBlockAtlas;
|
15239 | uniform sampler2D uLightMap;
|
15240 |
|
15241 | uniform vec3 uLightBoxSize;
|
15242 | uniform vec3 uLightBoxMin;
|
15243 | uniform mat4 uModel;
|
15244 |
|
15245 | uniform float uTime;
|
15246 | uniform mat4 uViewProjection;
|
15247 | uniform vec3 uCameraPos;
|
15248 |
|
15249 | void 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 |
|
15259 | out vec3 BoxCoord;
|
15260 |
|
15261 | void 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)
|
15278 | layout (depth_greater) out float gl_FragDepth;
|
15279 | #endif
|
15280 | #endif
|
15281 |
|
15282 | in vec3 BoxCoord;
|
15283 |
|
15284 | out vec4 FragColor;
|
15285 |
|
15286 | vec4 FLWBlockTexture(vec2 texCoords) {
|
15287 | return texture(uBlockAtlas, texCoords);
|
15288 | }
|
15289 |
|
15290 | void 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 |
|
15306 | vec4 FLWLight(vec2 lightCoords) {
|
15307 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
15308 |
|
15309 | return texture(uLightMap, shiftLight(lightCoords));
|
15310 | }
|
15311 |
|
15312 | #endif
|
15313 |
|
15314 |
|
15315 | mat4 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 |
|
15330 | mat4 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 |
|
15334 | mat3 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 |
|
15344 | float 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 | }
|
15348 | struct Vertex {
|
15349 | vec3 pos;
|
15350 | vec2 texCoords;
|
15351 | vec3 normal;
|
15352 | };
|
15353 |
|
15354 | struct BlockFrag {
|
15355 | vec2 texCoords;
|
15356 | vec4 color;
|
15357 | float diffuse;
|
15358 | vec2 light;
|
15359 | };
|
15360 |
|
15361 | #if defined(FRAGMENT_SHADER)
|
15362 | void 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 |
|
15375 | struct Rotating {
|
15376 | vec2 light;
|
15377 | vec4 color;
|
15378 | vec3 pos;
|
15379 | float speed;
|
15380 | float offset;
|
15381 | vec3 axis;
|
15382 | };
|
15383 |
|
15384 |
|
15385 |
|
15386 |
|
15387 | mat4 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)
|
15395 | BlockFrag 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 |
|
15423 | in vec2 v2f_texCoords;
|
15424 | in vec4 v2f_color;
|
15425 | in float v2f_diffuse;
|
15426 | in vec2 v2f_light;
|
15427 | void main() {
|
15428 | BlockFrag o;
|
15429 | o.texCoords = v2f_texCoords;
|
15430 | o.color = v2f_color;
|
15431 | o.diffuse = v2f_diffuse;
|
15432 | o.light = v2f_light;
|
15433 | fragment(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)
|
15442 | out float FragDistance;
|
15443 | #elif defined(FRAGMENT_SHADER)
|
15444 | in float FragDistance;
|
15445 | #endif
|
15446 | uniform vec4 uFogColor;
|
15447 | uniform vec2 uFogRange;
|
15448 |
|
15449 | float 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 |
|
15455 | float cylindrical_distance(vec3 worldPos) {
|
15456 | float distXZ = length(worldPos.xz);
|
15457 | float distY = abs(worldPos.y);
|
15458 | return max(distXZ, distY);
|
15459 | }
|
15460 |
|
15461 | float 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
|
15465 | vec2 shiftLight(vec2 lm) {
|
15466 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
15467 | }
|
15468 |
|
15469 |
|
15470 | uniform sampler3D uLightVolume;
|
15471 |
|
15472 | uniform sampler2D uBlockAtlas;
|
15473 | uniform sampler2D uLightMap;
|
15474 |
|
15475 | uniform vec3 uLightBoxSize;
|
15476 | uniform vec3 uLightBoxMin;
|
15477 | uniform mat4 uModel;
|
15478 |
|
15479 | uniform float uTime;
|
15480 | uniform mat4 uViewProjection;
|
15481 | uniform vec3 uCameraPos;
|
15482 |
|
15483 | void 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 |
|
15493 | out vec3 BoxCoord;
|
15494 |
|
15495 | void 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)
|
15512 | layout (depth_greater) out float gl_FragDepth;
|
15513 | #endif
|
15514 | #endif
|
15515 |
|
15516 | in vec3 BoxCoord;
|
15517 |
|
15518 | out vec4 FragColor;
|
15519 |
|
15520 | vec4 FLWBlockTexture(vec2 texCoords) {
|
15521 | return texture(uBlockAtlas, texCoords);
|
15522 | }
|
15523 |
|
15524 | void 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 |
|
15540 | vec4 FLWLight(vec2 lightCoords) {
|
15541 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
15542 |
|
15543 | return texture(uLightMap, shiftLight(lightCoords));
|
15544 | }
|
15545 |
|
15546 | #endif
|
15547 |
|
15548 |
|
15549 | mat4 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 |
|
15564 | mat4 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 |
|
15568 | mat3 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 |
|
15578 | float 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 | }
|
15582 | struct Vertex {
|
15583 | vec3 pos;
|
15584 | vec2 texCoords;
|
15585 | vec3 normal;
|
15586 | };
|
15587 |
|
15588 | struct BlockFrag {
|
15589 | vec2 texCoords;
|
15590 | vec4 color;
|
15591 | float diffuse;
|
15592 | vec2 light;
|
15593 | };
|
15594 |
|
15595 | #if defined(FRAGMENT_SHADER)
|
15596 | void 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 |
|
15609 | struct Rotating {
|
15610 | vec2 light;
|
15611 | vec4 color;
|
15612 | vec3 pos;
|
15613 | float speed;
|
15614 | float offset;
|
15615 | vec3 axis;
|
15616 | };
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 | mat4 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)
|
15629 | BlockFrag 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 |
|
15657 | in vec3 a_v_pos;
|
15658 | in vec2 a_v_texCoords;
|
15659 | in vec3 a_v_normal;
|
15660 | in vec2 a_i_light;
|
15661 | in vec4 a_i_color;
|
15662 | in vec3 a_i_pos;
|
15663 | in float a_i_speed;
|
15664 | in float a_i_offset;
|
15665 | in vec3 a_i_axis;
|
15666 | out vec2 v2f_texCoords;
|
15667 | out vec4 v2f_color;
|
15668 | out float v2f_diffuse;
|
15669 | out vec2 v2f_light;
|
15670 | void main() {
|
15671 | Vertex v;
|
15672 | v.pos = a_v_pos;
|
15673 | v.texCoords = a_v_texCoords;
|
15674 | v.normal = a_v_normal;
|
15675 | Rotating i;
|
15676 | i.light = a_i_light;
|
15677 | i.color = a_i_color;
|
15678 | i.pos = a_i_pos;
|
15679 | i.speed = a_i_speed;
|
15680 | i.offset = a_i_offset;
|
15681 | i.axis = a_i_axis;
|
15682 | BlockFrag o = vertex(v, i);
|
15683 | v2f_texCoords = o.texCoords;
|
15684 | v2f_color = o.color;
|
15685 | v2f_diffuse = o.diffuse;
|
15686 | v2f_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)
|
15695 | out float FragDistance;
|
15696 | #elif defined(FRAGMENT_SHADER)
|
15697 | in float FragDistance;
|
15698 | #endif
|
15699 | uniform vec4 uFogColor;
|
15700 | uniform vec2 uFogRange;
|
15701 |
|
15702 | float 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 |
|
15708 | float cylindrical_distance(vec3 worldPos) {
|
15709 | float distXZ = length(worldPos.xz);
|
15710 | float distY = abs(worldPos.y);
|
15711 | return max(distXZ, distY);
|
15712 | }
|
15713 |
|
15714 | float 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
|
15718 | vec2 shiftLight(vec2 lm) {
|
15719 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
15720 | }
|
15721 |
|
15722 |
|
15723 | uniform sampler3D uLightVolume;
|
15724 |
|
15725 | uniform sampler2D uBlockAtlas;
|
15726 | uniform sampler2D uLightMap;
|
15727 |
|
15728 | uniform vec3 uLightBoxSize;
|
15729 | uniform vec3 uLightBoxMin;
|
15730 | uniform mat4 uModel;
|
15731 |
|
15732 | uniform float uTime;
|
15733 | uniform mat4 uViewProjection;
|
15734 | uniform vec3 uCameraPos;
|
15735 |
|
15736 | void 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 |
|
15746 | out vec3 BoxCoord;
|
15747 |
|
15748 | void 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)
|
15765 | layout (depth_greater) out float gl_FragDepth;
|
15766 | #endif
|
15767 | #endif
|
15768 |
|
15769 | in vec3 BoxCoord;
|
15770 |
|
15771 | out vec4 FragColor;
|
15772 |
|
15773 | vec4 FLWBlockTexture(vec2 texCoords) {
|
15774 | return texture(uBlockAtlas, texCoords);
|
15775 | }
|
15776 |
|
15777 | void 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 |
|
15793 | vec4 FLWLight(vec2 lightCoords) {
|
15794 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
15795 |
|
15796 | return texture(uLightMap, shiftLight(lightCoords));
|
15797 | }
|
15798 |
|
15799 | #endif
|
15800 |
|
15801 |
|
15802 | mat4 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 |
|
15817 | mat4 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 |
|
15821 | mat3 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 |
|
15831 | float 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 | }
|
15835 | struct Vertex {
|
15836 | vec3 pos;
|
15837 | vec2 texCoords;
|
15838 | vec3 normal;
|
15839 | };
|
15840 |
|
15841 | struct BlockFrag {
|
15842 | vec2 texCoords;
|
15843 | vec4 color;
|
15844 | float diffuse;
|
15845 | vec2 light;
|
15846 | };
|
15847 |
|
15848 | #if defined(FRAGMENT_SHADER)
|
15849 | void 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 |
|
15862 | struct Rotating {
|
15863 | vec2 light;
|
15864 | vec4 color;
|
15865 | vec3 pos;
|
15866 | float speed;
|
15867 | float offset;
|
15868 | vec3 axis;
|
15869 | };
|
15870 |
|
15871 |
|
15872 |
|
15873 |
|
15874 | mat4 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)
|
15882 | BlockFrag 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 |
|
15910 | in vec2 v2f_texCoords;
|
15911 | in vec4 v2f_color;
|
15912 | in float v2f_diffuse;
|
15913 | in vec2 v2f_light;
|
15914 | void main() {
|
15915 | BlockFrag o;
|
15916 | o.texCoords = v2f_texCoords;
|
15917 | o.color = v2f_color;
|
15918 | o.diffuse = v2f_diffuse;
|
15919 | o.light = v2f_light;
|
15920 | fragment(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)
|
15928 | out float FragDistance;
|
15929 | #elif defined(FRAGMENT_SHADER)
|
15930 | in float FragDistance;
|
15931 | #endif
|
15932 | uniform vec4 uFogColor;
|
15933 | uniform vec2 uFogRange;
|
15934 |
|
15935 | float 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 |
|
15941 | float cylindrical_distance(vec3 worldPos) {
|
15942 | float distXZ = length(worldPos.xz);
|
15943 | float distY = abs(worldPos.y);
|
15944 | return max(distXZ, distY);
|
15945 | }
|
15946 |
|
15947 | float 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
|
15951 | vec2 shiftLight(vec2 lm) {
|
15952 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
15953 | }
|
15954 |
|
15955 |
|
15956 | uniform sampler3D uLightVolume;
|
15957 |
|
15958 | uniform sampler2D uBlockAtlas;
|
15959 | uniform sampler2D uLightMap;
|
15960 |
|
15961 | uniform vec3 uLightBoxSize;
|
15962 | uniform vec3 uLightBoxMin;
|
15963 | uniform mat4 uModel;
|
15964 |
|
15965 | uniform float uTime;
|
15966 | uniform mat4 uViewProjection;
|
15967 | uniform vec3 uCameraPos;
|
15968 |
|
15969 | void 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 |
|
15979 | out vec3 BoxCoord;
|
15980 |
|
15981 | void 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)
|
15998 | layout (depth_greater) out float gl_FragDepth;
|
15999 | #endif
|
16000 | #endif
|
16001 |
|
16002 | in vec3 BoxCoord;
|
16003 |
|
16004 | out vec4 FragColor;
|
16005 |
|
16006 | vec4 FLWBlockTexture(vec2 texCoords) {
|
16007 | return texture(uBlockAtlas, texCoords);
|
16008 | }
|
16009 |
|
16010 | void 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 |
|
16026 | vec4 FLWLight(vec2 lightCoords) {
|
16027 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
16028 |
|
16029 | return texture(uLightMap, shiftLight(lightCoords));
|
16030 | }
|
16031 |
|
16032 | #endif
|
16033 |
|
16034 |
|
16035 | mat4 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 |
|
16050 | mat4 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 |
|
16054 | mat3 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 |
|
16066 | vec4 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 |
|
16072 | vec4 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 |
|
16082 | vec3 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 |
|
16087 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
16088 | return rotateVertexByQuat(v, quat(axis, angle));
|
16089 | }
|
16090 |
|
16091 | float 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 | }
|
16095 | struct Vertex {
|
16096 | vec3 pos;
|
16097 | vec2 texCoords;
|
16098 | vec3 normal;
|
16099 | };
|
16100 |
|
16101 | struct BlockFrag {
|
16102 | vec2 texCoords;
|
16103 | vec4 color;
|
16104 | float diffuse;
|
16105 | vec2 light;
|
16106 | };
|
16107 |
|
16108 | #if defined(FRAGMENT_SHADER)
|
16109 | void 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 |
|
16123 | struct 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)
|
16137 | BlockFrag 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 |
|
16165 | in vec3 a_v_pos;
|
16166 | in vec2 a_v_texCoords;
|
16167 | in vec3 a_v_normal;
|
16168 | in vec3 a_i_pos;
|
16169 | in vec2 a_i_light;
|
16170 | in float a_i_offset;
|
16171 | in vec3 a_i_axis;
|
16172 | in vec4 a_i_rotation;
|
16173 | in vec3 a_i_rotationCenter;
|
16174 | in float a_i_speed;
|
16175 | out vec2 v2f_texCoords;
|
16176 | out vec4 v2f_color;
|
16177 | out float v2f_diffuse;
|
16178 | out vec2 v2f_light;
|
16179 | void main() {
|
16180 | Vertex v;
|
16181 | v.pos = a_v_pos;
|
16182 | v.texCoords = a_v_texCoords;
|
16183 | v.normal = a_v_normal;
|
16184 | Actor i;
|
16185 | i.pos = a_i_pos;
|
16186 | i.light = a_i_light;
|
16187 | i.offset = a_i_offset;
|
16188 | i.axis = a_i_axis;
|
16189 | i.rotation = a_i_rotation;
|
16190 | i.rotationCenter = a_i_rotationCenter;
|
16191 | i.speed = a_i_speed;
|
16192 | BlockFrag o = vertex(v, i);
|
16193 | v2f_texCoords = o.texCoords;
|
16194 | v2f_color = o.color;
|
16195 | v2f_diffuse = o.diffuse;
|
16196 | v2f_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)
|
16204 | out float FragDistance;
|
16205 | #elif defined(FRAGMENT_SHADER)
|
16206 | in float FragDistance;
|
16207 | #endif
|
16208 | uniform vec4 uFogColor;
|
16209 | uniform vec2 uFogRange;
|
16210 |
|
16211 | float 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 |
|
16217 | float cylindrical_distance(vec3 worldPos) {
|
16218 | float distXZ = length(worldPos.xz);
|
16219 | float distY = abs(worldPos.y);
|
16220 | return max(distXZ, distY);
|
16221 | }
|
16222 |
|
16223 | float 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
|
16227 | vec2 shiftLight(vec2 lm) {
|
16228 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
16229 | }
|
16230 |
|
16231 |
|
16232 | uniform sampler3D uLightVolume;
|
16233 |
|
16234 | uniform sampler2D uBlockAtlas;
|
16235 | uniform sampler2D uLightMap;
|
16236 |
|
16237 | uniform vec3 uLightBoxSize;
|
16238 | uniform vec3 uLightBoxMin;
|
16239 | uniform mat4 uModel;
|
16240 |
|
16241 | uniform float uTime;
|
16242 | uniform mat4 uViewProjection;
|
16243 | uniform vec3 uCameraPos;
|
16244 |
|
16245 | void 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 |
|
16255 | out vec3 BoxCoord;
|
16256 |
|
16257 | void 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)
|
16274 | layout (depth_greater) out float gl_FragDepth;
|
16275 | #endif
|
16276 | #endif
|
16277 |
|
16278 | in vec3 BoxCoord;
|
16279 |
|
16280 | out vec4 FragColor;
|
16281 |
|
16282 | vec4 FLWBlockTexture(vec2 texCoords) {
|
16283 | return texture(uBlockAtlas, texCoords);
|
16284 | }
|
16285 |
|
16286 | void 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 |
|
16302 | vec4 FLWLight(vec2 lightCoords) {
|
16303 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
16304 |
|
16305 | return texture(uLightMap, shiftLight(lightCoords));
|
16306 | }
|
16307 |
|
16308 | #endif
|
16309 |
|
16310 |
|
16311 | mat4 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 |
|
16326 | mat4 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 |
|
16330 | mat3 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 |
|
16342 | vec4 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 |
|
16348 | vec4 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 |
|
16358 | vec3 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 |
|
16363 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
16364 | return rotateVertexByQuat(v, quat(axis, angle));
|
16365 | }
|
16366 |
|
16367 | float 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 | }
|
16371 | struct Vertex {
|
16372 | vec3 pos;
|
16373 | vec2 texCoords;
|
16374 | vec3 normal;
|
16375 | };
|
16376 |
|
16377 | struct BlockFrag {
|
16378 | vec2 texCoords;
|
16379 | vec4 color;
|
16380 | float diffuse;
|
16381 | vec2 light;
|
16382 | };
|
16383 |
|
16384 | #if defined(FRAGMENT_SHADER)
|
16385 | void 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 |
|
16399 | struct 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)
|
16413 | BlockFrag 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 |
|
16441 | in vec2 v2f_texCoords;
|
16442 | in vec4 v2f_color;
|
16443 | in float v2f_diffuse;
|
16444 | in vec2 v2f_light;
|
16445 | void main() {
|
16446 | BlockFrag o;
|
16447 | o.texCoords = v2f_texCoords;
|
16448 | o.color = v2f_color;
|
16449 | o.diffuse = v2f_diffuse;
|
16450 | o.light = v2f_light;
|
16451 | fragment(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)
|
16460 | out float FragDistance;
|
16461 | #elif defined(FRAGMENT_SHADER)
|
16462 | in float FragDistance;
|
16463 | #endif
|
16464 | uniform vec4 uFogColor;
|
16465 | uniform vec2 uFogRange;
|
16466 |
|
16467 | float 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 |
|
16473 | float cylindrical_distance(vec3 worldPos) {
|
16474 | float distXZ = length(worldPos.xz);
|
16475 | float distY = abs(worldPos.y);
|
16476 | return max(distXZ, distY);
|
16477 | }
|
16478 |
|
16479 | float 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
|
16483 | vec2 shiftLight(vec2 lm) {
|
16484 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
16485 | }
|
16486 |
|
16487 |
|
16488 | uniform sampler3D uLightVolume;
|
16489 |
|
16490 | uniform sampler2D uBlockAtlas;
|
16491 | uniform sampler2D uLightMap;
|
16492 |
|
16493 | uniform vec3 uLightBoxSize;
|
16494 | uniform vec3 uLightBoxMin;
|
16495 | uniform mat4 uModel;
|
16496 |
|
16497 | uniform float uTime;
|
16498 | uniform mat4 uViewProjection;
|
16499 | uniform vec3 uCameraPos;
|
16500 |
|
16501 | void 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 |
|
16511 | out vec3 BoxCoord;
|
16512 |
|
16513 | void 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)
|
16530 | layout (depth_greater) out float gl_FragDepth;
|
16531 | #endif
|
16532 | #endif
|
16533 |
|
16534 | in vec3 BoxCoord;
|
16535 |
|
16536 | out vec4 FragColor;
|
16537 |
|
16538 | vec4 FLWBlockTexture(vec2 texCoords) {
|
16539 | return texture(uBlockAtlas, texCoords);
|
16540 | }
|
16541 |
|
16542 | void 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 |
|
16558 | vec4 FLWLight(vec2 lightCoords) {
|
16559 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
16560 |
|
16561 | return texture(uLightMap, shiftLight(lightCoords));
|
16562 | }
|
16563 |
|
16564 | #endif
|
16565 |
|
16566 |
|
16567 | mat4 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 |
|
16582 | mat4 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 |
|
16586 | mat3 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 |
|
16598 | vec4 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 |
|
16604 | vec4 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 |
|
16614 | vec3 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 |
|
16619 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
16620 | return rotateVertexByQuat(v, quat(axis, angle));
|
16621 | }
|
16622 |
|
16623 | float 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 | }
|
16627 | struct Vertex {
|
16628 | vec3 pos;
|
16629 | vec2 texCoords;
|
16630 | vec3 normal;
|
16631 | };
|
16632 |
|
16633 | struct BlockFrag {
|
16634 | vec2 texCoords;
|
16635 | vec4 color;
|
16636 | float diffuse;
|
16637 | vec2 light;
|
16638 | };
|
16639 |
|
16640 | #if defined(FRAGMENT_SHADER)
|
16641 | void 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 |
|
16655 | struct 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)
|
16669 | BlockFrag 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 |
|
16697 | in vec3 a_v_pos;
|
16698 | in vec2 a_v_texCoords;
|
16699 | in vec3 a_v_normal;
|
16700 | in vec3 a_i_pos;
|
16701 | in vec2 a_i_light;
|
16702 | in float a_i_offset;
|
16703 | in vec3 a_i_axis;
|
16704 | in vec4 a_i_rotation;
|
16705 | in vec3 a_i_rotationCenter;
|
16706 | in float a_i_speed;
|
16707 | out vec2 v2f_texCoords;
|
16708 | out vec4 v2f_color;
|
16709 | out float v2f_diffuse;
|
16710 | out vec2 v2f_light;
|
16711 | void main() {
|
16712 | Vertex v;
|
16713 | v.pos = a_v_pos;
|
16714 | v.texCoords = a_v_texCoords;
|
16715 | v.normal = a_v_normal;
|
16716 | Actor i;
|
16717 | i.pos = a_i_pos;
|
16718 | i.light = a_i_light;
|
16719 | i.offset = a_i_offset;
|
16720 | i.axis = a_i_axis;
|
16721 | i.rotation = a_i_rotation;
|
16722 | i.rotationCenter = a_i_rotationCenter;
|
16723 | i.speed = a_i_speed;
|
16724 | BlockFrag o = vertex(v, i);
|
16725 | v2f_texCoords = o.texCoords;
|
16726 | v2f_color = o.color;
|
16727 | v2f_diffuse = o.diffuse;
|
16728 | v2f_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)
|
16737 | out float FragDistance;
|
16738 | #elif defined(FRAGMENT_SHADER)
|
16739 | in float FragDistance;
|
16740 | #endif
|
16741 | uniform vec4 uFogColor;
|
16742 | uniform vec2 uFogRange;
|
16743 |
|
16744 | float 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 |
|
16750 | float cylindrical_distance(vec3 worldPos) {
|
16751 | float distXZ = length(worldPos.xz);
|
16752 | float distY = abs(worldPos.y);
|
16753 | return max(distXZ, distY);
|
16754 | }
|
16755 |
|
16756 | float 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
|
16760 | vec2 shiftLight(vec2 lm) {
|
16761 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
16762 | }
|
16763 |
|
16764 |
|
16765 | uniform sampler3D uLightVolume;
|
16766 |
|
16767 | uniform sampler2D uBlockAtlas;
|
16768 | uniform sampler2D uLightMap;
|
16769 |
|
16770 | uniform vec3 uLightBoxSize;
|
16771 | uniform vec3 uLightBoxMin;
|
16772 | uniform mat4 uModel;
|
16773 |
|
16774 | uniform float uTime;
|
16775 | uniform mat4 uViewProjection;
|
16776 | uniform vec3 uCameraPos;
|
16777 |
|
16778 | void 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 |
|
16788 | out vec3 BoxCoord;
|
16789 |
|
16790 | void 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)
|
16807 | layout (depth_greater) out float gl_FragDepth;
|
16808 | #endif
|
16809 | #endif
|
16810 |
|
16811 | in vec3 BoxCoord;
|
16812 |
|
16813 | out vec4 FragColor;
|
16814 |
|
16815 | vec4 FLWBlockTexture(vec2 texCoords) {
|
16816 | return texture(uBlockAtlas, texCoords);
|
16817 | }
|
16818 |
|
16819 | void 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 |
|
16835 | vec4 FLWLight(vec2 lightCoords) {
|
16836 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
16837 |
|
16838 | return texture(uLightMap, shiftLight(lightCoords));
|
16839 | }
|
16840 |
|
16841 | #endif
|
16842 |
|
16843 |
|
16844 | mat4 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 |
|
16859 | mat4 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 |
|
16863 | mat3 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 |
|
16875 | vec4 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 |
|
16881 | vec4 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 |
|
16891 | vec3 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 |
|
16896 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
16897 | return rotateVertexByQuat(v, quat(axis, angle));
|
16898 | }
|
16899 |
|
16900 | float 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 | }
|
16904 | struct Vertex {
|
16905 | vec3 pos;
|
16906 | vec2 texCoords;
|
16907 | vec3 normal;
|
16908 | };
|
16909 |
|
16910 | struct BlockFrag {
|
16911 | vec2 texCoords;
|
16912 | vec4 color;
|
16913 | float diffuse;
|
16914 | vec2 light;
|
16915 | };
|
16916 |
|
16917 | #if defined(FRAGMENT_SHADER)
|
16918 | void 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 |
|
16932 | struct 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)
|
16946 | BlockFrag 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 |
|
16974 | in vec2 v2f_texCoords;
|
16975 | in vec4 v2f_color;
|
16976 | in float v2f_diffuse;
|
16977 | in vec2 v2f_light;
|
16978 | void main() {
|
16979 | BlockFrag o;
|
16980 | o.texCoords = v2f_texCoords;
|
16981 | o.color = v2f_color;
|
16982 | o.diffuse = v2f_diffuse;
|
16983 | o.light = v2f_light;
|
16984 | fragment(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)
|
16992 | out float FragDistance;
|
16993 | #elif defined(FRAGMENT_SHADER)
|
16994 | in float FragDistance;
|
16995 | #endif
|
16996 | uniform vec4 uFogColor;
|
16997 | uniform vec2 uFogRange;
|
16998 |
|
16999 | float 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 |
|
17005 | float cylindrical_distance(vec3 worldPos) {
|
17006 | float distXZ = length(worldPos.xz);
|
17007 | float distY = abs(worldPos.y);
|
17008 | return max(distXZ, distY);
|
17009 | }
|
17010 |
|
17011 | float 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
|
17015 | vec2 shiftLight(vec2 lm) {
|
17016 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
17017 | }
|
17018 |
|
17019 |
|
17020 | uniform sampler3D uLightVolume;
|
17021 |
|
17022 | uniform sampler2D uBlockAtlas;
|
17023 | uniform sampler2D uLightMap;
|
17024 |
|
17025 | uniform vec3 uLightBoxSize;
|
17026 | uniform vec3 uLightBoxMin;
|
17027 | uniform mat4 uModel;
|
17028 |
|
17029 | uniform float uTime;
|
17030 | uniform mat4 uViewProjection;
|
17031 | uniform vec3 uCameraPos;
|
17032 |
|
17033 | void 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 |
|
17043 | out vec3 BoxCoord;
|
17044 |
|
17045 | void 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)
|
17062 | layout (depth_greater) out float gl_FragDepth;
|
17063 | #endif
|
17064 | #endif
|
17065 |
|
17066 | in vec3 BoxCoord;
|
17067 |
|
17068 | out vec4 FragColor;
|
17069 |
|
17070 | vec4 FLWBlockTexture(vec2 texCoords) {
|
17071 | return texture(uBlockAtlas, texCoords);
|
17072 | }
|
17073 |
|
17074 | void 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 |
|
17090 | vec4 FLWLight(vec2 lightCoords) {
|
17091 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
17092 |
|
17093 | return texture(uLightMap, shiftLight(lightCoords));
|
17094 | }
|
17095 |
|
17096 | #endif
|
17097 |
|
17098 |
|
17099 | mat4 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 |
|
17114 | mat4 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 |
|
17118 | mat3 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 |
|
17130 | vec4 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 |
|
17136 | vec4 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 |
|
17146 | vec3 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 |
|
17151 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
17152 | return rotateVertexByQuat(v, quat(axis, angle));
|
17153 | }
|
17154 |
|
17155 | float 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 | }
|
17159 | struct Vertex {
|
17160 | vec3 pos;
|
17161 | vec2 texCoords;
|
17162 | vec3 normal;
|
17163 | };
|
17164 |
|
17165 | struct BlockFrag {
|
17166 | vec2 texCoords;
|
17167 | vec4 color;
|
17168 | float diffuse;
|
17169 | vec2 light;
|
17170 | };
|
17171 |
|
17172 | #if defined(FRAGMENT_SHADER)
|
17173 | void 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 |
|
17187 | struct 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 |
|
17203 | float toRad(float degrees) {
|
17204 | return fract(degrees / 360.) * PI * 2.;
|
17205 | }
|
17206 |
|
17207 | float 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 |
|
17220 | BlockFrag 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 |
|
17248 | in vec3 a_v_pos;
|
17249 | in vec2 a_v_texCoords;
|
17250 | in vec3 a_v_normal;
|
17251 | in vec3 a_i_instancePos;
|
17252 | in vec2 a_i_light;
|
17253 | in vec3 a_i_segmentOffset;
|
17254 | in vec3 a_i_pivot;
|
17255 | in float a_i_horizontalAngle;
|
17256 | in float a_i_intensity;
|
17257 | in float a_i_flapScale;
|
17258 | in float a_i_flapness;
|
17259 | out vec2 v2f_texCoords;
|
17260 | out vec4 v2f_color;
|
17261 | out float v2f_diffuse;
|
17262 | out vec2 v2f_light;
|
17263 | void main() {
|
17264 | Vertex v;
|
17265 | v.pos = a_v_pos;
|
17266 | v.texCoords = a_v_texCoords;
|
17267 | v.normal = a_v_normal;
|
17268 | Flap i;
|
17269 | i.instancePos = a_i_instancePos;
|
17270 | i.light = a_i_light;
|
17271 | i.segmentOffset = a_i_segmentOffset;
|
17272 | i.pivot = a_i_pivot;
|
17273 | i.horizontalAngle = a_i_horizontalAngle;
|
17274 | i.intensity = a_i_intensity;
|
17275 | i.flapScale = a_i_flapScale;
|
17276 | i.flapness = a_i_flapness;
|
17277 | BlockFrag o = vertex(v, i);
|
17278 | v2f_texCoords = o.texCoords;
|
17279 | v2f_color = o.color;
|
17280 | v2f_diffuse = o.diffuse;
|
17281 | v2f_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)
|
17289 | out float FragDistance;
|
17290 | #elif defined(FRAGMENT_SHADER)
|
17291 | in float FragDistance;
|
17292 | #endif
|
17293 | uniform vec4 uFogColor;
|
17294 | uniform vec2 uFogRange;
|
17295 |
|
17296 | float 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 |
|
17302 | float cylindrical_distance(vec3 worldPos) {
|
17303 | float distXZ = length(worldPos.xz);
|
17304 | float distY = abs(worldPos.y);
|
17305 | return max(distXZ, distY);
|
17306 | }
|
17307 |
|
17308 | float 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
|
17312 | vec2 shiftLight(vec2 lm) {
|
17313 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
17314 | }
|
17315 |
|
17316 |
|
17317 | uniform sampler3D uLightVolume;
|
17318 |
|
17319 | uniform sampler2D uBlockAtlas;
|
17320 | uniform sampler2D uLightMap;
|
17321 |
|
17322 | uniform vec3 uLightBoxSize;
|
17323 | uniform vec3 uLightBoxMin;
|
17324 | uniform mat4 uModel;
|
17325 |
|
17326 | uniform float uTime;
|
17327 | uniform mat4 uViewProjection;
|
17328 | uniform vec3 uCameraPos;
|
17329 |
|
17330 | void 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 |
|
17340 | out vec3 BoxCoord;
|
17341 |
|
17342 | void 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)
|
17359 | layout (depth_greater) out float gl_FragDepth;
|
17360 | #endif
|
17361 | #endif
|
17362 |
|
17363 | in vec3 BoxCoord;
|
17364 |
|
17365 | out vec4 FragColor;
|
17366 |
|
17367 | vec4 FLWBlockTexture(vec2 texCoords) {
|
17368 | return texture(uBlockAtlas, texCoords);
|
17369 | }
|
17370 |
|
17371 | void 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 |
|
17387 | vec4 FLWLight(vec2 lightCoords) {
|
17388 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
17389 |
|
17390 | return texture(uLightMap, shiftLight(lightCoords));
|
17391 | }
|
17392 |
|
17393 | #endif
|
17394 |
|
17395 |
|
17396 | mat4 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 |
|
17411 | mat4 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 |
|
17415 | mat3 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 |
|
17427 | vec4 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 |
|
17433 | vec4 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 |
|
17443 | vec3 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 |
|
17448 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
17449 | return rotateVertexByQuat(v, quat(axis, angle));
|
17450 | }
|
17451 |
|
17452 | float 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 | }
|
17456 | struct Vertex {
|
17457 | vec3 pos;
|
17458 | vec2 texCoords;
|
17459 | vec3 normal;
|
17460 | };
|
17461 |
|
17462 | struct BlockFrag {
|
17463 | vec2 texCoords;
|
17464 | vec4 color;
|
17465 | float diffuse;
|
17466 | vec2 light;
|
17467 | };
|
17468 |
|
17469 | #if defined(FRAGMENT_SHADER)
|
17470 | void 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 |
|
17484 | struct 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 |
|
17500 | float toRad(float degrees) {
|
17501 | return fract(degrees / 360.) * PI * 2.;
|
17502 | }
|
17503 |
|
17504 | float 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 |
|
17517 | BlockFrag 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 |
|
17545 | in vec2 v2f_texCoords;
|
17546 | in vec4 v2f_color;
|
17547 | in float v2f_diffuse;
|
17548 | in vec2 v2f_light;
|
17549 | void main() {
|
17550 | BlockFrag o;
|
17551 | o.texCoords = v2f_texCoords;
|
17552 | o.color = v2f_color;
|
17553 | o.diffuse = v2f_diffuse;
|
17554 | o.light = v2f_light;
|
17555 | fragment(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)
|
17564 | out float FragDistance;
|
17565 | #elif defined(FRAGMENT_SHADER)
|
17566 | in float FragDistance;
|
17567 | #endif
|
17568 | uniform vec4 uFogColor;
|
17569 | uniform vec2 uFogRange;
|
17570 |
|
17571 | float 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 |
|
17577 | float cylindrical_distance(vec3 worldPos) {
|
17578 | float distXZ = length(worldPos.xz);
|
17579 | float distY = abs(worldPos.y);
|
17580 | return max(distXZ, distY);
|
17581 | }
|
17582 |
|
17583 | float 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
|
17587 | vec2 shiftLight(vec2 lm) {
|
17588 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
17589 | }
|
17590 |
|
17591 |
|
17592 | uniform sampler3D uLightVolume;
|
17593 |
|
17594 | uniform sampler2D uBlockAtlas;
|
17595 | uniform sampler2D uLightMap;
|
17596 |
|
17597 | uniform vec3 uLightBoxSize;
|
17598 | uniform vec3 uLightBoxMin;
|
17599 | uniform mat4 uModel;
|
17600 |
|
17601 | uniform float uTime;
|
17602 | uniform mat4 uViewProjection;
|
17603 | uniform vec3 uCameraPos;
|
17604 |
|
17605 | void 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 |
|
17615 | out vec3 BoxCoord;
|
17616 |
|
17617 | void 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)
|
17634 | layout (depth_greater) out float gl_FragDepth;
|
17635 | #endif
|
17636 | #endif
|
17637 |
|
17638 | in vec3 BoxCoord;
|
17639 |
|
17640 | out vec4 FragColor;
|
17641 |
|
17642 | vec4 FLWBlockTexture(vec2 texCoords) {
|
17643 | return texture(uBlockAtlas, texCoords);
|
17644 | }
|
17645 |
|
17646 | void 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 |
|
17662 | vec4 FLWLight(vec2 lightCoords) {
|
17663 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
17664 |
|
17665 | return texture(uLightMap, shiftLight(lightCoords));
|
17666 | }
|
17667 |
|
17668 | #endif
|
17669 |
|
17670 |
|
17671 | mat4 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 |
|
17686 | mat4 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 |
|
17690 | mat3 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 |
|
17702 | vec4 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 |
|
17708 | vec4 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 |
|
17718 | vec3 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 |
|
17723 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
17724 | return rotateVertexByQuat(v, quat(axis, angle));
|
17725 | }
|
17726 |
|
17727 | float 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 | }
|
17731 | struct Vertex {
|
17732 | vec3 pos;
|
17733 | vec2 texCoords;
|
17734 | vec3 normal;
|
17735 | };
|
17736 |
|
17737 | struct BlockFrag {
|
17738 | vec2 texCoords;
|
17739 | vec4 color;
|
17740 | float diffuse;
|
17741 | vec2 light;
|
17742 | };
|
17743 |
|
17744 | #if defined(FRAGMENT_SHADER)
|
17745 | void 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 |
|
17759 | struct 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 |
|
17775 | float toRad(float degrees) {
|
17776 | return fract(degrees / 360.) * PI * 2.;
|
17777 | }
|
17778 |
|
17779 | float 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 |
|
17792 | BlockFrag 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 |
|
17820 | in vec3 a_v_pos;
|
17821 | in vec2 a_v_texCoords;
|
17822 | in vec3 a_v_normal;
|
17823 | in vec3 a_i_instancePos;
|
17824 | in vec2 a_i_light;
|
17825 | in vec3 a_i_segmentOffset;
|
17826 | in vec3 a_i_pivot;
|
17827 | in float a_i_horizontalAngle;
|
17828 | in float a_i_intensity;
|
17829 | in float a_i_flapScale;
|
17830 | in float a_i_flapness;
|
17831 | out vec2 v2f_texCoords;
|
17832 | out vec4 v2f_color;
|
17833 | out float v2f_diffuse;
|
17834 | out vec2 v2f_light;
|
17835 | void main() {
|
17836 | Vertex v;
|
17837 | v.pos = a_v_pos;
|
17838 | v.texCoords = a_v_texCoords;
|
17839 | v.normal = a_v_normal;
|
17840 | Flap i;
|
17841 | i.instancePos = a_i_instancePos;
|
17842 | i.light = a_i_light;
|
17843 | i.segmentOffset = a_i_segmentOffset;
|
17844 | i.pivot = a_i_pivot;
|
17845 | i.horizontalAngle = a_i_horizontalAngle;
|
17846 | i.intensity = a_i_intensity;
|
17847 | i.flapScale = a_i_flapScale;
|
17848 | i.flapness = a_i_flapness;
|
17849 | BlockFrag o = vertex(v, i);
|
17850 | v2f_texCoords = o.texCoords;
|
17851 | v2f_color = o.color;
|
17852 | v2f_diffuse = o.diffuse;
|
17853 | v2f_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)
|
17862 | out float FragDistance;
|
17863 | #elif defined(FRAGMENT_SHADER)
|
17864 | in float FragDistance;
|
17865 | #endif
|
17866 | uniform vec4 uFogColor;
|
17867 | uniform vec2 uFogRange;
|
17868 |
|
17869 | float 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 |
|
17875 | float cylindrical_distance(vec3 worldPos) {
|
17876 | float distXZ = length(worldPos.xz);
|
17877 | float distY = abs(worldPos.y);
|
17878 | return max(distXZ, distY);
|
17879 | }
|
17880 |
|
17881 | float 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
|
17885 | vec2 shiftLight(vec2 lm) {
|
17886 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
17887 | }
|
17888 |
|
17889 |
|
17890 | uniform sampler3D uLightVolume;
|
17891 |
|
17892 | uniform sampler2D uBlockAtlas;
|
17893 | uniform sampler2D uLightMap;
|
17894 |
|
17895 | uniform vec3 uLightBoxSize;
|
17896 | uniform vec3 uLightBoxMin;
|
17897 | uniform mat4 uModel;
|
17898 |
|
17899 | uniform float uTime;
|
17900 | uniform mat4 uViewProjection;
|
17901 | uniform vec3 uCameraPos;
|
17902 |
|
17903 | void 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 |
|
17913 | out vec3 BoxCoord;
|
17914 |
|
17915 | void 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)
|
17932 | layout (depth_greater) out float gl_FragDepth;
|
17933 | #endif
|
17934 | #endif
|
17935 |
|
17936 | in vec3 BoxCoord;
|
17937 |
|
17938 | out vec4 FragColor;
|
17939 |
|
17940 | vec4 FLWBlockTexture(vec2 texCoords) {
|
17941 | return texture(uBlockAtlas, texCoords);
|
17942 | }
|
17943 |
|
17944 | void 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 |
|
17960 | vec4 FLWLight(vec2 lightCoords) {
|
17961 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
17962 |
|
17963 | return texture(uLightMap, shiftLight(lightCoords));
|
17964 | }
|
17965 |
|
17966 | #endif
|
17967 |
|
17968 |
|
17969 | mat4 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 |
|
17984 | mat4 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 |
|
17988 | mat3 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 |
|
18000 | vec4 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 |
|
18006 | vec4 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 |
|
18016 | vec3 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 |
|
18021 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
18022 | return rotateVertexByQuat(v, quat(axis, angle));
|
18023 | }
|
18024 |
|
18025 | float 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 | }
|
18029 | struct Vertex {
|
18030 | vec3 pos;
|
18031 | vec2 texCoords;
|
18032 | vec3 normal;
|
18033 | };
|
18034 |
|
18035 | struct BlockFrag {
|
18036 | vec2 texCoords;
|
18037 | vec4 color;
|
18038 | float diffuse;
|
18039 | vec2 light;
|
18040 | };
|
18041 |
|
18042 | #if defined(FRAGMENT_SHADER)
|
18043 | void 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 |
|
18057 | struct 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 |
|
18073 | float toRad(float degrees) {
|
18074 | return fract(degrees / 360.) * PI * 2.;
|
18075 | }
|
18076 |
|
18077 | float 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 |
|
18090 | BlockFrag 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 |
|
18118 | in vec2 v2f_texCoords;
|
18119 | in vec4 v2f_color;
|
18120 | in float v2f_diffuse;
|
18121 | in vec2 v2f_light;
|
18122 | void main() {
|
18123 | BlockFrag o;
|
18124 | o.texCoords = v2f_texCoords;
|
18125 | o.color = v2f_color;
|
18126 | o.diffuse = v2f_diffuse;
|
18127 | o.light = v2f_light;
|
18128 | fragment(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)
|
18136 | out float FragDistance;
|
18137 | #elif defined(FRAGMENT_SHADER)
|
18138 | in float FragDistance;
|
18139 | #endif
|
18140 | uniform vec4 uFogColor;
|
18141 | uniform vec2 uFogRange;
|
18142 |
|
18143 | float 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 |
|
18149 | float cylindrical_distance(vec3 worldPos) {
|
18150 | float distXZ = length(worldPos.xz);
|
18151 | float distY = abs(worldPos.y);
|
18152 | return max(distXZ, distY);
|
18153 | }
|
18154 |
|
18155 | float 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
|
18159 | vec2 shiftLight(vec2 lm) {
|
18160 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
18161 | }
|
18162 |
|
18163 |
|
18164 | uniform sampler3D uLightVolume;
|
18165 |
|
18166 | uniform sampler2D uBlockAtlas;
|
18167 | uniform sampler2D uLightMap;
|
18168 |
|
18169 | uniform vec3 uLightBoxSize;
|
18170 | uniform vec3 uLightBoxMin;
|
18171 | uniform mat4 uModel;
|
18172 |
|
18173 | uniform float uTime;
|
18174 | uniform mat4 uViewProjection;
|
18175 | uniform vec3 uCameraPos;
|
18176 |
|
18177 | void 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 |
|
18187 | out vec3 BoxCoord;
|
18188 |
|
18189 | void 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)
|
18206 | layout (depth_greater) out float gl_FragDepth;
|
18207 | #endif
|
18208 | #endif
|
18209 |
|
18210 | in vec3 BoxCoord;
|
18211 |
|
18212 | out vec4 FragColor;
|
18213 |
|
18214 | vec4 FLWBlockTexture(vec2 texCoords) {
|
18215 | return texture(uBlockAtlas, texCoords);
|
18216 | }
|
18217 |
|
18218 | void 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 |
|
18234 | vec4 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 |
|
18245 | vec4 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 |
|
18251 | vec4 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 |
|
18261 | vec3 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 |
|
18266 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
18267 | return rotateVertexByQuat(v, quat(axis, angle));
|
18268 | }
|
18269 |
|
18270 | mat4 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 |
|
18285 | mat4 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 |
|
18289 | mat3 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 |
|
18299 | float 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 | }
|
18303 | struct Vertex {
|
18304 | vec3 pos;
|
18305 | vec2 texCoords;
|
18306 | vec3 normal;
|
18307 | };
|
18308 |
|
18309 | struct BlockFrag {
|
18310 | vec2 texCoords;
|
18311 | vec4 color;
|
18312 | float diffuse;
|
18313 | vec2 light;
|
18314 | };
|
18315 |
|
18316 | #if defined(FRAGMENT_SHADER)
|
18317 | void 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 |
|
18331 | struct 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)
|
18347 | BlockFrag 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 |
|
18377 | in vec3 a_v_pos;
|
18378 | in vec2 a_v_texCoords;
|
18379 | in vec3 a_v_normal;
|
18380 | in vec2 a_i_light;
|
18381 | in vec4 a_i_color;
|
18382 | in vec3 a_i_pos;
|
18383 | in float a_i_speed;
|
18384 | in float a_i_offset;
|
18385 | in vec4 a_i_rotation;
|
18386 | in vec2 a_i_sourceTexture;
|
18387 | in vec4 a_i_scrollTexture;
|
18388 | in float a_i_scrollMult;
|
18389 | out vec2 v2f_texCoords;
|
18390 | out vec4 v2f_color;
|
18391 | out float v2f_diffuse;
|
18392 | out vec2 v2f_light;
|
18393 | void main() {
|
18394 | Vertex v;
|
18395 | v.pos = a_v_pos;
|
18396 | v.texCoords = a_v_texCoords;
|
18397 | v.normal = a_v_normal;
|
18398 | Belt i;
|
18399 | i.light = a_i_light;
|
18400 | i.color = a_i_color;
|
18401 | i.pos = a_i_pos;
|
18402 | i.speed = a_i_speed;
|
18403 | i.offset = a_i_offset;
|
18404 | i.rotation = a_i_rotation;
|
18405 | i.sourceTexture = a_i_sourceTexture;
|
18406 | i.scrollTexture = a_i_scrollTexture;
|
18407 | i.scrollMult = a_i_scrollMult;
|
18408 | BlockFrag o = vertex(v, i);
|
18409 | v2f_texCoords = o.texCoords;
|
18410 | v2f_color = o.color;
|
18411 | v2f_diffuse = o.diffuse;
|
18412 | v2f_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)
|
18420 | out float FragDistance;
|
18421 | #elif defined(FRAGMENT_SHADER)
|
18422 | in float FragDistance;
|
18423 | #endif
|
18424 | uniform vec4 uFogColor;
|
18425 | uniform vec2 uFogRange;
|
18426 |
|
18427 | float 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 |
|
18433 | float cylindrical_distance(vec3 worldPos) {
|
18434 | float distXZ = length(worldPos.xz);
|
18435 | float distY = abs(worldPos.y);
|
18436 | return max(distXZ, distY);
|
18437 | }
|
18438 |
|
18439 | float 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
|
18443 | vec2 shiftLight(vec2 lm) {
|
18444 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
18445 | }
|
18446 |
|
18447 |
|
18448 | uniform sampler3D uLightVolume;
|
18449 |
|
18450 | uniform sampler2D uBlockAtlas;
|
18451 | uniform sampler2D uLightMap;
|
18452 |
|
18453 | uniform vec3 uLightBoxSize;
|
18454 | uniform vec3 uLightBoxMin;
|
18455 | uniform mat4 uModel;
|
18456 |
|
18457 | uniform float uTime;
|
18458 | uniform mat4 uViewProjection;
|
18459 | uniform vec3 uCameraPos;
|
18460 |
|
18461 | void 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 |
|
18471 | out vec3 BoxCoord;
|
18472 |
|
18473 | void 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)
|
18490 | layout (depth_greater) out float gl_FragDepth;
|
18491 | #endif
|
18492 | #endif
|
18493 |
|
18494 | in vec3 BoxCoord;
|
18495 |
|
18496 | out vec4 FragColor;
|
18497 |
|
18498 | vec4 FLWBlockTexture(vec2 texCoords) {
|
18499 | return texture(uBlockAtlas, texCoords);
|
18500 | }
|
18501 |
|
18502 | void 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 |
|
18518 | vec4 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 |
|
18529 | vec4 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 |
|
18535 | vec4 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 |
|
18545 | vec3 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 |
|
18550 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
18551 | return rotateVertexByQuat(v, quat(axis, angle));
|
18552 | }
|
18553 |
|
18554 | mat4 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 |
|
18569 | mat4 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 |
|
18573 | mat3 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 |
|
18583 | float 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 | }
|
18587 | struct Vertex {
|
18588 | vec3 pos;
|
18589 | vec2 texCoords;
|
18590 | vec3 normal;
|
18591 | };
|
18592 |
|
18593 | struct BlockFrag {
|
18594 | vec2 texCoords;
|
18595 | vec4 color;
|
18596 | float diffuse;
|
18597 | vec2 light;
|
18598 | };
|
18599 |
|
18600 | #if defined(FRAGMENT_SHADER)
|
18601 | void 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 |
|
18615 | struct 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)
|
18631 | BlockFrag 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 |
|
18661 | in vec2 v2f_texCoords;
|
18662 | in vec4 v2f_color;
|
18663 | in float v2f_diffuse;
|
18664 | in vec2 v2f_light;
|
18665 | void main() {
|
18666 | BlockFrag o;
|
18667 | o.texCoords = v2f_texCoords;
|
18668 | o.color = v2f_color;
|
18669 | o.diffuse = v2f_diffuse;
|
18670 | o.light = v2f_light;
|
18671 | fragment(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)
|
18680 | out float FragDistance;
|
18681 | #elif defined(FRAGMENT_SHADER)
|
18682 | in float FragDistance;
|
18683 | #endif
|
18684 | uniform vec4 uFogColor;
|
18685 | uniform vec2 uFogRange;
|
18686 |
|
18687 | float 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 |
|
18693 | float cylindrical_distance(vec3 worldPos) {
|
18694 | float distXZ = length(worldPos.xz);
|
18695 | float distY = abs(worldPos.y);
|
18696 | return max(distXZ, distY);
|
18697 | }
|
18698 |
|
18699 | float 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
|
18703 | vec2 shiftLight(vec2 lm) {
|
18704 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
18705 | }
|
18706 |
|
18707 |
|
18708 | uniform sampler3D uLightVolume;
|
18709 |
|
18710 | uniform sampler2D uBlockAtlas;
|
18711 | uniform sampler2D uLightMap;
|
18712 |
|
18713 | uniform vec3 uLightBoxSize;
|
18714 | uniform vec3 uLightBoxMin;
|
18715 | uniform mat4 uModel;
|
18716 |
|
18717 | uniform float uTime;
|
18718 | uniform mat4 uViewProjection;
|
18719 | uniform vec3 uCameraPos;
|
18720 |
|
18721 | void 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 |
|
18731 | out vec3 BoxCoord;
|
18732 |
|
18733 | void 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)
|
18750 | layout (depth_greater) out float gl_FragDepth;
|
18751 | #endif
|
18752 | #endif
|
18753 |
|
18754 | in vec3 BoxCoord;
|
18755 |
|
18756 | out vec4 FragColor;
|
18757 |
|
18758 | vec4 FLWBlockTexture(vec2 texCoords) {
|
18759 | return texture(uBlockAtlas, texCoords);
|
18760 | }
|
18761 |
|
18762 | void 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 |
|
18778 | vec4 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 |
|
18789 | vec4 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 |
|
18795 | vec4 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 |
|
18805 | vec3 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 |
|
18810 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
18811 | return rotateVertexByQuat(v, quat(axis, angle));
|
18812 | }
|
18813 |
|
18814 | mat4 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 |
|
18829 | mat4 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 |
|
18833 | mat3 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 |
|
18843 | float 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 | }
|
18847 | struct Vertex {
|
18848 | vec3 pos;
|
18849 | vec2 texCoords;
|
18850 | vec3 normal;
|
18851 | };
|
18852 |
|
18853 | struct BlockFrag {
|
18854 | vec2 texCoords;
|
18855 | vec4 color;
|
18856 | float diffuse;
|
18857 | vec2 light;
|
18858 | };
|
18859 |
|
18860 | #if defined(FRAGMENT_SHADER)
|
18861 | void 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 |
|
18875 | struct 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)
|
18891 | BlockFrag 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 |
|
18921 | in vec3 a_v_pos;
|
18922 | in vec2 a_v_texCoords;
|
18923 | in vec3 a_v_normal;
|
18924 | in vec2 a_i_light;
|
18925 | in vec4 a_i_color;
|
18926 | in vec3 a_i_pos;
|
18927 | in float a_i_speed;
|
18928 | in float a_i_offset;
|
18929 | in vec4 a_i_rotation;
|
18930 | in vec2 a_i_sourceTexture;
|
18931 | in vec4 a_i_scrollTexture;
|
18932 | in float a_i_scrollMult;
|
18933 | out vec2 v2f_texCoords;
|
18934 | out vec4 v2f_color;
|
18935 | out float v2f_diffuse;
|
18936 | out vec2 v2f_light;
|
18937 | void main() {
|
18938 | Vertex v;
|
18939 | v.pos = a_v_pos;
|
18940 | v.texCoords = a_v_texCoords;
|
18941 | v.normal = a_v_normal;
|
18942 | Belt i;
|
18943 | i.light = a_i_light;
|
18944 | i.color = a_i_color;
|
18945 | i.pos = a_i_pos;
|
18946 | i.speed = a_i_speed;
|
18947 | i.offset = a_i_offset;
|
18948 | i.rotation = a_i_rotation;
|
18949 | i.sourceTexture = a_i_sourceTexture;
|
18950 | i.scrollTexture = a_i_scrollTexture;
|
18951 | i.scrollMult = a_i_scrollMult;
|
18952 | BlockFrag o = vertex(v, i);
|
18953 | v2f_texCoords = o.texCoords;
|
18954 | v2f_color = o.color;
|
18955 | v2f_diffuse = o.diffuse;
|
18956 | v2f_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)
|
18965 | out float FragDistance;
|
18966 | #elif defined(FRAGMENT_SHADER)
|
18967 | in float FragDistance;
|
18968 | #endif
|
18969 | uniform vec4 uFogColor;
|
18970 | uniform vec2 uFogRange;
|
18971 |
|
18972 | float 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 |
|
18978 | float cylindrical_distance(vec3 worldPos) {
|
18979 | float distXZ = length(worldPos.xz);
|
18980 | float distY = abs(worldPos.y);
|
18981 | return max(distXZ, distY);
|
18982 | }
|
18983 |
|
18984 | float 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
|
18988 | vec2 shiftLight(vec2 lm) {
|
18989 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
18990 | }
|
18991 |
|
18992 |
|
18993 | uniform sampler3D uLightVolume;
|
18994 |
|
18995 | uniform sampler2D uBlockAtlas;
|
18996 | uniform sampler2D uLightMap;
|
18997 |
|
18998 | uniform vec3 uLightBoxSize;
|
18999 | uniform vec3 uLightBoxMin;
|
19000 | uniform mat4 uModel;
|
19001 |
|
19002 | uniform float uTime;
|
19003 | uniform mat4 uViewProjection;
|
19004 | uniform vec3 uCameraPos;
|
19005 |
|
19006 | void 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 |
|
19016 | out vec3 BoxCoord;
|
19017 |
|
19018 | void 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)
|
19035 | layout (depth_greater) out float gl_FragDepth;
|
19036 | #endif
|
19037 | #endif
|
19038 |
|
19039 | in vec3 BoxCoord;
|
19040 |
|
19041 | out vec4 FragColor;
|
19042 |
|
19043 | vec4 FLWBlockTexture(vec2 texCoords) {
|
19044 | return texture(uBlockAtlas, texCoords);
|
19045 | }
|
19046 |
|
19047 | void 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 |
|
19063 | vec4 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 |
|
19074 | vec4 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 |
|
19080 | vec4 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 |
|
19090 | vec3 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 |
|
19095 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
19096 | return rotateVertexByQuat(v, quat(axis, angle));
|
19097 | }
|
19098 |
|
19099 | mat4 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 |
|
19114 | mat4 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 |
|
19118 | mat3 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 |
|
19128 | float 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 | }
|
19132 | struct Vertex {
|
19133 | vec3 pos;
|
19134 | vec2 texCoords;
|
19135 | vec3 normal;
|
19136 | };
|
19137 |
|
19138 | struct BlockFrag {
|
19139 | vec2 texCoords;
|
19140 | vec4 color;
|
19141 | float diffuse;
|
19142 | vec2 light;
|
19143 | };
|
19144 |
|
19145 | #if defined(FRAGMENT_SHADER)
|
19146 | void 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 |
|
19160 | struct 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)
|
19176 | BlockFrag 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 |
|
19206 | in vec2 v2f_texCoords;
|
19207 | in vec4 v2f_color;
|
19208 | in float v2f_diffuse;
|
19209 | in vec2 v2f_light;
|
19210 | void main() {
|
19211 | BlockFrag o;
|
19212 | o.texCoords = v2f_texCoords;
|
19213 | o.color = v2f_color;
|
19214 | o.diffuse = v2f_diffuse;
|
19215 | o.light = v2f_light;
|
19216 | fragment(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)
|
19225 | out float FragDistance;
|
19226 | #elif defined(FRAGMENT_SHADER)
|
19227 | in float FragDistance;
|
19228 | #endif
|
19229 | uniform vec4 uFogColor;
|
19230 | uniform vec2 uFogRange;
|
19231 |
|
19232 | float 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 |
|
19238 | float cylindrical_distance(vec3 worldPos) {
|
19239 | float distXZ = length(worldPos.xz);
|
19240 | float distY = abs(worldPos.y);
|
19241 | return max(distXZ, distY);
|
19242 | }
|
19243 |
|
19244 | float 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
|
19248 | vec2 shiftLight(vec2 lm) {
|
19249 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
19250 | }
|
19251 |
|
19252 |
|
19253 | uniform sampler3D uLightVolume;
|
19254 |
|
19255 | uniform sampler2D uBlockAtlas;
|
19256 | uniform sampler2D uLightMap;
|
19257 |
|
19258 | uniform vec3 uLightBoxSize;
|
19259 | uniform vec3 uLightBoxMin;
|
19260 | uniform mat4 uModel;
|
19261 |
|
19262 | uniform float uTime;
|
19263 | uniform mat4 uViewProjection;
|
19264 | uniform vec3 uCameraPos;
|
19265 |
|
19266 | void 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 |
|
19276 | out vec3 BoxCoord;
|
19277 |
|
19278 | void 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)
|
19295 | layout (depth_greater) out float gl_FragDepth;
|
19296 | #endif
|
19297 | #endif
|
19298 |
|
19299 | in vec3 BoxCoord;
|
19300 |
|
19301 | out vec4 FragColor;
|
19302 |
|
19303 | vec4 FLWBlockTexture(vec2 texCoords) {
|
19304 | return texture(uBlockAtlas, texCoords);
|
19305 | }
|
19306 |
|
19307 | void 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 |
|
19323 | vec4 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 |
|
19334 | vec4 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 |
|
19340 | vec4 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 |
|
19350 | vec3 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 |
|
19355 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
19356 | return rotateVertexByQuat(v, quat(axis, angle));
|
19357 | }
|
19358 |
|
19359 | mat4 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 |
|
19374 | mat4 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 |
|
19378 | mat3 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 |
|
19388 | float 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 | }
|
19392 | struct Vertex {
|
19393 | vec3 pos;
|
19394 | vec2 texCoords;
|
19395 | vec3 normal;
|
19396 | };
|
19397 |
|
19398 | struct BlockFrag {
|
19399 | vec2 texCoords;
|
19400 | vec4 color;
|
19401 | float diffuse;
|
19402 | vec2 light;
|
19403 | };
|
19404 |
|
19405 | #if defined(FRAGMENT_SHADER)
|
19406 | void 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 |
|
19420 | struct 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)
|
19436 | BlockFrag 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 |
|
19466 | in vec3 a_v_pos;
|
19467 | in vec2 a_v_texCoords;
|
19468 | in vec3 a_v_normal;
|
19469 | in vec2 a_i_light;
|
19470 | in vec4 a_i_color;
|
19471 | in vec3 a_i_pos;
|
19472 | in float a_i_speed;
|
19473 | in float a_i_offset;
|
19474 | in vec4 a_i_rotation;
|
19475 | in vec2 a_i_sourceTexture;
|
19476 | in vec4 a_i_scrollTexture;
|
19477 | in float a_i_scrollMult;
|
19478 | out vec2 v2f_texCoords;
|
19479 | out vec4 v2f_color;
|
19480 | out float v2f_diffuse;
|
19481 | out vec2 v2f_light;
|
19482 | void main() {
|
19483 | Vertex v;
|
19484 | v.pos = a_v_pos;
|
19485 | v.texCoords = a_v_texCoords;
|
19486 | v.normal = a_v_normal;
|
19487 | Belt i;
|
19488 | i.light = a_i_light;
|
19489 | i.color = a_i_color;
|
19490 | i.pos = a_i_pos;
|
19491 | i.speed = a_i_speed;
|
19492 | i.offset = a_i_offset;
|
19493 | i.rotation = a_i_rotation;
|
19494 | i.sourceTexture = a_i_sourceTexture;
|
19495 | i.scrollTexture = a_i_scrollTexture;
|
19496 | i.scrollMult = a_i_scrollMult;
|
19497 | BlockFrag o = vertex(v, i);
|
19498 | v2f_texCoords = o.texCoords;
|
19499 | v2f_color = o.color;
|
19500 | v2f_diffuse = o.diffuse;
|
19501 | v2f_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)
|
19510 | out float FragDistance;
|
19511 | #elif defined(FRAGMENT_SHADER)
|
19512 | in float FragDistance;
|
19513 | #endif
|
19514 | uniform vec4 uFogColor;
|
19515 | uniform vec2 uFogRange;
|
19516 |
|
19517 | float 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 |
|
19523 | float cylindrical_distance(vec3 worldPos) {
|
19524 | float distXZ = length(worldPos.xz);
|
19525 | float distY = abs(worldPos.y);
|
19526 | return max(distXZ, distY);
|
19527 | }
|
19528 |
|
19529 | float 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
|
19533 | vec2 shiftLight(vec2 lm) {
|
19534 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
19535 | }
|
19536 |
|
19537 |
|
19538 | uniform sampler3D uLightVolume;
|
19539 |
|
19540 | uniform sampler2D uBlockAtlas;
|
19541 | uniform sampler2D uLightMap;
|
19542 |
|
19543 | uniform vec3 uLightBoxSize;
|
19544 | uniform vec3 uLightBoxMin;
|
19545 | uniform mat4 uModel;
|
19546 |
|
19547 | uniform float uTime;
|
19548 | uniform mat4 uViewProjection;
|
19549 | uniform vec3 uCameraPos;
|
19550 |
|
19551 | void 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 |
|
19561 | out vec3 BoxCoord;
|
19562 |
|
19563 | void 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)
|
19580 | layout (depth_greater) out float gl_FragDepth;
|
19581 | #endif
|
19582 | #endif
|
19583 |
|
19584 | in vec3 BoxCoord;
|
19585 |
|
19586 | out vec4 FragColor;
|
19587 |
|
19588 | vec4 FLWBlockTexture(vec2 texCoords) {
|
19589 | return texture(uBlockAtlas, texCoords);
|
19590 | }
|
19591 |
|
19592 | void 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 |
|
19608 | vec4 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 |
|
19619 | vec4 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 |
|
19625 | vec4 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 |
|
19635 | vec3 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 |
|
19640 | vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
|
19641 | return rotateVertexByQuat(v, quat(axis, angle));
|
19642 | }
|
19643 |
|
19644 | mat4 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 |
|
19659 | mat4 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 |
|
19663 | mat3 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 |
|
19673 | float 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 | }
|
19677 | struct Vertex {
|
19678 | vec3 pos;
|
19679 | vec2 texCoords;
|
19680 | vec3 normal;
|
19681 | };
|
19682 |
|
19683 | struct BlockFrag {
|
19684 | vec2 texCoords;
|
19685 | vec4 color;
|
19686 | float diffuse;
|
19687 | vec2 light;
|
19688 | };
|
19689 |
|
19690 | #if defined(FRAGMENT_SHADER)
|
19691 | void 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 |
|
19705 | struct 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)
|
19721 | BlockFrag 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 |
|
19751 | in vec2 v2f_texCoords;
|
19752 | in vec4 v2f_color;
|
19753 | in float v2f_diffuse;
|
19754 | in vec2 v2f_light;
|
19755 | void main() {
|
19756 | BlockFrag o;
|
19757 | o.texCoords = v2f_texCoords;
|
19758 | o.color = v2f_color;
|
19759 | o.diffuse = v2f_diffuse;
|
19760 | o.light = v2f_light;
|
19761 | fragment(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)
|
19770 | out float FragDistance;
|
19771 | #elif defined(FRAGMENT_SHADER)
|
19772 | in float FragDistance;
|
19773 | #endif
|
19774 | uniform vec4 uFogColor;
|
19775 | uniform vec2 uFogRange;
|
19776 |
|
19777 | float 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 |
|
19783 | float cylindrical_distance(vec3 worldPos) {
|
19784 | float distXZ = length(worldPos.xz);
|
19785 | float distY = abs(worldPos.y);
|
19786 | return max(distXZ, distY);
|
19787 | }
|
19788 |
|
19789 | float 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
|
19793 | vec2 shiftLight(vec2 lm) {
|
19794 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
19795 | }
|
19796 |
|
19797 |
|
19798 | uniform sampler3D uLightVolume;
|
19799 |
|
19800 | uniform sampler2D uBlockAtlas;
|
19801 | uniform sampler2D uLightMap;
|
19802 |
|
19803 | uniform vec3 uLightBoxSize;
|
19804 | uniform vec3 uLightBoxMin;
|
19805 | uniform mat4 uModel;
|
19806 |
|
19807 | uniform float uTime;
|
19808 | uniform mat4 uViewProjection;
|
19809 | uniform vec3 uCameraPos;
|
19810 |
|
19811 | void 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 |
|
19821 | out vec3 BoxCoord;
|
19822 |
|
19823 | void 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)
|
19840 | layout (depth_greater) out float gl_FragDepth;
|
19841 | #endif
|
19842 | #endif
|
19843 |
|
19844 | in vec3 BoxCoord;
|
19845 |
|
19846 | out vec4 FragColor;
|
19847 |
|
19848 | vec4 FLWBlockTexture(vec2 texCoords) {
|
19849 | return texture(uBlockAtlas, texCoords);
|
19850 | }
|
19851 |
|
19852 | void 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 |
|
19868 | vec4 FLWLight(vec2 lightCoords) {
|
19869 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
19870 |
|
19871 | return texture(uLightMap, shiftLight(lightCoords));
|
19872 | }
|
19873 |
|
19874 | #endif
|
19875 |
|
19876 |
|
19877 | mat4 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 |
|
19892 | mat4 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 |
|
19896 | mat3 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 |
|
19906 | float 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 |
|
19911 | struct BlockFrag {
|
19912 | vec2 texCoords;
|
19913 | vec4 color;
|
19914 | float diffuse;
|
19915 | vec2 light;
|
19916 | };
|
19917 |
|
19918 | #if defined(FRAGMENT_SHADER)
|
19919 | void 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 |
|
19932 | struct 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)
|
19943 | BlockFrag 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 |
|
19965 | in vec3 a_v_pos;
|
19966 | in vec4 a_v_color;
|
19967 | in vec2 a_v_texCoords;
|
19968 | in vec2 a_v_modelLight;
|
19969 | in vec3 a_v_normal;
|
19970 | out vec2 v2f_texCoords;
|
19971 | out vec4 v2f_color;
|
19972 | out float v2f_diffuse;
|
19973 | out vec2 v2f_light;
|
19974 | void main() {
|
19975 | Vertex v;
|
19976 | v.pos = a_v_pos;
|
19977 | v.color = a_v_color;
|
19978 | v.texCoords = a_v_texCoords;
|
19979 | v.modelLight = a_v_modelLight;
|
19980 | v.normal = a_v_normal;
|
19981 | BlockFrag o = vertex(v);
|
19982 | v2f_texCoords = o.texCoords;
|
19983 | v2f_color = o.color;
|
19984 | v2f_diffuse = o.diffuse;
|
19985 | v2f_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)
|
19993 | out float FragDistance;
|
19994 | #elif defined(FRAGMENT_SHADER)
|
19995 | in float FragDistance;
|
19996 | #endif
|
19997 | uniform vec4 uFogColor;
|
19998 | uniform vec2 uFogRange;
|
19999 |
|
20000 | float 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 |
|
20006 | float cylindrical_distance(vec3 worldPos) {
|
20007 | float distXZ = length(worldPos.xz);
|
20008 | float distY = abs(worldPos.y);
|
20009 | return max(distXZ, distY);
|
20010 | }
|
20011 |
|
20012 | float 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
|
20016 | vec2 shiftLight(vec2 lm) {
|
20017 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
20018 | }
|
20019 |
|
20020 |
|
20021 | uniform sampler3D uLightVolume;
|
20022 |
|
20023 | uniform sampler2D uBlockAtlas;
|
20024 | uniform sampler2D uLightMap;
|
20025 |
|
20026 | uniform vec3 uLightBoxSize;
|
20027 | uniform vec3 uLightBoxMin;
|
20028 | uniform mat4 uModel;
|
20029 |
|
20030 | uniform float uTime;
|
20031 | uniform mat4 uViewProjection;
|
20032 | uniform vec3 uCameraPos;
|
20033 |
|
20034 | void 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 |
|
20044 | out vec3 BoxCoord;
|
20045 |
|
20046 | void 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)
|
20063 | layout (depth_greater) out float gl_FragDepth;
|
20064 | #endif
|
20065 | #endif
|
20066 |
|
20067 | in vec3 BoxCoord;
|
20068 |
|
20069 | out vec4 FragColor;
|
20070 |
|
20071 | vec4 FLWBlockTexture(vec2 texCoords) {
|
20072 | return texture(uBlockAtlas, texCoords);
|
20073 | }
|
20074 |
|
20075 | void 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 |
|
20091 | vec4 FLWLight(vec2 lightCoords) {
|
20092 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
20093 |
|
20094 | return texture(uLightMap, shiftLight(lightCoords));
|
20095 | }
|
20096 |
|
20097 | #endif
|
20098 |
|
20099 |
|
20100 | mat4 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 |
|
20115 | mat4 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 |
|
20119 | mat3 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 |
|
20129 | float 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 |
|
20134 | struct BlockFrag {
|
20135 | vec2 texCoords;
|
20136 | vec4 color;
|
20137 | float diffuse;
|
20138 | vec2 light;
|
20139 | };
|
20140 |
|
20141 | #if defined(FRAGMENT_SHADER)
|
20142 | void 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 |
|
20155 | struct 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)
|
20166 | BlockFrag 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 |
|
20188 | in vec2 v2f_texCoords;
|
20189 | in vec4 v2f_color;
|
20190 | in float v2f_diffuse;
|
20191 | in vec2 v2f_light;
|
20192 | void main() {
|
20193 | BlockFrag o;
|
20194 | o.texCoords = v2f_texCoords;
|
20195 | o.color = v2f_color;
|
20196 | o.diffuse = v2f_diffuse;
|
20197 | o.light = v2f_light;
|
20198 | fragment(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)
|
20207 | out float FragDistance;
|
20208 | #elif defined(FRAGMENT_SHADER)
|
20209 | in float FragDistance;
|
20210 | #endif
|
20211 | uniform vec4 uFogColor;
|
20212 | uniform vec2 uFogRange;
|
20213 |
|
20214 | float 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 |
|
20220 | float cylindrical_distance(vec3 worldPos) {
|
20221 | float distXZ = length(worldPos.xz);
|
20222 | float distY = abs(worldPos.y);
|
20223 | return max(distXZ, distY);
|
20224 | }
|
20225 |
|
20226 | float 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
|
20230 | vec2 shiftLight(vec2 lm) {
|
20231 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
20232 | }
|
20233 |
|
20234 |
|
20235 | uniform sampler3D uLightVolume;
|
20236 |
|
20237 | uniform sampler2D uBlockAtlas;
|
20238 | uniform sampler2D uLightMap;
|
20239 |
|
20240 | uniform vec3 uLightBoxSize;
|
20241 | uniform vec3 uLightBoxMin;
|
20242 | uniform mat4 uModel;
|
20243 |
|
20244 | uniform float uTime;
|
20245 | uniform mat4 uViewProjection;
|
20246 | uniform vec3 uCameraPos;
|
20247 |
|
20248 | void 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 |
|
20258 | out vec3 BoxCoord;
|
20259 |
|
20260 | void 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)
|
20277 | layout (depth_greater) out float gl_FragDepth;
|
20278 | #endif
|
20279 | #endif
|
20280 |
|
20281 | in vec3 BoxCoord;
|
20282 |
|
20283 | out vec4 FragColor;
|
20284 |
|
20285 | vec4 FLWBlockTexture(vec2 texCoords) {
|
20286 | return texture(uBlockAtlas, texCoords);
|
20287 | }
|
20288 |
|
20289 | void 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 |
|
20305 | vec4 FLWLight(vec2 lightCoords) {
|
20306 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
20307 |
|
20308 | return texture(uLightMap, shiftLight(lightCoords));
|
20309 | }
|
20310 |
|
20311 | #endif
|
20312 |
|
20313 |
|
20314 | mat4 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 |
|
20329 | mat4 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 |
|
20333 | mat3 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 |
|
20343 | float 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 |
|
20348 | struct BlockFrag {
|
20349 | vec2 texCoords;
|
20350 | vec4 color;
|
20351 | float diffuse;
|
20352 | vec2 light;
|
20353 | };
|
20354 |
|
20355 | #if defined(FRAGMENT_SHADER)
|
20356 | void 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 |
|
20369 | struct 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)
|
20380 | BlockFrag 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 |
|
20402 | in vec3 a_v_pos;
|
20403 | in vec4 a_v_color;
|
20404 | in vec2 a_v_texCoords;
|
20405 | in vec2 a_v_modelLight;
|
20406 | in vec3 a_v_normal;
|
20407 | out vec2 v2f_texCoords;
|
20408 | out vec4 v2f_color;
|
20409 | out float v2f_diffuse;
|
20410 | out vec2 v2f_light;
|
20411 | void main() {
|
20412 | Vertex v;
|
20413 | v.pos = a_v_pos;
|
20414 | v.color = a_v_color;
|
20415 | v.texCoords = a_v_texCoords;
|
20416 | v.modelLight = a_v_modelLight;
|
20417 | v.normal = a_v_normal;
|
20418 | BlockFrag o = vertex(v);
|
20419 | v2f_texCoords = o.texCoords;
|
20420 | v2f_color = o.color;
|
20421 | v2f_diffuse = o.diffuse;
|
20422 | v2f_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)
|
20431 | out float FragDistance;
|
20432 | #elif defined(FRAGMENT_SHADER)
|
20433 | in float FragDistance;
|
20434 | #endif
|
20435 | uniform vec4 uFogColor;
|
20436 | uniform vec2 uFogRange;
|
20437 |
|
20438 | float 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 |
|
20444 | float cylindrical_distance(vec3 worldPos) {
|
20445 | float distXZ = length(worldPos.xz);
|
20446 | float distY = abs(worldPos.y);
|
20447 | return max(distXZ, distY);
|
20448 | }
|
20449 |
|
20450 | float 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
|
20454 | vec2 shiftLight(vec2 lm) {
|
20455 | return lm * 0.99609375 + 0.03125;// * 255/256 + 1/32
|
20456 | }
|
20457 |
|
20458 |
|
20459 | uniform sampler3D uLightVolume;
|
20460 |
|
20461 | uniform sampler2D uBlockAtlas;
|
20462 | uniform sampler2D uLightMap;
|
20463 |
|
20464 | uniform vec3 uLightBoxSize;
|
20465 | uniform vec3 uLightBoxMin;
|
20466 | uniform mat4 uModel;
|
20467 |
|
20468 | uniform float uTime;
|
20469 | uniform mat4 uViewProjection;
|
20470 | uniform vec3 uCameraPos;
|
20471 |
|
20472 | void 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 |
|
20482 | out vec3 BoxCoord;
|
20483 |
|
20484 | void 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)
|
20501 | layout (depth_greater) out float gl_FragDepth;
|
20502 | #endif
|
20503 | #endif
|
20504 |
|
20505 | in vec3 BoxCoord;
|
20506 |
|
20507 | out vec4 FragColor;
|
20508 |
|
20509 | vec4 FLWBlockTexture(vec2 texCoords) {
|
20510 | return texture(uBlockAtlas, texCoords);
|
20511 | }
|
20512 |
|
20513 | void 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 |
|
20529 | vec4 FLWLight(vec2 lightCoords) {
|
20530 | lightCoords = max(lightCoords, texture(uLightVolume, BoxCoord).rg);
|
20531 |
|
20532 | return texture(uLightMap, shiftLight(lightCoords));
|
20533 | }
|
20534 |
|
20535 | #endif
|
20536 |
|
20537 |
|
20538 | mat4 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 |
|
20553 | mat4 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 |
|
20557 | mat3 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 |
|
20567 | float 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 |
|
20572 | struct BlockFrag {
|
20573 | vec2 texCoords;
|
20574 | vec4 color;
|
20575 | float diffuse;
|
20576 | vec2 light;
|
20577 | };
|
20578 |
|
20579 | #if defined(FRAGMENT_SHADER)
|
20580 | void 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 |
|
20593 | struct 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)
|
20604 | BlockFrag 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 |
|
20626 | in vec2 v2f_texCoords;
|
20627 | in vec4 v2f_color;
|
20628 | in float v2f_diffuse;
|
20629 | in vec2 v2f_light;
|
20630 | void main() {
|
20631 | BlockFrag o;
|
20632 | o.texCoords = v2f_texCoords;
|
20633 | o.color = v2f_color;
|
20634 | o.diffuse = v2f_diffuse;
|
20635 | o.light = v2f_light;
|
20636 | fragment(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!
|