From 311659d8a9049b2b1cd0a9068e8eb35aeff0bfb7 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Thu, 6 Oct 2016 01:31:53 +0200 Subject: [PATCH] merging light shading paths part1 --- WickedEngine/ConstantBufferMapping.h | 31 +- WickedEngine/Editor.h | 4 +- WickedEngine/ResourceMapping.h | 62 ++-- WickedEngine/WickedEngine_SHADERS.vcxproj | 7 +- .../WickedEngine_SHADERS.vcxproj.filters | 17 +- WickedEngine/cubeShadowPS.hlsl | 3 +- .../{lightHF.hlsli => deferredLightHF.hlsli} | 46 ++- WickedEngine/dirLightHF.hlsli | 108 ------- WickedEngine/dirLightPS.hlsl | 7 +- WickedEngine/dirLightSoftPS.hlsl | 8 +- WickedEngine/dirLightVS.hlsl | 5 +- WickedEngine/environmentalLightPS.hlsl | 2 +- WickedEngine/globals.hlsli | 16 +- WickedEngine/lightCullingCS.hlsl | 2 +- WickedEngine/lightingHF.hlsli | 194 ++++++++++++ WickedEngine/objectHF.hlsli | 180 +---------- WickedEngine/pointLightPS.hlsl | 6 +- WickedEngine/pointLightVS.hlsl | 8 +- WickedEngine/spotLightPS.hlsl | 6 +- WickedEngine/spotLightVS.hlsl | 6 +- WickedEngine/tiledLightingHF.hlsli | 28 -- WickedEngine/wiLoader.cpp | 1 + WickedEngine/wiLoader.h | 1 + WickedEngine/wiRenderer.cpp | 283 +++++++++--------- WickedEngine/wiRenderer.h | 35 +-- 25 files changed, 454 insertions(+), 612 deletions(-) rename WickedEngine/{lightHF.hlsli => deferredLightHF.hlsli} (50%) delete mode 100644 WickedEngine/dirLightHF.hlsli create mode 100644 WickedEngine/lightingHF.hlsli delete mode 100644 WickedEngine/tiledLightingHF.hlsli diff --git a/WickedEngine/ConstantBufferMapping.h b/WickedEngine/ConstantBufferMapping.h index ee18f8ebe..d91b81db2 100644 --- a/WickedEngine/ConstantBufferMapping.h +++ b/WickedEngine/ConstantBufferMapping.h @@ -10,31 +10,28 @@ #define CBSLOT_RENDERER_FRAME 1 #define CBSLOT_RENDERER_CAMERA 2 #define CBSLOT_RENDERER_MATERIAL 3 -#define CBSLOT_RENDERER_DIRLIGHT 4 -#define CBSLOT_RENDERER_MISC 5 -#define CBSLOT_RENDERER_SHADOW 6 +#define CBSLOT_RENDERER_MISC 4 +#define CBSLOT_RENDERER_SHADOW 5 -#define CBSLOT_IMAGE_IMAGE 7 -#define CBSLOT_IMAGE_POSTPROCESS 8 +#define CBSLOT_IMAGE_IMAGE 6 +#define CBSLOT_IMAGE_POSTPROCESS 7 -#define CBSLOT_FONT_FONT 9 +#define CBSLOT_FONT_FONT 8 -#define CBSLOT_API 10 +#define CBSLOT_API 9 // On demand buffers: // These are bound on demand and alive until another is bound at the same slot -#define CBSLOT_RENDERER_CUBEMAPRENDER 11 -#define CBSLOT_RENDERER_POINTLIGHT 12 -#define CBSLOT_RENDERER_SPOTLIGHT 13 -#define CBSLOT_RENDERER_VOLUMELIGHT 11 -#define CBSLOT_RENDERER_DECAL 11 -#define CBSLOT_RENDERER_TESSELLATION 11 -#define CBSLOT_RENDERER_DISPATCHPARAMS 11 +#define CBSLOT_RENDERER_CUBEMAPRENDER 10 +#define CBSLOT_RENDERER_VOLUMELIGHT 10 +#define CBSLOT_RENDERER_DECAL 10 +#define CBSLOT_RENDERER_TESSELLATION 10 +#define CBSLOT_RENDERER_DISPATCHPARAMS 10 -#define CBSLOT_OTHER_EMITTEDPARTICLE 11 -#define CBSLOT_OTHER_HAIRPARTICLE 11 -#define CBSLOT_OTHER_LENSFLARE 11 +#define CBSLOT_OTHER_EMITTEDPARTICLE 10 +#define CBSLOT_OTHER_HAIRPARTICLE 10 +#define CBSLOT_OTHER_LENSFLARE 10 diff --git a/WickedEngine/Editor.h b/WickedEngine/Editor.h index aca43710a..603afa8a3 100644 --- a/WickedEngine/Editor.h +++ b/WickedEngine/Editor.h @@ -24,9 +24,9 @@ public: class Editor; class EditorComponent - //: public DeferredRenderableComponent + : public DeferredRenderableComponent //: public ForwardRenderableComponent - : public TiledForwardRenderableComponent + //: public TiledForwardRenderableComponent { private: wiGraphicsTypes::Texture2D pointLightTex, spotLightTex, dirLightTex; diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 1a8831b92..7f0f44eb2 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -18,49 +18,43 @@ // Textures, StructuredBuffers (t slot): -#define TEXSLOT_DEPTH 0 -#define TEXSLOT_LINEARDEPTH 1 +#define TEXSLOT_DEPTH 0 +#define TEXSLOT_LINEARDEPTH 1 -#define TEXSLOT_GBUFFER0 2 -#define TEXSLOT_GBUFFER1 3 -#define TEXSLOT_GBUFFER2 4 -#define TEXSLOT_GBUFFER3 5 -#define TEXSLOT_GBUFFER4 6 +#define TEXSLOT_GBUFFER0 2 +#define TEXSLOT_GBUFFER1 3 +#define TEXSLOT_GBUFFER2 4 +#define TEXSLOT_GBUFFER3 5 +#define TEXSLOT_GBUFFER4 6 -#define TEXSLOT_ENV_GLOBAL 7 -#define TEXSLOT_ENV0 8 -#define TEXSLOT_ENV1 9 -#define TEXSLOT_ENV2 10 +#define TEXSLOT_ENV_GLOBAL 7 +#define TEXSLOT_ENV0 8 +#define TEXSLOT_ENV1 9 +#define TEXSLOT_ENV2 10 -#define TEXSLOT_SHADOW0 11 -#define TEXSLOT_SHADOW1 12 -#define TEXSLOT_SHADOW2 13 -#define TEXSLOT_SHADOW_CUBE 14 +#define TEXSLOT_SHADOWARRAY_2D 11 +#define TEXSLOT_SHADOWARRAY_CUBE 12 -#define TEXSLOT_ONDEMAND0 15 -#define TEXSLOT_ONDEMAND1 16 -#define TEXSLOT_ONDEMAND2 17 -#define TEXSLOT_ONDEMAND3 18 -#define TEXSLOT_ONDEMAND4 19 -#define TEXSLOT_ONDEMAND5 20 -#define TEXSLOT_ONDEMAND6 21 -#define TEXSLOT_ONDEMAND7 22 -#define TEXSLOT_ONDEMAND8 23 -#define TEXSLOT_ONDEMAND9 24 +#define TEXSLOT_ONDEMAND0 13 +#define TEXSLOT_ONDEMAND1 14 +#define TEXSLOT_ONDEMAND2 15 +#define TEXSLOT_ONDEMAND3 16 +#define TEXSLOT_ONDEMAND4 17 +#define TEXSLOT_ONDEMAND5 18 +#define TEXSLOT_ONDEMAND6 19 +#define TEXSLOT_ONDEMAND7 20 +#define TEXSLOT_ONDEMAND8 21 +#define TEXSLOT_ONDEMAND9 22 #define TEXSLOT_ONDEMAND_COUNT (TEXSLOT_ONDEMAND9 - TEXSLOT_ONDEMAND0 + 1) -#define TEXSLOT_LIGHTGRID 25 +#define TEXSLOT_LIGHTGRID 23 #define TEXSLOT_COUNT TEXSLOT_LIGHTGRID -#define SBSLOT_BONE 0 -#define SBSLOT_TILEFRUSTUMS 25 -#define SBSLOT_LIGHTARRAY 26 -#define SBSLOT_LIGHTINDEXLIST 27 - - -#define TEXSLOT_SHADOWARRAY_2D 28 -#define TEXSLOT_SHADOWARRAY_CUBE 29 +#define SBSLOT_BONE 0 +#define SBSLOT_TILEFRUSTUMS 23 +#define SBSLOT_LIGHTINDEXLIST 24 +#define SBSLOT_LIGHTARRAY 25 /////////////////////////// diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj b/WickedEngine/WickedEngine_SHADERS.vcxproj index 99f259503..4de834cb0 100644 --- a/WickedEngine/WickedEngine_SHADERS.vcxproj +++ b/WickedEngine/WickedEngine_SHADERS.vcxproj @@ -17,7 +17,6 @@ - @@ -29,21 +28,19 @@ - + + - - - diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters index 7c49ea0d5..2de9501e9 100644 --- a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters +++ b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters @@ -13,9 +13,6 @@ HF - - HF - HF @@ -43,9 +40,6 @@ HF - - HF - HF @@ -58,9 +52,6 @@ HF - - HF - HF @@ -79,9 +70,6 @@ HF - - HF - HF @@ -106,7 +94,10 @@ HF - + + HF + + HF diff --git a/WickedEngine/cubeShadowPS.hlsl b/WickedEngine/cubeShadowPS.hlsl index e974c510a..529420de4 100644 --- a/WickedEngine/cubeShadowPS.hlsl +++ b/WickedEngine/cubeShadowPS.hlsl @@ -1,4 +1,3 @@ -#include "pointLightHF.hlsli" #include "objectHF.hlsli" struct VertextoPixel @@ -12,5 +11,5 @@ struct VertextoPixel float main(VertextoPixel PSIn) : SV_DEPTH { ALPHATEST(xBaseColorMap.Sample(sampler_linear_wrap,PSIn.tex).a); - return distance(PSIn.pos3D.xyz, xLightPos.xyz) / xLightEnerDis.y; + return distance(PSIn.pos3D.xyz, g_xColor.xyz) / g_xColor.w; } \ No newline at end of file diff --git a/WickedEngine/lightHF.hlsli b/WickedEngine/deferredLightHF.hlsli similarity index 50% rename from WickedEngine/lightHF.hlsli rename to WickedEngine/deferredLightHF.hlsli index e83964eb7..957765185 100644 --- a/WickedEngine/lightHF.hlsli +++ b/WickedEngine/deferredLightHF.hlsli @@ -3,19 +3,16 @@ #include "globals.hlsli" #include "brdf.hlsli" #include "packHF.hlsli" +#include "lightingHF.hlsli" struct VertexToPixel{ float4 pos : SV_POSITION; float4 pos2D : POSITION2D; + nointerpolation int lightIndex : LIGHTARRAYINDEX; }; #include "reconstructPositionHF.hlsli" -//Texture2D depthMap:register(t0); -//Texture2D normalMap:register(t1); -////Texture2D specularMap:register(t2); -//Texture2D materialMap:register(t2); - static const float specularMaximumIntensity = 1; @@ -29,31 +26,50 @@ struct LightOutputType // MACROS #define DEFERREDLIGHT_MAKEPARAMS \ + LightArrayType light = LightArray[PSIn.lightIndex]; \ float3 diffuse, specular; \ float2 screenPos = float2(1, -1) * PSIn.pos2D.xy / PSIn.pos2D.w / 2.0f + 0.5f; \ float depth = texture_depth.SampleLevel(sampler_point_clamp, screenPos, 0); \ float4 baseColor = texture_gbuffer0.SampleLevel(sampler_point_clamp,screenPos,0); \ float4 g1 = texture_gbuffer1.SampleLevel(sampler_point_clamp,screenPos,0); \ float4 g3 = texture_gbuffer3.SampleLevel(sampler_point_clamp,screenPos,0); \ - float3 N = decode(g1.xy); \ + float3 N = decode(g1.xy); \ float roughness = g3.x; \ float reflectance = g3.y; \ float metalness = g3.z; \ BRDF_HELPER_MAKEINPUTS( baseColor, reflectance, metalness ) \ float3 P = getPosition(screenPos, depth); \ - float3 V = normalize(g_xCamera_CamPos - P); - -#define DEFERREDLIGHT_RETURN \ - LightOutputType Out = (LightOutputType)0; \ - Out.diffuse = float4(diffuse, 1); \ - Out.specular = float4(specular, 1); \ - return Out; + float3 V = normalize(g_xCamera_CamPos - P); \ + float3 L = light.positionWS - P; \ + float lightDistance = length(L); -#define DEFERREDLIGHT_ENVIRONMENTALLIGHT \ - diffuse = 0; \ +#define DEFERREDLIGHT_ENVIRONMENTALLIGHT \ + diffuse = 0; \ specular = EnvironmentReflection(N, V, P, roughness, f0); +#define DEFERREDLIGHT_DIRECTIONAL \ + LightingResult result = DirectionalLight(light, N, V, P, roughness, f0); \ + diffuse = result.diffuse; \ + specular = result.specular; + +#define DEFERREDLIGHT_SPOT \ + LightingResult result = SpotLight(light, L, lightDistance, N, V, P, roughness, f0); \ + diffuse = result.diffuse; \ + specular = result.specular; + +#define DEFERREDLIGHT_POINT \ + LightingResult result = PointLight(light, L, lightDistance, N, V, P, roughness, f0);\ + diffuse = result.diffuse; \ + specular = result.specular; + + +#define DEFERREDLIGHT_RETURN \ + LightOutputType Out = (LightOutputType)0; \ + Out.diffuse = float4(diffuse, 1); \ + Out.specular = float4(specular, 1); \ + return Out; + #endif // _LIGHTHF_ diff --git a/WickedEngine/dirLightHF.hlsli b/WickedEngine/dirLightHF.hlsli deleted file mode 100644 index 7c3f9f0c5..000000000 --- a/WickedEngine/dirLightHF.hlsli +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef _DIRLIGHT_HF_ -#define _DIRLIGHT_HF_ -#include "brdf.hlsli" -#include "envReflectionHF.hlsli" - -// dir light constant buffer is global - -//Texture2D xTextureSh[3]:register(t13); - -inline float offset_lookup(Texture2D intex, SamplerComparisonState map, - float2 loc, - float2 offset, - float scale, - float biasedDistance) -{ - return intex.SampleCmpLevelZero( map, loc + offset / scale, biasedDistance).r; -} - - -inline float shadowCascade(float4 shadowPos, float2 ShTex, float bias, Texture2D shadowTexture){ - float realDistance = shadowPos.z/shadowPos.w - bias; - float sum = 0; - float scale = g_xDirLight_mBiasResSoftshadow.y; - float retVal = 1; - -#ifdef DIRECTIONALLIGHT_SOFT - //[branch]if(g_xDirLight_mBiasResSoftshadow.z) - { - float samples = 0.0f; - static const float range = 1.5f; - for (float y = -range; y <= range; y += 1.0f) - for (float x = -range; x <= range; x += 1.0f) - { - sum += offset_lookup(shadowTexture, sampler_cmp_depth, ShTex, float2(x, y), scale, realDistance); - samples++; - } - - retVal *= sum / samples; - } - //else -#else - retVal *= offset_lookup(shadowTexture, sampler_cmp_depth, ShTex, float2(0, 0), scale, realDistance); -#endif - - return retVal; -} - -inline void dirLight(in float3 P, in float3 N, in float3 V, in float roughness, in float3 f0, - out float3 diffuse, out float3 specular) -{ - float3 L = g_xDirLight_direction.xyz; - BRDF_MAKE(N, L, V); - specular = g_xDirLight_col.rgb * BRDF_SPECULAR(roughness, f0); - diffuse = g_xDirLight_col.rgb * BRDF_DIFFUSE(roughness); - - float sh = max(NdotL, 0); - float4 ShPos[3]; - ShPos[0] = mul(float4(P,1),g_xDirLight_ShM[0]); - ShPos[1] = mul(float4(P,1),g_xDirLight_ShM[1]); - ShPos[2] = mul(float4(P,1),g_xDirLight_ShM[2]); - float3 ShTex[3]; - ShTex[0] = ShPos[0].xyz*float3(1,-1,1)/ShPos[0].w/2.0f +0.5f; - ShTex[1] = ShPos[1].xyz*float3(1,-1,1)/ShPos[1].w/2.0f +0.5f; - ShTex[2] = ShPos[2].xyz*float3(1,-1,1)/ShPos[2].w/2.0f +0.5f; - const float shadows[3]={ - shadowCascade(ShPos[0],ShTex[0].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow0), - shadowCascade(ShPos[1],ShTex[1].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow1), - shadowCascade(ShPos[2],ShTex[2].xy, g_xDirLight_mBiasResSoftshadow.x,texture_shadow2) - }; - [branch]if((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z)) - { - //color.r+=0.5f; - const float2 lerpVal = abs( ShTex[2].xy*2-1 ); - sh *= lerp( shadows[2],shadows[1], pow( max(lerpVal.x,lerpVal.y),4 ) ); - } - else [branch]if((saturate(ShTex[1].x) == ShTex[1].x) && (saturate(ShTex[1].y) == ShTex[1].y) && (saturate(ShTex[1].z) == ShTex[1].z)) - { - //color.g+=0.5f; - const float2 lerpVal = abs( ShTex[1].xy*2-1 ); - sh *= lerp( shadows[1],shadows[0], pow( max(lerpVal.x,lerpVal.y),4 ) ); - } - else [branch]if((saturate(ShTex[0].x) == ShTex[0].x) && (saturate(ShTex[0].y) == ShTex[0].y) && (saturate(ShTex[0].z) == ShTex[0].z)) - { - //color.b+=0.5f; - sh *= shadows[0]; - } - - diffuse *= sh; - specular *= sh; - - //specular += EnvironmentReflection(N, V, P, roughness, f0); - - diffuse = max(diffuse, 0); - specular = max(specular, 0); -} - - -// MACROS - -//#define DEFERRED_DIRLIGHT_MAIN \ -// float lighting = dirLight(P,N,color); \ -// color.rgb *= lighting; \ -// applySpecular(color, (color*lighting).rgb, N, V, g_xDirLight_direction.xyz, 1, specular_power, specular); - -#define DEFERRED_DIRLIGHT_MAIN \ - dirLight(P, N, V, roughness, f0, diffuse, specular); - -#endif // _DIRLIGHT_HF_ \ No newline at end of file diff --git a/WickedEngine/dirLightPS.hlsl b/WickedEngine/dirLightPS.hlsl index 2b08ab862..136f1dcea 100644 --- a/WickedEngine/dirLightPS.hlsl +++ b/WickedEngine/dirLightPS.hlsl @@ -1,13 +1,10 @@ -#include "lightHF.hlsli" -#include "dirLightHF.hlsli" - - +#include "deferredLightHF.hlsli" LightOutputType main( VertexToPixel PSIn ) { DEFERREDLIGHT_MAKEPARAMS - DEFERRED_DIRLIGHT_MAIN + DEFERREDLIGHT_DIRECTIONAL DEFERREDLIGHT_RETURN } \ No newline at end of file diff --git a/WickedEngine/dirLightSoftPS.hlsl b/WickedEngine/dirLightSoftPS.hlsl index 8d56cbd94..0cbe9798a 100644 --- a/WickedEngine/dirLightSoftPS.hlsl +++ b/WickedEngine/dirLightSoftPS.hlsl @@ -1,15 +1,11 @@ -#include "lightHF.hlsli" - #define DIRECTIONALLIGHT_SOFT -#include "dirLightHF.hlsli" - - +#include "deferredLightHF.hlsli" LightOutputType main(VertexToPixel PSIn) { DEFERREDLIGHT_MAKEPARAMS - DEFERRED_DIRLIGHT_MAIN + DEFERREDLIGHT_DIRECTIONAL DEFERREDLIGHT_RETURN } \ No newline at end of file diff --git a/WickedEngine/dirLightVS.hlsl b/WickedEngine/dirLightVS.hlsl index 0426c2b67..29fd7d97c 100644 --- a/WickedEngine/dirLightVS.hlsl +++ b/WickedEngine/dirLightVS.hlsl @@ -1,5 +1,4 @@ -#include "lightHF.hlsli" -#include "quad.hlsli" +#include "deferredLightHF.hlsli" #include "fullScreenTriangleHF.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) @@ -9,5 +8,7 @@ VertexToPixel main(uint vid : SV_VERTEXID) FullScreenTriangle(vid, Out.pos); Out.pos2D = Out.pos; + Out.lightIndex = g_xMisc_int4[0]; + return Out; } \ No newline at end of file diff --git a/WickedEngine/environmentalLightPS.hlsl b/WickedEngine/environmentalLightPS.hlsl index da0dcf51b..d39267198 100644 --- a/WickedEngine/environmentalLightPS.hlsl +++ b/WickedEngine/environmentalLightPS.hlsl @@ -1,4 +1,4 @@ -#include "lightHF.hlsli" +#include "deferredLightHF.hlsli" #include "envReflectionHF.hlsli" diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli index d9915948d..fb131f0a8 100644 --- a/WickedEngine/globals.hlsli +++ b/WickedEngine/globals.hlsli @@ -15,10 +15,8 @@ TEXTURECUBE(texture_env_global, float4, TEXSLOT_ENV_GLOBAL) TEXTURECUBE(texture_env0, float4, TEXSLOT_ENV0) TEXTURECUBE(texture_env1, float4, TEXSLOT_ENV1) TEXTURECUBE(texture_env2, float4, TEXSLOT_ENV2) -TEXTURE2D(texture_shadow0, float, TEXSLOT_SHADOW0) -TEXTURE2D(texture_shadow1, float, TEXSLOT_SHADOW1) -TEXTURE2D(texture_shadow2, float, TEXSLOT_SHADOW2) -TEXTURECUBE(texture_shadow_cube, float, TEXSLOT_SHADOW_CUBE) +TEXTURE2DARRAY(texture_shadowarray_2d, float, TEXSLOT_SHADOWARRAY_2D) +TEXTURECUBEARRAY(texture_shadowarray_cube, float, TEXSLOT_SHADOWARRAY_CUBE) TEXTURE2D(texture_0, float4, TEXSLOT_ONDEMAND0) TEXTURE2D(texture_1, float4, TEXSLOT_ONDEMAND1) TEXTURE2D(texture_2, float4, TEXSLOT_ONDEMAND2) @@ -30,8 +28,6 @@ TEXTURE2D(texture_7, float4, TEXSLOT_ONDEMAND7) TEXTURE2D(texture_8, float4, TEXSLOT_ONDEMAND8) TEXTURE2D(texture_9, float4, TEXSLOT_ONDEMAND9) -TEXTURE2DARRAY(texture_shadowarray_2d, float, TEXSLOT_SHADOWARRAY_2D) -TEXTURECUBEARRAY(texture_shadowarray_cube,float,TEXSLOT_SHADOWARRAY_CUBE) SAMPLERSTATE( sampler_linear_clamp, SSLOT_LINEAR_CLAMP ) SAMPLERSTATE( sampler_linear_wrap, SSLOT_LINEAR_WRAP ) @@ -96,17 +92,11 @@ CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL) float g_xMat_normalMapStrength; float g_xMat_parallaxOcclusionMapping; }; -CBUFFER(DirectionalLightCB, CBSLOT_RENDERER_DIRLIGHT) -{ - float4 g_xDirLight_direction; - float4 g_xDirLight_col; - float4 g_xDirLight_mBiasResSoftshadow; - float4x4 g_xDirLight_ShM[3]; -}; CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) { float4x4 g_xTransform; float4 g_xColor; + int4 g_xMisc_int4; }; CBUFFER(ShadowCB, CBSLOT_RENDERER_SHADOW) { diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index d872c1b44..569e75e40 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -1,6 +1,6 @@ #include "globals.hlsli" #include "cullingShaderHF.hlsli" -#include "tiledLightingHF.hlsli" +#include "lightingHF.hlsli" #ifdef DEBUG_TILEDLIGHTCULLING RWTEXTURE2D(DebugTexture, float4, UAVSLOT_DEBUGTEXTURE); diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli new file mode 100644 index 000000000..277680a75 --- /dev/null +++ b/WickedEngine/lightingHF.hlsli @@ -0,0 +1,194 @@ +#ifndef _LIGHTING_HF_ +#define _LIGHTING_HF_ +#include "globals.hlsli" +#include "brdf.hlsli" + +struct LightArrayType +{ + float3 positionVS; // View Space! + float range; + // -- + float4 color; + // -- + float3 positionWS; + float energy; + // -- + float3 directionVS; + float _pad0; + // -- + float3 directionWS; + uint type; + // -- + float shadowBias; + int shadowMap_index; + float coneAngle; + float coneAngleCos; + // -- + float4x4 shadowMat[3]; +}; + +TEXTURE2D(LightGrid, uint2, TEXSLOT_LIGHTGRID); +STRUCTUREDBUFFER(LightIndexList, uint, SBSLOT_LIGHTINDEXLIST); +STRUCTUREDBUFFER(LightArray, LightArrayType, SBSLOT_LIGHTARRAY); + +struct LightingResult +{ + float3 diffuse; + float3 specular; +}; + +inline float offset_lookup(float2 loc, float2 offset, float scale, float biasedDistance, float slice) +{ + return texture_shadowarray_2d.SampleCmpLevelZero(sampler_cmp_depth, float3(loc + offset / scale, slice), biasedDistance).r; +} +inline float shadowCascade(float4 shadowPos, float2 ShTex, float bias, float slice) { + float realDistance = shadowPos.z / shadowPos.w - bias; + float sum = 0; + float scale = 1.0f; + float retVal = 1; +#ifdef DIRECTIONALLIGHT_SOFT + float samples = 0.0f; + static const float range = 1.5f; + for (float y = -range; y <= range; y += 1.0f) + { + for (float x = -range; x <= range; x += 1.0f) + { + sum += offset_lookup(ShTex, float2(x, y), scale, realDistance, slice); + samples++; + } + } + retVal *= sum / samples; +#else + retVal *= offset_lookup(ShTex, float2(0, 0), scale, realDistance, slice); +#endif + return retVal; +} + +inline LightingResult DirectionalLight(in LightArrayType light, in float3 N, in float3 V, in float3 P, in float roughness, in float3 f0) +{ + LightingResult result; + float3 lightColor = light.color.rgb*light.energy; + + float3 L = light.directionWS.xyz; + BRDF_MAKE(N, L, V); + result.specular = lightColor * BRDF_SPECULAR(roughness, f0); + result.diffuse = lightColor * BRDF_DIFFUSE(roughness); + + float sh = max(NdotL, 0); + + [branch] + if (light.shadowMap_index >= 0) + { + float4 ShPos[3]; + ShPos[0] = mul(float4(P, 1), light.shadowMat[0]); + ShPos[1] = mul(float4(P, 1), light.shadowMat[1]); + ShPos[2] = mul(float4(P, 1), light.shadowMat[2]); + float3 ShTex[3]; + ShTex[0] = ShPos[0].xyz*float3(1, -1, 1) / ShPos[0].w / 2.0f + 0.5f; + ShTex[1] = ShPos[1].xyz*float3(1, -1, 1) / ShPos[1].w / 2.0f + 0.5f; + ShTex[2] = ShPos[2].xyz*float3(1, -1, 1) / ShPos[2].w / 2.0f + 0.5f; + [branch]if ((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z)) + { + const float shadows[] = { + shadowCascade(ShPos[1],ShTex[1].xy, light.shadowBias,light.shadowMap_index + 1), + shadowCascade(ShPos[2],ShTex[2].xy, light.shadowBias,light.shadowMap_index + 2) + }; + const float2 lerpVal = abs(ShTex[2].xy * 2 - 1); + sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); + } + else[branch]if ((saturate(ShTex[1].x) == ShTex[1].x) && (saturate(ShTex[1].y) == ShTex[1].y) && (saturate(ShTex[1].z) == ShTex[1].z)) + { + const float shadows[] = { + shadowCascade(ShPos[0],ShTex[0].xy, light.shadowBias,light.shadowMap_index + 0), + shadowCascade(ShPos[1],ShTex[1].xy, light.shadowBias,light.shadowMap_index + 1), + }; + const float2 lerpVal = abs(ShTex[1].xy * 2 - 1); + sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); + } + else[branch]if ((saturate(ShTex[0].x) == ShTex[0].x) && (saturate(ShTex[0].y) == ShTex[0].y) && (saturate(ShTex[0].z) == ShTex[0].z)) + { + sh *= shadowCascade(ShPos[0], ShTex[0].xy, light.shadowBias, light.shadowMap_index + 0); + } + } + + result.diffuse *= sh; + result.specular *= sh; + + result.diffuse = max(0.0f, result.diffuse); + result.specular = max(0.0f, result.specular); + return result; +} +inline LightingResult PointLight(in LightArrayType light, in float3 L, in float distance, in float3 N, in float3 V, in float3 P, in float roughness, in float3 f0) +{ + LightingResult result = (LightingResult)0; + float3 lightColor = light.color.rgb*light.energy; + + BRDF_MAKE(N, L, V); + result.specular = lightColor * BRDF_SPECULAR(roughness, f0); + result.diffuse = lightColor * BRDF_DIFFUSE(roughness); + + float att = (light.energy * (light.range / (light.range + 1 + distance))); + float attenuation = (att * (light.range - distance) / light.range); + result.diffuse *= attenuation; + result.specular *= attenuation; + + float sh = max(NdotL, 0); + [branch] + if (light.shadowMap_index >= 0) { + static const float bias = 0.025; + sh *= texture_shadowarray_cube.SampleCmpLevelZero(sampler_cmp_depth, float4(-L, light.shadowMap_index), distance / light.range - bias).r; + } + result.diffuse *= sh; + result.specular *= sh; + + result.diffuse = max(0.0f, result.diffuse); + result.specular = max(0.0f, result.specular); + return result; +} +inline LightingResult SpotLight(in LightArrayType light, in float3 L, in float distance, in float3 N, in float3 V, in float3 P, in float roughness, in float3 f0) +{ + LightingResult result = (LightingResult)0; + float3 lightColor = light.color.rgb*light.energy; + + float SpotFactor = dot(L, light.directionWS); + float spotCutOff = light.coneAngleCos; + + [branch] + if (SpotFactor > spotCutOff) + { + + BRDF_MAKE(N, L, V); + result.specular = lightColor * BRDF_SPECULAR(roughness, f0); + result.diffuse = lightColor * BRDF_DIFFUSE(roughness); + + float att = (light.energy * (light.range / (light.range + 1 + distance))); + float attenuation = (att * (light.range - distance) / light.range); + attenuation *= saturate((1.0 - (1.0 - SpotFactor) * 1.0 / (1.0 - spotCutOff))); + result.diffuse *= attenuation; + result.specular *= attenuation; + + float sh = max(NdotL, 0); + [branch] + if (light.shadowMap_index >= 0) + { + float4 ShPos = mul(float4(P, 1), light.shadowMat[0]); + float2 ShTex = ShPos.xy / ShPos.w * float2(0.5f, -0.5f) + float2(0.5f, 0.5f); + [branch] + if ((saturate(ShTex.x) == ShTex.x) && (saturate(ShTex.y) == ShTex.y)) + { + sh *= shadowCascade(ShPos, ShTex.xy, light.shadowBias, light.shadowMap_index); + } + } + result.diffuse *= sh; + result.specular *= sh; + + result.diffuse = max(result.diffuse, 0); + result.specular = max(result.specular, 0); + } + + result.diffuse = max(0.0f, result.diffuse); + result.specular = max(0.0f, result.specular); + return result; +} + +#endif // _LIGHTING_HF_ \ No newline at end of file diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 3e6835663..9848a5273 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -7,20 +7,15 @@ #include "tangentComputeHF.hlsli" #include "depthConvertHF.hlsli" #include "fogHF.hlsli" -#include "dirLightHF.hlsli" #include "brdf.hlsli" #include "envReflectionHF.hlsli" #include "packHF.hlsli" #include "lightCullingCSInterop.h" -#include "tiledLightingHF.hlsli" +#include "lightingHF.hlsli" // DEFINITIONS ////////////////// -TEXTURE2D(LightGrid, uint2, TEXSLOT_LIGHTGRID); -STRUCTUREDBUFFER(LightIndexList, uint, SBSLOT_LIGHTINDEXLIST); -STRUCTUREDBUFFER(LightArray, LightArrayType, SBSLOT_LIGHTARRAY); - #define xBaseColorMap texture_0 #define xNormalMap texture_1 #define xRoughnessMap texture_2 @@ -57,12 +52,6 @@ struct GBUFFEROutputType float4 g3 : SV_TARGET3; // texture_gbuffer3 }; -struct LightingResult -{ - float3 diffuse; - float3 specular; -}; - // METHODS //////////// @@ -119,63 +108,11 @@ inline void Refraction(in float2 ScreenCoord, in float2 normal2D, in float3 bump inline void DirectionalLight(in float3 N, in float3 V, in float3 P, in float3 f0, in float3 albedo, in float roughness, inout float3 diffuse, out float3 specular) { - float3 L = GetSunDirection(); - float3 lightColor = GetSunColor(); - BRDF_MAKE(N, L, V); - specular = lightColor * BRDF_SPECULAR(roughness, f0); - diffuse = lightColor * BRDF_DIFFUSE(roughness); - - float sh = max(NdotL, 0); - float4 ShPos[3]; - ShPos[0] = mul(float4(P, 1), g_xDirLight_ShM[0]); - ShPos[1] = mul(float4(P, 1), g_xDirLight_ShM[1]); - ShPos[2] = mul(float4(P, 1), g_xDirLight_ShM[2]); - float3 ShTex[3]; - ShTex[0] = ShPos[0].xyz*float3(1, -1, 1) / ShPos[0].w / 2.0f + 0.5f; - ShTex[1] = ShPos[1].xyz*float3(1, -1, 1) / ShPos[1].w / 2.0f + 0.5f; - ShTex[2] = ShPos[2].xyz*float3(1, -1, 1) / ShPos[2].w / 2.0f + 0.5f; - [branch]if ((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z)) - { - const float shadows[] = { - shadowCascade(ShPos[1],ShTex[1].xy,0.0001f,texture_shadow1), - shadowCascade(ShPos[2],ShTex[2].xy,0.0001f,texture_shadow2) - }; - const float2 lerpVal = abs(ShTex[2].xy * 2 - 1); - sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); - } - else[branch]if ((saturate(ShTex[1].x) == ShTex[1].x) && (saturate(ShTex[1].y) == ShTex[1].y) && (saturate(ShTex[1].z) == ShTex[1].z)) - { - const float shadows[] = { - shadowCascade(ShPos[0],ShTex[0].xy,0.0001f,texture_shadow0), - shadowCascade(ShPos[1],ShTex[1].xy,0.0001f,texture_shadow1), - }; - const float2 lerpVal = abs(ShTex[1].xy * 2 - 1); - sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); - } - else[branch]if ((saturate(ShTex[0].x) == ShTex[0].x) && (saturate(ShTex[0].y) == ShTex[0].y) && (saturate(ShTex[0].z) == ShTex[0].z)) - { - sh *= shadowCascade(ShPos[0], ShTex[0].xy, 0.0001f, texture_shadow0); - } - - diffuse *= sh; - specular *= sh; - - diffuse = max(diffuse, 0); - specular = max(specular, 0); + LightingResult result = DirectionalLight(LightArray[0], N, V, P, roughness, f0); + diffuse = result.diffuse; + specular = result.specular; } -inline float offset_lookup1(float2 loc, float2 offset, float scale, float biasedDistance,float slice) -{ - return texture_shadowarray_2d.SampleCmpLevelZero(sampler_cmp_depth, float3(loc + offset / scale, slice), biasedDistance).r; -} -inline float shadowCascade1(float4 shadowPos, float2 ShTex, float bias, float slice) { - float realDistance = shadowPos.z / shadowPos.w - bias; - float sum = 0; - float scale = g_xDirLight_mBiasResSoftshadow.y; - float retVal = 1; - retVal *= offset_lookup1(ShTex, float2(0, 0), scale, realDistance,slice); - return retVal; -} inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P, in float3 f0, in float3 albedo, in float roughness, inout float3 diffuse, out float3 specular) @@ -184,6 +121,8 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P uint startOffset = LightGrid[tileIndex].x; uint lightCount = LightGrid[tileIndex].y; + LightingResult result = (LightingResult)0; + specular = 0; diffuse = 0; for (uint i = 0; i < lightCount; i++) @@ -197,123 +136,22 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P continue; L /= lightDistance; - LightingResult result = (LightingResult)0; - - float3 lightColor = light.color.rgb * light.energy; - [branch] switch (light.type) { case 0/*DIRECTIONAL*/: { - L = light.directionWS.xyz; - BRDF_MAKE(N, L, V); - result.specular = lightColor * BRDF_SPECULAR(roughness, f0); - result.diffuse = lightColor * BRDF_DIFFUSE(roughness); - - float sh = max(NdotL, 0); - - [branch] - if (light.shadowMap_index >= 0) - { - float4 ShPos[3]; - ShPos[0] = mul(float4(P, 1), light.shadowMat[0]); - ShPos[1] = mul(float4(P, 1), light.shadowMat[1]); - ShPos[2] = mul(float4(P, 1), light.shadowMat[2]); - float3 ShTex[3]; - ShTex[0] = ShPos[0].xyz*float3(1, -1, 1) / ShPos[0].w / 2.0f + 0.5f; - ShTex[1] = ShPos[1].xyz*float3(1, -1, 1) / ShPos[1].w / 2.0f + 0.5f; - ShTex[2] = ShPos[2].xyz*float3(1, -1, 1) / ShPos[2].w / 2.0f + 0.5f; - [branch]if ((saturate(ShTex[2].x) == ShTex[2].x) && (saturate(ShTex[2].y) == ShTex[2].y) && (saturate(ShTex[2].z) == ShTex[2].z)) - { - const float shadows[] = { - shadowCascade1(ShPos[1],ShTex[1].xy, light.shadowBias,light.shadowMap_index + 1), - shadowCascade1(ShPos[2],ShTex[2].xy, light.shadowBias,light.shadowMap_index + 2) - }; - const float2 lerpVal = abs(ShTex[2].xy * 2 - 1); - sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); - } - else[branch]if ((saturate(ShTex[1].x) == ShTex[1].x) && (saturate(ShTex[1].y) == ShTex[1].y) && (saturate(ShTex[1].z) == ShTex[1].z)) - { - const float shadows[] = { - shadowCascade1(ShPos[0],ShTex[0].xy, light.shadowBias,light.shadowMap_index + 0), - shadowCascade1(ShPos[1],ShTex[1].xy, light.shadowBias,light.shadowMap_index + 1), - }; - const float2 lerpVal = abs(ShTex[1].xy * 2 - 1); - sh *= lerp(shadows[1], shadows[0], pow(max(lerpVal.x, lerpVal.y), 4)); - } - else[branch]if ((saturate(ShTex[0].x) == ShTex[0].x) && (saturate(ShTex[0].y) == ShTex[0].y) && (saturate(ShTex[0].z) == ShTex[0].z)) - { - sh *= shadowCascade1(ShPos[0], ShTex[0].xy, light.shadowBias, light.shadowMap_index + 0); - } - } - - result.diffuse *= sh; - result.specular *= sh; - - result.diffuse = max(result.diffuse, 0); - result.specular = max(result.specular, 0); + result = DirectionalLight(light, N, V, P, roughness, f0); } break; case 1/*POINT*/: { - BRDF_MAKE(N, L, V); - result.specular = lightColor * BRDF_SPECULAR(roughness, f0); - result.diffuse = lightColor * BRDF_DIFFUSE(roughness); - - float att = (light.energy * (light.range / (light.range + 1 + lightDistance))); - float attenuation = (att * (light.range - lightDistance) / light.range); - result.diffuse *= attenuation; - result.specular *= attenuation; - - float sh = max(NdotL, 0); - [branch] - if (light.shadowMap_index >=0) { - static const float bias = 0.025; - sh *= texture_shadowarray_cube.SampleCmpLevelZero(sampler_cmp_depth, float4(-L,light.shadowMap_index), lightDistance / light.range - bias).r; - } - result.diffuse *= sh; - result.specular *= sh; + result = PointLight(light, L, lightDistance, N, V, P, roughness, f0); } break; case 2/*SPOT*/: { - float SpotFactor = dot(L, light.directionWS); - - float spotCutOff = light.coneAngleCos; - - [branch] - if (SpotFactor > spotCutOff) - { - - BRDF_MAKE(N, L, V); - result.specular = lightColor * BRDF_SPECULAR(roughness, f0); - result.diffuse = lightColor * BRDF_DIFFUSE(roughness); - - float att = (light.energy * (light.range / (light.range + 1 + lightDistance))); - float attenuation = (att * (light.range - lightDistance) / light.range); - attenuation *= saturate((1.0 - (1.0 - SpotFactor) * 1.0 / (1.0 - spotCutOff))); - result.diffuse *= attenuation; - result.specular *= attenuation; - - float sh = max(NdotL, 0); - [branch] - if (light.shadowMap_index >= 0) - { - float4 ShPos = mul(float4(P, 1), light.shadowMat[0]); - float2 ShTex = ShPos.xy / ShPos.w * float2(0.5f, -0.5f) + float2(0.5f, 0.5f); - [branch] - if ((saturate(ShTex.x) == ShTex.x) && (saturate(ShTex.y) == ShTex.y)) - { - sh *= shadowCascade1(ShPos, ShTex.xy, light.shadowBias, light.shadowMap_index); - } - } - result.diffuse *= sh; - result.specular *= sh; - - result.diffuse = max(result.diffuse, 0); - result.specular = max(result.specular, 0); - } + result = SpotLight(light, L, lightDistance, N, V, P, roughness, f0); } break; } diff --git a/WickedEngine/pointLightPS.hlsl b/WickedEngine/pointLightPS.hlsl index d85c04fcf..33883a0a7 100644 --- a/WickedEngine/pointLightPS.hlsl +++ b/WickedEngine/pointLightPS.hlsl @@ -1,12 +1,10 @@ -#include "lightHF.hlsli" -#include "pointLightHF.hlsli" - +#include "deferredLightHF.hlsli" LightOutputType main(VertexToPixel PSIn) { DEFERREDLIGHT_MAKEPARAMS - DEFERRED_POINTLIGHT_MAIN + DEFERREDLIGHT_POINT DEFERREDLIGHT_RETURN } \ No newline at end of file diff --git a/WickedEngine/pointLightVS.hlsl b/WickedEngine/pointLightVS.hlsl index d6e6444d2..fadc1d0ea 100644 --- a/WickedEngine/pointLightVS.hlsl +++ b/WickedEngine/pointLightVS.hlsl @@ -1,14 +1,12 @@ -#include "lightHF.hlsli" +#include "deferredLightHF.hlsli" #include "icosphere.hlsli" -#include "pointLightHF.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) { VertexToPixel Out = (VertexToPixel)0; float4 pos = float4(ICOSPHERE[vid],1); - pos.xyz *= xLightEnerDis.y+1; - pos.xyz += xLightPos; - Out.pos = Out.pos2D = mul(pos,g_xCamera_VP); + Out.pos = Out.pos2D = mul(mul(pos,g_xTransform),g_xCamera_VP); + Out.lightIndex = g_xMisc_int4[0]; return Out; } \ No newline at end of file diff --git a/WickedEngine/spotLightPS.hlsl b/WickedEngine/spotLightPS.hlsl index deed90b68..034700ba7 100644 --- a/WickedEngine/spotLightPS.hlsl +++ b/WickedEngine/spotLightPS.hlsl @@ -1,12 +1,10 @@ -#include "lightHF.hlsli" -#include "spotLightHF.hlsli" - +#include "deferredLightHF.hlsli" LightOutputType main(VertexToPixel PSIn) { DEFERREDLIGHT_MAKEPARAMS - DEFERRED_SPOTLIGHT_MAIN + DEFERREDLIGHT_SPOT DEFERREDLIGHT_RETURN } \ No newline at end of file diff --git a/WickedEngine/spotLightVS.hlsl b/WickedEngine/spotLightVS.hlsl index 83a8b186a..12b5089d5 100644 --- a/WickedEngine/spotLightVS.hlsl +++ b/WickedEngine/spotLightVS.hlsl @@ -1,6 +1,5 @@ -#include "lightHF.hlsli" +#include "deferredLightHF.hlsli" #include "cone.hlsli" -#include "spotLightHF.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) @@ -8,7 +7,8 @@ VertexToPixel main(uint vid : SV_VERTEXID) VertexToPixel Out = (VertexToPixel)0; float4 pos = float4(CONE[vid],1); - pos = mul( pos,xLightWorld ); + pos = mul( pos, g_xTransform ); Out.pos = Out.pos2D = mul(pos,g_xCamera_VP); + Out.lightIndex = g_xMisc_int4[0]; return Out; } \ No newline at end of file diff --git a/WickedEngine/tiledLightingHF.hlsli b/WickedEngine/tiledLightingHF.hlsli deleted file mode 100644 index 6ed678262..000000000 --- a/WickedEngine/tiledLightingHF.hlsli +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _TILEDLIGHTING_HF_ -#define _TILEDLIGHTING_HF_ - -struct LightArrayType -{ - float3 positionVS; // View Space! - float range; - // -- - float4 color; - // -- - float3 positionWS; - float energy; - // -- - float3 directionVS; - float _pad0; - // -- - float3 directionWS; - uint type; - // -- - float shadowBias; - int shadowMap_index; - float coneAngle; - float coneAngleCos; - // -- - float4x4 shadowMat[3]; -}; - -#endif // _TILEDLIGHTING_HF_ \ No newline at end of file diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 313bfbefa..789adf313 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -4042,6 +4042,7 @@ Light::Light():Transform() { lensFlareRimTextures.resize(0); lensFlareNames.resize(0); shadowMap_index = -1; + lightArray_index = 0; shadowBias = 0.0001f; } Light::~Light() { diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index b67667996..7258868b8 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -778,6 +778,7 @@ struct Light : public Cullable , public Transform static wiGraphicsTypes::Texture2D* shadowMapArray_2D; static wiGraphicsTypes::Texture2D* shadowMapArray_Cube; int shadowMap_index; + int lightArray_index; vector shadowCam_pointLight; vector shadowCam_dirLight; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 84e8d2820..9ff77848f 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -22,6 +22,7 @@ #include "ResourceMapping.h" #include "wiGraphicsDevice_DX11.h" #include "wiTranslator.h" +#include "lightCullingCSInterop.h" using namespace wiGraphicsTypes; @@ -561,9 +562,6 @@ void wiRenderer::LoadBuffers() bd.ByteWidth = sizeof(MaterialCB); GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MATERIAL]); - bd.ByteWidth = sizeof(DirectionalLightCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_DIRLIGHT]); - bd.ByteWidth = sizeof(MiscCB); GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_MISC]); @@ -575,11 +573,6 @@ void wiRenderer::LoadBuffers() // On demand buffers... - bd.ByteWidth = sizeof(PointLightCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_POINTLIGHT]); - - bd.ByteWidth = sizeof(SpotLightCB); - GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_SPOTLIGHT]); bd.ByteWidth = sizeof(VolumeLightCB); GetDevice()->CreateBuffer(&bd, nullptr, constantBuffers[CBTYPE_VOLUMELIGHT]); @@ -616,7 +609,7 @@ void wiRenderer::LoadBuffers() bd.StructureByteStride = sizeof(ShaderBoneType); GetDevice()->CreateBuffer(&bd, nullptr, resourceBuffers[RBTYPE_BONE]); - bd.ByteWidth = sizeof(LightArrayType) * 1024; + bd.ByteWidth = sizeof(LightArrayType) * MAX_LIGHTS; bd.BindFlags = BIND_SHADER_RESOURCE; bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; bd.StructureByteStride = sizeof(LightArrayType); @@ -1214,9 +1207,6 @@ void wiRenderer::BindPersistentState(GRAPHICSTHREAD threadID) GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_MATERIAL], CB_GETBINDSLOT(MaterialCB), threadID); - GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); - GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_DIRLIGHT], CB_GETBINDSLOT(DirectionalLightCB), threadID); - GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); @@ -1454,6 +1444,12 @@ void wiRenderer::UpdatePerFrameData() Frustum frustum; frustum.ConstructFrustum(min(camera->zFarP, GetScene().worldInfo.fogSEH.y), camera->Projection, camera->View); wiSPTree::getVisible(spTree_lights->root, frustum, culling.culledLights); + UINT i = 0; + for (auto& l : culling.culledLights) + { + ((Light*)l)->lightArray_index = i; + i++; + } } } } @@ -1591,6 +1587,68 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) GetDevice()->BindResourcePS(envMaps[1], TEXSLOT_ENV1, threadID); } + // Fill Light Array with lights in the frustum + { + const FrameCulling& culling = frameCullings[getCamera()]; + const CulledList& culledLights = culling.culledLights; + + static LightArrayType* lightArray = (LightArrayType*)_mm_malloc(sizeof(LightArrayType)*MAX_LIGHTS, 16); + ZeroMemory(lightArray, sizeof(lightArray)); + + XMMATRIX viewMatrix = cam->GetView(); + + UINT lightCounter = 0; + for (Cullable* c : culledLights) + { + Light* l = (Light*)c; + + lightArray[lightCounter].posWS = l->translation; + XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].posWS), viewMatrix)); + lightArray[lightCounter].distance = l->enerDis.y; + lightArray[lightCounter].col = l->color; + lightArray[lightCounter].energy = l->enerDis.x; + lightArray[lightCounter].type = l->type; + lightArray[lightCounter].shadowBias = l->shadowBias; + lightArray[lightCounter].shadowMap_index = l->shadowMap_index; + switch (l->type) + { + case Light::DIRECTIONAL: + { + lightArray[lightCounter].directionWS = l->GetDirection(); + for (unsigned int shmap = 0; shmap < min(l->shadowCam_dirLight.size(), ARRAYSIZE(lightArray[lightCounter].shadowMatrix)); ++shmap) { + lightArray[lightCounter].shadowMatrix[shmap] = l->shadowCam_dirLight[shmap].getVP(); + } + } + break; + case Light::SPOT: + { + lightArray[lightCounter].coneAngle = (l->enerDis.z * 0.5f); + lightArray[lightCounter].coneAngleCos = cosf(lightArray[lightCounter].coneAngle); + lightArray[lightCounter].directionWS = l->GetDirection(); + XMStoreFloat3(&lightArray[lightCounter].directionVS, XMVector3TransformNormal(XMLoadFloat3(&lightArray[lightCounter].directionWS), viewMatrix)); + if (l->shadow && l->shadowMap_index >= 0) + { + lightArray[lightCounter].shadowMatrix[0] = l->shadowCam_spotLight[0].getVP(); + } + } + break; + default: + break; + } + + lightCounter++; + if (lightCounter == MAX_LIGHTS) + { + assert(0 && "Maximum Lightcount exceeded for a single tiled lightculling pass! Please redefine MAX_LIGHTS to fit!"); + lightCounter--; + break; + } + } + GetDevice()->UpdateBuffer(resourceBuffers[RBTYPE_LIGHTARRAY], lightArray, threadID, (int)(sizeof(LightArrayType)*lightCounter)); + + GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID); + GetDevice()->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID); + } } void wiRenderer::UpdateImages(){ @@ -2170,12 +2228,6 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID) GetDevice()->Draw(3, threadID); } - GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); - - GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); - GetDevice()->BindConstantBufferVS(constantBuffers[CBTYPE_SPOTLIGHT], CB_GETBINDSLOT(SpotLightCB), threadID); - for(int type=0;type<3;++type){ @@ -2214,67 +2266,88 @@ void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID) if(type==0) //dir { - DirectionalLightCB lcb; - lcb.direction=XMVector3Normalize( - -XMVector3Transform( XMVectorSet(0,-1,0,1), XMMatrixRotationQuaternion( XMLoadFloat4(&l->rotation) ) ) - ); - lcb.col=XMFLOAT4(l->color.x*l->enerDis.x,l->color.y*l->enerDis.x,l->color.z*l->enerDis.x,1); - lcb.mBiasResSoftshadow=XMFLOAT4(l->shadowBias,(float)SHADOWRES_2D,(float)SOFTSHADOWQUALITY_2D,0); - //for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){ - // lcb.mShM[shmap]=l->shadowCam_dirLight[shmap].getVP(); - // if(l->shadowMaps_dirLight[shmap].depth) - // GetDevice()->BindResourcePS(l->shadowMaps_dirLight[shmap].depth->GetTexture(),TEXSLOT_SHADOW0+shmap,threadID); - //} - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],&lcb,threadID); + //DirectionalLightCB lcb; + //lcb.direction=XMVector3Normalize( + // -XMVector3Transform( XMVectorSet(0,-1,0,1), XMMatrixRotationQuaternion( XMLoadFloat4(&l->rotation) ) ) + // ); + //lcb.col=XMFLOAT4(l->color.x*l->enerDis.x,l->color.y*l->enerDis.x,l->color.z*l->enerDis.x,1); + //lcb.mBiasResSoftshadow=XMFLOAT4(l->shadowBias,(float)SHADOWRES_2D,(float)SOFTSHADOWQUALITY_2D,0); + ////for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){ + //// lcb.mShM[shmap]=l->shadowCam_dirLight[shmap].getVP(); + //// if(l->shadowMaps_dirLight[shmap].depth) + //// GetDevice()->BindResourcePS(l->shadowMaps_dirLight[shmap].depth->GetTexture(),TEXSLOT_SHADOW0+shmap,threadID); + ////} + //GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],&lcb,threadID); + + MiscCB miscCb; + miscCb.mInt[0] = l->lightArray_index; + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(3, threadID); } else if(type==1) //point { - PointLightCB lcb; - lcb.pos=l->translation; - lcb.col=l->color; - lcb.enerdis=l->enerDis; - lcb.enerdis.w = 0.f; + //PointLightCB lcb; + //lcb.pos=l->translation; + //lcb.col=l->color; + //lcb.enerdis=l->enerDis; + //lcb.enerdis.w = 0.f; - //if (l->shadow && l->shadowMap_index>=0) - //{ - // lcb.enerdis.w = 1.f; - // if(Light::shadowMaps_pointLight[l->shadowMap_index].depth) - // GetDevice()->BindResourcePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW_CUBE, threadID); - //} - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], &lcb, threadID); + ////if (l->shadow && l->shadowMap_index>=0) + ////{ + //// lcb.enerdis.w = 1.f; + //// if(Light::shadowMaps_pointLight[l->shadowMap_index].depth) + //// GetDevice()->BindResourcePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW_CUBE, threadID); + ////} + //GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], &lcb, threadID); + + MiscCB miscCb; + miscCb.mInt[0] = l->lightArray_index; + float sca = l->enerDis.y + 1; + miscCb.mTransform = XMMatrixTranspose(XMMatrixScaling(sca,sca,sca)*XMMatrixTranslation(l->translation.x, l->translation.y, l->translation.z)); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(240, threadID); } else if(type==2) //spot { - SpotLightCB lcb; - const float coneS = (const float)(l->enerDis.z / XM_PIDIV4); - XMMATRIX world,rot; - world = XMMatrixTranspose( - XMMatrixScaling(coneS*l->enerDis.y,l->enerDis.y,coneS*l->enerDis.y)* - XMMatrixRotationQuaternion( XMLoadFloat4( &l->rotation ) )* - XMMatrixTranslationFromVector( XMLoadFloat3(&l->translation) ) - ); - rot=XMMatrixRotationQuaternion( XMLoadFloat4(&l->rotation) ); - lcb.direction=XMVector3Normalize( - -XMVector3Transform( XMVectorSet(0,-1,0,1), rot ) - ); - lcb.world=world; - lcb.mBiasResSoftshadow=XMFLOAT4(l->shadowBias,(float)SHADOWRES_2D,(float)SOFTSHADOWQUALITY_2D,0); - lcb.mShM = XMMatrixIdentity(); - lcb.col=l->color; - lcb.enerdis=l->enerDis; - lcb.enerdis.z=(float)cos(l->enerDis.z/2.0); + //SpotLightCB lcb; + //const float coneS = (const float)(l->enerDis.z / XM_PIDIV4); + //XMMATRIX world,rot; + //world = XMMatrixTranspose( + // XMMatrixScaling(coneS*l->enerDis.y,l->enerDis.y,coneS*l->enerDis.y)* + // XMMatrixRotationQuaternion( XMLoadFloat4( &l->rotation ) )* + // XMMatrixTranslationFromVector( XMLoadFloat3(&l->translation) ) + // ); + //rot=XMMatrixRotationQuaternion( XMLoadFloat4(&l->rotation) ); + //lcb.direction=XMVector3Normalize( + // -XMVector3Transform( XMVectorSet(0,-1,0,1), rot ) + // ); + //lcb.world=world; + //lcb.mBiasResSoftshadow=XMFLOAT4(l->shadowBias,(float)SHADOWRES_2D,(float)SOFTSHADOWQUALITY_2D,0); + //lcb.mShM = XMMatrixIdentity(); + //lcb.col=l->color; + //lcb.enerdis=l->enerDis; + //lcb.enerdis.z=(float)cos(l->enerDis.z/2.0); - //if (l->shadow && l->shadowMap_index>=0) - //{ - // lcb.mShM = l->shadowCam_spotLight[0].getVP(); - // if(Light::shadowMaps_spotLight[l->shadowMap_index].depth) - // GetDevice()->BindResourcePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW0, threadID); - //} - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], &lcb, threadID); + ////if (l->shadow && l->shadowMap_index>=0) + ////{ + //// lcb.mShM = l->shadowCam_spotLight[0].getVP(); + //// if(Light::shadowMaps_spotLight[l->shadowMap_index].depth) + //// GetDevice()->BindResourcePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->GetTexture(), TEXSLOT_SHADOW0, threadID); + ////} + //GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], &lcb, threadID); + + + MiscCB miscCb; + miscCb.mInt[0] = l->lightArray_index; + const float coneS = (const float)(l->enerDis.z / XM_PIDIV4); + miscCb.mTransform = XMMatrixTranspose( + XMMatrixScaling(coneS*l->enerDis.y, l->enerDis.y, coneS*l->enerDis.y)* + XMMatrixRotationQuaternion(XMLoadFloat4(&l->rotation))* + XMMatrixTranslationFromVector(XMLoadFloat3(&l->translation)) + ); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); GetDevice()->Draw(192, threadID); } @@ -2741,7 +2814,6 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], threadID); GetDevice()->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], threadID); - GetDevice()->BindConstantBufferPS(constantBuffers[CBTYPE_POINTLIGHT], CB_GETBINDSLOT(PointLightCB), threadID); GetDevice()->BindConstantBufferGS(constantBuffers[CBTYPE_CUBEMAPRENDER], CB_GETBINDSLOT(CubeMapRenderCB), threadID); //int i = 0; @@ -2762,10 +2834,9 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) GetDevice()->BindViewports(1, &vp, threadID); GetDevice()->BindRenderTargets(0, nullptr, Light::shadowMapArray_Cube, threadID, l->shadowMap_index); - PointLightCB lcb; - lcb.enerdis = l->enerDis; - lcb.pos = l->translation; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], &lcb, threadID); + MiscCB miscCb; + miscCb.mColor = XMFLOAT4(l->translation.x, l->translation.y, l->translation.z, l->enerDis.y); + GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &miscCb, threadID); CubeMapRenderCB cb; for (unsigned int shcam = 0; shcam < l->shadowCam_pointLight.size(); ++shcam) @@ -3058,7 +3129,6 @@ void wiRenderer::DrawWorld(Camera* camera, bool tessellation, GRAPHICSTHREAD thr if (shaderType == SHADERTYPE_TILEDFORWARD) { - GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID); GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTINDEXLIST_OPAQUE], SBSLOT_LIGHTINDEXLIST, threadID); GetDevice()->BindResourcePS(textures[TEXTYPE_2D_LIGHTGRID_OPAQUE], TEXSLOT_LIGHTGRID, threadID); @@ -3323,7 +3393,6 @@ void wiRenderer::DrawWorldTransparent(Camera* camera, SHADERTYPE shaderType, Tex if (shaderType == SHADERTYPE_TILEDFORWARD) { - GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTARRAY], SBSLOT_LIGHTARRAY, threadID); GetDevice()->BindResourcePS(resourceBuffers[RBTYPE_LIGHTINDEXLIST_TRANSPARENT], SBSLOT_LIGHTINDEXLIST, threadID); GetDevice()->BindResourcePS(textures[TEXTYPE_2D_LIGHTGRID_TRANSPARENT], TEXSLOT_LIGHTGRID, threadID); } @@ -3598,7 +3667,6 @@ void wiRenderer::DrawDecals(Camera* camera, GRAPHICSTHREAD threadID) void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID) { -#include "lightCullingCSInterop.h" GraphicsDevice* device = wiRenderer::GetDevice(); @@ -3626,72 +3694,11 @@ void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID) dispatchParams.numThreadGroups[0] = (UINT)ceilf(dispatchParams.numThreads[0] / (float)BLOCK_SIZE); dispatchParams.numThreadGroups[1] = (UINT)ceilf(dispatchParams.numThreads[1] / (float)BLOCK_SIZE); dispatchParams.numThreadGroups[2] = 1; - - // Fill Light Array with lights in the frustum - const FrameCulling& culling = frameCullings[getCamera()]; - const CulledList& culledLights = culling.culledLights; - - static LightArrayType* lightArray = (LightArrayType*)_mm_malloc(sizeof(LightArrayType)*MAX_LIGHTS, 16); - ZeroMemory(lightArray, sizeof(lightArray)); - - XMMATRIX viewMatrix = cam->GetView(); - - UINT lightCounter = 0; - for (Cullable* c : culledLights) - { - Light* l = (Light*)c; - - lightArray[lightCounter].posWS = l->translation; - XMStoreFloat3(&lightArray[lightCounter].posVS, XMVector3TransformCoord(XMLoadFloat3(&lightArray[lightCounter].posWS), viewMatrix)); - lightArray[lightCounter].distance = l->enerDis.y; - lightArray[lightCounter].col = l->color; - lightArray[lightCounter].energy = l->enerDis.x; - lightArray[lightCounter].type = l->type; - lightArray[lightCounter].shadowBias = l->shadowBias; - lightArray[lightCounter].shadowMap_index = l->shadowMap_index; - switch (l->type) - { - case Light::DIRECTIONAL: - { - lightArray[lightCounter].directionWS = l->GetDirection(); - for (unsigned int shmap = 0; shmap < min(l->shadowCam_dirLight.size(),ARRAYSIZE(lightArray[lightCounter].shadowMatrix)); ++shmap) { - lightArray[lightCounter].shadowMatrix[shmap] = l->shadowCam_dirLight[shmap].getVP(); - } - } - break; - case Light::SPOT: - { - lightArray[lightCounter].coneAngle = (l->enerDis.z * 0.5f); - lightArray[lightCounter].coneAngleCos = cosf(lightArray[lightCounter].coneAngle); - lightArray[lightCounter].directionWS = l->GetDirection(); - XMStoreFloat3(&lightArray[lightCounter].directionVS, XMVector3TransformNormal(XMLoadFloat3(&lightArray[lightCounter].directionWS), viewMatrix)); - if (l->shadow && l->shadowMap_index >= 0) - { - lightArray[lightCounter].shadowMatrix[0] = l->shadowCam_spotLight[0].getVP(); - } - } - break; - default: - break; - } - - lightCounter++; - if (lightCounter == MAX_LIGHTS) - { - assert(0 && "Maximum Lightcount exceeded for a single tiled lightculling pass! Please redefine MAX_LIGHTS to fit!"); - lightCounter--; - break; - } - } - device->UpdateBuffer(resourceBuffers[RBTYPE_LIGHTARRAY], lightArray, threadID, (int)(sizeof(LightArrayType)*lightCounter)); - - dispatchParams.value0 = lightCounter; - + dispatchParams.value0 = (UINT)frameCullings[getCamera()].culledLights.size(); device->UpdateBuffer(constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); device->BindConstantBufferCS(constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); } - static GPUBuffer* frustumBuffer = nullptr; if (frustumBuffer == nullptr || _resolutionChanged) { @@ -3807,8 +3814,6 @@ void wiRenderer::ComputeTiledLightCulling(GRAPHICSTHREAD threadID) device->EventBegin(L"Light Culling", threadID); device->UnBindResources(TEXSLOT_LIGHTGRID, SBSLOT_LIGHTINDEXLIST - TEXSLOT_LIGHTGRID + 1, threadID); - - device->BindResourceCS(resourceBuffers[RBTYPE_LIGHTARRAY], STRUCTUREDBUFFER_GETBINDSLOT(LightArrayType), threadID); device->BindResourceCS(frustumBuffer, SBSLOT_TILEFRUSTUMS, threadID); diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 85b28c027..797277c54 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -160,21 +160,11 @@ public: ALIGN_16 }; - GFX_STRUCT DirectionalLightCB - { - XMVECTOR direction; - XMFLOAT4 col; - XMFLOAT4 mBiasResSoftshadow; - XMMATRIX mShM[3]; - - CB_SETBINDSLOT(CBSLOT_RENDERER_DIRLIGHT) - - ALIGN_16 - }; GFX_STRUCT MiscCB { XMMATRIX mTransform; XMFLOAT4 mColor; + int mInt[4]; CB_SETBINDSLOT(CBSLOT_RENDERER_MISC) @@ -190,29 +180,6 @@ public: }; // On demand buffers: - GFX_STRUCT PointLightCB - { - XMFLOAT3 pos; float pad; - XMFLOAT4 col; - XMFLOAT4 enerdis; - - CB_SETBINDSLOT(CBSLOT_RENDERER_POINTLIGHT) - - ALIGN_16 - }; - GFX_STRUCT SpotLightCB - { - XMMATRIX world; - XMVECTOR direction; - XMFLOAT4 col; - XMFLOAT4 enerdis; - XMFLOAT4 mBiasResSoftshadow; - XMMATRIX mShM; - - CB_SETBINDSLOT(CBSLOT_RENDERER_SPOTLIGHT) - - ALIGN_16 - }; GFX_STRUCT VolumeLightCB { XMMATRIX world;