indirect lighting updates
This commit is contained in:
@@ -1039,9 +1039,6 @@
|
||||
<FxCompile Include="vTubeLightVS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="waterVS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8C15DC72-70C8-4212-B046-0B166A688A7C}</ProjectGuid>
|
||||
|
||||
@@ -153,9 +153,6 @@
|
||||
<FxCompile Include="trailPS.hlsl">
|
||||
<Filter>PS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="waterVS.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="decalVS.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
|
||||
@@ -22,9 +22,9 @@ void main(uint3 DTid : SV_DispatchThreadID)
|
||||
if (mipgen_options & MIPGEN_OPTION_BIT_PRESERVE_COVERAGE)
|
||||
{
|
||||
float4 alphas = input.GatherAlpha(customsampler, uv, 0);
|
||||
alphas = pow(alphas, 2.2f);
|
||||
alphas = pow(saturate(alphas), 2.2f);
|
||||
float alpha = (alphas.x + alphas.y + alphas.z + alphas.w) / 4.0f;
|
||||
alpha = pow(alpha, 1.0f / 2.2f);
|
||||
alpha = pow(saturate(alpha), 1.0f / 2.2f);
|
||||
color.a = alpha;
|
||||
//color.a = max(alphas.x, max(alphas.y, max(alphas.z, alphas.w)));
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ inline float3 GetSunDirection() { return g_xFrame_SunDirection; }
|
||||
inline float3 GetHorizonColor() { return g_xFrame_Horizon.rgb; }
|
||||
inline float3 GetZenithColor() { return g_xFrame_Zenith.rgb; }
|
||||
inline float3 GetAmbientColor() { return g_xFrame_Ambient.rgb; }
|
||||
inline float3 GetAmbient(in float3 N) { return lerp(GetHorizonColor(), GetZenithColor(), saturate(N.y * 0.5f + 0.5f)) + GetAmbientColor(); }
|
||||
inline float2 GetScreenResolution() { return g_xFrame_ScreenWidthHeight; }
|
||||
inline float GetScreenWidth() { return g_xFrame_ScreenWidthHeight.x; }
|
||||
inline float GetScreenHeight() { return g_xFrame_ScreenWidthHeight.y; }
|
||||
@@ -561,4 +560,66 @@ inline float dither(in float2 pixel)
|
||||
return ditherMask8(pixel);
|
||||
}
|
||||
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// center : sphere center
|
||||
// radius : sphere radius
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_sphere(float3 o, float3 d, float3 center, float radius)
|
||||
{
|
||||
float3 rc = o - center;
|
||||
float c = dot(rc, rc) - (radius * radius);
|
||||
float b = dot(d, rc);
|
||||
float dd = b * b - c;
|
||||
float t = -b - sqrt(abs(dd));
|
||||
float st = step(0.0, min(t, dd));
|
||||
return lerp(-1.0, t, st);
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_plane(float3 o, float3 d, float3 planeOrigin, float3 planeNormal)
|
||||
{
|
||||
return dot(planeNormal, (planeOrigin - o) / dot(planeNormal, d));
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// A,B,C : traingle corners
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_triangle(float3 o, float3 d, float3 A, float3 B, float3 C)
|
||||
{
|
||||
float3 planeNormal = normalize(cross(B - A, C - B));
|
||||
float t = Trace_plane(o, d, A, planeNormal);
|
||||
float3 p = o + d * t;
|
||||
|
||||
float3 N1 = normalize(cross(B - A, p - B));
|
||||
float3 N2 = normalize(cross(C - B, p - C));
|
||||
float3 N3 = normalize(cross(A - C, p - A));
|
||||
|
||||
float d0 = dot(N1, N2);
|
||||
float d1 = dot(N2, N3);
|
||||
|
||||
float threshold = 1.0f - 0.001f;
|
||||
return (d0 > threshold && d1 > threshold) ? 1.0f : 0.0f;
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// A,B,C,D : rectangle corners
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_rectangle(float3 o, float3 d, float3 A, float3 B, float3 C, float3 D)
|
||||
{
|
||||
return max(Trace_triangle(o, d, A, B, C), Trace_triangle(o, d, C, D, A));
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// diskNormal : disk facing direction
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_disk(float3 o, float3 d, float3 diskCenter, float diskRadius, float3 diskNormal)
|
||||
{
|
||||
float t = Trace_plane(o, d, diskCenter, diskNormal);
|
||||
float3 p = o + d * t;
|
||||
float3 diff = p - diskCenter;
|
||||
return dot(diff, diff) < sqr(diskRadius);
|
||||
}
|
||||
|
||||
#endif // WI_SHADER_GLOBALS_HF
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "globals.hlsli"
|
||||
#include "brdf.hlsli"
|
||||
#include "voxelConeTracingHF.hlsli"
|
||||
#include "skyHF.hlsli"
|
||||
|
||||
struct LightingContribution
|
||||
{
|
||||
@@ -319,68 +320,6 @@ float RectangleSolidAngle(float3 worldPos,
|
||||
}
|
||||
|
||||
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// center : sphere center
|
||||
// radius : sphere radius
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_sphere(float3 o, float3 d, float3 center, float radius)
|
||||
{
|
||||
float3 rc = o - center;
|
||||
float c = dot(rc, rc) - (radius*radius);
|
||||
float b = dot(d, rc);
|
||||
float dd = b*b - c;
|
||||
float t = -b - sqrt(abs(dd));
|
||||
float st = step(0.0, min(t, dd));
|
||||
return lerp(-1.0, t, st);
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_plane(float3 o, float3 d, float3 planeOrigin, float3 planeNormal)
|
||||
{
|
||||
return dot(planeNormal, (planeOrigin - o) / dot(planeNormal, d));
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// A,B,C : traingle corners
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_triangle(float3 o, float3 d, float3 A, float3 B, float3 C)
|
||||
{
|
||||
float3 planeNormal = normalize(cross(B - A, C - B));
|
||||
float t = Trace_plane(o, d, A, planeNormal);
|
||||
float3 p = o + d*t;
|
||||
|
||||
float3 N1 = normalize(cross(B - A, p - B));
|
||||
float3 N2 = normalize(cross(C - B, p - C));
|
||||
float3 N3 = normalize(cross(A - C, p - A));
|
||||
|
||||
float d0 = dot(N1, N2);
|
||||
float d1 = dot(N2, N3);
|
||||
|
||||
float threshold = 1.0f - 0.001f;
|
||||
return (d0 > threshold && d1 > threshold) ? 1.0f : 0.0f;
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// A,B,C,D : rectangle corners
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_rectangle(float3 o, float3 d, float3 A, float3 B, float3 C, float3 D)
|
||||
{
|
||||
return max(Trace_triangle(o, d, A, B, C), Trace_triangle(o, d, C, D, A));
|
||||
}
|
||||
// o : ray origin
|
||||
// d : ray direction
|
||||
// diskNormal : disk facing direction
|
||||
// returns distance on the ray to the object if hit, 0 otherwise
|
||||
float Trace_disk(float3 o, float3 d, float3 diskCenter, float diskRadius, float3 diskNormal)
|
||||
{
|
||||
float t = Trace_plane(o, d, diskCenter, diskNormal);
|
||||
float3 p = o + d*t;
|
||||
float3 diff = p - diskCenter;
|
||||
return dot(diff, diff)<sqr(diskRadius);
|
||||
}
|
||||
|
||||
inline float3 getDiffuseDominantDir(float3 N, float3 V, float NdotV, float roughness)
|
||||
{
|
||||
float a = 1.02341f * roughness - 1.51174f;
|
||||
@@ -784,6 +723,25 @@ inline LightingContribution VoxelGI(in Surface surface, inout Lighting lighting)
|
||||
// ENVIRONMENT MAPS
|
||||
|
||||
|
||||
inline float3 GetAmbient(in float3 N)
|
||||
{
|
||||
float3 ambient;
|
||||
|
||||
#ifndef ENVMAPRENDERING
|
||||
[branch]
|
||||
if (g_xFrame_GlobalEnvProbeIndex >= 0)
|
||||
{
|
||||
ambient = texture_envmaparray.SampleLevel(sampler_linear_clamp, float4(N, g_xFrame_GlobalEnvProbeIndex), g_xFrame_EnvProbeMipCount).rgb;
|
||||
}
|
||||
else
|
||||
#endif // ENVMAPRENDERING
|
||||
{
|
||||
ambient = lerp(GetHorizonColor(), GetZenithColor(), saturate(N.y * 0.5f + 0.5f)) + GetAmbientColor();
|
||||
}
|
||||
|
||||
return ambient;
|
||||
}
|
||||
|
||||
// surface: surface descriptor
|
||||
// MIP: mip level to sample
|
||||
// return: color of the environment color (rgb)
|
||||
@@ -802,10 +760,9 @@ inline float3 EnvironmentReflection_Global(in Surface surface, in float MIP)
|
||||
#endif // ENVMAPRENDERING
|
||||
{
|
||||
// There are no envmaps, approximate sky color:
|
||||
float3 realSkyColor = lerp(GetHorizonColor(), GetZenithColor(), pow(saturate(surface.R.y), 0.25f));
|
||||
float3 roughSkyColor = (GetHorizonColor() + GetZenithColor()) * 0.5f;
|
||||
float blendSkyByRoughness = saturate(MIP * g_xFrame_EnvProbeMipCount_rcp);
|
||||
envColor = lerp(realSkyColor, roughSkyColor, blendSkyByRoughness);
|
||||
float3 realSkyColor = GetDynamicSkyColor(surface.R, false, false, false); // false: disable sun disk and clouds
|
||||
float3 roughSkyColor = lerp(GetHorizonColor(), GetZenithColor(), saturate(surface.R.y * 0.5f + 0.5f));
|
||||
envColor = lerp(realSkyColor, roughSkyColor, saturate(surface.roughness));
|
||||
}
|
||||
|
||||
return envColor;
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
#define DISABLE_TRANSPARENT_SHADOWMAP
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PLANARREFLECTION
|
||||
#define DISABLE_ENVMAPS
|
||||
#define DISABLE_VOXELGI
|
||||
#endif
|
||||
|
||||
#ifdef WATER
|
||||
#define DISABLE_VOXELGI
|
||||
#endif
|
||||
|
||||
|
||||
@@ -702,11 +706,6 @@ inline void ApplyFog(in float dist, inout float4 color)
|
||||
#define PIXELINPUT PixelInputType
|
||||
#endif // SIMPLE_INPUT
|
||||
|
||||
#ifdef PLANARREFLECTION
|
||||
#define DISABLE_ENVMAPS
|
||||
#define DISABLE_VOXELGI
|
||||
#endif // PLANARREFLECTION
|
||||
|
||||
|
||||
// entry point:
|
||||
#if defined(ALPHATESTONLY)
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
#include "globals.hlsli"
|
||||
#include "ShaderInterop_Raytracing.h"
|
||||
#include "ShaderInterop_BVH.h"
|
||||
|
||||
#define NOSUN
|
||||
#include "skyHF.hlsli"
|
||||
#include "lightingHF.hlsli"
|
||||
|
||||
|
||||
static const float INFINITE_RAYHIT = 1000000;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef WI_SKY_HF
|
||||
#define WI_SKY_HF
|
||||
#include "globals.hlsli"
|
||||
#include "lightingHF.hlsli"
|
||||
|
||||
// Atmosphere based on: https://www.shadertoy.com/view/Ml2cWG
|
||||
// Cloud noise based on: https://www.shadertoy.com/view/4tdSWr
|
||||
@@ -32,7 +31,8 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab
|
||||
const float3 skyColor = GetZenithColor();
|
||||
const float3 sunDirection = GetSunDirection();
|
||||
const float3 sunColor = GetSunColor();
|
||||
sun_enabled = sun_enabled && any(sunColor);
|
||||
const bool sun_present = any(sunColor);
|
||||
sun_enabled = sun_enabled && sun_present;
|
||||
|
||||
const float zenith = V.y; // how much is above (0: horizon, 1: directly above)
|
||||
const float sunScatter = saturate(sunDirection.y + 0.1f); // how much the sun is directly above. Even if sunis at horizon, we add a constant scattering amount so that light still scatters at horizon
|
||||
@@ -43,10 +43,10 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab
|
||||
|
||||
const float3 aberration = float3(0.39, 0.57, 1.0); // the chromatic aberration effect on the horizon-zenith fade line
|
||||
const float3 skyAbsorption = saturate(exp2(aberration * -zenithDensity) * 2.0f); // gradient on horizon
|
||||
const float3 sunAbsorption = sun_enabled ? saturate(sunColor * exp2(aberration * -sunScatterDensity) * 2.0f) : 1; // gradient of sun when it's getting below horizon
|
||||
const float3 sunAbsorption = sun_present ? saturate(sunColor * exp2(aberration * -sunScatterDensity) * 2.0f) : 1; // gradient of sun when it's getting below horizon
|
||||
|
||||
const float sunAmount = distance(V, sunDirection); // sun falloff descreasing from mid point
|
||||
const float rayleigh = sun_enabled ? 1.0 + pow(1.0 - saturate(sunAmount), 2.0) * PI * 0.5 : 1;
|
||||
const float rayleigh = sun_present ? 1.0 + pow(1.0 - saturate(sunAmount), 2.0) * PI * 0.5 : 1;
|
||||
const float mie_disk = saturate(1.0 - pow(sunAmount, 0.1));
|
||||
const float3 mie = mie_disk * mie_disk*(3.0 - 2.0 * mie_disk) * 2.0 * PI * sunAbsorption;
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "objectHF.hlsli"
|
||||
|
||||
PixelInputType main(Input_Object_POS_TEX input)
|
||||
{
|
||||
PixelInputType Out;
|
||||
|
||||
float4x4 WORLD = MakeWorldMatrixFromInstance(input.inst);
|
||||
VertexSurface surface = MakeVertexSurfaceFromInput(input);
|
||||
|
||||
surface.position = mul(WORLD, surface.position);
|
||||
surface.normal = normalize(mul((float3x3)WORLD, surface.normal));
|
||||
|
||||
Out.clip = 0;
|
||||
|
||||
Out.pos = Out.pos2D = mul(g_xCamera_VP, surface.position);
|
||||
Out.pos2DPrev = Out.pos2D; // no need for water
|
||||
Out.pos3D = surface.position.xyz;
|
||||
Out.color = surface.color;
|
||||
Out.uvsets = surface.uvsets;
|
||||
Out.atl = 0;
|
||||
Out.nor = surface.normal;
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -119,7 +119,6 @@ enum VSTYPES
|
||||
VSTYPE_IMPOSTOR,
|
||||
VSTYPE_VERTEXCOLOR,
|
||||
VSTYPE_TRAIL,
|
||||
VSTYPE_WATER,
|
||||
VSTYPE_DIRLIGHT,
|
||||
VSTYPE_POINTLIGHT,
|
||||
VSTYPE_SPOTLIGHT,
|
||||
|
||||
+13
-10
@@ -1193,7 +1193,6 @@ void LoadShaders()
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER], "cubeShadowVS.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST], "cubeShadowVS_alphatest.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_SKY], "skyVS.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_WATER], "waterVS.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_VOXELIZER], "objectVS_voxelizer.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_VOXEL], "voxelVS.cso"); });
|
||||
wiJobSystem::Execute(ctx, [] { LoadShader(VS, vertexShaders[VSTYPE_FORCEFIELDVISUALIZER_POINT], "forceFieldPointVisualizerVS.cso"); });
|
||||
@@ -1631,11 +1630,11 @@ void LoadShaders()
|
||||
|
||||
wiJobSystem::Execute(ctx, [device] {
|
||||
PipelineStateDesc desc;
|
||||
desc.vs = &vertexShaders[VSTYPE_WATER];
|
||||
desc.vs = &vertexShaders[VSTYPE_OBJECT_COMMON];
|
||||
desc.rs = &rasterizers[RSTYPE_DOUBLESIDED];
|
||||
desc.bs = &blendStates[BSTYPE_TRANSPARENT];
|
||||
desc.dss = &depthStencils[DSSTYPE_DEFAULT];
|
||||
desc.il = &inputLayouts[ILTYPE_OBJECT_POS_TEX];
|
||||
desc.il = &inputLayouts[ILTYPE_OBJECT_ALL];
|
||||
|
||||
desc.ps = &pixelShaders[PSTYPE_OBJECT_FORWARD_WATER];
|
||||
device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_FORWARD]);
|
||||
@@ -1650,6 +1649,14 @@ void LoadShaders()
|
||||
desc.ps = &pixelShaders[PSTYPE_SHADOW_WATER];
|
||||
|
||||
device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_SHADOW]);
|
||||
|
||||
desc.dss = &depthStencils[DSSTYPE_DEFAULT];
|
||||
desc.rs = &rasterizers[RSTYPE_DOUBLESIDED];
|
||||
desc.bs = &blendStates[BSTYPE_OPAQUE];
|
||||
desc.il = &inputLayouts[GetILTYPE(RENDERPASS_ENVMAPCAPTURE, false, false, true)];
|
||||
desc.vs = &vertexShaders[GetVSTYPE(RENDERPASS_ENVMAPCAPTURE, false, false, true)];
|
||||
desc.ps = &pixelShaders[GetPSTYPE(RENDERPASS_ENVMAPCAPTURE, false, true, false, false, false)];
|
||||
device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_ENVMAPCAPTURE]);
|
||||
});
|
||||
wiJobSystem::Execute(ctx, [device] {
|
||||
PipelineStateDesc desc;
|
||||
@@ -3251,7 +3258,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, uint32_
|
||||
}
|
||||
}
|
||||
|
||||
if (pso == nullptr)
|
||||
if (pso == nullptr || !pso->IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -3306,11 +3313,6 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, uint32_
|
||||
}
|
||||
}
|
||||
|
||||
if (material.IsWater())
|
||||
{
|
||||
boundVBType = BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD;
|
||||
}
|
||||
|
||||
if (IsWireRender())
|
||||
{
|
||||
boundVBType = BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD;
|
||||
@@ -6743,8 +6745,9 @@ void RefreshEnvProbes(CommandList cmd)
|
||||
if (!renderQueue.empty())
|
||||
{
|
||||
BindShadowmaps(PS, cmd);
|
||||
device->BindResource(PS, GetGlobalLightmap(), TEXSLOT_GLOBALLIGHTMAP, cmd);
|
||||
|
||||
RenderMeshes(renderQueue, RENDERPASS_ENVMAPCAPTURE, RENDERTYPE_OPAQUE | RENDERTYPE_TRANSPARENT, cmd, false, cameras);
|
||||
RenderMeshes(renderQueue, RENDERPASS_ENVMAPCAPTURE, RENDERTYPE_ALL, cmd, false, cameras);
|
||||
|
||||
GetRenderFrameAllocator(cmd).free(sizeof(RenderBatch) * renderQueue.batchCount);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates
|
||||
const int minor = 39;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 58;
|
||||
const int revision = 59;
|
||||
|
||||
|
||||
long GetVersion()
|
||||
|
||||
Reference in New Issue
Block a user