Browse Source

Enable cascaded shadows on Emscripten.

Lasse Öörni 10 years ago
parent
commit
3f2f88441d

+ 2 - 2
Source/Urho3D/Graphics/GraphicsDefs.h

@@ -30,8 +30,8 @@ namespace Urho3D
 
 class Vector3;
 
-/// Graphics capability support level. WebGL will at least for now also behave similarly as mobiles
-#if defined(ANDROID) || defined(IOS) || defined(RPI) || defined(EMSCRIPTEN)
+/// Graphics capability support level. WebGL also uses OpenGL ES, but is considered a desktop platform capability-wise
+#if defined(ANDROID) || defined(IOS) || defined(RPI)
 #define MOBILE_GRAPHICS
 #else
 #define DESKTOP_GRAPHICS

+ 3 - 0
Source/Urho3D/Graphics/OpenGL/OGLShaderVariation.cpp

@@ -148,6 +148,9 @@ bool ShaderVariation::Create()
     if (type_ == VS)
         shaderCode += "#define RPI\n";
     #endif
+    #ifdef EMSCRIPTEN
+    shaderCode += "#define WEBGL\n";
+    #endif
 
     // When version define found, do not insert it a second time
     if (verEnd > 0)

+ 10 - 8
bin/CoreData/Shaders/GLSL/Lighting.glsl

@@ -60,7 +60,7 @@ float GetVertexLightVolumetric(int index, vec3 worldPos)
 
 #ifdef SHADOW
 
-#if defined(DIRLIGHT) && !defined(GL_ES)
+#if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL))
     #define NUMCASCADES 4
 #else
     #define NUMCASCADES 1
@@ -118,7 +118,7 @@ float GetIntensity(vec3 color)
 
 #ifdef SHADOW
 
-#if defined(DIRLIGHT) && !defined(GL_ES)
+#if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL))
     #define NUMCASCADES 4
 #else
     #define NUMCASCADES 1
@@ -193,7 +193,7 @@ float GetDirShadowFade(float inLight, float depth)
     return min(inLight + max((depth - cShadowDepthFade.z) * cShadowDepthFade.w, 0.0), 1.0);
 }
 
-#ifndef GL_ES
+#if !defined(GL_ES) || defined(WEBGL)
 float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
 {
     vec4 shadowPos;
@@ -209,7 +209,14 @@ float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
         
     return GetDirShadowFade(GetShadow(shadowPos), depth);
 }
+#else
+float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
+{
+    return GetDirShadowFade(GetShadow(iShadowPos[0]), depth);
+}
+#endif
 
+#ifndef GL_ES
 float GetDirShadowDeferred(vec4 projWorldPos, float depth)
 {
     vec4 shadowPos;
@@ -225,11 +232,6 @@ float GetDirShadowDeferred(vec4 projWorldPos, float depth)
 
     return GetDirShadowFade(GetShadow(shadowPos), depth);
 }
-#else
-float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
-{
-    return GetDirShadowFade(GetShadow(iShadowPos[0]), depth);
-}
 #endif
 #endif
 

+ 1 - 1
bin/CoreData/Shaders/GLSL/Uniforms.glsl

@@ -18,7 +18,7 @@ uniform mat4 cViewProj;
 uniform vec4 cUOffset;
 uniform vec4 cVOffset;
 uniform mat4 cZone;
-#ifndef GL_ES
+#if !defined(GL_ES) || defined(WEBGL)
     uniform mat4 cLightMatrices[4];
 #else
     uniform mat4 cLightMatrices[2];