diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj b/WickedEngine/WickedEngine_SHADERS.vcxproj
index 92ff70ac5..cb08365e0 100644
--- a/WickedEngine/WickedEngine_SHADERS.vcxproj
+++ b/WickedEngine/WickedEngine_SHADERS.vcxproj
@@ -1039,9 +1039,6 @@
Vertex
-
- Vertex
-
{8C15DC72-70C8-4212-B046-0B166A688A7C}
diff --git a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
index e6e1bc874..5138c08c3 100644
--- a/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
+++ b/WickedEngine/WickedEngine_SHADERS.vcxproj.filters
@@ -153,9 +153,6 @@
PS
-
- VS
-
VS
diff --git a/WickedEngine/generateMIPChain2D_float4_SimpleFilterCS.hlsl b/WickedEngine/generateMIPChain2D_float4_SimpleFilterCS.hlsl
index cddca16d2..d946ae988 100644
--- a/WickedEngine/generateMIPChain2D_float4_SimpleFilterCS.hlsl
+++ b/WickedEngine/generateMIPChain2D_float4_SimpleFilterCS.hlsl
@@ -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)));
}
diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli
index 512c83b73..04f117c95 100644
--- a/WickedEngine/globals.hlsli
+++ b/WickedEngine/globals.hlsli
@@ -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
diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli
index e44003637..8e2972981 100644
--- a/WickedEngine/lightingHF.hlsli
+++ b/WickedEngine/lightingHF.hlsli
@@ -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)= 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;
diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli
index c2f958d81..0d35599ae 100644
--- a/WickedEngine/objectHF.hlsli
+++ b/WickedEngine/objectHF.hlsli
@@ -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)
diff --git a/WickedEngine/raytracingHF.hlsli b/WickedEngine/raytracingHF.hlsli
index d2d0c68a6..c6efbe627 100644
--- a/WickedEngine/raytracingHF.hlsli
+++ b/WickedEngine/raytracingHF.hlsli
@@ -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;
diff --git a/WickedEngine/skyHF.hlsli b/WickedEngine/skyHF.hlsli
index 97ce45e1b..c689ab428 100644
--- a/WickedEngine/skyHF.hlsli
+++ b/WickedEngine/skyHF.hlsli
@@ -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;
diff --git a/WickedEngine/waterVS.hlsl b/WickedEngine/waterVS.hlsl
deleted file mode 100644
index 747e270c9..000000000
--- a/WickedEngine/waterVS.hlsl
+++ /dev/null
@@ -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;
-}
\ No newline at end of file
diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h
index 0451e0d12..78e492cc9 100644
--- a/WickedEngine/wiEnums.h
+++ b/WickedEngine/wiEnums.h
@@ -119,7 +119,6 @@ enum VSTYPES
VSTYPE_IMPOSTOR,
VSTYPE_VERTEXCOLOR,
VSTYPE_TRAIL,
- VSTYPE_WATER,
VSTYPE_DIRLIGHT,
VSTYPE_POINTLIGHT,
VSTYPE_SPOTLIGHT,
diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp
index 98d4be386..493c7e1c9 100644
--- a/WickedEngine/wiRenderer.cpp
+++ b/WickedEngine/wiRenderer.cpp
@@ -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);
}
diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp
index eac60ae18..7408f2023 100644
--- a/WickedEngine/wiVersion.cpp
+++ b/WickedEngine/wiVersion.cpp
@@ -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()