mainline refactor in light rendering paths complete
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef _POINTLIGHT_HF_
|
||||
#define _POINTLIGHT_HF_
|
||||
#include "globals.hlsli"
|
||||
#include "brdf.hlsli"
|
||||
|
||||
CBUFFER(PointLightCB, CBSLOT_RENDERER_POINTLIGHT)
|
||||
{
|
||||
float3 xLightPos; float pad;
|
||||
float4 xLightColor;
|
||||
float4 xLightEnerDis;
|
||||
};
|
||||
|
||||
inline void pointLight(in float3 P, in float3 N, in float3 V, in float roughness, in float3 f0,
|
||||
out float3 diffuse, out float3 specular)
|
||||
{
|
||||
float3 L = normalize(xLightPos - P);
|
||||
BRDF_MAKE(N, L, V);
|
||||
specular = xLightColor.rgb * BRDF_SPECULAR(roughness, f0);
|
||||
diffuse = xLightColor.rgb * BRDF_DIFFUSE(roughness);
|
||||
diffuse *= xLightEnerDis.x;
|
||||
specular *= xLightEnerDis.x;
|
||||
|
||||
float lightdis = distance(P, xLightPos);
|
||||
float att = (xLightEnerDis.x * (xLightEnerDis.y / (xLightEnerDis.y + 1 + lightdis)));
|
||||
float attenuation = /*saturate*/(att * (xLightEnerDis.y - lightdis) / xLightEnerDis.y);
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
float sh = max(NdotL, 0);
|
||||
[branch]if(xLightEnerDis.w){
|
||||
const float3 lv = P - xLightPos.xyz;
|
||||
static const float bias = 0.025;
|
||||
sh *= texture_shadow_cube.SampleCmpLevelZero(sampler_cmp_depth,lv,length(lv)/ xLightEnerDis.y-bias ).r;
|
||||
}
|
||||
diffuse *= sh;
|
||||
specular *= sh;
|
||||
|
||||
diffuse = max(diffuse, 0);
|
||||
specular = max(specular, 0);
|
||||
}
|
||||
|
||||
|
||||
// MACROS
|
||||
|
||||
#define DEFERRED_POINTLIGHT_MAIN \
|
||||
pointLight(P, N, V, roughness, f0, diffuse, specular);
|
||||
|
||||
#endif // _POINTLIGHT_HF_
|
||||
@@ -1,87 +0,0 @@
|
||||
#ifndef _SPOTLIGHT_HF_
|
||||
#define _SPOTLIGHT_HF_
|
||||
|
||||
//Texture2D<float> xTextureSh:register(t4);
|
||||
|
||||
|
||||
CBUFFER(SpotLightCB, CBSLOT_RENDERER_SPOTLIGHT)
|
||||
{
|
||||
float4x4 xLightWorld;
|
||||
float4 xLightDir;
|
||||
float4 xLightColor;
|
||||
float4 xLightEnerDisCone;
|
||||
float4 xBiasResSoftshadow;
|
||||
float4x4 xShMat;
|
||||
};
|
||||
|
||||
inline float offset_lookup(Texture2D<float> intex, SamplerComparisonState map,
|
||||
float2 loc,
|
||||
float2 offset,
|
||||
float scale,
|
||||
float realDistance)
|
||||
{
|
||||
float BiasedDistance = realDistance - xBiasResSoftshadow.x;
|
||||
|
||||
return intex.SampleCmpLevelZero( map, loc + offset / scale, BiasedDistance).r;
|
||||
}
|
||||
inline float shadowCascade(float4 shadowPos, float2 ShTex, Texture2D<float> shadowTexture){
|
||||
float realDistance = shadowPos.z/shadowPos.w;
|
||||
float sum = 0;
|
||||
float scale = xBiasResSoftshadow.y;
|
||||
float retVal = 1;
|
||||
retVal *= offset_lookup(shadowTexture, sampler_cmp_depth, ShTex, float2(0, 0), scale, realDistance);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline void spotLight(in float3 P, in float3 N, in float3 V, in float roughness, in float3 f0,
|
||||
out float3 diffuse, out float3 specular)
|
||||
{
|
||||
float3 lightPos = float3( xLightWorld._41, xLightWorld._42, xLightWorld._43 );
|
||||
diffuse = 0;
|
||||
specular = 0;
|
||||
|
||||
float3 L = normalize(lightPos - P);
|
||||
|
||||
float SpotFactor = dot(L, xLightDir.xyz);
|
||||
|
||||
float spotCutOff = xLightEnerDisCone.z;
|
||||
|
||||
[branch]if (SpotFactor > spotCutOff){
|
||||
|
||||
BRDF_MAKE(N, L, V);
|
||||
specular = xLightColor.rgb * BRDF_SPECULAR(roughness, f0);
|
||||
diffuse = xLightColor.rgb * BRDF_DIFFUSE(roughness);
|
||||
diffuse *= xLightEnerDisCone.x;
|
||||
specular *= xLightEnerDisCone.x;
|
||||
//color.rgb = max(dot(normalize(xLightDir.xyz), normalize(N)), 0)*xLightEnerDisCone.x;
|
||||
|
||||
float sh = max(NdotL, 0);
|
||||
float4 ShPos = mul(float4(P,1),xShMat);
|
||||
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))
|
||||
{
|
||||
//light.r+=1.0f;
|
||||
sh *= shadowCascade(ShPos,ShTex,texture_shadow0);
|
||||
}
|
||||
diffuse *= sh;
|
||||
specular *= sh;
|
||||
|
||||
|
||||
float attenuation=saturate( (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - spotCutOff)) );
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
}
|
||||
|
||||
diffuse = max(diffuse, 0);
|
||||
specular = max(specular, 0);
|
||||
|
||||
}
|
||||
|
||||
// MACROS
|
||||
|
||||
#define DEFERRED_SPOTLIGHT_MAIN \
|
||||
spotLight(P, N, V, roughness, f0, diffuse, specular);
|
||||
|
||||
#endif // _SPOTLIGHT_HF_
|
||||
@@ -790,6 +790,7 @@ struct Light : public Cullable , public Transform
|
||||
DIRECTIONAL,
|
||||
POINT,
|
||||
SPOT,
|
||||
LIGHTTYPE_COUNT,
|
||||
};
|
||||
LightType type;
|
||||
|
||||
|
||||
+213
-274
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ namespace wiVersion
|
||||
// minor features, major updates
|
||||
const int minor = 9;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 6;
|
||||
const int revision = 7;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user