diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index a148bc89b..99653a442 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -19,7 +19,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); materialWindow = new wiWindow(GUI, "Material Window"); - materialWindow->SetSize(XMFLOAT2(760, 860)); + materialWindow->SetSize(XMFLOAT2(760, 890)); materialWindow->SetEnabled(false); GUI->AddWidget(materialWindow); @@ -98,6 +98,26 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) }); materialWindow->AddWidget(specularGlossinessCheckBox); + occlusionPrimaryCheckBox = new wiCheckBox("Occlusion - Primary: "); + occlusionPrimaryCheckBox->SetTooltip("If enabled, surface map's RED channel will be used as occlusion map"); + occlusionPrimaryCheckBox->SetPos(XMFLOAT2(670, y += step)); + occlusionPrimaryCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetOcclusionEnabled_Primary(args.bValue); + }); + materialWindow->AddWidget(occlusionPrimaryCheckBox); + + occlusionSecondaryCheckBox = new wiCheckBox("Occlusion - Secondary: "); + occlusionSecondaryCheckBox->SetTooltip("If enabled, occlusion map's RED channel will be used as occlusion map"); + occlusionSecondaryCheckBox->SetPos(XMFLOAT2(670, y += step)); + occlusionSecondaryCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetOcclusionEnabled_Secondary(args.bValue); + }); + materialWindow->AddWidget(occlusionSecondaryCheckBox); + step = 35; @@ -821,6 +841,8 @@ void MaterialWindow::SetEntity(Entity entity) flipNormalMapCheckBox->SetCheck(material->IsFlipNormalMap()); useVertexColorsCheckBox->SetCheck(material->IsUsingVertexColors()); specularGlossinessCheckBox->SetCheck(material->IsUsingSpecularGlossinessWorkflow()); + occlusionPrimaryCheckBox->SetCheck(material->IsOcclusionEnabled_Primary()); + occlusionSecondaryCheckBox->SetCheck(material->IsOcclusionEnabled_Secondary()); normalMapSlider->SetValue(material->normalMapStrength); roughnessSlider->SetValue(material->roughness); reflectanceSlider->SetValue(material->reflectance); diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index 5c7ab1fdd..ef2146b0c 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -29,6 +29,8 @@ public: wiCheckBox* flipNormalMapCheckBox; wiCheckBox* useVertexColorsCheckBox; wiCheckBox* specularGlossinessCheckBox; + wiCheckBox* occlusionPrimaryCheckBox; + wiCheckBox* occlusionSecondaryCheckBox; wiSlider* normalMapSlider; wiSlider* roughnessSlider; wiSlider* reflectanceSlider; diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 08cc119a8..87754b475 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -374,6 +374,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) RegisterTexture2D(&img, "occlusion"); material.occlusionMapName = img.uri; material.uvset_occlusionMap = occlusionTexture->second.TextureTexCoord(); + material.SetOcclusionEnabled_Secondary(true); } if (baseColorFactor != x.values.end()) diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index 648de7dd8..c610c2599 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -350,7 +350,7 @@ void RenderPath3D::RenderSSAO(GRAPHICSTHREAD threadID) const GraphicsDevice* device = wiRenderer::GetDevice(); wiImageParams fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - device->UnbindResources(TEXSLOT_RENDERABLECOMPONENT_SSAO, 1, threadID); + device->UnbindResources(TEXSLOT_RENDERPATH_SSAO, 1, threadID); device->EventBegin("SSAO", threadID); fx.stencilRef = STENCILREF_DEFAULT; fx.stencilComp = STENCILMODE_LESS; @@ -409,7 +409,7 @@ void RenderPath3D::RenderSSR(const Texture2D& srcSceneRT, GRAPHICSTHREAD threadI GraphicsDevice* device = wiRenderer::GetDevice(); wiImageParams fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - device->UnbindResources(TEXSLOT_RENDERABLECOMPONENT_SSR, 1, threadID); + device->UnbindResources(TEXSLOT_RENDERPATH_SSR, 1, threadID); device->EventBegin("SSR", threadID); { const Texture2D* rts[] = { &rtSSR }; @@ -647,9 +647,9 @@ void RenderPath3D::RenderTransparents(const Texture2D& dstSceneRT, RENDERPASS re { wiProfiler::BeginRange("Transparent Scene", wiProfiler::DOMAIN_GPU, threadID); - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - device->BindResource(PS, &rtSceneCopy, TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID); - device->BindResource(PS, &rtWaterRipple, TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID); + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID); + device->BindResource(PS, &rtSceneCopy, TEXSLOT_RENDERPATH_REFRACTION, threadID); + device->BindResource(PS, &rtWaterRipple, TEXSLOT_RENDERPATH_WATERRIPPLES, threadID); wiRenderer::DrawScene_Transparent(wiRenderer::GetCamera(), renderPass, threadID, getHairParticlesEnabled(), true, getLayerMask()); wiProfiler::EndRange(threadID); // Transparent Scene diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp index c09737b92..773d044cf 100644 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ b/WickedEngine/RenderPath3D_Deferred.cpp @@ -104,8 +104,8 @@ void RenderPath3D_Deferred::Render() const vp.Height = (float)rts[0]->GetDesc().Height; device->BindViewports(1, &vp, threadID); - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID); + device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); wiProfiler::EndRange(threadID); // Opaque Scene @@ -137,8 +137,8 @@ void RenderPath3D_Deferred::Render() const vp.Height = (float)rts[0]->GetDesc().Height; device->BindViewports(1, &vp, threadID); - device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); + device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, threadID); wiRenderer::DrawLights(wiRenderer::GetCamera(), threadID); } diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp index c9c69cad2..851154942 100644 --- a/WickedEngine/RenderPath3D_Forward.cpp +++ b/WickedEngine/RenderPath3D_Forward.cpp @@ -87,9 +87,9 @@ void RenderPath3D_Forward::Render() const vp.Height = (float)rts[0]->GetDesc().Height; device->BindViewports(1, &vp, threadID); - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID); + device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); + device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, threadID); wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_FORWARD, getHairParticlesEnabled(), true, getLayerMask()); wiRenderer::DrawSky(threadID); diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp index 696fcc0c7..22209c5b9 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred.cpp @@ -44,8 +44,8 @@ void RenderPath3D_TiledDeferred::Render() const vp.Height = (float)rts[0]->GetDesc().Height; device->BindViewports(1, &vp, threadID); - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID); + device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_DEFERRED, getHairParticlesEnabled(), true, getLayerMask()); wiProfiler::EndRange(threadID); // Opaque Scene @@ -65,8 +65,8 @@ void RenderPath3D_TiledDeferred::Render() const wiRenderer::BindGBufferTextures(&rtGBuffer[0], &rtGBuffer[1], &rtGBuffer[2], threadID); - device->BindResource(CS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - device->BindResource(CS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + device->BindResource(CS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); + device->BindResource(CS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, threadID); wiRenderer::ComputeTiledLightCulling(threadID, &lightbuffer_diffuse, &lightbuffer_specular); diff --git a/WickedEngine/RenderPath3D_TiledForward.cpp b/WickedEngine/RenderPath3D_TiledForward.cpp index aaf887407..9533794c2 100644 --- a/WickedEngine/RenderPath3D_TiledForward.cpp +++ b/WickedEngine/RenderPath3D_TiledForward.cpp @@ -87,9 +87,9 @@ void RenderPath3D_TiledForward::Render() const vp.Height = (float)rts[0]->GetDesc().Height; device->BindViewports(1, &vp, threadID); - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID); - device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID); - device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, threadID); + device->BindResource(PS, getSSAOEnabled() ? &rtSSAO[0] : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_SSAO, threadID); + device->BindResource(PS, getSSREnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, threadID); wiRenderer::DrawScene(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, RENDERPASS_TILEDFORWARD, true, true); wiRenderer::DrawSky(threadID); diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 720eca882..27d7e94f8 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -72,11 +72,11 @@ // RenderPath texture mappings: -#define TEXSLOT_RENDERABLECOMPONENT_REFLECTION TEXSLOT_ONDEMAND6 -#define TEXSLOT_RENDERABLECOMPONENT_REFRACTION TEXSLOT_ONDEMAND7 -#define TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES TEXSLOT_ONDEMAND8 -#define TEXSLOT_RENDERABLECOMPONENT_SSAO TEXSLOT_ONDEMAND8 -#define TEXSLOT_RENDERABLECOMPONENT_SSR TEXSLOT_ONDEMAND9 +#define TEXSLOT_RENDERPATH_REFLECTION TEXSLOT_ONDEMAND6 +#define TEXSLOT_RENDERPATH_REFRACTION TEXSLOT_ONDEMAND7 +#define TEXSLOT_RENDERPATH_WATERRIPPLES TEXSLOT_ONDEMAND8 +#define TEXSLOT_RENDERPATH_SSAO TEXSLOT_ONDEMAND8 +#define TEXSLOT_RENDERPATH_SSR TEXSLOT_ONDEMAND9 #endif // _RESOURCEBUFFER_MAPPING_H_ diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index 71499eecc..08132b95f 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -262,7 +262,9 @@ CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL) uint g_xMat_uvset_occlusionMap; uint g_xMat_specularGlossinessWorkflow; - uint3 g_xMat_padding; + uint g_xMat_occlusion_primary; + uint g_xMat_occlusion_secondary; + uint g_xMat_padding; }; CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) diff --git a/WickedEngine/ShaderInterop_TracedRendering.h b/WickedEngine/ShaderInterop_TracedRendering.h index 125db5286..85f7ae6fc 100644 --- a/WickedEngine/ShaderInterop_TracedRendering.h +++ b/WickedEngine/ShaderInterop_TracedRendering.h @@ -52,7 +52,9 @@ struct TracedRenderingMaterial uint uvset_occlusionMap; uint specularGlossinessWorkflow; - uint3 padding; + uint occlusion_primary; + uint occlusion_secondary; + uint padding; float4 baseColorAtlasMulAdd; float4 surfaceMapAtlasMulAdd; diff --git a/WickedEngine/brdf.hlsli b/WickedEngine/brdf.hlsli index af609559c..21f01d4d8 100644 --- a/WickedEngine/brdf.hlsli +++ b/WickedEngine/brdf.hlsli @@ -79,7 +79,7 @@ struct Surface float3 N; // world space normal float3 V; // world space view vector float4 baseColor; // base color [0 -> 1] (rgba) - float ao; // ambient occlusion [0 -> 1] + float occlusion; // occlusion [0 -> 1] float roughness; // roughness: [0:smooth -> 1:rough] (linear) float metalness; // metalness [0:dielectric -> 1:metal] float reflectance; // reflectivity [0:diffuse -> 1:specular] @@ -104,7 +104,7 @@ struct Surface R = -reflect(V, N); float f90 = saturate(50.0 * dot(f0, 0.33)); - F = F_Schlick(f0, f90, NdotV); + F = F_Schlick(f0, f90, NdotV) * occlusion; } }; inline Surface CreateSurface( @@ -112,7 +112,7 @@ inline Surface CreateSurface( in float3 N, in float3 V, in float4 baseColor, - in float ao, + in float occlusion, in float roughness, in float metalness, in float reflectance, @@ -125,7 +125,7 @@ inline Surface CreateSurface( surface.N = N; surface.V = V; surface.baseColor = baseColor; - surface.ao = ao; + surface.occlusion = occlusion; surface.roughness = roughness; surface.metalness = metalness; surface.reflectance = reflectance; diff --git a/WickedEngine/captureImpostorPS_surface.hlsl b/WickedEngine/captureImpostorPS_surface.hlsl index 6bf8fccdb..1b9338654 100644 --- a/WickedEngine/captureImpostorPS_surface.hlsl +++ b/WickedEngine/captureImpostorPS_surface.hlsl @@ -3,18 +3,18 @@ float4 main(PixelInputType input) : SV_Target0 { const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; - float4 surface_ao_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap); + float4 surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap); if (g_xMat_specularGlossinessWorkflow) { - ConvertToSpecularGlossiness(surface_ao_roughness_metallic_reflectance); + ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance); } float4 surface; - surface.r = surface_ao_roughness_metallic_reflectance.r; - surface.g = g_xMat_roughness * surface_ao_roughness_metallic_reflectance.g; - surface.b = g_xMat_metalness * surface_ao_roughness_metallic_reflectance.b; - surface.a = g_xMat_reflectance * surface_ao_roughness_metallic_reflectance.a; + surface.r = surface_occlusion_roughness_metallic_reflectance.r; + surface.g = g_xMat_roughness * surface_occlusion_roughness_metallic_reflectance.g; + surface.b = g_xMat_metalness * surface_occlusion_roughness_metallic_reflectance.b; + surface.a = g_xMat_reflectance * surface_occlusion_roughness_metallic_reflectance.a; return surface; } diff --git a/WickedEngine/deferredLightHF.hlsli b/WickedEngine/deferredLightHF.hlsli index 5953140ee..f1ebd3f7d 100644 --- a/WickedEngine/deferredLightHF.hlsli +++ b/WickedEngine/deferredLightHF.hlsli @@ -25,6 +25,8 @@ struct LightOutputType #define DEFERREDLIGHT_MAKEPARAMS \ ShaderEntityType light = EntityArray[(uint)g_xColor.x]; \ float3 diffuse, specular; \ + float diffuse_alpha = 1; \ + float specular_alpha = 1; \ float2 ScreenCoord = PSIn.pos2D.xy / PSIn.pos2D.w * float2(0.5f, -0.5f) + 0.5f; \ float depth = texture_depth[PSIn.pos.xy]; \ float4 g0 = texture_gbuffer0[PSIn.pos.xy]; \ @@ -76,8 +78,8 @@ struct LightOutputType #define DEFERREDLIGHT_RETURN \ LightOutputType Out; \ - Out.diffuse = float4(diffuse, 1); \ - Out.specular = float4(specular, 1); \ + Out.diffuse = float4(diffuse, diffuse_alpha); \ + Out.specular = float4(specular, specular_alpha); \ return Out; #endif // _LIGHTHF_ diff --git a/WickedEngine/deferredPS.hlsl b/WickedEngine/deferredPS.hlsl index a8a5d936c..579dcf72e 100644 --- a/WickedEngine/deferredPS.hlsl +++ b/WickedEngine/deferredPS.hlsl @@ -15,10 +15,10 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET float depth = texture_lineardepth[(uint2)PSIn.pos.xy].r * g_xFrame_MainCamera_ZFarP; - float4 diffuse = texture_0[uint2(PSIn.pos.xy)]; // light diffuse - float4 specular = texture_1[uint2(PSIn.pos.xy)]; // light specular + float3 diffuse = texture_0[uint2(PSIn.pos.xy)].rgb; // light diffuse + float3 specular = texture_1[uint2(PSIn.pos.xy)].rgb; // light specular - float4 color = float4(diffuse.rgb * albedo + specular.rgb, 1); + float4 color = float4(albedo * diffuse + specular, 1); ApplyFog(depth, color); diff --git a/WickedEngine/environmentalLightPS.hlsl b/WickedEngine/environmentalLightPS.hlsl index 85223bded..27da1c896 100644 --- a/WickedEngine/environmentalLightPS.hlsl +++ b/WickedEngine/environmentalLightPS.hlsl @@ -7,18 +7,19 @@ LightOutputType main(VertexToPixel PSIn) { DEFERREDLIGHT_MAKEPARAMS - diffuse = 0; float envMapMIP = surface.roughness * g_xFrame_EnvProbeMipCount; - specular = max(0, EnvironmentReflection_Global(surface, envMapMIP)); + specular = max(0, EnvironmentReflection_Global(surface, envMapMIP)) * surface.F; + specular_alpha = 1; - VoxelGI(surface, diffuse, specular); - float3 ambient = GetAmbient(N) * surface.ao; - diffuse += ambient; + VoxelGIResult vxgiresult = VoxelGI(surface); + diffuse = vxgiresult.diffuse.rgb; + diffuse_alpha = vxgiresult.diffuse.a; + specular = lerp(specular, vxgiresult.specular.rgb, vxgiresult.specular.a); float4 ssr = xSSR.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0); - specular = lerp(specular, ssr.rgb, ssr.a); + specular = lerp(specular, ssr.rgb * surface.F, ssr.a); - specular *= surface.F; + specular_alpha = max(vxgiresult.specular.a, ssr.a); DEFERREDLIGHT_RETURN } \ No newline at end of file diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli index 127a7dd1d..8c3e70d21 100644 --- a/WickedEngine/globals.hlsli +++ b/WickedEngine/globals.hlsli @@ -99,12 +99,12 @@ inline float2 GetInternalResolution() { return g_xFrame_InternalResolution; } inline float GetTime() { return g_xFrame_Time; } inline uint2 GetTemporalAASampleRotation() { return float2((g_xFrame_TemporalAASampleRotation >> 0) & 0x000000FF, (g_xFrame_TemporalAASampleRotation >> 8) & 0x000000FF); } inline bool IsStaticSky() { return g_xFrame_StaticSkyGamma > 0.0f; } -inline void ConvertToSpecularGlossiness(inout float4 surface_ao_roughness_metallic_reflectance) +inline void ConvertToSpecularGlossiness(inout float4 surface_occlusion_roughness_metallic_reflectance) { - surface_ao_roughness_metallic_reflectance.r = 1; - surface_ao_roughness_metallic_reflectance.g = 1 - surface_ao_roughness_metallic_reflectance.a; - surface_ao_roughness_metallic_reflectance.b = max(surface_ao_roughness_metallic_reflectance.r, max(surface_ao_roughness_metallic_reflectance.g, surface_ao_roughness_metallic_reflectance.b)); - surface_ao_roughness_metallic_reflectance.a = 0.02f; + surface_occlusion_roughness_metallic_reflectance.r = 1; + surface_occlusion_roughness_metallic_reflectance.g = 1 - surface_occlusion_roughness_metallic_reflectance.a; + surface_occlusion_roughness_metallic_reflectance.b = max(surface_occlusion_roughness_metallic_reflectance.r, max(surface_occlusion_roughness_metallic_reflectance.g, surface_occlusion_roughness_metallic_reflectance.b)); + surface_occlusion_roughness_metallic_reflectance.a = 0.02f; } struct ComputeShaderInput diff --git a/WickedEngine/hairparticlePS_deferred.hlsl b/WickedEngine/hairparticlePS_deferred.hlsl index a3d159bee..d29d47d37 100644 --- a/WickedEngine/hairparticlePS_deferred.hlsl +++ b/WickedEngine/hairparticlePS_deferred.hlsl @@ -15,7 +15,9 @@ GBUFFEROutputType main(VertexToPixel input) ALPHATEST(color.a) float emissive = 0; Surface surface = CreateSurface(0, input.nor, 0, color, 1, 1, 0, 0); + float3 diffuse = GetAmbient(surface.N); + float3 specular = 0; float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - return CreateGbuffer(color, surface, velocity, 0, 0); + return CreateGbuffer(color, surface, velocity, diffuse, 0); } \ No newline at end of file diff --git a/WickedEngine/hairparticlePS_forward.hlsl b/WickedEngine/hairparticlePS_forward.hlsl index c44cb9c02..d042b3dcd 100644 --- a/WickedEngine/hairparticlePS_forward.hlsl +++ b/WickedEngine/hairparticlePS_forward.hlsl @@ -21,12 +21,11 @@ GBUFFEROutputType_Thin main(VertexToPixel input) Surface surface = CreateSurface(input.pos3D, input.nor, V, color, 1, 1, 0, 0); float2 pixel = input.pos.xy; float depth = input.pos.z; - float3 diffuse = 0; + float3 diffuse = GetAmbient(surface.N); float3 specular = 0; - float3 reflection = 0; float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - ForwardLighting(surface, diffuse, specular, reflection); + ForwardLighting(surface, diffuse, specular); ApplyLighting(surface, diffuse, specular, color); diff --git a/WickedEngine/hairparticlePS_tiledforward.hlsl b/WickedEngine/hairparticlePS_tiledforward.hlsl index ed3fae8d4..6a5c94430 100644 --- a/WickedEngine/hairparticlePS_tiledforward.hlsl +++ b/WickedEngine/hairparticlePS_tiledforward.hlsl @@ -21,13 +21,12 @@ GBUFFEROutputType_Thin main(VertexToPixel input) Surface surface = CreateSurface(input.pos3D, input.nor, V, color, 1, 1, 0, 0); float2 pixel = input.pos.xy; float depth = input.pos.z; - float3 diffuse = 0; + float3 diffuse = GetAmbient(surface.N); float3 specular = 0; float3 reflection = 0; float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - TiledLighting(pixel, surface, diffuse, specular, reflection); - VoxelGI(surface, diffuse, reflection); + TiledLighting(pixel, surface, diffuse, specular); ApplyLighting(surface, diffuse, specular, color); diff --git a/WickedEngine/impostorPS_forward.hlsl b/WickedEngine/impostorPS_forward.hlsl index 5a9475652..f529423b8 100644 --- a/WickedEngine/impostorPS_forward.hlsl +++ b/WickedEngine/impostorPS_forward.hlsl @@ -31,10 +31,9 @@ GBUFFEROutputType_Thin main(VSOut input) float depth = input.pos.z; float3 diffuse = 0; float3 specular = 0; - float3 reflection = 0; float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - ForwardLighting(surface, diffuse, specular, reflection); + ForwardLighting(surface, diffuse, specular); ApplyLighting(surface, diffuse, specular, color); diff --git a/WickedEngine/impostorPS_tiledforward.hlsl b/WickedEngine/impostorPS_tiledforward.hlsl index 53555ff8e..d968efd04 100644 --- a/WickedEngine/impostorPS_tiledforward.hlsl +++ b/WickedEngine/impostorPS_tiledforward.hlsl @@ -28,10 +28,9 @@ GBUFFEROutputType_Thin main(VSOut input) float depth = input.pos.z; float3 diffuse = 0; float3 specular = 0; - float3 reflection = 0; float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - TiledLighting(pixel, surface, diffuse, specular, reflection); + TiledLighting(pixel, surface, diffuse, specular); ApplyLighting(surface, diffuse, specular, color); diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index 3ca1ddb19..c2ca0383e 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -331,8 +331,8 @@ void main(ComputeShaderInput IN) if (pixel.x >= (uint)GetInternalResolution().x || pixel.y >= (uint)GetInternalResolution().y) continue; - float3 diffuse = 0, specular = 0; - float3 reflection = 0; + float3 diffuse = deferred_Diffuse[pixel].rgb; + float3 specular = deferred_Specular[pixel].rgb; float4 g0 = texture_gbuffer0[pixel]; float4 g1 = texture_gbuffer1[pixel]; float4 g2 = texture_gbuffer2[pixel]; @@ -411,9 +411,15 @@ void main(ComputeShaderInput IN) { envmapAccumulation.rgb = lerp(EnvironmentReflection_Global(surface, envMapMIP), envmapAccumulation.rgb, envmapAccumulation.a); } - reflection = max(0, envmapAccumulation.rgb); + specular += max(0, envmapAccumulation.rgb) * surface.F; #endif // DISABLE_ENVMAPS +#ifndef DISABLE_VOXELGI + VoxelGIResult vxgiresult = VoxelGI(surface); + diffuse = lerp(diffuse, vxgiresult.diffuse.rgb, vxgiresult.diffuse.a); + specular = lerp(specular, vxgiresult.specular.rgb, vxgiresult.specular.a); +#endif //DISABLE_VOXELGI + [branch] if (g_xFrame_LightArrayCount > 0) { @@ -495,21 +501,14 @@ void main(ComputeShaderInput IN) } } - VoxelGI(surface, diffuse, reflection); - float2 ScreenCoord = (float2)pixel * g_xFrame_ScreenWidthHeight_Inverse; float2 velocity = g1.zw; float2 ReprojectedScreenCoord = ScreenCoord + velocity; float4 ssr = xSSR.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0); - reflection = lerp(reflection, ssr.rgb, ssr.a); + specular = lerp(specular, ssr.rgb * surface.F, ssr.a); - specular += reflection * surface.F; - - float3 ambient = GetAmbient(N) * surface.ao; - diffuse += ambient; - - deferred_Diffuse[pixel] += float4(diffuse, 1); - deferred_Specular[pixel] += float4(specular, 1); + deferred_Diffuse[pixel] = float4(diffuse, 1); + deferred_Specular[pixel] = float4(specular, 1); } #endif // DEFERRED diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index b05ae2a02..4188a5fe3 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -695,8 +695,15 @@ inline LightingResult TubeLight(in ShaderEntityType light, in Surface surface) // VOXEL RADIANCE -inline void VoxelGI(inout Surface surface, inout float3 diffuse, inout float3 specular) +struct VoxelGIResult { + float4 diffuse; // diffuse + contribution(alpha) + float4 specular; // specular + contribution(alpha) +}; +inline VoxelGIResult VoxelGI(in Surface surface) +{ + VoxelGIResult result; + [branch]if (g_xFrame_VoxelRadianceDataRes != 0) { // determine blending factor (we will blend out voxel GI on grid edges): @@ -707,16 +714,26 @@ inline void VoxelGI(inout Surface surface, inout float3 diffuse, inout float3 sp float blend = 1 - pow(max(voxelSpacePos.x, max(voxelSpacePos.y, voxelSpacePos.z)), 4); float4 radiance = ConeTraceRadiance(texture_voxelradiance, surface.P, surface.N); - diffuse += lerp(0, radiance.rgb, blend); - surface.ao *= 1 - lerp(0, radiance.a, blend); + result.diffuse = float4(radiance.rgb * surface.occlusion, radiance.a * blend); [branch] if (g_xFrame_VoxelRadianceReflectionsEnabled) { float4 reflection = ConeTraceReflection(texture_voxelradiance, surface.P, surface.N, surface.V, surface.roughness); - specular = lerp(specular, reflection.rgb, reflection.a * blend); + result.specular = float4(reflection.rgb * surface.F, reflection.a * blend); + } + else + { + result.specular = 0; } } + else + { + result.diffuse = 0; + result.specular = 0; + } + + return result; } diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 58c75dbc9..10e00aae8 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -34,10 +34,10 @@ // These are bound by wiRenderer (based on Material): #define xBaseColorMap texture_0 // rgb: baseColor, a: opacity #define xNormalMap texture_1 // rgb: normal -#define xSurfaceMap texture_2 // r: ao, g: roughness, b: metallic, a: reflectance +#define xSurfaceMap texture_2 // r: occlusion, g: roughness, b: metallic, a: reflectance #define xDisplacementMap texture_3 // r: heightmap #define xEmissiveMap texture_4 // rgba: emissive -#define xOcclusionMap texture_5 // r: ao +#define xOcclusionMap texture_5 // r: occlusion // These are bound by RenderPath (based on Render Path): #define xReflection texture_6 // rgba: scene color from reflected camera angle @@ -80,11 +80,11 @@ struct GBUFFEROutputType inline GBUFFEROutputType CreateGbuffer(in float4 color, in Surface surface, in float2 velocity, in float3 diffuse, in float3 specular) { GBUFFEROutputType Out; - Out.g0 = float4(color.rgb, surface.sss); /*FORMAT_R8G8B8A8_UNORM*/ - Out.g1 = float4(encode(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ - Out.g2 = float4(surface.ao, surface.roughness, surface.metalness, surface.reflectance); /*FORMAT_R8G8B8A8_UNORM*/ - Out.diffuse = float4(diffuse, 1); /*wiRenderer::RTFormat_deferred_lightbuffer*/ - Out.specular = float4(specular, 1); /*wiRenderer::RTFormat_deferred_lightbuffer*/ + Out.g0 = float4(color.rgb, surface.sss); /*FORMAT_R8G8B8A8_UNORM*/ + Out.g1 = float4(encode(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ + Out.g2 = float4(surface.occlusion, surface.roughness, surface.metalness, surface.reflectance); /*FORMAT_R8G8B8A8_UNORM*/ + Out.diffuse = float4(diffuse, 1); /*wiRenderer::RTFormat_deferred_lightbuffer*/ + Out.specular = float4(specular, 1); /*wiRenderer::RTFormat_deferred_lightbuffer*/ return Out; } @@ -110,7 +110,7 @@ inline void ApplyEmissive(in Surface surface, inout float3 specular) specular += surface.emissiveColor.rgb * surface.emissiveColor.a; } -inline void LightMapping(in float2 ATLAS, inout float3 diffuse, inout float3 specular, inout float ao, in float ssao) +inline void LightMapping(in float2 ATLAS, inout float3 diffuse, inout float3 specular) { if (any(ATLAS)) { @@ -119,8 +119,7 @@ inline void LightMapping(in float2 ATLAS, inout float3 diffuse, inout float3 spe #else float4 lightmap = texture_globallightmap.SampleLevel(sampler_linear_clamp, ATLAS, 0); #endif // LIGHTMAP_QUALITY_BICUBIC - diffuse += lightmap.rgb * ssao; - ao *= saturate(1 - lightmap.a); + diffuse = lerp(diffuse, lightmap.rgb, lightmap.a); } } @@ -196,7 +195,7 @@ inline void Refraction(in float2 ScreenCoord, in float2 normal2D, in float3 bump } } -inline void ForwardLighting(inout Surface surface, inout float3 diffuse, inout float3 specular, inout float3 reflection) +inline void ForwardLighting(inout Surface surface, inout float3 diffuse, inout float3 specular) { #ifndef DISABLE_DECALS [branch] @@ -263,11 +262,6 @@ inline void ForwardLighting(inout Surface surface, inout float3 diffuse, inout f #endif // DISABLE_DECALS -//#ifndef DISABLE_ENVMAPS -// const float envMapMIP = surface.roughness * g_xFrame_EnvProbeMipCount; -// reflection = max(0, EnvironmentReflection_Global(surface, envMapMIP)); -//#endif - #ifndef DISABLE_ENVMAPS // Apply environment maps: float4 envmapAccumulation = 0; @@ -329,9 +323,15 @@ inline void ForwardLighting(inout Surface surface, inout float3 diffuse, inout f { envmapAccumulation.rgb = lerp(EnvironmentReflection_Global(surface, envMapMIP), envmapAccumulation.rgb, envmapAccumulation.a); } - reflection = max(0, envmapAccumulation.rgb); + specular += max(0, envmapAccumulation.rgb) * surface.F; #endif // DISABLE_ENVMAPS +#ifndef DISABLE_VOXELGI + VoxelGIResult vxgiresult = VoxelGI(surface); + diffuse = lerp(diffuse, vxgiresult.diffuse.rgb, vxgiresult.diffuse.a); + specular = lerp(specular, vxgiresult.specular.rgb, vxgiresult.specular.a); +#endif //DISABLE_VOXELGI + [branch] if (any(xForwardLightMask)) { @@ -409,7 +409,7 @@ inline void ForwardLighting(inout Surface surface, inout float3 diffuse, inout f } -inline void TiledLighting(in float2 pixel, inout Surface surface, inout float3 diffuse, inout float3 specular, inout float3 reflection) +inline void TiledLighting(in float2 pixel, inout Surface surface, inout float3 diffuse, inout float3 specular) { const uint2 tileIndex = uint2(floor(pixel / TILED_CULLING_BLOCKSIZE)); const uint flatTileIndex = flatten2D(tileIndex, g_xFrame_EntityCullingTileCount.xy) * SHADER_ENTITY_TILE_BUCKET_COUNT; @@ -567,9 +567,14 @@ inline void TiledLighting(in float2 pixel, inout Surface surface, inout float3 d { envmapAccumulation.rgb = lerp(EnvironmentReflection_Global(surface, envMapMIP), envmapAccumulation.rgb, envmapAccumulation.a); } - reflection = max(0, envmapAccumulation.rgb); + specular += max(0, envmapAccumulation.rgb) * surface.F; #endif // DISABLE_ENVMAPS +#ifndef DISABLE_VOXELGI + VoxelGIResult vxgiresult = VoxelGI(surface); + diffuse = lerp(diffuse, vxgiresult.diffuse.rgb, vxgiresult.diffuse.a); + specular = lerp(specular, vxgiresult.specular.rgb, vxgiresult.specular.a); +#endif //DISABLE_VOXELGI [branch] if (g_xFrame_LightArrayCount > 0) @@ -665,7 +670,7 @@ inline void TiledLighting(in float2 pixel, inout Surface surface, inout float3 d inline void ApplyLighting(in Surface surface, in float3 diffuse, in float3 specular, inout float4 color) { - color.rgb = (GetAmbient(surface.N) * surface.ao + diffuse) * surface.albedo + specular; + color.rgb = surface.albedo * diffuse + specular; } inline void ApplyFog(in float dist, inout float4 color) @@ -703,6 +708,11 @@ 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) @@ -760,9 +770,8 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) ALPHATEST(color.a); #ifndef SIMPLE_INPUT - float3 diffuse = 0; + float3 diffuse = GetAmbient(surface.N); float3 specular = 0; - float3 reflection = 0; float3 bumpColor = 0; float opacity = color.a; float depth = input.pos.z; @@ -789,11 +798,15 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #endif // NORMALMAP const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; - float4 surface_ao_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap); + float4 surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap); + if (g_xMat_occlusion_primary == 0) + { + surface_occlusion_roughness_metallic_reflectance.r = 1; + } if (g_xMat_specularGlossinessWorkflow) { - ConvertToSpecularGlossiness(surface_ao_roughness_metallic_reflectance); + ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance); } float4 emissiveColor; @@ -810,18 +823,22 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) emissiveColor = 0; } - const float2 UV_occlusionMap = g_xMat_uvset_occlusionMap == 0 ? input.uvsets.xy : input.uvsets.zw; - float occlusion = xOcclusionMap.Sample(sampler_objectshader, UV_occlusionMap).r; + float occlusion = 1; + if (g_xMat_occlusion_secondary) + { + const float2 UV_occlusionMap = g_xMat_uvset_occlusionMap == 0 ? input.uvsets.xy : input.uvsets.zw; + occlusion = xOcclusionMap.Sample(sampler_objectshader, UV_occlusionMap).r; + } surface = CreateSurface( surface.P, surface.N, surface.V, color, - surface_ao_roughness_metallic_reflectance.r * occlusion, - g_xMat_roughness * surface_ao_roughness_metallic_reflectance.g, - g_xMat_metalness * surface_ao_roughness_metallic_reflectance.b, - g_xMat_reflectance * surface_ao_roughness_metallic_reflectance.a, + surface_occlusion_roughness_metallic_reflectance.r * occlusion, + g_xMat_roughness * surface_occlusion_roughness_metallic_reflectance.g, + g_xMat_metalness * surface_occlusion_roughness_metallic_reflectance.b, + g_xMat_reflectance * surface_occlusion_roughness_metallic_reflectance.a, emissiveColor, g_xMat_subsurfaceScattering ); @@ -864,7 +881,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #ifndef ENVMAPRENDERING #ifndef TRANSPARENT ssao = xSSAO.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0).r; - surface.ao *= ssao; + surface.occlusion *= ssao; #endif // TRANSPARENT #endif // ENVMAPRENDERING @@ -872,11 +889,12 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) SpecularAA(surface.N, surface.roughness); + LightMapping(input.atl, diffuse, specular); + + diffuse *= surface.occlusion; + ApplyEmissive(surface, specular); - LightMapping(input.atl, diffuse, specular, surface.ao, ssao); - - #ifdef DEFERRED @@ -885,42 +903,33 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) specular += PlanarReflection(refUV, bumpColor.rg) * surface.F; #endif - - #else // not DEFERRED + +#ifdef PLANARREFLECTION + specular += PlanarReflection(refUV, bumpColor.rg) * surface.F; +#endif + #ifdef FORWARD - ForwardLighting(surface, diffuse, specular, reflection); + ForwardLighting(surface, diffuse, specular); #endif // FORWARD #ifdef TILEDFORWARD - TiledLighting(pixel, surface, diffuse, specular, reflection); + TiledLighting(pixel, surface, diffuse, specular); #endif // TILEDFORWARD #ifndef WATER #ifndef ENVMAPRENDERING - - VoxelGI(surface, diffuse, reflection); - -#ifdef PLANARREFLECTION - reflection = PlanarReflection(refUV, bumpColor.rg); -#endif - - #ifdef TRANSPARENT Refraction(ScreenCoord, input.nor2D, bumpColor, surface, color, diffuse); #else float4 ssr = xSSR.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0); - reflection = lerp(reflection, ssr.rgb, ssr.a); + specular = lerp(specular, ssr.rgb * surface.F, ssr.a); #endif // TRANSPARENT - - #endif // ENVMAPRENDERING #endif // WATER - specular += reflection * surface.F; - ApplyLighting(surface, diffuse, specular, color); #ifdef WATER diff --git a/WickedEngine/oceanSurfacePS.hlsl b/WickedEngine/oceanSurfacePS.hlsl index 60f6bc491..e274d7807 100644 --- a/WickedEngine/oceanSurfacePS.hlsl +++ b/WickedEngine/oceanSurfacePS.hlsl @@ -22,9 +22,8 @@ float4 main(PSIn input) : SV_TARGET Surface surface = CreateSurface(input.pos3D, normalize(float3(gradient.x, xOceanTexelLength * 2, gradient.y)), V, color, 1, 0.001, 0, 0.02); float2 pixel = input.pos.xy; float depth = input.pos.z; - float3 diffuse = 0; + float3 diffuse = GetAmbient(surface.N); float3 specular = 0; - float3 reflection = 0; float lineardepth = input.pos2D.w; float2 refUV = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w * 0.5f + 0.5f; @@ -47,10 +46,9 @@ float4 main(PSIn input) : SV_TARGET float ramp = pow(abs(1.0f / (1.0f + NdotV)), 16); reflectiveColor.rgb = lerp(float3(0.38f, 0.45f, 0.56f), reflectiveColor.rgb, ramp); // skycolor hack surface.albedo.rgb = lerp(refractiveColor, reflectiveColor.rgb, fresnelTerm); + surface.F = fresnelTerm; - TiledLighting(pixel, surface, diffuse, specular, reflection); - - specular += reflection * fresnelTerm; + TiledLighting(pixel, surface, diffuse, specular); ApplyLighting(surface, diffuse, specular, color); diff --git a/WickedEngine/raySceneIntersectHF.hlsli b/WickedEngine/raySceneIntersectHF.hlsli index c99b1ac38..62d28780d 100644 --- a/WickedEngine/raySceneIntersectHF.hlsli +++ b/WickedEngine/raySceneIntersectHF.hlsli @@ -302,19 +302,19 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2 float4 baseColorMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_baseColorMap * mat.baseColorAtlasMulAdd.xy + mat.baseColorAtlasMulAdd.zw, 0); const float2 UV_surfaceMap = mat.uvset_surfaceMap == 0 ? hit.uvsets.xy : hit.uvsets.zw; - float4 surface_ao_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); + float4 surface_occlusion_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); if (mat.specularGlossinessWorkflow) { - ConvertToSpecularGlossiness(surface_ao_roughness_metallic_reflectance); + ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance); } float4 baseColor = baseColorMap; baseColor.rgb = DEGAMMA(baseColor.rgb); baseColor *= hit.color; - float roughness = mat.roughness * surface_ao_roughness_metallic_reflectance.g; - float metalness = mat.metalness * surface_ao_roughness_metallic_reflectance.b; - float reflectance = mat.reflectance * surface_ao_roughness_metallic_reflectance.a; + float roughness = mat.roughness * surface_occlusion_roughness_metallic_reflectance.g; + float metalness = mat.metalness * surface_occlusion_roughness_metallic_reflectance.b; + float reflectance = mat.reflectance * surface_occlusion_roughness_metallic_reflectance.a; roughness = sqr(roughness); // convert linear roughness to cone aperture float4 emissiveColor; [branch] diff --git a/WickedEngine/raytrace_lightsamplingCS.hlsl b/WickedEngine/raytrace_lightsamplingCS.hlsl index 4540a7992..0ba2e3275 100644 --- a/WickedEngine/raytrace_lightsamplingCS.hlsl +++ b/WickedEngine/raytrace_lightsamplingCS.hlsl @@ -56,19 +56,19 @@ void main( uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) float4 baseColorMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_baseColorMap * mat.baseColorAtlasMulAdd.xy + mat.baseColorAtlasMulAdd.zw, 0); const float2 UV_surfaceMap = mat.uvset_surfaceMap == 0 ? uvsets.xy : uvsets.zw; - float4 surface_ao_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); + float4 surface_occlusion_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); if (mat.specularGlossinessWorkflow) { - ConvertToSpecularGlossiness(surface_ao_roughness_metallic_reflectance); + ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance); } float4 baseColor = baseColorMap; baseColor.rgb = DEGAMMA(baseColor.rgb); baseColor *= mat.baseColor; - float roughness = mat.roughness * surface_ao_roughness_metallic_reflectance.g; - float metalness = mat.metalness * surface_ao_roughness_metallic_reflectance.b; - float reflectance = mat.reflectance * surface_ao_roughness_metallic_reflectance.a; + float roughness = mat.roughness * surface_occlusion_roughness_metallic_reflectance.g; + float metalness = mat.metalness * surface_occlusion_roughness_metallic_reflectance.b; + float reflectance = mat.reflectance * surface_occlusion_roughness_metallic_reflectance.a; Surface surface = CreateSurface(P, N, V, baseColor, 1, roughness, metalness, reflectance); diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index 9e6e3f4dd..5a38605b5 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -161,6 +161,8 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, GRAPHICSTHREAD global_material.uvset_emissiveMap = material.uvset_emissiveMap; global_material.uvset_occlusionMap = material.uvset_occlusionMap; global_material.specularGlossinessWorkflow = material.IsUsingSpecularGlossinessWorkflow() ? 1 : 0; + global_material.occlusion_primary = material.IsOcclusionEnabled_Primary() ? 1 : 0; + global_material.occlusion_secondary = material.IsOcclusionEnabled_Secondary() ? 1 : 0; // Add extended properties: const TextureDesc& desc = globalMaterialAtlas.GetDesc(); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index d086a1f78..aa78151f5 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1416,7 +1416,6 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re // Do we need to bind all textures or just a reduced amount for this pass? const bool easyTextureBind = - renderPass == RENDERPASS_TEXTURE || renderPass == RENDERPASS_SHADOW || renderPass == RENDERPASS_SHADOWCUBE || renderPass == RENDERPASS_DEPTHONLY; @@ -1730,18 +1729,31 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re device->BindConstantBuffer(VS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - material.GetDisplacementMap(), - material.GetEmissiveMap(), - material.GetOcclusionMap(), - }; - device->BindResources(PS, res, TEXSLOT_ONDEMAND0, (easyTextureBind ? 2 : ARRAYSIZE(res)), threadID); + if (easyTextureBind) + { + const GPUResource* res[] = { + material.GetBaseColorMap(), + }; + device->BindResources(PS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); + } + else + { + const GPUResource* res[] = { + material.GetBaseColorMap(), + material.GetNormalMap(), + material.GetSurfaceMap(), + material.GetDisplacementMap(), + material.GetEmissiveMap(), + material.GetOcclusionMap(), + }; + device->BindResources(PS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); + } if (tessellatorRequested) { + const GPUResource* res[] = { + material.GetDisplacementMap(), + }; device->BindResources(DS, res, TEXSLOT_ONDEMAND0, ARRAYSIZE(res), threadID); device->BindConstantBuffer(DS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); } @@ -3424,17 +3436,17 @@ void SetUpStates() bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; device->CreateBlendState(&bd, &blendStates[BSTYPE_DEFERREDLIGHT]); - + bd.RenderTarget[0].BlendEnable = true; bd.RenderTarget[0].SrcBlend = BLEND_ONE; - bd.RenderTarget[0].DestBlend = BLEND_ONE; + bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; bd.RenderTarget[0].BlendOp = BLEND_OP_ADD; bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; bd.RenderTarget[0].DestBlendAlpha = BLEND_ONE; bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; - bd.IndependentBlendEnable = false, - bd.AlphaToCoverageEnable = false; + bd.IndependentBlendEnable = false; + bd.AlphaToCoverageEnable = false; device->CreateBlendState(&bd, &blendStates[BSTYPE_ENVIRONMENTALLIGHT]); bd.RenderTarget[0].SrcBlend = BLEND_INV_SRC_COLOR; @@ -3814,6 +3826,8 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) materialGPUData.g_xMat_uvset_emissiveMap = material.uvset_emissiveMap; materialGPUData.g_xMat_uvset_occlusionMap = material.uvset_occlusionMap; materialGPUData.g_xMat_specularGlossinessWorkflow = material.IsUsingSpecularGlossinessWorkflow() ? 1 : 0; + materialGPUData.g_xMat_occlusion_primary = material.IsOcclusionEnabled_Primary() ? 1 : 0; + materialGPUData.g_xMat_occlusion_secondary = material.IsOcclusionEnabled_Secondary() ? 1 : 0; device->UpdateBuffer(material.constantBuffer.get(), &materialGPUData, threadID); } diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 3f265acc5..f0ea3d051 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -106,6 +106,8 @@ namespace wiSceneSystem FLIP_NORMALMAP = 1 << 4, USE_VERTEXCOLORS = 1 << 5, SPECULAR_GLOSSINESS_WORKFLOW = 1 << 6, + OCCLUSION_PRIMARY = 1 << 7, + OCCLUSION_SECONDARY = 1 << 8, }; uint32_t _flags = DIRTY | CAST_SHADOW; @@ -183,6 +185,8 @@ namespace wiSceneSystem inline void SetCastShadow(bool value) { if (value) { _flags |= CAST_SHADOW; } else { _flags &= ~CAST_SHADOW; } } inline void SetPlanarReflections(bool value) { if (value) { _flags |= PLANAR_REFLECTION; } else { _flags &= ~PLANAR_REFLECTION; } } inline void SetWater(bool value) { if (value) { _flags |= WATER; } else { _flags &= ~WATER; } } + inline void SetOcclusionEnabled_Primary(bool value) { SetDirty(); if (value) { _flags |= OCCLUSION_PRIMARY; } else { _flags &= ~OCCLUSION_PRIMARY; } } + inline void SetOcclusionEnabled_Secondary(bool value) { SetDirty(); if (value) { _flags |= OCCLUSION_SECONDARY; } else { _flags &= ~OCCLUSION_SECONDARY; } } inline bool IsTransparent() const { return GetOpacity() < 1.0f || blendMode != BLENDMODE_OPAQUE || IsCustomShader(); } inline bool IsWater() const { return _flags & WATER; } @@ -192,6 +196,8 @@ namespace wiSceneSystem inline bool IsFlipNormalMap() const { return _flags & FLIP_NORMALMAP; } inline bool IsUsingVertexColors() const { return _flags & USE_VERTEXCOLORS; } inline bool IsUsingSpecularGlossinessWorkflow() const { return _flags & SPECULAR_GLOSSINESS_WORKFLOW; } + inline bool IsOcclusionEnabled_Primary() const { return _flags & OCCLUSION_PRIMARY; } + inline bool IsOcclusionEnabled_Secondary() const { return _flags & OCCLUSION_SECONDARY; } inline bool IsCustomShader() const { return customShaderID >= 0; } inline void SetBaseColor(const XMFLOAT4& value) { SetDirty(); baseColor = value; } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index b9576568b..65b3d81ca 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 26; // minor bug fixes, alterations, refactors, updates - const int revision = 0; + const int revision = 1; long GetVersion()