Josh Engebretson 10 vuotta sitten
vanhempi
sitoutus
27e9586d33

+ 10 - 8
Data/AtomicPlayer/Resources/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
Data/AtomicPlayer/Resources/CoreData/Shaders/GLSL/Uniforms.glsl

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

+ 1 - 1
Source/Atomic/Engine/Engine.cpp

@@ -89,7 +89,7 @@ Engine::Engine(Context* context) :
     timeStep_(0.0f),
     timeStepSmoothing_(2),
     minFps_(10),
-    #if defined(ANDROID) || defined(IOS) || defined(RPI) || defined(EMSCRIPTEN)
+    #if defined(ANDROID) || defined(IOS) || defined(RPI)
     maxFps_(60),
     maxInactiveFps_(10),
     pauseMinimized_(true),

+ 8 - 1
Source/Atomic/Graphics/GraphicsDefs.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -30,6 +30,13 @@ namespace Atomic
 
 class Vector3;
 
+/// Graphics capability support level. HTML5 (Emscripten) 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
+#endif
+
 /// Primitive type.
 enum PrimitiveType
 {

+ 2 - 2
Source/Atomic/Graphics/Light.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -44,7 +44,7 @@ enum LightType
 static const float SHADOW_MIN_QUANTIZE = 0.1f;
 static const float SHADOW_MIN_VIEW = 1.0f;
 static const int MAX_LIGHT_SPLITS = 6;
-#if !defined(ANDROID) && !defined(IOS) && !defined(RPI)
+#ifdef DESKTOP_GRAPHICS
 static const int MAX_CASCADE_SPLITS = 4;
 #else
 static const int MAX_CASCADE_SPLITS = 1;

+ 8 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -2701,7 +2701,11 @@ void Graphics::CheckFeatureSupport(String& extensions)
         glesDepthStencilFormat = GL_DEPTH_COMPONENT24_OES;
     if (CheckExtension(extensions, "GL_OES_packed_depth_stencil"))
         glesDepthStencilFormat = GL_DEPTH24_STENCIL8_OES;
+    #ifdef EMSCRIPTEN
+    if (!CheckExtension(extensions, "WEBGL_depth_texture"))
+    #else
     if (!CheckExtension(extensions, "GL_OES_depth_texture"))
+    #endif
     {
         shadowMapFormat_ = 0;
         hiresShadowMapFormat_ = 0;
@@ -2716,6 +2720,10 @@ void Graphics::CheckFeatureSupport(String& extensions)
         #endif
         shadowMapFormat_ = GL_DEPTH_COMPONENT;
         hiresShadowMapFormat_ = 0;
+        // WebGL shadow map rendering seems to be extremely slow without an attached dummy color texture
+        #ifdef EMSCRIPTEN
+        dummyColorFormat_ = GetRGBAFormat();
+        #endif
     }
     #endif
 }

+ 4 - 1
Source/Atomic/Graphics/OpenGL/OGLShaderVariation.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -149,6 +149,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)

+ 6 - 12
Source/Atomic/Graphics/Technique.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 the Urho3D project.
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -70,9 +70,6 @@ static const char* lightingModeNames[] =
     0
 };
 
-static bool desktopSupportChecked = false;
-static bool desktopSupportResult = false;
-
 Pass::Pass(StringHash type) :
     type_(type),
     blendMode_(BLEND_REPLACE),
@@ -174,14 +171,11 @@ Technique::Technique(Context* context) :
     Graphics* graphics = GetSubsystem<Graphics>();
     sm3Support_ = graphics ? graphics->GetSM3Support() : true;
     
-    if (!desktopSupportChecked)
-    {
-        String platformString = GetPlatform();
-        desktopSupportResult = (platformString == "Windows" || platformString == "Mac OS X" || platformString == "Linux");
-        desktopSupportChecked = true;
-    }
-    
-    desktopSupport_ = desktopSupportResult;
+    #ifdef DESKTOP_GRAPHICS
+    desktopSupport_ = true;
+    #else
+    desktopSupport_ = false;
+    #endif
 }
 
 Technique::~Technique()