From 30a4f4910b7cde38bbfb7ea123f1ae97096c55cf Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sat, 2 Mar 2019 16:23:54 +0000 Subject: [PATCH] material emissive color separated from base color; voxel gi fix; gamma fixes; slightly reordered gbuffer; --- Editor/LightWindow.cpp | 3 +- Editor/MaterialWindow.cpp | 59 +++++++++++++----- Editor/MaterialWindow.h | 4 +- Editor/ModelImporter_GLTF.cpp | 40 ++++++++---- Editor/ModelImporter_OBJ.cpp | 5 +- Editor/ObjectWindow.cpp | 2 +- Editor/OceanWindow.cpp | 3 +- WickedEngine/ArchiveVersionHistory.txt | 3 +- WickedEngine/ShaderInterop_Renderer.h | 5 +- WickedEngine/ShaderInterop_TracedRendering.h | 5 +- WickedEngine/brdf.hlsli | 6 +- WickedEngine/captureImpostorPS_albedo.hlsl | 5 +- WickedEngine/deferredLightHF.hlsli | 7 +-- WickedEngine/deferredPS.hlsl | 13 ++-- WickedEngine/environmentalLightPS.hlsl | 4 +- WickedEngine/hairparticlePS_deferred.hlsl | 2 +- WickedEngine/hairparticlePS_forward.hlsl | 2 +- WickedEngine/hairparticlePS_tiledforward.hlsl | 4 +- WickedEngine/lightCullingCS.hlsl | 9 +-- WickedEngine/lightingHF.hlsli | 2 +- WickedEngine/objectHF.hlsli | 39 ++++++++---- WickedEngine/objectPS_hologram.hlsl | 2 +- WickedEngine/objectPS_voxelizer.hlsl | 19 +++++- WickedEngine/oceanSurfacePS.hlsl | 1 - WickedEngine/raySceneIntersectHF.hlsli | 21 +++++-- WickedEngine/raytrace_lightsamplingCS.hlsl | 8 +-- WickedEngine/shadowPS_transparent.hlsl | 3 +- WickedEngine/shadowPS_water.hlsl | 3 +- WickedEngine/skyPS_static.hlsl | 2 +- WickedEngine/ssss.hlsl | 2 +- WickedEngine/wiArchive.cpp | 2 +- WickedEngine/wiRenderer.cpp | 9 +-- WickedEngine/wiSceneSystem.cpp | 2 +- WickedEngine/wiSceneSystem.h | 13 ++-- WickedEngine/wiSceneSystem_Serializers.cpp | 18 +++++- WickedEngine/wiVersion.cpp | 2 +- models/lightmap_bake_test.wiscene | Bin 126480 -> 126585 bytes 37 files changed, 218 insertions(+), 111 deletions(-) diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 0a2fc9233..9997eef68 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -190,8 +190,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); if (light != nullptr) { - XMFLOAT3 col = args.color.toFloat3(); - light->color = XMFLOAT3(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f)); + light->color = args.color.toFloat3(); } }); lightWindow->AddWidget(colorPicker); diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index 2d6f2b87e..d38132049 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, 720)); + materialWindow->SetSize(XMFLOAT2(760, 840)); materialWindow->SetEnabled(false); GUI->AddWidget(materialWindow); @@ -68,6 +68,16 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) }); materialWindow->AddWidget(shadowCasterCheckBox); + flipNormalMapCheckBox = new wiCheckBox("Flip Normal Map: "); + flipNormalMapCheckBox->SetTooltip("The normal map green channel will be inverted. Useful for imported models coming from OpenGL space (such as GLTF)."); + flipNormalMapCheckBox->SetPos(XMFLOAT2(570, y += step)); + flipNormalMapCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetFlipNormalMap(args.bValue); + }); + materialWindow->AddWidget(flipNormalMapCheckBox); + normalMapSlider = new wiSlider(0, 4, 1, 4000, "Normalmap: "); normalMapSlider->SetTooltip("How much the normal map should distort the face normals (bumpiness)."); normalMapSlider->SetSize(XMFLOAT2(100, 30)); @@ -152,7 +162,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) emissiveSlider->OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); if (material != nullptr) - material->SetEmissive(args.fValue); + material->SetEmissiveStrength(args.fValue); }); materialWindow->AddWidget(emissiveSlider); @@ -246,20 +256,36 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) materialWindow->AddWidget(texMulSliderY); - colorPicker = new wiColorPicker(GUI, "Material Color"); - colorPicker->SetPos(XMFLOAT2(10, 400)); - colorPicker->RemoveWidgets(); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { + baseColorPicker = new wiColorPicker(GUI, "Base Color"); + baseColorPicker->SetPos(XMFLOAT2(10, 280)); + baseColorPicker->RemoveWidgets(); + baseColorPicker->SetVisible(true); + baseColorPicker->SetEnabled(true); + baseColorPicker->OnColorChanged([&](wiEventArgs args) { MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); if (material != nullptr) { XMFLOAT3 col = args.color.toFloat3(); - material->SetBaseColor(XMFLOAT4(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f), material->GetOpacity())); + material->SetBaseColor(XMFLOAT4(col.x, col.y, col.z, material->GetOpacity())); } }); - materialWindow->AddWidget(colorPicker); + materialWindow->AddWidget(baseColorPicker); + + + emissiveColorPicker = new wiColorPicker(GUI, "Emissive Color"); + emissiveColorPicker->SetPos(XMFLOAT2(10, 550)); + emissiveColorPicker->RemoveWidgets(); + emissiveColorPicker->SetVisible(true); + emissiveColorPicker->SetEnabled(true); + emissiveColorPicker->OnColorChanged([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + XMFLOAT3 col = args.color.toFloat3(); + material->SetEmissiveColor(XMFLOAT4(col.x, col.y, col.z, material->GetEmissiveStrength())); + } + }); + materialWindow->AddWidget(emissiveColorPicker); blendModeComboBox = new wiComboBox("Blend mode: "); @@ -577,7 +603,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) materialWindow->AddWidget(texture_emissive_Button); - materialWindow->Translate(XMFLOAT3(screenW - 760, 50, 0)); + materialWindow->Translate(XMFLOAT3(screenW - 760, 120, 0)); materialWindow->SetVisible(false); SetEntity(INVALID_ENTITY); @@ -614,13 +640,14 @@ void MaterialWindow::SetEntity(Entity entity) waterCheckBox->SetCheck(material->IsWater()); planarReflCheckBox->SetCheck(material->HasPlanarReflection()); shadowCasterCheckBox->SetCheck(material->IsCastingShadow()); + flipNormalMapCheckBox->SetCheck(material->IsFlipNormalMap()); normalMapSlider->SetValue(material->normalMapStrength); roughnessSlider->SetValue(material->roughness); reflectanceSlider->SetValue(material->reflectance); metalnessSlider->SetValue(material->metalness); alphaSlider->SetValue(material->GetOpacity()); refractionIndexSlider->SetValue(material->refractionIndex); - emissiveSlider->SetValue(material->emissive); + emissiveSlider->SetValue(material->emissiveColor.w); sssSlider->SetValue(material->subsurfaceScattering); pomSlider->SetValue(material->parallaxOcclusionMapping); texAnimFrameRateSlider->SetValue(material->texAnimFrameRate); @@ -630,23 +657,27 @@ void MaterialWindow::SetEntity(Entity entity) texMulSliderY->SetValue(material->texMulAdd.y); alphaRefSlider->SetValue(material->alphaRef); materialWindow->SetEnabled(true); - colorPicker->SetEnabled(true); + baseColorPicker->SetEnabled(true); + emissiveColorPicker->SetEnabled(true); blendModeComboBox->SetSelected((int)material->blendMode); texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName)); texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); + texture_emissive_Button->SetText(wiHelper::GetFileNameFromPath(material->emissiveMapName)); } else { materialNameField->SetValue("No material selected"); materialWindow->SetEnabled(false); - colorPicker->SetEnabled(false); + baseColorPicker->SetEnabled(false); + emissiveColorPicker->SetEnabled(false); texture_baseColor_Button->SetText(""); texture_normal_Button->SetText(""); texture_surface_Button->SetText(""); texture_displacement_Button->SetText(""); + texture_emissive_Button->SetText(""); } } diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index 76fe4562a..79991c1c7 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -26,6 +26,7 @@ public: wiCheckBox* waterCheckBox; wiCheckBox* planarReflCheckBox; wiCheckBox* shadowCasterCheckBox; + wiCheckBox* flipNormalMapCheckBox; wiSlider* normalMapSlider; wiSlider* roughnessSlider; wiSlider* reflectanceSlider; @@ -40,7 +41,8 @@ public: wiSlider* texAnimDirectionSliderV; wiSlider* texMulSliderX; wiSlider* texMulSliderY; - wiColorPicker* colorPicker; + wiColorPicker* baseColorPicker; + wiColorPicker* emissiveColorPicker; wiSlider* alphaRefSlider; wiComboBox* blendModeComboBox; wiComboBox* shaderTypeComboBox; diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 2fa37b20a..37f4470a6 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -315,7 +315,6 @@ void ImportModel_GLTF(const std::string& fileName) material.roughness = 1.0f; material.metalness = 1.0f; material.reflectance = 0.02f; - material.emissive = 0; auto& baseColorTexture = x.values.find("baseColorTexture"); auto& metallicRoughnessTexture = x.values.find("metallicRoughnessTexture"); @@ -352,6 +351,7 @@ void ImportModel_GLTF(const std::string& fileName) auto& img = state.gltfModel.images[tex.source]; RegisterTexture2D(&img, "normal"); material.normalMapName = img.uri; + material.SetFlipNormalMap(true); } if (metallicRoughnessTexture != x.values.end()) { @@ -383,6 +383,7 @@ void ImportModel_GLTF(const std::string& fileName) material.baseColor.x = static_cast(baseColorFactor->second.ColorFactor()[0]); material.baseColor.y = static_cast(baseColorFactor->second.ColorFactor()[1]); material.baseColor.z = static_cast(baseColorFactor->second.ColorFactor()[2]); + material.baseColor.w = static_cast(baseColorFactor->second.ColorFactor()[3]); } if (roughnessFactor != x.values.end()) { @@ -394,7 +395,10 @@ void ImportModel_GLTF(const std::string& fileName) } if (emissiveFactor != x.additionalValues.end()) { - material.emissive = static_cast(emissiveFactor->second.ColorFactor()[0]); + material.emissiveColor.x = static_cast(emissiveFactor->second.ColorFactor()[0]); + material.emissiveColor.y = static_cast(emissiveFactor->second.ColorFactor()[1]); + material.emissiveColor.z = static_cast(emissiveFactor->second.ColorFactor()[2]); + material.emissiveColor.w = static_cast(emissiveFactor->second.ColorFactor()[3]); } if (alphaCutoff != x.additionalValues.end()) { @@ -449,31 +453,45 @@ void ImportModel_GLTF(const std::string& fileName) const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; + int index_remap[3]; + if (transform_to_LH) + { + index_remap[0] = 0; + index_remap[1] = 1; + index_remap[2] = 2; + } + else + { + index_remap[0] = 0; + index_remap[1] = 2; + index_remap[2] = 1; + } + if (stride == 1) { for (size_t i = 0; i < indexCount; i += 3) { - mesh.indices[indexOffset + i + 0] = vertexOffset + data[i + 0]; - mesh.indices[indexOffset + i + 1] = vertexOffset + data[i + 1]; - mesh.indices[indexOffset + i + 2] = vertexOffset + data[i + 2]; + mesh.indices[indexOffset + i + 0] = vertexOffset + data[i + index_remap[0]]; + mesh.indices[indexOffset + i + 1] = vertexOffset + data[i + index_remap[1]]; + mesh.indices[indexOffset + i + 2] = vertexOffset + data[i + index_remap[2]]; } } else if (stride == 2) { for (size_t i = 0; i < indexCount; i += 3) { - mesh.indices[indexOffset + i + 0] = vertexOffset + ((uint16_t*)data)[i + 0]; - mesh.indices[indexOffset + i + 1] = vertexOffset + ((uint16_t*)data)[i + 1]; - mesh.indices[indexOffset + i + 2] = vertexOffset + ((uint16_t*)data)[i + 2]; + mesh.indices[indexOffset + i + 0] = vertexOffset + ((uint16_t*)data)[i + index_remap[0]]; + mesh.indices[indexOffset + i + 1] = vertexOffset + ((uint16_t*)data)[i + index_remap[1]]; + mesh.indices[indexOffset + i + 2] = vertexOffset + ((uint16_t*)data)[i + index_remap[2]]; } } else if (stride == 4) { for (size_t i = 0; i < indexCount; i += 3) { - mesh.indices[indexOffset + i + 0] = vertexOffset + ((uint32_t*)data)[i + 0]; - mesh.indices[indexOffset + i + 1] = vertexOffset + ((uint32_t*)data)[i + 1]; - mesh.indices[indexOffset + i + 2] = vertexOffset + ((uint32_t*)data)[i + 2]; + mesh.indices[indexOffset + i + 0] = vertexOffset + ((uint32_t*)data)[i + index_remap[0]]; + mesh.indices[indexOffset + i + 1] = vertexOffset + ((uint32_t*)data)[i + index_remap[1]]; + mesh.indices[indexOffset + i + 2] = vertexOffset + ((uint32_t*)data)[i + index_remap[2]]; } } else diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 810942b5a..72018c4a5 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -47,7 +47,10 @@ void ImportModel_OBJ(const std::string& fileName) material.baseColor = XMFLOAT4(obj_material.diffuse[0], obj_material.diffuse[1], obj_material.diffuse[2], 1); material.baseColorMapName = obj_material.diffuse_texname; material.displacementMapName = obj_material.displacement_texname; - material.emissive = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); + material.emissiveColor.x = obj_material.emission[0]; + material.emissiveColor.y = obj_material.emission[1]; + material.emissiveColor.z = obj_material.emission[2]; + material.emissiveColor.w = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); material.refractionIndex = obj_material.ior; material.metalness = obj_material.metallic; material.normalMapName = obj_material.normal_texname; diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 6acd58f14..2d532c304 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -303,7 +303,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) if (object != nullptr) { XMFLOAT3 col = args.color.toFloat3(); - object->color = XMFLOAT4(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f), object->color.w); + object->color = XMFLOAT4(col.x, col.y, col.z, object->color.w); } }); objectWindow->AddWidget(colorPicker); diff --git a/Editor/OceanWindow.cpp b/Editor/OceanWindow.cpp index 66b459e79..08d77ee70 100644 --- a/Editor/OceanWindow.cpp +++ b/Editor/OceanWindow.cpp @@ -157,8 +157,7 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) if (wiRenderer::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; - XMFLOAT3 col = args.color.toFloat3(); - weather.oceanParameters.waterColor = XMFLOAT3(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f)); + weather.oceanParameters.waterColor = args.color.toFloat3(); } }); oceanWindow->AddWidget(colorPicker); diff --git a/WickedEngine/ArchiveVersionHistory.txt b/WickedEngine/ArchiveVersionHistory.txt index 61311f807..6269eff70 100644 --- a/WickedEngine/ArchiveVersionHistory.txt +++ b/WickedEngine/ArchiveVersionHistory.txt @@ -1,6 +1,7 @@ This file contains changelog of wiArchive versions -24: emissive map moved to separate texture (non-grayscale) +25: emissiveColor separated from baseColor +24: emissive map moved to separate texture (non-grayscale) 23: serialize lightmap atlas per object 22: rewrite all systems --VERSION_BARRIER------------------ diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index 144a25165..732699219 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -226,14 +226,17 @@ CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) CBUFFER(MaterialCB, CBSLOT_RENDERER_MATERIAL) { float4 g_xMat_baseColor; + float4 g_xMat_emissiveColor; float4 g_xMat_texMulAdd; + float g_xMat_roughness; float g_xMat_reflectance; float g_xMat_metalness; - float g_xMat_emissive; float g_xMat_refractionIndex; + float g_xMat_subsurfaceScattering; float g_xMat_normalMapStrength; + float g_xMat_normalMapFlip; float g_xMat_parallaxOcclusionMapping; }; diff --git a/WickedEngine/ShaderInterop_TracedRendering.h b/WickedEngine/ShaderInterop_TracedRendering.h index a7ea5c575..f12fae4ce 100644 --- a/WickedEngine/ShaderInterop_TracedRendering.h +++ b/WickedEngine/ShaderInterop_TracedRendering.h @@ -28,14 +28,17 @@ struct TracedRenderingStoredRay struct TracedRenderingMaterial { float4 baseColor; + float4 emissiveColor; float4 texMulAdd; + float roughness; float reflectance; float metalness; - float emissive; float refractionIndex; + float subsurfaceScattering; float normalMapStrength; + float normalMapFlip; float parallaxOcclusionMapping; float4 baseColorAtlasMulAdd; diff --git a/WickedEngine/brdf.hlsli b/WickedEngine/brdf.hlsli index 49891dfaf..af609559c 100644 --- a/WickedEngine/brdf.hlsli +++ b/WickedEngine/brdf.hlsli @@ -83,7 +83,7 @@ struct Surface float roughness; // roughness: [0:smooth -> 1:rough] (linear) float metalness; // metalness [0:dielectric -> 1:metal] float reflectance; // reflectivity [0:diffuse -> 1:specular] - float3 emissive; // light emission [0 -> 1] + float4 emissiveColor; // light emission [0 -> 1] float sss; // subsurface scattering [0 -> 1] float roughness_brdf; // roughness remapped from linear to BRDF @@ -116,7 +116,7 @@ inline Surface CreateSurface( in float roughness, in float metalness, in float reflectance, - in float3 emissive = 0, + in float4 emissiveColor = 0, in float sss = 0) { Surface surface; @@ -129,7 +129,7 @@ inline Surface CreateSurface( surface.roughness = roughness; surface.metalness = metalness; surface.reflectance = reflectance; - surface.emissive = emissive; + surface.emissiveColor = emissiveColor; surface.sss = sss; surface.Update(); diff --git a/WickedEngine/captureImpostorPS_albedo.hlsl b/WickedEngine/captureImpostorPS_albedo.hlsl index ddebedb66..0504ac597 100644 --- a/WickedEngine/captureImpostorPS_albedo.hlsl +++ b/WickedEngine/captureImpostorPS_albedo.hlsl @@ -4,10 +4,11 @@ float4 main(PixelInputType input) : SV_Target0 { float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; - float4 color = g_xMat_baseColor * xBaseColorMap.Sample(sampler_objectshader, UV); + float4 color = xBaseColorMap.Sample(sampler_objectshader, UV); + color.rgb = DEGAMMA(color.rgb); + color *= g_xMat_baseColor; ALPHATEST(color.a); color.a = 1; - color.rgb = DEGAMMA(color.rgb); return color; } diff --git a/WickedEngine/deferredLightHF.hlsli b/WickedEngine/deferredLightHF.hlsli index a58456775..5953140ee 100644 --- a/WickedEngine/deferredLightHF.hlsli +++ b/WickedEngine/deferredLightHF.hlsli @@ -28,19 +28,14 @@ struct LightOutputType 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]; \ - float4 baseColor = float4(g0.rgb, 1); \ - float ao = g0.a; \ float4 g1 = texture_gbuffer1[PSIn.pos.xy]; \ float4 g2 = texture_gbuffer2[PSIn.pos.xy]; \ float3 N = decode(g1.xy); \ float2 velocity = g1.zw; \ - float roughness = g2.x; \ - float reflectance = g2.y; \ - float metalness = g2.z; \ float2 ReprojectedScreenCoord = ScreenCoord + velocity; \ float3 P = getPosition(ScreenCoord, depth); \ float3 V = normalize(g_xCamera_CamPos - P); \ - Surface surface = CreateSurface(P, N, V, baseColor, ao, roughness, metalness, reflectance); + Surface surface = CreateSurface(P, N, V, float4(g0.rgb, 1), g2.r, g2.g, g2.b, g2.a); #define DEFERREDLIGHT_DIRECTIONAL \ diff --git a/WickedEngine/deferredPS.hlsl b/WickedEngine/deferredPS.hlsl index 16ee49f5a..a8a5d936c 100644 --- a/WickedEngine/deferredPS.hlsl +++ b/WickedEngine/deferredPS.hlsl @@ -9,19 +9,16 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET { - float4 color = texture_gbuffer0[uint2(PSIn.pos.xy)]; - - float4 g2 = texture_gbuffer2[int2(PSIn.pos.xy)]; - float roughness = g2.x; - float reflectance = g2.y; - float metalness = g2.z; - float3 albedo = ComputeAlbedo(color, metalness, reflectance); + float4 g0 = texture_gbuffer0[PSIn.pos.xy]; + float4 g2 = texture_gbuffer2[PSIn.pos.xy]; + float3 albedo = ComputeAlbedo(float4(g0.rgb, 1), g2.b, g2.a); 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 - color.rgb = diffuse.rgb * albedo + specular.rgb; + + float4 color = float4(diffuse.rgb * albedo + specular.rgb, 1); ApplyFog(depth, color); diff --git a/WickedEngine/environmentalLightPS.hlsl b/WickedEngine/environmentalLightPS.hlsl index 89301701a..85223bded 100644 --- a/WickedEngine/environmentalLightPS.hlsl +++ b/WickedEngine/environmentalLightPS.hlsl @@ -8,11 +8,11 @@ LightOutputType main(VertexToPixel PSIn) DEFERREDLIGHT_MAKEPARAMS diffuse = 0; - float envMapMIP = roughness * g_xFrame_EnvProbeMipCount; + float envMapMIP = surface.roughness * g_xFrame_EnvProbeMipCount; specular = max(0, EnvironmentReflection_Global(surface, envMapMIP)); VoxelGI(surface, diffuse, specular); - float3 ambient = GetAmbient(N) * ao; + float3 ambient = GetAmbient(N) * surface.ao; diffuse += ambient; float4 ssr = xSSR.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0); diff --git a/WickedEngine/hairparticlePS_deferred.hlsl b/WickedEngine/hairparticlePS_deferred.hlsl index b6b317e1e..a3d159bee 100644 --- a/WickedEngine/hairparticlePS_deferred.hlsl +++ b/WickedEngine/hairparticlePS_deferred.hlsl @@ -10,9 +10,9 @@ GBUFFEROutputType main(VertexToPixel input) #endif float4 color = texture_0.Sample(sampler_linear_clamp, input.tex); + color.rgb = DEGAMMA(color.rgb); color.rgb *= input.color; ALPHATEST(color.a) - color = DEGAMMA(color); float emissive = 0; Surface surface = CreateSurface(0, input.nor, 0, color, 1, 1, 0, 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); diff --git a/WickedEngine/hairparticlePS_forward.hlsl b/WickedEngine/hairparticlePS_forward.hlsl index a88ba4995..c44cb9c02 100644 --- a/WickedEngine/hairparticlePS_forward.hlsl +++ b/WickedEngine/hairparticlePS_forward.hlsl @@ -10,10 +10,10 @@ GBUFFEROutputType_Thin main(VertexToPixel input) #endif float4 color = texture_0.Sample(sampler_linear_clamp, input.tex); + color.rgb = DEGAMMA(color.rgb); color.rgb *= input.color; ALPHATEST(color.a) float opacity = 1; // keep edge diffuse shading - color.rgb = DEGAMMA(color.rgb); float3 V = g_xCamera_CamPos - input.pos3D; float dist = length(V); V /= dist; diff --git a/WickedEngine/hairparticlePS_tiledforward.hlsl b/WickedEngine/hairparticlePS_tiledforward.hlsl index fa249e3b8..ed3fae8d4 100644 --- a/WickedEngine/hairparticlePS_tiledforward.hlsl +++ b/WickedEngine/hairparticlePS_tiledforward.hlsl @@ -9,11 +9,11 @@ GBUFFEROutputType_Thin main(VertexToPixel input) { float4 color = texture_0.Sample(sampler_linear_wrap, input.tex); + color.rgb = DEGAMMA(color.rgb); color.rgb *= input.color; color.a *= 1.0 - input.fade; - clip(color.a - 1.0f / 256.0f); // cancel heaviest overdraw for the alpha composition effect + clip(color.a - 1.0f / 255.0f); // cancel heaviest overdraw for the alpha composition effect float opacity = 1; - color.rgb = DEGAMMA(color.rgb); float3 V = g_xCamera_CamPos - input.pos3D; float dist = length(V); V /= dist; diff --git a/WickedEngine/lightCullingCS.hlsl b/WickedEngine/lightCullingCS.hlsl index c095b730c..3ca1ddb19 100644 --- a/WickedEngine/lightCullingCS.hlsl +++ b/WickedEngine/lightCullingCS.hlsl @@ -334,17 +334,12 @@ void main(ComputeShaderInput IN) float3 diffuse = 0, specular = 0; float3 reflection = 0; float4 g0 = texture_gbuffer0[pixel]; - float4 baseColor = float4(g0.rgb, 1); - float ao = g0.a; float4 g1 = texture_gbuffer1[pixel]; float4 g2 = texture_gbuffer2[pixel]; float3 N = decode(g1.xy); - float roughness = g2.x; - float reflectance = g2.y; - float metalness = g2.z; float3 P = getPosition((float2)pixel * g_xFrame_InternalResolution_Inverse, depth[granularity]); float3 V = normalize(g_xFrame_MainCamera_CamPos - P); - Surface surface = CreateSurface(P, N, V, baseColor, ao, roughness, metalness, reflectance); + Surface surface = CreateSurface(P, N, V, float4(g0.rgb, 1), g2.r, g2.g, g2.b, g2.a); #ifndef DISABLE_ENVMAPS // Apply environment maps: @@ -510,7 +505,7 @@ void main(ComputeShaderInput IN) specular += reflection * surface.F; - float3 ambient = GetAmbient(N) * ao; + float3 ambient = GetAmbient(N) * surface.ao; diffuse += ambient; deferred_Diffuse[pixel] += float4(diffuse, 1); diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index 3e81bdb60..b05ae2a02 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -695,7 +695,7 @@ inline LightingResult TubeLight(in ShaderEntityType light, in Surface surface) // VOXEL RADIANCE -inline void VoxelGI(in Surface surface, inout float3 diffuse, inout float3 specular) +inline void VoxelGI(inout Surface surface, inout float3 diffuse, inout float3 specular) { [branch]if (g_xFrame_VoxelRadianceDataRes != 0) { diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index bb86a0f8c..d6c4fc999 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -36,7 +36,7 @@ #define xNormalMap texture_1 // rgb: normal #define xSurfaceMap texture_2 // r: ao, g: roughness, b: metallic, a: reflectance #define xDisplacementMap texture_3 // r: heightmap -#define xEmissiveMap texture_4 // rgb: emissive +#define xEmissiveMap texture_4 // rgba: emissive // These are bound by RenderPath (based on Render Path): #define xReflection texture_6 // rgba: scene color from reflected camera angle @@ -81,9 +81,9 @@ 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.ao); /*FORMAT_R8G8B8A8_UNORM*/ + Out.g0 = float4(color.rgb, surface.sss); /*FORMAT_R8G8B8A8_UNORM*/ Out.g1 = float4(encode(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ - Out.g2 = float4(surface.roughness, surface.reflectance, surface.metalness, surface.sss); /*FORMAT_R8G8B8A8_UNORM*/ + 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*/ return Out; @@ -108,7 +108,7 @@ inline GBUFFEROutputType_Thin CreateGbuffer_Thin(in float4 color, in Surface sur inline void ApplyEmissive(in Surface surface, inout float3 specular) { - specular += surface.emissive; + 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) @@ -128,7 +128,8 @@ inline void LightMapping(in float2 ATLAS, inout float3 diffuse, inout float3 spe inline void NormalMapping(in float2 UV, in float3 V, inout float3 N, in float3x3 TBN, inout float3 bumpColor) { float3 normalMap = xNormalMap.Sample(sampler_objectshader, UV).rgb; - bumpColor = 2.0f * normalMap.rgb - 1.0f; + bumpColor = normalMap.rgb * 2 - 1; + bumpColor.g *= g_xMat_normalMapFlip; N = normalize(lerp(N, mul(bumpColor, TBN), g_xMat_normalMapStrength)); bumpColor *= g_xMat_normalMapStrength; } @@ -145,9 +146,9 @@ inline void SpecularAA(in float3 N, inout float roughness) } } -inline float3 PlanarReflection(in float2 reflectionUV, in Surface surface) +inline float3 PlanarReflection(in float2 reflectionUV, in float2 bumpColor) { - return xReflection.SampleLevel(sampler_linear_clamp, reflectionUV + surface.N.xz*g_xMat_normalMapStrength, 0).rgb; + return xReflection.SampleLevel(sampler_linear_clamp, reflectionUV + bumpColor*g_xMat_normalMapStrength, 0).rgb; } #define NUM_PARALLAX_OCCLUSION_STEPS 32 @@ -751,8 +752,9 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) ParallaxOcclusionMapping(UV, surface.V, TBN); #endif // POM - float4 color = g_xMat_baseColor * float4(input.instanceColor, 1) * xBaseColorMap.Sample(sampler_objectshader, UV); + float4 color = xBaseColorMap.Sample(sampler_objectshader, UV); color.rgb = DEGAMMA(color.rgb); + color *= g_xMat_baseColor * float4(input.instanceColor, 1); ALPHATEST(color.a); #ifndef SIMPLE_INPUT @@ -784,7 +786,18 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #endif // NORMALMAP float4 surface_ao_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV); - float3 emissive = DEGAMMA(g_xMat_baseColor.rgb * xEmissiveMap.Sample(sampler_objectshader, UV).rgb); + float4 emissiveColor; + [branch] + if (g_xMat_emissiveColor.a > 0) + { + emissiveColor = xEmissiveMap.Sample(sampler_objectshader, UV); + emissiveColor.rgb = DEGAMMA(emissiveColor.rgb); + emissiveColor *= g_xMat_emissiveColor; + } + else + { + emissiveColor = 0; + } surface = CreateSurface( surface.P, @@ -795,7 +808,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) 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, - g_xMat_emissive * emissive, + emissiveColor, g_xMat_subsurfaceScattering ); @@ -854,7 +867,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #ifdef PLANARREFLECTION - specular += PlanarReflection(refUV, surface) * surface.F; + specular += PlanarReflection(refUV, bumpColor.rg) * surface.F; #endif @@ -876,7 +889,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) VoxelGI(surface, diffuse, reflection); #ifdef PLANARREFLECTION - reflection = PlanarReflection(refUV, surface); + reflection = PlanarReflection(refUV, bumpColor.rg); #endif @@ -908,7 +921,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #ifdef TEXTUREONLY - color.rgb += color.rgb * surface.emissive; + color.rgb += surface.emissiveColor.rgb * surface.emissiveColor.a; #endif // TEXTUREONLY diff --git a/WickedEngine/objectPS_hologram.hlsl b/WickedEngine/objectPS_hologram.hlsl index 16017ac27..325497db8 100644 --- a/WickedEngine/objectPS_hologram.hlsl +++ b/WickedEngine/objectPS_hologram.hlsl @@ -5,9 +5,9 @@ float4 main(PixelInputType input) : SV_TARGET float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; float4 color = xBaseColorMap.Sample(sampler_objectshader, UV); + color.rgb = DEGAMMA(color.rgb); color.rgb = max(color.r, max(color.g, color.b)); color *= g_xMat_baseColor * float4(input.instanceColor, 1); - color.rgb = DEGAMMA(color.rgb); float time = g_xFrame_Time; diff --git a/WickedEngine/objectPS_voxelizer.hlsl b/WickedEngine/objectPS_voxelizer.hlsl index 75e12e6ae..932afb108 100644 --- a/WickedEngine/objectPS_voxelizer.hlsl +++ b/WickedEngine/objectPS_voxelizer.hlsl @@ -11,9 +11,22 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl [branch] if (is_saturated(uvw)) { - float4 baseColor = DEGAMMA(g_xMat_baseColor * float4(instanceColor, 1) * xBaseColorMap.Sample(sampler_linear_wrap, tex)); + float4 baseColor = xBaseColorMap.Sample(sampler_linear_wrap, tex); + baseColor.rgb = DEGAMMA(baseColor.rgb); + baseColor *= g_xMat_baseColor * float4(instanceColor, 1); float4 color = baseColor; - float3 emissive = g_xMat_emissive * DEGAMMA(xEmissiveMap.Sample(sampler_linear_wrap, tex).rgb); + float4 emissiveColor; + [branch] + if (g_xMat_emissiveColor.a > 0) + { + emissiveColor = xEmissiveMap.Sample(sampler_linear_wrap, tex); + emissiveColor.rgb = DEGAMMA(emissiveColor.rgb); + emissiveColor *= g_xMat_emissiveColor; + } + else + { + emissiveColor = 0; + } // fake normals are good enough because it's only coarse diffuse light, no need to normalize: // (just uncomment if there are any noticable artifacts) @@ -152,7 +165,7 @@ void main(float4 pos : SV_POSITION, float3 N : NORMAL, float2 tex : TEXCOORD, fl color.rgb *= diffuse; - color.rgb += baseColor.rgb * emissive; + color.rgb += emissiveColor.rgb * emissiveColor.a; uint color_encoded = EncodeColor(color); uint normal_encoded = EncodeNormal(N); diff --git a/WickedEngine/oceanSurfacePS.hlsl b/WickedEngine/oceanSurfacePS.hlsl index efa6c19f4..60f6bc491 100644 --- a/WickedEngine/oceanSurfacePS.hlsl +++ b/WickedEngine/oceanSurfacePS.hlsl @@ -15,7 +15,6 @@ float4 main(PSIn input) : SV_TARGET float4 color = float4(xOceanWaterColor, 1); float opacity = 1; // keep edge diffuse shading - color.rgb = DEGAMMA(color.rgb); float3 V = g_xCamera_CamPos - input.pos3D; float dist = length(V); V /= dist; diff --git a/WickedEngine/raySceneIntersectHF.hlsli b/WickedEngine/raySceneIntersectHF.hlsli index 57232175d..03212ae29 100644 --- a/WickedEngine/raySceneIntersectHF.hlsli +++ b/WickedEngine/raySceneIntersectHF.hlsli @@ -298,14 +298,27 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2 hit.UV = frac(hit.UV); // emulate wrap float4 baseColorMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, hit.UV * mat.baseColorAtlasMulAdd.xy + mat.baseColorAtlasMulAdd.zw, 0); float4 surfaceMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, hit.UV * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); - float3 emissiveMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, hit.UV * mat.emissiveMapAtlasMulAdd.xy + mat.emissiveMapAtlasMulAdd.zw, 0).rgb; - float4 baseColor = DEGAMMA(mat.baseColor * baseColorMap); + float4 baseColor = baseColorMap; + baseColor.rgb = DEGAMMA(baseColor.rgb); + baseColor *= mat.baseColor; float roughness = mat.roughness * surfaceMap.g; float metalness = mat.metalness * surfaceMap.b; float reflectance = mat.reflectance * surfaceMap.a; roughness = sqr(roughness); // convert linear roughness to cone aperture - float3 emissive = mat.emissive * DEGAMMA(mat.baseColor.rgb * emissiveMap); + float4 emissiveColor; + [branch] + if (mat.emissiveColor.a > 0) + { + emissiveColor = materialTextureAtlas.SampleLevel(sampler_linear_clamp, hit.UV * mat.emissiveMapAtlasMulAdd.xy + mat.emissiveMapAtlasMulAdd.zw, 0); + emissiveColor.rgb = DEGAMMA(emissiveColor.rgb); + emissiveColor *= mat.emissiveColor; + } + else + { + emissiveColor = 0; + } + // Calculate chances of reflection types: @@ -358,7 +371,7 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2 ray.bary = hit.bary; ray.Update(); - return emissive; + return emissiveColor.rgb * emissiveColor.a; } else { diff --git a/WickedEngine/raytrace_lightsamplingCS.hlsl b/WickedEngine/raytrace_lightsamplingCS.hlsl index 870dc20dd..6322850a5 100644 --- a/WickedEngine/raytrace_lightsamplingCS.hlsl +++ b/WickedEngine/raytrace_lightsamplingCS.hlsl @@ -53,15 +53,15 @@ void main( uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) UV = frac(UV); // emulate wrap float4 baseColorMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV * mat.baseColorAtlasMulAdd.xy + mat.baseColorAtlasMulAdd.zw, 0); float4 surfaceMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0); - float3 emissiveMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV * mat.emissiveMapAtlasMulAdd.xy + mat.emissiveMapAtlasMulAdd.zw, 0).rgb; - float4 baseColor = DEGAMMA(mat.baseColor * baseColorMap); + float4 baseColor = baseColorMap; + baseColor.rgb = DEGAMMA(baseColor.rgb); + baseColor *= mat.baseColor; float roughness = mat.roughness * surfaceMap.g; float metalness = mat.metalness * surfaceMap.b; float reflectance = mat.reflectance * surfaceMap.a; - float3 emissive = mat.emissive * DEGAMMA(mat.baseColor.rgb * emissiveMap); - Surface surface = CreateSurface(P, N, V, baseColor, 1, roughness, metalness, reflectance, emissive); + Surface surface = CreateSurface(P, N, V, baseColor, 1, roughness, metalness, reflectance); [loop] for (uint iterator = 0; iterator < g_xFrame_LightArrayCount; iterator++) diff --git a/WickedEngine/shadowPS_transparent.hlsl b/WickedEngine/shadowPS_transparent.hlsl index aeca0f6a5..ddf011ac9 100644 --- a/WickedEngine/shadowPS_transparent.hlsl +++ b/WickedEngine/shadowPS_transparent.hlsl @@ -17,8 +17,9 @@ float4 main(VertextoPixel input) : SV_TARGET float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; - float4 color = g_xMat_baseColor * float4(input.instanceColor, 1) * xBaseColorMap.Sample(sampler_objectshader, UV); + float4 color = xBaseColorMap.Sample(sampler_objectshader, UV); color.rgb = DEGAMMA(color.rgb); + color *= g_xMat_baseColor * float4(input.instanceColor, 1); ALPHATEST(color.a); float opacity = color.a; diff --git a/WickedEngine/shadowPS_water.hlsl b/WickedEngine/shadowPS_water.hlsl index 3887efa1a..38356d235 100644 --- a/WickedEngine/shadowPS_water.hlsl +++ b/WickedEngine/shadowPS_water.hlsl @@ -17,8 +17,9 @@ float4 main(VertextoPixel input) : SV_TARGET float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; - float4 color = g_xMat_baseColor * float4(input.instanceColor, 1) * xBaseColorMap.Sample(sampler_objectshader, UV); + float4 color = xBaseColorMap.Sample(sampler_objectshader, UV); color.rgb = DEGAMMA(color.rgb); + color *= g_xMat_baseColor * float4(input.instanceColor, 1); ALPHATEST(color.a); float opacity = color.a; diff --git a/WickedEngine/skyPS_static.hlsl b/WickedEngine/skyPS_static.hlsl index 36ced2eef..589f09474 100644 --- a/WickedEngine/skyPS_static.hlsl +++ b/WickedEngine/skyPS_static.hlsl @@ -15,7 +15,7 @@ GBUFFEROutputType_Thin main(VSOut input) float4 color = float4(DEGAMMA_SKY(texture_globalenvmap.SampleLevel(sampler_linear_clamp, normal, 0).rgb), 1); 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); - GBUFFEROutputType_Thin Out = (GBUFFEROutputType_Thin)0; + GBUFFEROutputType_Thin Out; Out.g0 = color; Out.g1 = float4(0, 0, velocity); return Out; diff --git a/WickedEngine/ssss.hlsl b/WickedEngine/ssss.hlsl index 8745c8e0c..288847dcb 100644 --- a/WickedEngine/ssss.hlsl +++ b/WickedEngine/ssss.hlsl @@ -27,7 +27,7 @@ float4 main(VertexToPixelPostProcess input) : SV_TARGET // Fetch color and linear depth for current pixel: float4 colorM = xTexture.Sample(Sampler, input.tex); float depthM = texture_lineardepth[input.pos.xy]; - float sss = texture_gbuffer2[input.pos.xy].a; + float sss = texture_gbuffer0[input.pos.xy].a; sss *= 0.01f; // Accumulate center sample, multiplying it with its gaussian weight: diff --git a/WickedEngine/wiArchive.cpp b/WickedEngine/wiArchive.cpp index 68e1a6560..8eeb8c232 100644 --- a/WickedEngine/wiArchive.cpp +++ b/WickedEngine/wiArchive.cpp @@ -7,7 +7,7 @@ using namespace std; // this should always be only INCREMENTED and only if a new serialization is implemeted somewhere! -uint64_t __archiveVersion = 24; +uint64_t __archiveVersion = 25; // this is the version number of which below the archive is not compatible with the current version uint64_t __archiveVersionBarrier = 22; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 6cea0ec9f..2b6f99770 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1413,8 +1413,7 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re renderPass == RENDERPASS_TEXTURE || renderPass == RENDERPASS_SHADOW || renderPass == RENDERPASS_SHADOWCUBE || - renderPass == RENDERPASS_DEPTHONLY || - renderPass == RENDERPASS_VOXELIZE; + renderPass == RENDERPASS_DEPTHONLY; // Do we need to compute a light mask for this pass on the CPU? const bool forwardLightmaskRequest = @@ -3803,14 +3802,15 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) const MaterialComponent& material = scene.materials[materialIndex]; materialGPUData.g_xMat_baseColor = material.baseColor; + materialGPUData.g_xMat_emissiveColor = material.emissiveColor; materialGPUData.g_xMat_texMulAdd = material.texMulAdd; materialGPUData.g_xMat_roughness = material.roughness; materialGPUData.g_xMat_reflectance = material.reflectance; materialGPUData.g_xMat_metalness = material.metalness; - materialGPUData.g_xMat_emissive = material.emissive; materialGPUData.g_xMat_refractionIndex = material.refractionIndex; materialGPUData.g_xMat_subsurfaceScattering = material.subsurfaceScattering; materialGPUData.g_xMat_normalMapStrength = (material.normalMap == nullptr ? 0 : material.normalMapStrength); + materialGPUData.g_xMat_normalMapFlip = (material._flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f); materialGPUData.g_xMat_parallaxOcclusionMapping = material.parallaxOcclusionMapping; device->UpdateBuffer(material.constantBuffer.get(), &materialGPUData, threadID); @@ -7176,14 +7176,15 @@ void UpdateGlobalMaterialResources(GRAPHICSTHREAD threadID) // Copy base params: global_material.baseColor = material.baseColor; + global_material.emissiveColor = material.emissiveColor; global_material.texMulAdd = material.texMulAdd; global_material.roughness = material.roughness; global_material.reflectance = material.reflectance; global_material.metalness = material.metalness; - global_material.emissive = material.emissive; global_material.refractionIndex = material.refractionIndex; global_material.subsurfaceScattering = material.subsurfaceScattering; global_material.normalMapStrength = material.normalMapStrength; + global_material.normalMapFlip = (material._flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f); global_material.parallaxOcclusionMapping = material.parallaxOcclusionMapping; // Add extended properties: diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 67b5fe7df..f2085e416 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -1817,7 +1817,7 @@ namespace wiSceneSystem const MaterialComponent& material = *materials.GetComponent(entity); decal.color = material.baseColor; - decal.emissive = material.emissive; + decal.emissive = material.emissiveColor.w; decal.texture = material.GetBaseColorMap(); decal.normal = material.GetNormalMap(); }); diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index e51ecd3c2..adc1b9167 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -103,6 +103,7 @@ namespace wiSceneSystem CAST_SHADOW = 1 << 1, PLANAR_REFLECTION = 1 << 2, WATER = 1 << 3, + FLIP_NORMALMAP = 1 << 4, }; uint32_t _flags = DIRTY | CAST_SHADOW; @@ -111,11 +112,11 @@ namespace wiSceneSystem BLENDMODE blendMode = BLENDMODE_OPAQUE; XMFLOAT4 baseColor = XMFLOAT4(1, 1, 1, 1); + XMFLOAT4 emissiveColor = XMFLOAT4(1, 1, 1, 0); XMFLOAT4 texMulAdd = XMFLOAT4(1, 1, 0, 0); float roughness = 0.2f; float reflectance = 0.02f; float metalness = 0.0f; - float emissive = 0.0f; float refractionIndex = 0.0f; float subsurfaceScattering = 0.0f; float normalMapStrength = 1.0f; @@ -158,6 +159,7 @@ namespace wiSceneSystem wiGraphicsTypes::Texture2D* GetEmissiveMap() const; inline float GetOpacity() const { return baseColor.w; } + inline float GetEmissiveStrength() const { return emissiveColor.w; } inline void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } } inline bool IsDirty() const { return _flags & DIRTY; } @@ -171,18 +173,21 @@ namespace wiSceneSystem inline bool HasPlanarReflection() const { return (_flags & PLANAR_REFLECTION) || IsWater(); } inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; } inline bool IsAlphaTestEnabled() const { return alphaRef <= 1.0f - 1.0f / 256.0f; } + inline bool IsFlipNormalMap() const { return _flags & FLIP_NORMALMAP; } inline void SetBaseColor(const XMFLOAT4& value) { SetDirty(); baseColor = value; } + inline void SetEmissiveColor(const XMFLOAT4& value) { SetDirty(); emissiveColor = value; } inline void SetRoughness(float value) { SetDirty(); roughness = value; } inline void SetReflectance(float value) { SetDirty(); reflectance = value; } inline void SetMetalness(float value) { SetDirty(); metalness = value; } - inline void SetEmissive(float value) { SetDirty(); emissive = value; } + inline void SetEmissiveStrength(float value) { SetDirty(); emissiveColor.w = value; } inline void SetRefractionIndex(float value) { SetDirty(); refractionIndex = value; } inline void SetSubsurfaceScattering(float value) { SetDirty(); subsurfaceScattering = value; } inline void SetNormalMapStrength(float value) { SetDirty(); normalMapStrength = value; } inline void SetParallaxOcclusionMapping(float value) { SetDirty(); parallaxOcclusionMapping = value; } inline void SetOpacity(float value) { SetDirty(); baseColor.w = value; } - inline void SetAlphaRef(float value) { alphaRef = value; } + inline void SetAlphaRef(float value) { SetDirty(); alphaRef = value; } + inline void SetFlipNormalMap(bool value) { SetDirty(); if (value) { _flags |= FLIP_NORMALMAP; } else { _flags &= ~FLIP_NORMALMAP; } } void Serialize(wiArchive& archive, uint32_t seed = 0); }; @@ -887,7 +892,7 @@ namespace wiSceneSystem float choppy_scale = 1.3f; - XMFLOAT3 waterColor = XMFLOAT3(powf(0.07f, 1.0f / 2.2f), powf(0.15f, 1.0f / 2.2f), powf(0.2f, 1.0f / 2.2f)); + XMFLOAT3 waterColor = XMFLOAT3(0.07f, 0.15f, 0.2f); float waterHeight = 0.0f; uint32_t surfaceDetail = 4; float surfaceDisplacementTolerance = 2; diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index 83ce05dd3..df42c8ba0 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -85,11 +85,18 @@ namespace wiSceneSystem archive >> userStencilRef; archive >> (uint8_t&)blendMode; archive >> baseColor; + if (archive.GetVersion() >= 25) + { + archive >> emissiveColor; + } archive >> texMulAdd; archive >> roughness; archive >> reflectance; archive >> metalness; - archive >> emissive; + if (archive.GetVersion() < 25) + { + archive >> emissiveColor.w; + } archive >> refractionIndex; archive >> subsurfaceScattering; archive >> normalMapStrength; @@ -140,11 +147,18 @@ namespace wiSceneSystem archive << userStencilRef; archive << (uint8_t)blendMode; archive << baseColor; + if (archive.GetVersion() >= 25) + { + archive << emissiveColor; + } archive << texMulAdd; archive << roughness; archive << reflectance; archive << metalness; - archive << emissive; + if (archive.GetVersion() < 25) + { + archive << emissiveColor.w; + } archive << refractionIndex; archive << subsurfaceScattering; archive << normalMapStrength; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index debbdaa62..7d80cc266 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 24; // minor bug fixes, alterations, refactors, updates - const int revision = 44; + const int revision = 45; long GetVersion() diff --git a/models/lightmap_bake_test.wiscene b/models/lightmap_bake_test.wiscene index 9d293349b40255efbd901974871aa833714328ba..c294a4c3eb17d96cbf81e321009ad9c6f0ee8819 100644 GIT binary patch delta 938 zcmbPmhyCXrc1FpKj5iqT?TlWUGXR0);v*3tI^N}yJBa?##bN}ai(-SKK=cjqQ_3LP zM9SC`MDIC~#s#9++8$H`(Q{M^bV2m|gQ6-RnvFStA4L0XzL^A~H~F=DfoKLPM;#EQ z@%dOikm6-1X|Zqw3AF6Vs-B$6TWDp040D;NBnDiMLCTlT+ z$S5$`1txca$yZ=fiUlO=#iCzNslDtFTj3!|qWdQo2MbQ-WL0Hrum?NdfL(2}AFJKu z1~$&g{A}Elr?X07m*Sr+!79M>^T!Wcr~@1)8?cK^wgc*MXLW_^pUZ|rKlfw>c5G5A zu%rP?3b3e$MKvf2H}7F@;a~x&-0UI{z{&zryLpDFgA@x$_2xVJ2eeo~>YEotZC?<@ zn9#=p(lwpsC8L50EUCeg7Az^jk`5@TOx_SAGCk%cBL@pe^>l|^rg>$U&@ delta 911 zcmex)hke2wc1H1yj5iqTl{q!l7=VCf28$<%cB&T&1JO@69#IC-`Dv59LG)1_E+Y`F zsrWepL@)fjOd3RQU}H1~(T(yOY(R9=udAjYTH0cQ9Ec9=kSqq#>r36ELA0!5qb-Ow zJ;9a-q<9%J_x}h03CwI?l{Gn)$;T7s5}3^}n_woRn}}=x$RG|70R)Vbe=+GZGEUZF z)}OBWicxHGKC={%+rc2ZgEHAwkquUXr36^a!(tj1v!EE;tjf{C!2(jbd96SID+@^NW=1gwDHf3G&8`Lq zv{*pun>nMmb4D{J^s#_+P0xMFsGtH%S+JA@OF6KV0!kUvH@;+)VF9U}e(@!v3kyi? z^pCHAERbr57)U+3EJ7XF6rf%k6LKPR`p4IdTgcN{_?A&-@>v0n>3`oaI33f;a!ud=mT?nDyw+wWP?P}xwnOsr