Browse Source

Fixed editor gizmo movement in local axes mode.
Added local Z-direction ambient color gradient support to Zone.
Draw Zone debug geometry as an oriented bounding box.
Shader code cleanup.

Lasse Öörni 14 years ago
parent
commit
1b08deec28

+ 3 - 3
Bin/Data/Scripts/Editor/EditorGizmo.as

@@ -216,11 +216,11 @@ void UseGizmo()
         {
         {
             Vector3 adjust(0, 0, 0);
             Vector3 adjust(0, 0, 0);
             if (gizmoAxisX.selected)
             if (gizmoAxisX.selected)
-                adjust += gizmoAxisX.axisRay.direction * (gizmoAxisX.t - gizmoAxisX.lastT);
+                adjust += Vector3(1, 0, 0) * (gizmoAxisX.t - gizmoAxisX.lastT);
             if (gizmoAxisY.selected)
             if (gizmoAxisY.selected)
-                adjust += gizmoAxisY.axisRay.direction * (gizmoAxisY.t - gizmoAxisY.lastT);
+                adjust += Vector3(0, 1, 0) * (gizmoAxisY.t - gizmoAxisY.lastT);
             if (gizmoAxisZ.selected)
             if (gizmoAxisZ.selected)
-                adjust += gizmoAxisZ.axisRay.direction * (gizmoAxisZ.t - gizmoAxisZ.lastT);
+                adjust += Vector3(0, 0, 1) * (gizmoAxisZ.t - gizmoAxisZ.lastT);
 
 
             moved = MoveNodes(adjust);
             moved = MoveNodes(adjust);
         }
         }

+ 4 - 1
Engine/Engine/GraphicsAPI.cpp

@@ -506,7 +506,10 @@ static void RegisterZone(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Zone", "void set_boundingBox(const BoundingBox&in)", asMETHOD(Zone, SetBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_boundingBox(const BoundingBox&in)", asMETHOD(Zone, SetBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "const BoundingBox& get_boundingBox() const", asMETHOD(Zone, GetBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "const BoundingBox& get_boundingBox() const", asMETHOD(Zone, GetBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_ambientColor(const Color&in)", asMETHOD(Zone, SetAmbientColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_ambientColor(const Color&in)", asMETHOD(Zone, SetAmbientColor), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Zone", "const Color& get_ambientColor() const", asMETHOD(Zone, GetAmbientColor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Zone", "void set_ambientStartColor(const Color&in)", asMETHOD(Zone, SetAmbientStartColor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Zone", "const Color& get_ambientStartColor() const", asMETHOD(Zone, GetAmbientStartColor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Zone", "void set_ambientEndColor(const Color&in)", asMETHOD(Zone, SetAmbientEndColor), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Zone", "const Color& get_ambientEndColor() const", asMETHOD(Zone, GetAmbientEndColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_fogColor(const Color&in)", asMETHOD(Zone, SetFogColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_fogColor(const Color&in)", asMETHOD(Zone, SetFogColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "const Color& get_fogColor() const", asMETHOD(Zone, GetFogColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "const Color& get_fogColor() const", asMETHOD(Zone, GetFogColor), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_fogStart(float)", asMETHOD(Zone, SetFogStart), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "void set_fogStart(float)", asMETHOD(Zone, SetFogStart), asCALL_THISCALL);

+ 1 - 1
Engine/Graphics/AnimatedModel.h

@@ -60,7 +60,7 @@ public:
     virtual UpdateGeometryType GetUpdateGeometryType();
     virtual UpdateGeometryType GetUpdateGeometryType();
     /// Fill rendering batch with distance, geometry, material and world transform.
     /// Fill rendering batch with distance, geometry, material and world transform.
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex);
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex);
-    /// Add debug geometry to the debug graphics.
+    /// Add debug geometry to the debug renderer.
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     
     
     /// %Set model.
     /// %Set model.

+ 16 - 2
Engine/Graphics/Batch.cpp

@@ -157,8 +157,22 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
     // Set zone-related shader parameters
     // Set zone-related shader parameters
     if (zone_)
     if (zone_)
     {
     {
-        if (graphics->NeedParameterUpdate(PSP_AMBIENTCOLOR, zone_))
-            graphics->SetShaderParameter(PSP_AMBIENTCOLOR, zone_->GetAmbientColor().ToVector4());
+        if (graphics->NeedParameterUpdate(VSP_ZONE, zone_))
+        {
+            const BoundingBox& box = zone_->GetBoundingBox();
+            Vector3 boxSize = box.Size();
+            Matrix3x4 adjust(Matrix3x4::IDENTITY);
+            adjust.SetScale(Vector3(1.0f / boxSize.x_, 1.0f / boxSize.y_, 1.0f / boxSize.z_));
+            adjust.SetTranslation(Vector3(0.5f, 0.5f, 0.5f));
+            Matrix3x4 zoneTransform = adjust * zone_->GetWorldTransform().Inverse();
+            
+            graphics->SetShaderParameter(VSP_ZONE, zoneTransform);
+        }
+        
+        if (graphics->NeedParameterUpdate(PSP_AMBIENTSTARTCOLOR, zone_))
+            graphics->SetShaderParameter(PSP_AMBIENTSTARTCOLOR, zone_->GetAmbientStartColor().ToVector4());
+        if (graphics->NeedParameterUpdate(PSP_AMBIENTENDCOLOR, zone_))
+            graphics->SetShaderParameter(PSP_AMBIENTENDCOLOR, zone_->GetAmbientEndColor().ToVector4());
         
         
         // If the pass is additive, override fog color to black so that shaders do not need a separate additive path
         // If the pass is additive, override fog color to black so that shaders do not need a separate additive path
         BlendMode blend = pass_->GetBlendMode();
         BlendMode blend = pass_->GetBlendMode();

+ 2 - 2
Engine/Graphics/Drawable.h

@@ -105,9 +105,9 @@ public:
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex) {}
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex) {}
     /// Return number of occlusion geometry triangles.
     /// Return number of occlusion geometry triangles.
     virtual unsigned GetNumOccluderTriangles() { return 0; }
     virtual unsigned GetNumOccluderTriangles() { return 0; }
-    /// Draw to occlusion buffer.
+    /// Draw to occlusion buffer. Return true if did not run out of triangles.
     virtual bool DrawOcclusion(OcclusionBuffer* buffer) { return true; }
     virtual bool DrawOcclusion(OcclusionBuffer* buffer) { return true; }
-    /// Draw debug geometry.
+    /// Add debug geometry to the debug renderer.
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     
     
     /// %Set draw distance.
     /// %Set draw distance.

+ 3 - 1
Engine/Graphics/GraphicsDefs.cpp

@@ -41,8 +41,10 @@ StringHash VSP_UOFFSET("UOffset");
 StringHash VSP_VOFFSET("VOffset");
 StringHash VSP_VOFFSET("VOffset");
 StringHash VSP_VIEWRIGHTVECTOR("ViewRightVector");
 StringHash VSP_VIEWRIGHTVECTOR("ViewRightVector");
 StringHash VSP_VIEWUPVECTOR("ViewUpVector");
 StringHash VSP_VIEWUPVECTOR("ViewUpVector");
+StringHash VSP_ZONE("Zone");
 StringHash VSP_SKINMATRICES("SkinMatrices");
 StringHash VSP_SKINMATRICES("SkinMatrices");
-StringHash PSP_AMBIENTCOLOR("AmbientColor");
+StringHash PSP_AMBIENTSTARTCOLOR("AmbientStartColor");
+StringHash PSP_AMBIENTENDCOLOR("AmbientEndColor");
 StringHash PSP_FOGCOLOR("FogColor");
 StringHash PSP_FOGCOLOR("FogColor");
 StringHash PSP_FOGPARAMS("FogParams");
 StringHash PSP_FOGPARAMS("FogParams");
 StringHash PSP_LIGHTCOLOR("LightColor");
 StringHash PSP_LIGHTCOLOR("LightColor");

+ 3 - 1
Engine/Graphics/GraphicsDefs.h

@@ -209,8 +209,10 @@ extern StringHash VSP_UOFFSET;
 extern StringHash VSP_VOFFSET;
 extern StringHash VSP_VOFFSET;
 extern StringHash VSP_VIEWRIGHTVECTOR;
 extern StringHash VSP_VIEWRIGHTVECTOR;
 extern StringHash VSP_VIEWUPVECTOR;
 extern StringHash VSP_VIEWUPVECTOR;
+extern StringHash VSP_ZONE;
 extern StringHash VSP_SKINMATRICES;
 extern StringHash VSP_SKINMATRICES;
-extern StringHash PSP_AMBIENTCOLOR;
+extern StringHash PSP_AMBIENTSTARTCOLOR;
+extern StringHash PSP_AMBIENTENDCOLOR;
 extern StringHash PSP_FOGCOLOR;
 extern StringHash PSP_FOGCOLOR;
 extern StringHash PSP_FOGPARAMS;
 extern StringHash PSP_FOGPARAMS;
 extern StringHash PSP_LIGHTCOLOR;
 extern StringHash PSP_LIGHTCOLOR;

+ 1 - 1
Engine/Graphics/Light.h

@@ -162,7 +162,7 @@ public:
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     /// Calculate distance for rendering. May be called from worker thread(s), possibly re-entrantly.
     /// Calculate distance for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateDistance(const FrameInfo& frame);
     virtual void UpdateDistance(const FrameInfo& frame);
-    /// Add debug geometry to the debug graphics.
+    /// Add debug geometry to the debug renderer.
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     
     
     /// %Set light type.
     /// %Set light type.

+ 1 - 1
Engine/Graphics/Octree.h

@@ -191,7 +191,7 @@ public:
     void CancelUpdate(Drawable* drawable);
     void CancelUpdate(Drawable* drawable);
     /// Remove drawable object from reinsertion list.
     /// Remove drawable object from reinsertion list.
     void CancelReinsertion(Drawable* drawable);
     void CancelReinsertion(Drawable* drawable);
-    /// Add debug geometry to the debug graphics.
+    /// Add debug geometry to the debug renderer.
     void DrawDebugGeometry(bool depthTest);
     void DrawDebugGeometry(bool depthTest);
     
     
 protected:
 protected:

+ 1 - 1
Engine/Graphics/Renderer.h

@@ -223,7 +223,7 @@ public:
     void Update(float timeStep);
     void Update(float timeStep);
     /// Render. Called by Engine.
     /// Render. Called by Engine.
     void Render();
     void Render();
-    /// Add debug geometry to the debug renderer(s).
+    /// Add debug geometry to the debug renderer.
     void DrawDebugGeometry(bool depthTest);
     void DrawDebugGeometry(bool depthTest);
     /// Add a view. Return true if successful.
     /// Add a view. Return true if successful.
     bool AddView(RenderSurface* renderTarget, const Viewport& viewport);
     bool AddView(RenderSurface* renderTarget, const Viewport& viewport);

+ 1 - 1
Engine/Graphics/StaticModel.h

@@ -50,7 +50,7 @@ public:
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex);
     virtual void GetBatch(Batch& batch, const FrameInfo& frame, unsigned batchIndex);
     /// Return number of occlusion geometry triangles.
     /// Return number of occlusion geometry triangles.
     virtual unsigned GetNumOccluderTriangles();
     virtual unsigned GetNumOccluderTriangles();
-    /// Draw to occlusion buffer.
+    /// Draw to occlusion buffer. Return true if did not run out of triangles.
     virtual bool DrawOcclusion(OcclusionBuffer* buffer);
     virtual bool DrawOcclusion(OcclusionBuffer* buffer);
     
     
     /// %Set model.
     /// %Set model.

+ 21 - 3
Engine/Graphics/Zone.cpp

@@ -23,6 +23,7 @@
 
 
 #include "Precompiled.h"
 #include "Precompiled.h"
 #include "Context.h"
 #include "Context.h"
+#include "DebugRenderer.h"
 #include "Octree.h"
 #include "Octree.h"
 #include "XMLElement.h"
 #include "XMLElement.h"
 #include "Zone.h"
 #include "Zone.h"
@@ -36,7 +37,8 @@ OBJECTTYPESTATIC(Zone);
 
 
 Zone::Zone(Context* context) :
 Zone::Zone(Context* context) :
     Drawable(context),
     Drawable(context),
-    ambientColor_(DEFAULT_AMBIENT_COLOR),
+    ambientStartColor_(DEFAULT_AMBIENT_COLOR),
+    ambientEndColor_(DEFAULT_AMBIENT_COLOR),
     fogColor_(DEFAULT_FOG_COLOR),
     fogColor_(DEFAULT_FOG_COLOR),
     fogStart_(DEFAULT_FOG_START),
     fogStart_(DEFAULT_FOG_START),
     fogEnd_(DEFAULT_FOG_END),
     fogEnd_(DEFAULT_FOG_END),
@@ -56,7 +58,8 @@ void Zone::RegisterObject(Context* context)
     
     
     ATTRIBUTE(Zone, VAR_VECTOR3, "Bounding Box Min", boundingBox_.min_, Vector3::ZERO, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_VECTOR3, "Bounding Box Min", boundingBox_.min_, Vector3::ZERO, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_VECTOR3, "Bounding Box Max", boundingBox_.max_, Vector3::ZERO, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_VECTOR3, "Bounding Box Max", boundingBox_.max_, Vector3::ZERO, AM_DEFAULT);
-    ATTRIBUTE(Zone, VAR_COLOR, "Ambient Color", ambientColor_, DEFAULT_AMBIENT_COLOR, AM_DEFAULT);
+    ATTRIBUTE(Zone, VAR_COLOR, "Ambient Color (Min Z)", ambientStartColor_, DEFAULT_AMBIENT_COLOR, AM_DEFAULT);
+    ATTRIBUTE(Zone, VAR_COLOR, "Ambient Color (Max Z)", ambientEndColor_, DEFAULT_AMBIENT_COLOR, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_COLOR, "Fog Color", fogColor_, DEFAULT_FOG_COLOR, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_COLOR, "Fog Color", fogColor_, DEFAULT_FOG_COLOR, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_FLOAT, "Fog Start", fogStart_, DEFAULT_FOG_START, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_FLOAT, "Fog Start", fogStart_, DEFAULT_FOG_START, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_FLOAT, "Fog End", fogEnd_, DEFAULT_FOG_END, AM_DEFAULT);
     ATTRIBUTE(Zone, VAR_FLOAT, "Fog End", fogEnd_, DEFAULT_FOG_END, AM_DEFAULT);
@@ -83,6 +86,11 @@ void Zone::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
     }
     }
 }
 }
 
 
+void Zone::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
+{
+    debug->AddBoundingBox(boundingBox_, GetWorldTransform(), Color::GREEN, depthTest);
+}
+
 void Zone::SetBoundingBox(const BoundingBox& box)
 void Zone::SetBoundingBox(const BoundingBox& box)
 {
 {
     boundingBox_ = box;
     boundingBox_ = box;
@@ -91,7 +99,17 @@ void Zone::SetBoundingBox(const BoundingBox& box)
 
 
 void Zone::SetAmbientColor(const Color& color)
 void Zone::SetAmbientColor(const Color& color)
 {
 {
-    ambientColor_ = Color(color, 1.0f);
+    ambientStartColor_ = ambientEndColor_ = Color(color, 1.0f);
+}
+
+void Zone::SetAmbientStartColor(const Color& color)
+{
+    ambientStartColor_ = Color(color, 1.0f);
+}
+
+void Zone::SetAmbientEndColor(const Color& color)
+{
+    ambientEndColor_ = Color(color, 1.0f);
 }
 }
 
 
 void Zone::SetFogColor(const Color& color)
 void Zone::SetFogColor(const Color& color)

+ 15 - 5
Engine/Graphics/Zone.h

@@ -41,11 +41,17 @@ public:
     
     
     /// Handle attribute write access.
     /// Handle attribute write access.
     virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
     virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
+    /// Add debug geometry to the debug renderer.
+    virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     
     
     /// %Set bounding box. Will be used as an oriented bounding box to test whether the camera is inside.
     /// %Set bounding box. Will be used as an oriented bounding box to test whether the camera is inside.
     void SetBoundingBox(const BoundingBox& box);
     void SetBoundingBox(const BoundingBox& box);
-    /// %Set ambient color.
+    /// %Set ambient color, both start and end.
     void SetAmbientColor(const Color& color);
     void SetAmbientColor(const Color& color);
+    /// %Set ambient start color at bounding box Z minimum.
+    void SetAmbientStartColor(const Color& color);
+    /// %Set ambient end color at bounding box Z maximum.
+    void SetAmbientEndColor(const Color& color);
     /// %Set fog color.
     /// %Set fog color.
     void SetFogColor(const Color& color);
     void SetFogColor(const Color& color);
     /// %Set fog start distance.
     /// %Set fog start distance.
@@ -59,8 +65,10 @@ public:
     
     
     /// Return bounding box.
     /// Return bounding box.
     const BoundingBox& GetBoundingBox() const { return boundingBox_; }
     const BoundingBox& GetBoundingBox() const { return boundingBox_; }
-    /// Return ambient color.
-    const Color& GetAmbientColor() const { return ambientColor_; }
+    /// Return ambient start color.
+    const Color& GetAmbientStartColor() const { return ambientStartColor_; }
+    /// Return ambient end color.
+    const Color& GetAmbientEndColor() const { return ambientEndColor_; }
     /// Return fog color.
     /// Return fog color.
     const Color& GetFogColor() const { return fogColor_; }
     const Color& GetFogColor() const { return fogColor_; }
     /// Return fog start distance.
     /// Return fog start distance.
@@ -85,8 +93,10 @@ protected:
     BoundingBox boundingBox_;
     BoundingBox boundingBox_;
     /// Last bounding box.
     /// Last bounding box.
     BoundingBox lastBoundingBox_;
     BoundingBox lastBoundingBox_;
-    /// Ambient color.
-    Color ambientColor_;
+    /// Ambient start color.
+    Color ambientStartColor_;
+    /// Ambient end start color.
+    Color ambientEndColor_;
     /// Fog color.
     /// Fog color.
     Color fogColor_;
     Color fogColor_;
     /// Fog start distance.
     /// Fog start distance.

+ 1 - 1
Engine/Physics/CollisionShape.h

@@ -172,7 +172,7 @@ public:
     
     
     /// Update geometry transform and associate with rigid body if available.
     /// Update geometry transform and associate with rigid body if available.
     void UpdateTransform(bool nodeUpdate = false);
     void UpdateTransform(bool nodeUpdate = false);
-    /// Add debug geometry to the debug graphics.
+    /// Add debug geometry to the debug renderer.
     void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
     
     
     /// %Set model attribute.
     /// %Set model attribute.

+ 1 - 1
Engine/Physics/PhysicsWorld.h

@@ -185,7 +185,7 @@ public:
     void RemoveJoint(Joint* joint);
     void RemoveJoint(Joint* joint);
     /// Send accumulated collision events.
     /// Send accumulated collision events.
     void SendCollisionEvents();
     void SendCollisionEvents();
-    /// Add debug geometry to the debug graphics.
+    /// Add debug geometry to the debug renderer.
     void DrawDebugGeometry(bool depthTest);
     void DrawDebugGeometry(bool depthTest);
     
     
     /// Clean up the geometry cache.
     /// Clean up the geometry cache.

+ 3 - 2
SourceAssets/GLSLShaders/Ambient.frag

@@ -1,12 +1,13 @@
 #include "Uniforms.frag"
 #include "Uniforms.frag"
 #include "Samplers.frag"
 #include "Samplers.frag"
 #include "Fog.frag"
 #include "Fog.frag"
+#include "Lighting.frag"
 
 
 varying vec2 vTexCoord;
 varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec2 vZonePosDepth;
 
 
 void main()
 void main()
 {
 {
@@ -20,5 +21,5 @@ void main()
         diffColor *= vColor;
         diffColor *= vColor;
     #endif
     #endif
 
 
-    gl_FragColor = vec4(GetFog(cAmbientColor * diffColor.rgb, vLightVec.w), diffColor.a);
+    gl_FragColor = vec4(GetFog(GetAmbient(vZonePosDepth.x) * diffColor.rgb, vZonePosDepth.y), diffColor.a);
 }
 }

+ 2 - 2
SourceAssets/GLSLShaders/Ambient.vert

@@ -5,7 +5,7 @@ varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec2 vZonePosDepth;
 
 
 void main()
 void main()
 {
 {
@@ -13,7 +13,7 @@ void main()
     vec3 worldPos = GetWorldPos(modelMatrix);
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
     gl_Position = GetClipPos(worldPos);
     vTexCoord = GetTexCoord(iTexCoord);
     vTexCoord = GetTexCoord(iTexCoord);
-    vLightVec = vec4(0.0, 0.0, 0.0, GetDepth(gl_Position));
+    vZonePosDepth = vec2(GetZonePos(worldPos), GetDepth(gl_Position));
 
 
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         vColor = iColor;
         vColor = iColor;

+ 13 - 13
SourceAssets/GLSLShaders/BlinnPhong.frag

@@ -3,11 +3,11 @@
 #include "Lighting.frag"
 #include "Lighting.frag"
 #include "Fog.frag"
 #include "Fog.frag"
 
 
-varying vec2 vTexCoord;
+varying vec4 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec3 vLightVec;
 #ifdef SPECULAR
 #ifdef SPECULAR
     varying vec3 vEyeVec;
     varying vec3 vEyeVec;
 #endif
 #endif
@@ -33,7 +33,7 @@ varying vec4 vLightVec;
 void main()
 void main()
 {
 {
     #ifdef DIFFMAP
     #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
+        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord.xy);
     #else
     #else
         vec4 diffColor = cMatDiffColor;
         vec4 diffColor = cMatDiffColor;
     #endif
     #endif
@@ -48,26 +48,26 @@ void main()
     float diff;
     float diff;
 
 
     #ifdef NORMALMAP
     #ifdef NORMALMAP
-        vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord));
+        vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord.xy));
     #else
     #else
         vec3 normal = normalize(vNormal);
         vec3 normal = normalize(vNormal);
     #endif
     #endif
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
         #ifdef NORMALMAP
         #ifdef NORMALMAP
-            lightDir = normalize(vLightVec.xyz);
+            lightDir = normalize(vLightVec);
         #else
         #else
-            lightDir = vLightVec.xyz;
+            lightDir = vLightVec;
         #endif
         #endif
         diff = GetDiffuseDir(normal, lightDir);
         diff = GetDiffuseDir(normal, lightDir);
     #else
     #else
-        diff = GetDiffusePointOrSpot(normal, vLightVec.xyz, lightDir);
+        diff = GetDiffusePointOrSpot(normal, vLightVec, lightDir);
     #endif
     #endif
 
 
     #ifdef SHADOW
     #ifdef SHADOW
         #if defined(DIRLIGHT)
         #if defined(DIRLIGHT)
-            vec4 shadowPos = GetDirShadowPos(vShadowPos, vLightVec.w);
-            diff *= min(GetShadow(shadowPos) + GetShadowFade(vLightVec.w), 1.0);
+            vec4 shadowPos = GetDirShadowPos(vShadowPos, vTexCoord.w);
+            diff *= min(GetShadow(shadowPos) + GetShadowFade(vTexCoord.w), 1.0);
         #elif defined(SPOTLIGHT)
         #elif defined(SPOTLIGHT)
             diff *= GetShadow(vShadowPos);
             diff *= GetShadow(vShadowPos);
         #else
         #else
@@ -85,7 +85,7 @@ void main()
 
 
     #ifdef SPECULAR
     #ifdef SPECULAR
         #ifdef SPECMAP
         #ifdef SPECMAP
-            float specStrength = cMatSpecProperties.x * texture2D(sSpecMap, vTexCoord).g;
+            float specStrength = cMatSpecProperties.x * texture2D(sSpecMap, vTexCoord.xy).g;
         #else
         #else
             float specStrength = cMatSpecProperties.x;
             float specStrength = cMatSpecProperties.x;
         #endif
         #endif
@@ -96,9 +96,9 @@ void main()
     #endif
     #endif
 
 
     #ifdef AMBIENT
     #ifdef AMBIENT
-        finalColor += cAmbientColor * diffColor.rgb;
-        gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
+        finalColor += GetAmbient(vTexCoord.z) * diffColor.rgb;
+        gl_FragColor = vec4(GetFog(finalColor, vTexCoord.w), diffColor.a);
     #else
     #else
-        gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
+        gl_FragColor = vec4(GetLitFog(finalColor, vTexCoord.w), diffColor.a);
     #endif
     #endif
 }
 }

+ 7 - 7
SourceAssets/GLSLShaders/BlinnPhong.vert

@@ -1,11 +1,11 @@
 #include "Uniforms.vert"
 #include "Uniforms.vert"
 #include "Transform.vert"
 #include "Transform.vert"
 
 
-varying vec2 vTexCoord;
+varying vec4 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec3 vLightVec;
 #ifdef SPECULAR
 #ifdef SPECULAR
     varying vec3 vEyeVec;
     varying vec3 vEyeVec;
 #endif
 #endif
@@ -33,7 +33,7 @@ void main()
     mat4 modelMatrix = iModelMatrix;
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
     gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
+    vTexCoord = vec4(GetTexCoord(iTexCoord), GetZonePos(worldPos), GetDepth(gl_Position));
 
 
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         vColor = iColor;
         vColor = iColor;
@@ -50,9 +50,9 @@ void main()
     vec4 projWorldPos = vec4(worldPos, 1.0);
     vec4 projWorldPos = vec4(worldPos, 1.0);
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
-        vLightVec = vec4(cLightDir, GetDepth(gl_Position));
+        vLightVec = cLightDir;
     #else
     #else
-        vLightVec = vec4((cLightPos - centeredWorldPos) * cLightAtten, GetDepth(gl_Position));
+        vLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
     #endif
     #endif
 
 
     #ifdef SHADOW
     #ifdef SHADOW
@@ -75,14 +75,14 @@ void main()
     #endif
     #endif
 
 
     #ifdef POINTLIGHT
     #ifdef POINTLIGHT
-        vCubeMaskVec = cLightVecRot * vLightVec.xyz;
+        vCubeMaskVec = cLightVecRot * vLightVec;
     #endif
     #endif
 
 
     #ifdef NORMALMAP
     #ifdef NORMALMAP
         vTangent = GetWorldTangent(modelMatrix);
         vTangent = GetWorldTangent(modelMatrix);
         vBitangent = cross(vTangent, vNormal) * iTangent.w;
         vBitangent = cross(vTangent, vNormal) * iTangent.w;
         mat3 tbn = mat3(vTangent, vBitangent, vNormal);
         mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-        vLightVec.xyz = vLightVec.xyz * tbn;
+        vLightVec = vLightVec * tbn;
         #ifdef SPECULAR
         #ifdef SPECULAR
             vEyeVec = -centeredWorldPos * tbn;
             vEyeVec = -centeredWorldPos * tbn;
         #endif
         #endif

+ 5 - 0
SourceAssets/GLSLShaders/Lighting.frag

@@ -27,6 +27,11 @@ float GetSpecular(vec3 normal, vec3 eyeVec, vec3 lightDir, float specularPower)
     return pow(max(dot(normal, halfVec), 0.0), specularPower);
     return pow(max(dot(normal, halfVec), 0.0), specularPower);
 }
 }
 
 
+vec3 GetAmbient(float zonePos)
+{
+    return mix(cAmbientStartColor, cAmbientEndColor, zonePos);
+}
+
 float GetShadow(vec4 shadowPos)
 float GetShadow(vec4 shadowPos)
 {
 {
     // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
     // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed

+ 5 - 0
SourceAssets/GLSLShaders/Transform.vert

@@ -34,6 +34,11 @@ vec4 GetClipPos(vec3 worldPos)
     return cViewProj * vec4(worldPos, 1.0);
     return cViewProj * vec4(worldPos, 1.0);
 }
 }
 
 
+float GetZonePos(vec3 worldPos)
+{
+    return clamp((cZone * vec4(worldPos, 1.0)).z, 0.0, 1.0);
+}
+
 float GetDepth(vec4 clipPos)
 float GetDepth(vec4 clipPos)
 {
 {
     return dot(clipPos.zw, cDepthMode.zw);
     return dot(clipPos.zw, cDepthMode.zw);

+ 2 - 1
SourceAssets/GLSLShaders/Uniforms.frag

@@ -1,4 +1,5 @@
-uniform vec3 cAmbientColor;
+uniform vec3 cAmbientStartColor;
+uniform vec3 cAmbientEndColor;
 uniform vec4 cFogParams;
 uniform vec4 cFogParams;
 uniform vec3 cFogColor;
 uniform vec3 cFogColor;
 uniform vec4 cLightColor;
 uniform vec4 cLightColor;

+ 1 - 0
SourceAssets/GLSLShaders/Uniforms.vert

@@ -12,5 +12,6 @@ uniform vec4 cUOffset;
 uniform vec4 cVOffset;
 uniform vec4 cVOffset;
 uniform vec3 cViewRightVector;
 uniform vec3 cViewRightVector;
 uniform vec3 cViewUpVector;
 uniform vec3 cViewUpVector;
+uniform mat4 cZone;
 uniform mat4 cShadowProj[4];
 uniform mat4 cShadowProj[4];
 uniform vec4 cSkinMatrices[64*3];
 uniform vec4 cSkinMatrices[64*3];

+ 6 - 5
SourceAssets/GLSLShaders/Volumetric.frag

@@ -7,7 +7,8 @@ varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec3 vLightVec;
+varying vec2 vZonePosDepth;
 #ifdef SPOTLIGHT
 #ifdef SPOTLIGHT
     varying vec4 vSpotPos;
     varying vec4 vSpotPos;
 #endif
 #endif
@@ -35,7 +36,7 @@ void main()
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
         diff = GetDiffuseDirVolumetric();
         diff = GetDiffuseDirVolumetric();
     #else
     #else
-        diff = GetDiffusePointOrSpotVolumetric(vLightVec.xyz);
+        diff = GetDiffusePointOrSpotVolumetric(vLightVec);
     #endif
     #endif
 
 
     #if defined(SPOTLIGHT)
     #if defined(SPOTLIGHT)
@@ -49,9 +50,9 @@ void main()
     finalColor = diff * lightColor * diffColor.rgb;
     finalColor = diff * lightColor * diffColor.rgb;
     
     
     #ifdef AMBIENT
     #ifdef AMBIENT
-        finalColor += cAmbientColor * diffColor.rgb;
-        gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
+        finalColor += GetAmbient(vZonePosDepth.x) * diffColor.rgb;
+        gl_FragColor = vec4(GetFog(finalColor, vZonePosDepth.y), diffColor.a);
     #else
     #else
-        gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
+        gl_FragColor = vec4(GetLitFog(finalColor, vZonePosDepth.y), diffColor.a);
     #endif
     #endif
 }
 }

+ 6 - 3
SourceAssets/GLSLShaders/Volumetric.vert

@@ -5,7 +5,8 @@ varying vec2 vTexCoord;
 #ifdef VERTEXCOLOR
 #ifdef VERTEXCOLOR
     varying vec4 vColor;
     varying vec4 vColor;
 #endif
 #endif
-varying vec4 vLightVec;
+varying vec3 vLightVec;
+varying vec2 vZonePosDepth;
 #ifdef SPOTLIGHT
 #ifdef SPOTLIGHT
     varying vec4 vSpotPos;
     varying vec4 vSpotPos;
 #endif
 #endif
@@ -28,10 +29,12 @@ void main()
     vec4 projWorldPos = vec4(worldPos, 1.0);
     vec4 projWorldPos = vec4(worldPos, 1.0);
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
-        vLightVec = vec4(cLightDir, GetDepth(gl_Position));
+        vLightVec = cLightDir;
     #else
     #else
-        vLightVec = vec4((cLightPos - centeredWorldPos) * cLightAtten, GetDepth(gl_Position));
+        vLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
     #endif
     #endif
+    
+    vZonePosDepth = vec2(GetZonePos(worldPos), GetDepth(gl_Position));
 
 
     #ifdef SPOTLIGHT
     #ifdef SPOTLIGHT
         // Spotlight projection: transform from world space to projector texture coordinates
         // Spotlight projection: transform from world space to projector texture coordinates

+ 5 - 4
SourceAssets/HLSLShaders/Ambient.hlsl

@@ -1,6 +1,7 @@
 #include "Uniforms.hlsl"
 #include "Uniforms.hlsl"
 #include "Samplers.hlsl"
 #include "Samplers.hlsl"
 #include "Transform.hlsl"
 #include "Transform.hlsl"
+#include "Lighting.hlsl"
 #include "Fog.hlsl"
 #include "Fog.hlsl"
 
 
 void VS(float4 iPos : POSITION,
 void VS(float4 iPos : POSITION,
@@ -19,7 +20,7 @@ void VS(float4 iPos : POSITION,
         float2 iSize : TEXCOORD1,
         float2 iSize : TEXCOORD1,
     #endif
     #endif
     out float2 oTexCoord : TEXCOORD0,
     out float2 oTexCoord : TEXCOORD0,
-    out float4 oLightVec : TEXCOORD1,
+    out float2 oZonePosDepth : TEXCOORD1,
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         out float4 oColor : COLOR0,
         out float4 oColor : COLOR0,
     #endif
     #endif
@@ -29,7 +30,7 @@ void VS(float4 iPos : POSITION,
     float3 worldPos = GetWorldPos(modelMatrix);
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
     oPos = GetClipPos(worldPos);
     oTexCoord = GetTexCoord(iTexCoord);
     oTexCoord = GetTexCoord(iTexCoord);
-    oLightVec = float4(0.0, 0.0, 0.0, GetDepth(oPos));
+    oZonePosDepth = float2(GetZonePos(worldPos), GetDepth(oPos));
 
 
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         oColor = iColor;
         oColor = iColor;
@@ -37,7 +38,7 @@ void VS(float4 iPos : POSITION,
 }
 }
 
 
 void PS(float2 iTexCoord : TEXCOORD0,
 void PS(float2 iTexCoord : TEXCOORD0,
-    float4 iLightVec : TEXCOORD1,
+    float2 iZonePosDepth : TEXCOORD1,
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         float4 iColor : COLOR0,
         float4 iColor : COLOR0,
     #endif
     #endif
@@ -53,5 +54,5 @@ void PS(float2 iTexCoord : TEXCOORD0,
         diffColor *= iColor;
         diffColor *= iColor;
     #endif
     #endif
 
 
-    oColor = float4(GetFog(cAmbientColor * diffColor.rgb, iLightVec.w), diffColor.a);
+    oColor = float4(GetFog(GetAmbient(iZonePosDepth.x) * diffColor.rgb, iZonePosDepth.y), diffColor.a);
 }
 }

+ 22 - 20
SourceAssets/HLSLShaders/BlinnPhong.hlsl

@@ -23,8 +23,8 @@ void VS(float4 iPos : POSITION,
     #ifdef BILLBOARD
     #ifdef BILLBOARD
         float2 iSize : TEXCOORD1,
         float2 iSize : TEXCOORD1,
     #endif
     #endif
-    out float2 oTexCoord : TEXCOORD0,
-    out float4 oLightVec : TEXCOORD1,
+    out float4 oTexCoord : TEXCOORD0,
+    out float3 oLightVec : TEXCOORD1,
     #ifndef NORMALMAP
     #ifndef NORMALMAP
         out float3 oNormal : TEXCOORD2,
         out float3 oNormal : TEXCOORD2,
     #endif
     #endif
@@ -54,7 +54,7 @@ void VS(float4 iPos : POSITION,
     float4x3 modelMatrix = iModelMatrix;
     float4x3 modelMatrix = iModelMatrix;
     float3 worldPos = GetWorldPos(modelMatrix);
     float3 worldPos = GetWorldPos(modelMatrix);
     oPos = GetClipPos(worldPos);
     oPos = GetClipPos(worldPos);
-    oTexCoord = GetTexCoord(iTexCoord);
+    oTexCoord = float4(GetTexCoord(iTexCoord), GetZonePos(worldPos), GetDepth(oPos));
 
 
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         oColor = iColor;
         oColor = iColor;
@@ -71,9 +71,9 @@ void VS(float4 iPos : POSITION,
     float4 projWorldPos = float4(worldPos, 1.0);
     float4 projWorldPos = float4(worldPos, 1.0);
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
-        oLightVec = float4(cLightDir, GetDepth(oPos));
+        oLightVec = cLightDir;
     #else
     #else
-        oLightVec = float4((cLightPos - centeredWorldPos) * cLightAtten, GetDepth(oPos));
+        oLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
     #endif
     #endif
 
 
     #ifdef SHADOW
     #ifdef SHADOW
@@ -96,14 +96,14 @@ void VS(float4 iPos : POSITION,
     #endif
     #endif
 
 
     #ifdef POINTLIGHT
     #ifdef POINTLIGHT
-        oCubeMaskVec = mul(oLightVec.xyz, cLightVecRot);
+        oCubeMaskVec = mul(oLightVec, cLightVecRot);
     #endif
     #endif
 
 
     #ifdef NORMALMAP
     #ifdef NORMALMAP
         oTangent = GetWorldTangent(modelMatrix);
         oTangent = GetWorldTangent(modelMatrix);
         oBitangent = cross(oTangent, oNormal) * iTangent.w;
         oBitangent = cross(oTangent, oNormal) * iTangent.w;
         float3x3 tbn = float3x3(oTangent, oBitangent, oNormal);
         float3x3 tbn = float3x3(oTangent, oBitangent, oNormal);
-        oLightVec.xyz = mul(tbn, oLightVec.xyz);
+        oLightVec = mul(tbn, oLightVec);
         #ifdef SPECULAR
         #ifdef SPECULAR
             oEyeVec = mul(tbn, -centeredWorldPos);
             oEyeVec = mul(tbn, -centeredWorldPos);
         #endif
         #endif
@@ -112,8 +112,8 @@ void VS(float4 iPos : POSITION,
     #endif
     #endif
 }
 }
 
 
-void PS(float2 iTexCoord : TEXCOORD0,
-    float4 iLightVec : TEXCOORD1,
+void PS(float4 iTexCoord : TEXCOORD0,
+    float3 iLightVec : TEXCOORD1,
     #ifndef NORMALMAP
     #ifndef NORMALMAP
         float3 iNormal : TEXCOORD2,
         float3 iNormal : TEXCOORD2,
     #endif
     #endif
@@ -141,17 +141,19 @@ void PS(float2 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
     out float4 oColor : COLOR0)
 {
 {
     #ifdef DIFFMAP
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
+        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord.xy);
     #else
     #else
         float4 diffColor = cMatDiffColor;
         float4 diffColor = cMatDiffColor;
     #endif
     #endif
 
 
+    /*
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         diffColor *= iColor;
         diffColor *= iColor;
     #endif
     #endif
+    */
 
 
     #ifdef NORMALMAP
     #ifdef NORMALMAP
-        float3 normal = DecodeNormal(tex2D(sNormalMap, iTexCoord));
+        float3 normal = DecodeNormal(tex2D(sNormalMap, iTexCoord.xy));
     #else
     #else
         float3 normal = normalize(iNormal);
         float3 normal = normalize(iNormal);
     #endif
     #endif
@@ -163,19 +165,19 @@ void PS(float2 iTexCoord : TEXCOORD0,
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
         #ifdef NORMALMAP
         #ifdef NORMALMAP
-            lightDir = normalize(iLightVec.xyz);
+            lightDir = normalize(iLightVec);
         #else
         #else
-            lightDir = iLightVec.xyz;
+            lightDir = iLightVec;
         #endif
         #endif
         diff = GetDiffuseDir(normal, lightDir);
         diff = GetDiffuseDir(normal, lightDir);
     #else
     #else
-        diff = GetDiffusePointOrSpot(normal, iLightVec.xyz, lightDir);
+        diff = GetDiffusePointOrSpot(normal, iLightVec, lightDir);
     #endif
     #endif
 
 
     #ifdef SHADOW
     #ifdef SHADOW
         #if defined(DIRLIGHT)
         #if defined(DIRLIGHT)
-            float4 shadowPos = GetDirShadowPos(iShadowPos, iLightVec.w);
-            diff *= saturate(GetShadow(shadowPos) + GetShadowFade(iLightVec.w));
+            float4 shadowPos = GetDirShadowPos(iShadowPos, iTexCoord.w);
+            diff *= saturate(GetShadow(shadowPos) + GetShadowFade(iTexCoord.w));
         #elif defined(SPOTLIGHT)
         #elif defined(SPOTLIGHT)
             diff *= GetShadow(iShadowPos);
             diff *= GetShadow(iShadowPos);
         #else
         #else
@@ -193,7 +195,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
 
 
     #ifdef SPECULAR
     #ifdef SPECULAR
         #ifdef SPECMAP
         #ifdef SPECMAP
-            float specStrength = cMatSpecProperties.x * tex2D(sSpecMap, iTexCoord).g;
+            float specStrength = cMatSpecProperties.x * tex2D(sSpecMap, iTexCoord.xy).g;
         #else
         #else
             float specStrength = cMatSpecProperties.x;
             float specStrength = cMatSpecProperties.x;
         #endif
         #endif
@@ -204,9 +206,9 @@ void PS(float2 iTexCoord : TEXCOORD0,
     #endif
     #endif
 
 
     #ifdef AMBIENT
     #ifdef AMBIENT
-        finalColor += cAmbientColor * diffColor.rgb;
-        oColor = float4(GetFog(finalColor, iLightVec.w), diffColor.a);
+        finalColor += GetAmbient(iTexCoord.z) * diffColor.rgb;
+        oColor = float4(GetFog(finalColor, iTexCoord.w), diffColor.a);
     #else
     #else
-        oColor = float4(GetLitFog(finalColor, iLightVec.w), diffColor.a);
+        oColor = float4(GetLitFog(finalColor, iTexCoord.w), diffColor.a);
     #endif
     #endif
 }
 }

+ 5 - 0
SourceAssets/HLSLShaders/Lighting.hlsl

@@ -29,6 +29,11 @@ float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularP
     return pow(dot(normal, halfVec), specularPower);
     return pow(dot(normal, halfVec), specularPower);
 }
 }
 
 
+float3 GetAmbient(float zonePos)
+{
+    return lerp(cAmbientStartColor, cAmbientEndColor, zonePos);
+}
+
 float GetShadow(float4 shadowPos)
 float GetShadow(float4 shadowPos)
 {
 {
     // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
     // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed

+ 5 - 0
SourceAssets/HLSLShaders/Transform.hlsl

@@ -16,6 +16,11 @@ float4 GetClipPos(float3 worldPos)
     return mul(float4(worldPos, 1.0), cViewProj);
     return mul(float4(worldPos, 1.0), cViewProj);
 }
 }
 
 
+float GetZonePos(float3 worldPos)
+{
+    return saturate(mul(float4(worldPos, 1.0), cZone).z);
+}
+
 float GetDepth(float4 clipPos)
 float GetDepth(float4 clipPos)
 {
 {
     return dot(clipPos.zw, cDepthMode.zw);
     return dot(clipPos.zw, cDepthMode.zw);

+ 17 - 15
SourceAssets/HLSLShaders/Uniforms.hlsl

@@ -13,20 +13,22 @@ uniform float4 cUOffset : register(C22);
 uniform float4 cVOffset : register(C23);
 uniform float4 cVOffset : register(C23);
 uniform float3 cViewRightVector : register(C24);
 uniform float3 cViewRightVector : register(C24);
 uniform float3 cViewUpVector : register(C25);
 uniform float3 cViewUpVector : register(C25);
-uniform float4x4 cShadowProj[4] : register(C26);
-uniform float4x3 cSkinMatrices[64] : register(C42);
+uniform float4x3 cZone : register(C26);
+uniform float4x4 cShadowProj[4] : register(C29);
+uniform float4x3 cSkinMatrices[64] : register(C45);
 
 
 // Pixel shader parameters
 // Pixel shader parameters
-uniform float3 cAmbientColor : register(C0);
-uniform float4 cFogParams : register(C1);
-uniform float3 cFogColor : register(C2);
-uniform float4 cLightColor : register(C3);
-uniform float4 cMatDiffColor : register(C4);
-uniform float3 cMatEmissiveColor : register(C5);
-uniform float2 cMatSpecProperties : register(C6);
-uniform float2 cSampleOffsets : register(C7);
-uniform float4 cShadowCubeAdjust : register(C8);
-uniform float2 cShadowCubeProj : register(C9);
-uniform float2 cShadowFade : register(C10);
-uniform float4 cShadowIntensity : register(C11);
-uniform float4 cShadowSplits : register(C12);
+uniform float3 cAmbientStartColor : register(C0);
+uniform float3 cAmbientEndColor : register(C1);
+uniform float4 cFogParams : register(C2);
+uniform float3 cFogColor : register(C3);
+uniform float4 cLightColor : register(C4);
+uniform float4 cMatDiffColor : register(C5);
+uniform float3 cMatEmissiveColor : register(C6);
+uniform float2 cMatSpecProperties : register(C7);
+uniform float2 cSampleOffsets : register(C8);
+uniform float4 cShadowCubeAdjust : register(C9);
+uniform float2 cShadowCubeProj : register(C10);
+uniform float2 cShadowFade : register(C11);
+uniform float4 cShadowIntensity : register(C12);
+uniform float4 cShadowSplits : register(C13);

+ 17 - 13
SourceAssets/HLSLShaders/Volumetric.hlsl

@@ -21,12 +21,13 @@ void VS(float4 iPos : POSITION,
         float2 iSize : TEXCOORD1,
         float2 iSize : TEXCOORD1,
     #endif
     #endif
     out float2 oTexCoord : TEXCOORD0,
     out float2 oTexCoord : TEXCOORD0,
-    out float4 oLightVec : TEXCOORD1,
+    out float3 oLightVec : TEXCOORD1,
+    out float2 oZonePosDepth : TEXCOORD2,
     #ifdef SPOTLIGHT
     #ifdef SPOTLIGHT
-        out float4 oSpotPos : TEXCOORD2,
+        out float4 oSpotPos : TEXCOORD3,
     #endif
     #endif
     #ifdef POINTLIGHT
     #ifdef POINTLIGHT
-        out float3 oCubeMaskVec : TEXCOORD2,
+        out float3 oCubeMaskVec : TEXCOORD3,
     #endif
     #endif
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         out float4 oColor : COLOR0,
         out float4 oColor : COLOR0,
@@ -46,28 +47,31 @@ void VS(float4 iPos : POSITION,
     float4 projWorldPos = float4(worldPos, 1.0);
     float4 projWorldPos = float4(worldPos, 1.0);
 
 
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
-        oLightVec = float4(cLightDir, GetDepth(oPos));
+        oLightVec = cLightDir;
     #else
     #else
-        oLightVec = float4((cLightPos - centeredWorldPos) * cLightAtten, GetDepth(oPos));
+        oLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
     #endif
     #endif
 
 
+    oZonePosDepth = float2(GetZonePos(worldPos), GetDepth(oPos));
+
     #ifdef SPOTLIGHT
     #ifdef SPOTLIGHT
         // Spotlight projection: transform from world space to projector texture coordinates
         // Spotlight projection: transform from world space to projector texture coordinates
         oSpotPos = mul(projWorldPos, cSpotProj);
         oSpotPos = mul(projWorldPos, cSpotProj);
     #endif
     #endif
 
 
     #ifdef POINTLIGHT
     #ifdef POINTLIGHT
-        oCubeMaskVec = mul(oLightVec.xyz, cLightVecRot);
+        oCubeMaskVec = mul(oLightVec, cLightVecRot);
     #endif
     #endif
 }
 }
 
 
 void PS(float2 iTexCoord : TEXCOORD0,
 void PS(float2 iTexCoord : TEXCOORD0,
-    float4 iLightVec : TEXCOORD1,
+    float3 iLightVec : TEXCOORD1,
+    float2 iZonePosDepth : TEXCOORD2,
     #ifdef SPOTLIGHT
     #ifdef SPOTLIGHT
-        float4 iSpotPos : TEXCOORD2,
+        float4 iSpotPos : TEXCOORD3,
     #endif
     #endif
     #ifdef CUBEMASK
     #ifdef CUBEMASK
-        float3 iCubeMaskVec : TEXCOORD2,
+        float3 iCubeMaskVec : TEXCOORD3,
     #endif
     #endif
     #ifdef VERTEXCOLOR
     #ifdef VERTEXCOLOR
         float4 iColor : COLOR0,
         float4 iColor : COLOR0,
@@ -91,7 +95,7 @@ void PS(float2 iTexCoord : TEXCOORD0,
     #ifdef DIRLIGHT
     #ifdef DIRLIGHT
         diff = GetDiffuseDirVolumetric();
         diff = GetDiffuseDirVolumetric();
     #else
     #else
-        diff = GetDiffusePointOrSpotVolumetric(iLightVec.xyz);
+        diff = GetDiffusePointOrSpotVolumetric(iLightVec);
     #endif
     #endif
 
 
     #if defined(SPOTLIGHT)
     #if defined(SPOTLIGHT)
@@ -105,9 +109,9 @@ void PS(float2 iTexCoord : TEXCOORD0,
     finalColor = diff * lightColor * diffColor.rgb;
     finalColor = diff * lightColor * diffColor.rgb;
 
 
     #ifdef AMBIENT
     #ifdef AMBIENT
-        finalColor += cAmbientColor * diffColor.rgb;
-        oColor = float4(GetFog(finalColor, iLightVec.w), diffColor.a);
+        finalColor += GetAmbient(iZonePosDepth.x) * diffColor.rgb;
+        oColor = float4(GetFog(finalColor, iZonePosDepth.y), diffColor.a);
     #else
     #else
-        oColor = float4(GetLitFog(finalColor, iLightVec.w), diffColor.a);
+        oColor = float4(GetLitFog(finalColor, iZonePosDepth.y), diffColor.a);
     #endif
     #endif
 }
 }