Selaa lähdekoodia

Allow 6 vertex lights.

Lasse Öörni 14 vuotta sitten
vanhempi
sitoutus
bc5dd97e4b

+ 0 - 1
Bin/CoreData/Techniques/NoTextureAlpha.xml

@@ -1,5 +1,4 @@
 <technique>
     <pass name="base" vs="Ambient" ps="Ambient" depthwrite="false" blend="alpha" />
-    <pass name="litbase" vs="BlinnPhong" ps="BlinnPhong_Ambient" depthwrite="false" blend="alpha" />
     <pass name="light" vs="BlinnPhong" ps="BlinnPhong" depthwrite="false" blend="addalpha" />
 </technique>

+ 4 - 7
Engine/Graphics/Batch.cpp

@@ -203,17 +203,14 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
         light = lightQueue_->light_;
         shadowMap = lightQueue_->shadowMap_;
         
-        if (graphics->NeedParameterUpdate(VSP_LIGHTATTEN, light))
-        {
-            Vector4 lightAtten(1.0f / Max(light->GetRange(), M_EPSILON), 0.0f, 0.0f, 0.0f);
-            graphics->SetShaderParameter(VSP_LIGHTATTEN, lightAtten);
-        }
-        
         if (graphics->NeedParameterUpdate(VSP_LIGHTDIR, light))
             graphics->SetShaderParameter(VSP_LIGHTDIR, light->GetWorldRotation() * Vector3::BACK);
         
         if (graphics->NeedParameterUpdate(VSP_LIGHTPOS, light))
-            graphics->SetShaderParameter(VSP_LIGHTPOS, light->GetWorldPosition() - camera_->GetWorldPosition());
+        {
+            float atten = 1.0f / Max(light->GetRange(), M_EPSILON);
+            graphics->SetShaderParameter(VSP_LIGHTPOS, Vector4(light->GetWorldPosition() - camera_->GetWorldPosition(), atten));
+        }
         
         if (graphics->NeedParameterUpdate(VSP_LIGHTVECROT, light))
         {

+ 1 - 1
Engine/Graphics/Drawable.h

@@ -37,7 +37,7 @@ static const unsigned DEFAULT_LIGHTMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_SHADOWMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_ZONEMASK = M_MAX_UNSIGNED;
 static const int DRAWABLES_PER_WORK_ITEM = 16;
-static const int MAX_VERTEX_LIGHTS = 4;
+static const int MAX_VERTEX_LIGHTS = 6;
 
 struct Batch;
 class Camera;

+ 0 - 1
Engine/Graphics/GraphicsDefs.cpp

@@ -29,7 +29,6 @@
 StringHash VSP_CAMERAPOS("CameraPos");
 StringHash VSP_CAMERAROT("CameraRot");
 StringHash VSP_DEPTHMODE("DepthMode");
-StringHash VSP_LIGHTATTEN("LightAtten");
 StringHash VSP_LIGHTDIR("LightDir");
 StringHash VSP_LIGHTPOS("LightPos");
 StringHash VSP_LIGHTVECROT("LightVecRot");

+ 0 - 1
Engine/Graphics/GraphicsDefs.h

@@ -197,7 +197,6 @@ enum ShaderType
 extern StringHash VSP_CAMERAPOS;
 extern StringHash VSP_CAMERAROT;
 extern StringHash VSP_DEPTHMODE;
-extern StringHash VSP_LIGHTATTEN;
 extern StringHash VSP_LIGHTDIR;
 extern StringHash VSP_LIGHTPOS;
 extern StringHash VSP_LIGHTVECROT;

+ 5 - 5
Engine/Graphics/View.cpp

@@ -688,8 +688,8 @@ void View::GetBatches()
                         drawable->LimitVertexLights();
                         
                         // Find a vertex light queue. If not found, create new
-                        unsigned hash = GetVertexLightQueueHash(vertexLights);
-                        HashMap<unsigned, LightBatchQueue>::Iterator i = vertexLightQueues_.Find(hash);
+                        unsigned long long hash = GetVertexLightQueueHash(vertexLights);
+                        HashMap<unsigned long long, LightBatchQueue>::Iterator i = vertexLightQueues_.Find(hash);
                         if (i == vertexLightQueues_.End())
                         {
                             vertexLightQueues_[hash].vertexLights_ = vertexLights;
@@ -1678,11 +1678,11 @@ unsigned View::GetShadowMask(Drawable* drawable)
     return drawable->GetShadowMask() & GetZone(drawable)->GetShadowMask();
 }
 
-unsigned View::GetVertexLightQueueHash(const PODVector<Light*>& vertexLights)
+unsigned long long View::GetVertexLightQueueHash(const PODVector<Light*>& vertexLights)
 {
-    unsigned hash = 0;
+    unsigned long long hash = 0;
     for (PODVector<Light*>::ConstIterator i = vertexLights.Begin(); i != vertexLights.End(); ++i)
-        hash += (unsigned)(*i);
+        hash += (unsigned long long)(*i);
     return hash;
 }
 

+ 2 - 2
Engine/Graphics/View.h

@@ -162,7 +162,7 @@ private:
     /// Return the drawable's shadow mask, considering also its zone.
     unsigned GetShadowMask(Drawable* drawable);
     /// Return hash code for a vertex light queue.
-    unsigned GetVertexLightQueueHash(const PODVector<Light*>& vertexLights);
+    unsigned long long GetVertexLightQueueHash(const PODVector<Light*>& vertexLights);
     /// Return material technique, considering the drawable's LOD distance.
     Technique* GetTechnique(Drawable* drawable, Material*& material);
     /// Check if material should render an auxiliary view (if it has a camera attached.)
@@ -261,7 +261,7 @@ private:
     /// Per-pixel light queues.
     List<LightBatchQueue> lightQueues_;
     /// Per-vertex light queues.
-    HashMap<unsigned, LightBatchQueue> vertexLightQueues_;
+    HashMap<unsigned long long, LightBatchQueue> vertexLightQueues_;
     /// Current stencil value for light optimization.
     unsigned char lightStencilValue_;
     /// Camera zone's override flag.

+ 2 - 0
SourceAssets/GLSLShaders/Ambient.xml

@@ -6,6 +6,8 @@
         <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
         <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
         <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
+        <variation name="5VL" define="NUMVERTEXLIGHTS=5" />
+        <variation name="6VL" define="NUMVERTEXLIGHTS=6" />
         <option name="" /> <!-- Dummy option to separate the two variation groups -->
         <variation name="" />
         <variation name="Skinned" define="SKINNED" />

+ 2 - 2
SourceAssets/GLSLShaders/BlinnPhong.vert

@@ -52,7 +52,7 @@ void main()
     #ifdef DIRLIGHT
         vLightVec = cLightDir;
     #else
-        vLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
+        vLightVec = (cLightPos.xyz - centeredWorldPos) * cLightPos.w;
     #endif
 
     #ifdef SHADOW
@@ -65,7 +65,7 @@ void main()
         #elif defined(SPOTLIGHT)
             vShadowPos = cShadowProj[0] * projWorldPos;
         #else
-            vShadowPos = centeredWorldPos - cLightPos;
+            vShadowPos = centeredWorldPos - cLightPos.xyz;
         #endif
     #endif
 

+ 2 - 3
SourceAssets/GLSLShaders/Uniforms.vert

@@ -1,9 +1,8 @@
 uniform vec3 cCameraPos;
 uniform mat3 cCameraRot;
 uniform vec4 cDepthMode;
-uniform float cLightAtten;
 uniform vec3 cLightDir;
-uniform vec3 cLightPos;
+uniform vec4 cLightPos;
 uniform mat3 cLightVecRot;
 uniform mat4 cModel;
 uniform mat4 cSpotProj;
@@ -15,4 +14,4 @@ uniform vec3 cViewUpVector;
 uniform mat4 cZone;
 uniform mat4 cShadowProj[4];
 uniform vec4 cSkinMatrices[64*3];
-uniform vec4 cVertexLights[12];
+uniform vec4 cVertexLights[6*3];

+ 1 - 1
SourceAssets/GLSLShaders/Volumetric.vert

@@ -31,7 +31,7 @@ void main()
     #ifdef DIRLIGHT
         vLightVec = cLightDir;
     #else
-        vLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
+        vLightVec = (cLightPos.xyz - centeredWorldPos) * cLightPos.w;
     #endif
     
     vZonePosDepth = vec2(GetZonePos(worldPos), GetDepth(gl_Position));

+ 2 - 0
SourceAssets/HLSLShaders/Ambient.xml

@@ -6,6 +6,8 @@
         <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
         <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
         <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
+        <variation name="5VL" define="NUMVERTEXLIGHTS=5" />
+        <variation name="6VL" define="NUMVERTEXLIGHTS=6" />
         <option name="" /> <!-- Dummy option to separate the two variation groups -->
         <variation name="" />
         <variation name="Skinned" define="SKINNED" />

+ 2 - 2
SourceAssets/HLSLShaders/BlinnPhong.hlsl

@@ -73,7 +73,7 @@ void VS(float4 iPos : POSITION,
     #ifdef DIRLIGHT
         oLightVec = cLightDir;
     #else
-        oLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
+        oLightVec = (cLightPos.xyz - centeredWorldPos) * cLightPos.w;
     #endif
 
     #ifdef SHADOW
@@ -86,7 +86,7 @@ void VS(float4 iPos : POSITION,
         #elif defined(SPOTLIGHT)
             oShadowPos = mul(projWorldPos, cShadowProj[0]);
         #else
-            oShadowPos = centeredWorldPos - cLightPos;
+            oShadowPos = centeredWorldPos - cLightPos.xyz;
         #endif
     #endif
 

+ 0 - 10
SourceAssets/HLSLShaders/Fog.hlsl

@@ -7,13 +7,3 @@ float3 GetLitFog(float3 color, float depth)
 {
     return color * saturate((cFogParams.y - depth) * cFogParams.z);
 }
-
-float GetFogFactor(float depth)
-{
-    return saturate((depth - cFogParams.x) * cFogParams.z);
-}
-
-float GetReverseFogFactor(float depth)
-{
-    return saturate((cFogParams.y - depth) * cFogParams.z);
-}

+ 14 - 15
SourceAssets/HLSLShaders/Uniforms.hlsl

@@ -2,21 +2,20 @@
 uniform float3 cCameraPos : register(C0);
 uniform float3x3 cCameraRot : register(C1);
 uniform float4 cDepthMode : register(C4);
-uniform float cLightAtten : register(C5);
-uniform float3 cLightDir : register(C6);
-uniform float3 cLightPos : register(C7);
-uniform float3x3 cLightVecRot: register(C8);
-uniform float4x3 cModel : register(C11);
-uniform float4x4 cSpotProj : register(C14);
-uniform float4x4 cViewProj : register(C18);
-uniform float4 cUOffset : register(C22);
-uniform float4 cVOffset : register(C23);
-uniform float3 cViewRightVector : register(C24);
-uniform float3 cViewUpVector : register(C25);
-uniform float4x3 cZone : register(C26);
-uniform float4x4 cShadowProj[4] : register(C29);
-uniform float4x3 cSkinMatrices[64] : register(C45);
-uniform float4 cVertexLights[12] : register(C237);
+uniform float3 cLightDir : register(C5);
+uniform float4 cLightPos : register(C6);
+uniform float3x3 cLightVecRot: register(C7);
+uniform float4x3 cModel : register(C10);
+uniform float4x4 cSpotProj : register(C13);
+uniform float4x4 cViewProj : register(C17);
+uniform float4 cUOffset : register(C21);
+uniform float4 cVOffset : register(C22);
+uniform float3 cViewRightVector : register(C23);
+uniform float3 cViewUpVector : register(C24);
+uniform float4x3 cZone : register(C25);
+uniform float4x4 cShadowProj[4] : register(C28);
+uniform float4x3 cSkinMatrices[64] : register(C44);
+uniform float4 cVertexLights[6*3] : register(C236);
 
 // Pixel shader parameters
 uniform float3 cAmbientStartColor : register(C0);

+ 1 - 1
SourceAssets/HLSLShaders/Volumetric.hlsl

@@ -49,7 +49,7 @@ void VS(float4 iPos : POSITION,
     #ifdef DIRLIGHT
         oLightVec = cLightDir;
     #else
-        oLightVec = (cLightPos - centeredWorldPos) * cLightAtten;
+        oLightVec = (cLightPos.xyz - centeredWorldPos) * cLightPos.w;
     #endif
 
     oZonePosDepth = float2(GetZonePos(worldPos), GetDepth(oPos));