diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/ModelShader.java b/commons/src/main/com/mbrlabs/mundus/commons/shaders/ModelShader.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/compat.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/compat.glsl new file mode 100644 index 000000000..14cb476c4 --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/compat.glsl @@ -0,0 +1,10 @@ +#ifdef GL_ES +#define LOW lowp +#define MED mediump +#define HIGH highp +precision highp float; +#else +#define MED +#define LOW +#define HIGH +#endif \ No newline at end of file diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/depth.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/depth.frag.glsl index 018b43b1f..46b90d095 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/depth.frag.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/depth.frag.glsl @@ -14,9 +14,7 @@ * limitations under the License. */ -#ifdef GL_ES -precision highp float; -#endif +#include "compat.glsl" varying float v_clipDistance; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/light.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/light.glsl index 21bf425e6..ba132f351 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/light.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/light.glsl @@ -1,13 +1,7 @@ // Lighting adapted from OGLDEV tutorials https://www.youtube.com/c/OGLDEV -#ifdef GL_ES -#define LOW lowp -#define MED mediump -#define HIGH highp -precision highp float; -#else +// Just stops the static analysis from complaining +#ifndef MED #define MED -#define LOW -#define HIGH #endif struct BaseLight diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/model.vert.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/model.vert.glsl deleted file mode 100644 index e69de29bb..000000000 diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/shadowmap.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/shadowmap.frag.glsl index ba862f271..4388759ba 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/shadowmap.frag.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/shadowmap.frag.glsl @@ -14,9 +14,7 @@ * limitations under the License. */ -#ifdef GL_ES -precision highp float; -#endif +#include "compat.glsl" varying vec2 v_texCoords0; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/skybox.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/skybox.frag.glsl index c10f069a6..02d9f6e6f 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/skybox.frag.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/skybox.frag.glsl @@ -14,10 +14,7 @@ * limitations under the License. */ -#ifdef GL_ES -precision highp float; -#endif - +#include "compat.glsl" uniform samplerCube u_texture; uniform int u_fog; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.frag.glsl index 61fa4ff39..e62bdfdc4 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.frag.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.frag.glsl @@ -14,15 +14,12 @@ * limitations under the License. */ -#ifdef GL_ES -#define LOW lowp -#define MED mediump -#define HIGH highp -precision highp float; -#else +#include "compat.glsl" +#include "light.glsl" + +// Just stops the static analysis from complaining +#ifndef MED #define MED -#define LOW -#define HIGH #endif #define PI 3.1415926535897932384626433832795 @@ -88,9 +85,15 @@ varying vec3 v_pos; // light varying mat3 v_TBN; -varying MED vec2 v_texCoord0; +varying vec2 v_texCoord0; varying float v_clipDistance; +// Brings the normal from [0, 1] to [-1, 1] +vec3 unpackNormal(vec3 normal) +{ + return normalize(normal * 2.0 - 1.0); +} + void main(void) { if ( v_clipDistance < 0.0 ) discard; @@ -100,7 +103,7 @@ void main(void) { gl_FragColor = texture2D(u_baseTexture, v_texCoord0); #ifdef baseNormalFlag - normal = texture2D(u_texture_base_normal, v_texCoord0).rgb; + normal = unpackNormal(texture2D(u_texture_base_normal, v_texCoord0).rgb); #endif // Mix splat textures @@ -120,26 +123,31 @@ void main(void) { #endif #ifdef normalTextureFlag + vec3 splatNormal = vec3(0.0); // Splat normals #ifdef splatRNormalFlag - normal = mix(normal, texture2D(u_texture_r_normal, v_texCoord0).rgb, splat.r); + splatNormal += unpackNormal(texture2D(u_texture_r_normal, v_texCoord0).rgb) * splat.r; #endif #ifdef splatGNormalFlag - normal = mix(normal, texture2D(u_texture_g_normal, v_texCoord0).rgb, splat.g); + splatNormal += unpackNormal(texture2D(u_texture_g_normal, v_texCoord0).rgb) * splat.g; #endif #ifdef splatBNormalFlag - normal = mix(normal, texture2D(u_texture_b_normal, v_texCoord0).rgb, splat.b); + splatNormal += unpackNormal(texture2D(u_texture_b_normal, v_texCoord0).rgb) * splat.b; #endif #ifdef splatANormalFlag - normal = mix(normal, texture2D(u_texture_a_normal, v_texCoord0).rgb, splat.a); + splatNormal += unpackNormal(texture2D(u_texture_a_normal, v_texCoord0).rgb) * splat.a; #endif + // The base normal should only be visible when the sum of the splat weights is less than 1.0 + float normalBlendFactor = (1.0 - splat.r - splat.g - splat.b - splat.a); + normal = normalize((normal * normalBlendFactor) + splatNormal); #endif #endif #ifdef normalTextureFlag - normal = normalize(v_TBN * ((2.0 * normal - 1.0))); + // Apply TBN matrix to tangent space normal to get world space normal + normal = normalize(v_TBN * normal); #else normal = normalize(v_TBN[2].xyz); #endif diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.vert.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.vert.glsl index 860b7577f..35a86cd45 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.vert.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/terrain.uber.vert.glsl @@ -14,9 +14,7 @@ * limitations under the License. */ -#ifdef GL_ES -precision highp float; -#endif +#include "compat.glsl" attribute vec3 a_position; attribute vec3 a_normal; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.frag.glsl deleted file mode 100644 index 51aa7ba58..000000000 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.frag.glsl +++ /dev/null @@ -1,206 +0,0 @@ -#ifdef GL_ES -#define LOW lowp -#define MED mediump -#define HIGH highp -precision highp float; -#else -#define MED -#define LOW -#define HIGH -#endif - -varying MED vec2 v_texCoord0; -varying vec2 v_waterTexCoords; -varying vec4 v_clipSpace; -varying vec3 v_toCameraVector; -varying vec2 v_diffuseUV; - -uniform MED vec3 u_color; -uniform sampler2D u_texture; -uniform sampler2D u_refractionTexture; -uniform sampler2D u_refractionDepthTexture; -uniform sampler2D u_dudvTexture; -uniform sampler2D u_normalMapTexture; -uniform sampler2D u_foamTexture; -uniform MED float u_waveStrength; -uniform MED float u_moveFactor; -uniform MED float u_shineDamper; -uniform MED float u_reflectivity; -uniform MED float u_foamScale; -uniform MED float u_foamEdgeBias; -uniform MED float u_foamEdgeDistance; -uniform MED float u_foamFallOffDistance; -uniform MED float u_foamScrollSpeed; -uniform vec3 u_fogEquation; -uniform float u_camNearPlane; -uniform float u_camFarPlane; -uniform MED vec4 u_fogColor; -uniform MED float u_fogDensity; -uniform MED float u_fogGradient; - -const vec4 COLOR_TURQUOISE = vec4(0,0.5,0.686, 0.2); - -//https://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/ -float DecodeFloatRGBA( vec4 rgba ) { - return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0) ); -} - -vec3 calcSpecularHighlights(BaseLight baseLight, vec3 direction, vec3 normal, vec3 viewVector, float waterDepth) { - vec3 reflectedLight = reflect(normalize(direction), normal); - float specular = max(dot(reflectedLight, viewVector), 0.0); - specular = pow(specular, u_shineDamper); - vec3 specularHighlights = vec3(baseLight.Color) * baseLight.DiffuseIntensity * specular * u_reflectivity * clamp(waterDepth/5.0, 0.0, 1.0); - - return specularHighlights; -} - -void main() { - - // Normalized device coordinates - vec2 ndc = (v_clipSpace.xy/v_clipSpace.w)/2.0 + 0.5; - vec2 refractTexCoords = vec2(ndc.x, ndc.y); - vec2 reflectTexCoords = vec2(ndc.x, 1.0-ndc.y); - - float near = u_camNearPlane; - float far = u_camFarPlane; - float depth = DecodeFloatRGBA(texture2D(u_refractionDepthTexture, refractTexCoords)); - float floorDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); - - depth = gl_FragCoord.z; - float waterDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); - float waterDepth = floorDistance - waterDistance; - - // Dudv distortion - vec2 distortedTexCoords = texture2D(u_dudvTexture, vec2(v_waterTexCoords.x + u_moveFactor, v_waterTexCoords.y)).rg*0.1; - distortedTexCoords = v_waterTexCoords + vec2(distortedTexCoords.x, distortedTexCoords.y+u_moveFactor); - vec2 totalDistortion = (texture2D(u_dudvTexture, distortedTexCoords).rg * 2.0 - 1.0) * u_waveStrength * clamp(waterDepth/20.0, 0.0, 1.0); - - float minTexCoord = 0.005; - float maxTexCoord = 1.0 - minTexCoord; - - refractTexCoords = refractTexCoords + totalDistortion; - reflectTexCoords = reflectTexCoords + totalDistortion; - - refractTexCoords = clamp(refractTexCoords, 0.001, 0.999); - - reflectTexCoords.x = clamp(reflectTexCoords.x, 0.001, 0.999); - reflectTexCoords.y = clamp(reflectTexCoords.y, 0.001, 0.999); - - // Sample textures with distortion - vec4 reflectColor = texture2D(u_texture, reflectTexCoords); - vec4 refractColor = texture2D(u_refractionTexture, refractTexCoords); - - // Normal map - vec4 normalMapColor = texture2D(u_normalMapTexture, distortedTexCoords); - vec3 normal = vec3(normalMapColor.r * 2.0 - 1.0, normalMapColor.b * 3.0, normalMapColor.g * 2.0 - 1.0); - normal = normalize(normal); - - // Fresnel Effect - vec3 viewVector = normalize(v_toCameraVector); - float refractiveFactor = dot(viewVector, normal); - vec4 color = mix(reflectColor, refractColor, refractiveFactor); - - // Mix some color in - color = mix(color, COLOR_TURQUOISE, 0.2); - - // Water Foam implemented from http://fire-face.com/personal/water/ - float edgePatternScroll = u_moveFactor * u_foamScrollSpeed; - vec4 edgeFalloffColor = vec4(0.8,0.8,0.8,0.6); - - vec2 scaledUV = v_diffuseUV * u_foamScale; - - // Calculate linear falloff value - float falloff = 1.0 - (waterDepth / u_foamFallOffDistance) + u_foamEdgeBias; - - vec2 coords = v_texCoord0 + totalDistortion; - - // Sample the mask - float channelA = texture2D(u_foamTexture, scaledUV - vec2(edgePatternScroll, cos(coords.x))).r; - float channelB = texture2D(u_foamTexture, scaledUV * 0.5 + vec2(sin(coords.y), edgePatternScroll)).b; - - // Modify it to our liking - float mask = (channelA + channelB) * 0.95; - mask = pow(mask, 2.0); - mask = clamp(mask, 0.0, 1.0); - - // Is this pixel in the leading edge? - if(waterDepth < u_foamFallOffDistance * u_foamEdgeDistance) - { - // Modulate the surface alpha and the mask strength - float leading = waterDepth / (u_foamFallOffDistance * u_foamEdgeDistance); - color.a *= leading; - mask *= leading; - } - - // Color the foam, blend based on alpha - vec3 edge = edgeFalloffColor.rgb * falloff * edgeFalloffColor.a; - - // This is a workaround fix to resolve an issue when using packed depth that causes white borders on water - // so if the red channel is full 1.0 its probably pure white (border) so we ignore it. - if (edge.r < 0.99) { - // Fade foam out after a distance, otherwise we get ugly 1 pixel lines - float distanceToCam = length(v_worldPos - u_cameraPosition.xyz); - float foamVisibleFactor = clamp(1.0 - distanceToCam / 500.0, 0.0, 1.0); - - // Subtract mask value from foam gradient, then add the foam value to the final pixel color - color.rgb += clamp(edge - vec3(mask), 0.0, 1.0) * foamVisibleFactor; - } - - // Get directional light - vec4 totalLight = CalcDirectionalLight(normal); - - // Calculate specular hightlights for directional light - vec3 specularHighlights = calcSpecularHighlights(u_directionalLight.Base, u_directionalLight.Direction, normal, viewVector, waterDepth); - - // Calculate specular and lighting for point lights - for (int i = 0 ; i < numPointLights ; i++) { - if (i >= u_activeNumPointLights){break;} - vec4 lightColor = vec4(u_pointLights[i].Base.Color, 1.0) * u_pointLights[i].Base.DiffuseIntensity; - - vec3 lightDirection = v_worldPos - u_pointLights[i].LocalPos; - float dist = length(lightDirection); - lightDirection = normalize(lightDirection); - - float attenuation = u_pointLights[i].Atten.Constant + - u_pointLights[i].Atten.Linear * dist + - u_pointLights[i].Atten.Exp * dist * dist; - - float specularDistanceFactor = length(u_cameraPosition.xyz - u_pointLights[i].LocalPos); - - // Limit distance of point lights specular highlights over water by 500 units - specularDistanceFactor = clamp(1.0 - specularDistanceFactor / 500.0, 0.0, 1.0); - - // We want specular to adjust based on attenuation, but not to the same degree otherwise we lose too much - float specularAttenuationFactor = 0.1; - - // Add point light contribution to specular highlights - specularHighlights += (calcSpecularHighlights(u_pointLights[i].Base, lightDirection, normal, viewVector, waterDepth) * specularDistanceFactor) / (attenuation * specularAttenuationFactor); - - // Apply point light colors to overall color - totalLight += lightColor / attenuation; - } - - for (int i = 0; i < numSpotLights; i++) { - if (i >= u_activeNumSpotLights){break;} - totalLight += CalcSpotLight(u_spotLights[i], normal); - } - - // Apply all lighting - color *= totalLight; - - // Apply final specular values - color += vec4(specularHighlights, 0.0); - - // Fog - if (u_fogEquation.z > 0.0) { - float fog = (waterDistance - u_fogEquation.x) / (u_fogEquation.y - u_fogEquation.x); - fog = clamp(fog, 0.0, 1.0); - fog = pow(fog, u_fogEquation.z); - - color.rgb = mix(color.rgb, u_fogColor.rgb, fog * u_fogColor.a); - } - - gl_FragColor = color; - //gl_FragColor = vec4(waterDepth/50.0); - //gl_FragColor.a = clamp(waterDepth/5.0, 0.0, 1.0); -} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl index fcd1c9d98..6c517d142 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.frag.glsl @@ -1,12 +1,9 @@ -#ifdef GL_ES -#define LOW lowp -#define MED mediump -#define HIGH highp -precision highp float; -#else +#include "compat.glsl" +#include "light.glsl" + +// Just stops the static analysis from complaining +#ifndef MED #define MED -#define LOW -#define HIGH #endif varying MED vec2 v_texCoord0; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl index b575fafb9..5e8c83dc7 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl +++ b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.uber.vert.glsl @@ -1,6 +1,4 @@ -#ifdef GL_ES -precision highp float; -#endif +#include "compat.glsl" attribute vec3 a_position; attribute vec3 a_normal; diff --git a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.vert.glsl b/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.vert.glsl deleted file mode 100644 index 1495d4fc0..000000000 --- a/commons/src/main/com/mbrlabs/mundus/commons/shaders/water.vert.glsl +++ /dev/null @@ -1,39 +0,0 @@ -#ifdef GL_ES -precision highp float; -#endif - -attribute vec3 a_position; -attribute vec3 a_normal; -attribute vec2 a_texCoord0; - -uniform mat4 u_transMatrix; -uniform mat4 u_projViewMatrix; -uniform vec4 u_cameraPosition; -uniform float u_tiling; -uniform vec4 u_diffuseUVTransform; -varying vec2 v_diffuseUV; - -varying vec2 v_texCoord0; -varying vec2 v_waterTexCoords; -varying vec4 v_clipSpace; -varying vec3 v_toCameraVector; -varying vec3 v_worldPos; - -varying vec3 v_shadowMapUv; - -void main() { - vec4 worldPos = u_transMatrix * vec4(a_position, 1.0); - v_worldPos = worldPos.xyz; - - v_shadowMapUv = vec3(0.0); - - v_clipSpace = u_projViewMatrix * worldPos; - gl_Position = v_clipSpace; - - v_texCoord0 = a_texCoord0; - v_diffuseUV = u_diffuseUVTransform.xy + a_texCoord0 * u_diffuseUVTransform.zw; - - v_waterTexCoords = vec2(a_position.x/2.0 + 0.5, a_position.z/2.0 + 0.5) * u_tiling; - - v_toCameraVector = u_cameraPosition.xyz - worldPos.xyz; -} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderPreprocessor.java b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderPreprocessor.java new file mode 100644 index 000000000..abd18df2c --- /dev/null +++ b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderPreprocessor.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023. See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mbrlabs.mundus.commons.utils; + +import com.badlogic.gdx.files.FileHandle; + +import java.util.HashMap; +import java.util.Map; + +/** + * Preprocesses shader files and replaces all include directives with the + * content of the included file. + * gdx-gltf moved over to something a bit similar (ShaderParser) but it is not + * in a released version yet. May be worth using the gdx-gltf ShaderParser instead + * once it is available in a release + * + * @author JamesTKhan + * @version May 08, 2023 + */ +public class ShaderPreprocessor { + private static final String includeDirective = "#include"; + + // Cache for already parsed files + private static final Map cache = new HashMap<>(); + + /** + * Parses the shader file and replaces all include directives with the + * content of the included file. + * + * @param fileHandle The shader file + * @return The complete shader file as string + */ + public static String readShaderFile(FileHandle fileHandle) { + String filePath = fileHandle.path(); + + // Check if the file content is already in the cache + if (cache.containsKey(filePath)) { + return cache.get(filePath); + } + + String fileContent = fileHandle.readString(); + + StringBuilder stringBuffer = new StringBuilder(); + int cursor = 0; // Cursor to keep track of the current position in the file + int includeIndex; // Index of the include directive + + // Iterate the file and find the include directives + while ((includeIndex = fileContent.indexOf(includeDirective, cursor)) != -1) { + + // Append the content before the include directive + stringBuffer.append(fileContent, cursor, includeIndex); + + int startQuote = fileContent.indexOf("\"", includeIndex); + int endQuote = fileContent.indexOf("\"", startQuote + 1); + + // Get the included file path + String includedFilePath = fileContent.substring(startQuote + 1, endQuote); + + // Recursive include + String includedFileContent = readShaderFile(fileHandle.sibling(includedFilePath)); + + // Append the included file content + stringBuffer.append(includedFileContent); + + cursor = endQuote + 1; + } + + // Appends the remaining content after the last include directive + stringBuffer.append(fileContent.substring(cursor)); + + String processedFileContent = stringBuffer.toString(); + cache.put(filePath, processedFileContent); + return processedFileContent; + } +} diff --git a/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java index 2e49f06ab..425a020ba 100644 --- a/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java +++ b/commons/src/main/com/mbrlabs/mundus/commons/utils/ShaderUtils.java @@ -18,6 +18,7 @@ import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g3d.Renderable; import com.badlogic.gdx.graphics.g3d.Shader; @@ -34,8 +35,6 @@ */ public class ShaderUtils { - protected static final String LIGHT_SHADER_PREFIX = "com/mbrlabs/mundus/commons/shaders/light.glsl"; - /** * Compiles and links shader. * @@ -51,17 +50,20 @@ public class ShaderUtils { * @return compiled shader program */ public static ShaderProgram compile(String vertexShader, String fragmentShader, Shader shader, String customPrefix) { - String vert; - String frag; + FileHandle vertFile; + FileHandle fragFile; if (Gdx.app.getType() == Application.ApplicationType.WebGL) { - vert = Gdx.files.internal(vertexShader).readString(); - frag = Gdx.files.internal(fragmentShader).readString(); + vertFile = Gdx.files.internal(vertexShader); + fragFile = Gdx.files.internal(fragmentShader); } else { - vert = Gdx.files.classpath(vertexShader).readString(); - frag = Gdx.files.classpath(fragmentShader).readString(); + vertFile = Gdx.files.classpath(vertexShader); + fragFile = Gdx.files.classpath(fragmentShader); } + String vert = ShaderPreprocessor.readShaderFile(vertFile); + String frag = ShaderPreprocessor.readShaderFile(fragFile); + ShaderProgram program = new ShaderProgram(customPrefix + vert, customPrefix + getShaderPrefix(shader) + frag); if (!program.isCompiled()) { throw new GdxRuntimeException(program.getLog()); @@ -92,12 +94,6 @@ public static String getShaderPrefix(Shader shader) { if (shader instanceof LightShader) { fragPrefix += "#define numPointLights " + LightUtils.MAX_POINT_LIGHTS + "\n"; fragPrefix += "#define numSpotLights " + LightUtils.MAX_SPOT_LIGHTS + "\n"; - - if (Gdx.app.getType() == Application.ApplicationType.WebGL) { - fragPrefix += Gdx.files.internal(LIGHT_SHADER_PREFIX).readString(); - } else { - fragPrefix += Gdx.files.classpath(LIGHT_SHADER_PREFIX).readString(); - } } return fragPrefix; diff --git a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml index 962370ee4..72ddc5bb6 100644 --- a/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml +++ b/gdx-runtime/src/com/mbrlabs/mundus.gwt.xml @@ -15,6 +15,7 @@ +