occlusion updates and shader refactors
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
wiCheckBox* flipNormalMapCheckBox;
|
||||
wiCheckBox* useVertexColorsCheckBox;
|
||||
wiCheckBox* specularGlossinessCheckBox;
|
||||
wiCheckBox* occlusionPrimaryCheckBox;
|
||||
wiCheckBox* occlusionSecondaryCheckBox;
|
||||
wiSlider* normalMapSlider;
|
||||
wiSlider* roughnessSlider;
|
||||
wiSlider* reflectanceSlider;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+60
-51
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
+28
-14
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user