system updates, fixes

This commit is contained in:
turanszkij
2018-09-28 18:50:37 +01:00
parent 51a4eb2b32
commit c32d5fabc2
23 changed files with 388 additions and 273 deletions
+5
View File
@@ -112,6 +112,11 @@ void AnimationWindow::Update()
Scene& scene = wiRenderer::GetScene();
if (!scene.animations.Contains(entity))
{
entity = INVALID_ENTITY;
}
if (scene.animations.GetCount() == 0)
{
animWindow->SetEnabled(false);
+1
View File
@@ -25,6 +25,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();
camera_transform.MatrixTransform(wiRenderer::GetCamera().GetInvView());
camera_transform.UpdateTransform();
cameraWindow = new wiWindow(GUI, "Camera Window");
cameraWindow->SetSize(XMFLOAT2(600, 420));
+2 -2
View File
@@ -893,7 +893,7 @@ void EditorComponent::Update(float dt)
}
cameraWnd->camera_target.UpdateTransform();
cameraWnd->camera_transform.UpdateParentedTransform(cameraWnd->camera_target);
cameraWnd->camera_transform.UpdateTransform_Parented(cameraWnd->camera_target);
}
// Begin picking:
@@ -1827,7 +1827,7 @@ void EditorComponent::EndTranslate()
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parent->world_parent_inverse_bind);
transform_child->UpdateTransform_Parented(*transform_parent, parent->world_parent_inverse_bind);
}
}
+2 -2
View File
@@ -266,7 +266,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui)
MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity);
if (material != nullptr && args.iValue >= 0)
{
material->blendFlag = static_cast<BLENDMODE>(args.iValue);
material->blendMode = static_cast<BLENDMODE>(args.iValue);
}
});
blendModeComboBox->AddItem("Opaque");
@@ -571,7 +571,7 @@ void MaterialWindow::SetEntity(Entity entity)
alphaRefSlider->SetValue(material->alphaRef);
materialWindow->SetEnabled(true);
colorPicker->SetEnabled(true);
blendModeComboBox->SetSelected((int)material->blendFlag);
blendModeComboBox->SetSelected((int)material->blendMode);
texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName));
texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName));
+60 -25
View File
@@ -1,5 +1,8 @@
#include "stdafx.h"
#include "OceanWindow.h"
#include "wiSceneSystem.h"
using namespace wiSceneSystem;
OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
@@ -21,64 +24,84 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
enabledCheckBox = new wiCheckBox("Ocean simulation enabled: ");
enabledCheckBox->SetPos(XMFLOAT2(x, y += inc));
enabledCheckBox->OnClick([&](wiEventArgs args) {
wiRenderer::SetOceanEnabled(args.bValue, params);
wiRenderer::SetOceanEnabled(args.bValue);
});
enabledCheckBox->SetCheck(wiRenderer::GetOcean() != nullptr);
enabledCheckBox->SetCheck(wiRenderer::GetOceanEnabled());
oceanWindow->AddWidget(enabledCheckBox);
patchSizeSlider = new wiSlider(1, 1000, 1000, 100000, "Patch size: ");
patchSizeSlider->SetSize(XMFLOAT2(100, 30));
patchSizeSlider->SetPos(XMFLOAT2(x, y += inc));
patchSizeSlider->SetValue(params.patch_length);
patchSizeSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.patch_length);
patchSizeSlider->SetTooltip("Adjust water tiling patch size");
patchSizeSlider->OnSlide([&](wiEventArgs args) {
params.patch_length = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck(), params);
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.patch_length = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck());
}
});
oceanWindow->AddWidget(patchSizeSlider);
waveAmplitudeSlider = new wiSlider(0, 1000, 1000, 100000, "Wave amplitude: ");
waveAmplitudeSlider->SetSize(XMFLOAT2(100, 30));
waveAmplitudeSlider->SetPos(XMFLOAT2(x, y += inc));
waveAmplitudeSlider->SetValue(params.wave_amplitude);
waveAmplitudeSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.wave_amplitude);
waveAmplitudeSlider->SetTooltip("Adjust wave size");
waveAmplitudeSlider->OnSlide([&](wiEventArgs args) {
params.wave_amplitude = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck(), params);
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.wave_amplitude = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck());
}
});
oceanWindow->AddWidget(waveAmplitudeSlider);
choppyScaleSlider = new wiSlider(0, 10, 1000, 100000, "Choppiness: ");
choppyScaleSlider->SetSize(XMFLOAT2(100, 30));
choppyScaleSlider->SetPos(XMFLOAT2(x, y += inc));
choppyScaleSlider->SetValue(params.choppy_scale);
choppyScaleSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.choppy_scale);
choppyScaleSlider->SetTooltip("Adjust wave choppiness");
choppyScaleSlider->OnSlide([&](wiEventArgs args) {
params.choppy_scale = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck(), params);
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.choppy_scale = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck());
}
});
oceanWindow->AddWidget(choppyScaleSlider);
windDependencySlider = new wiSlider(0, 1, 1000, 100000, "Wind dependency: ");
windDependencySlider->SetSize(XMFLOAT2(100, 30));
windDependencySlider->SetPos(XMFLOAT2(x, y += inc));
windDependencySlider->SetValue(params.wind_dependency);
windDependencySlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.wind_dependency);
windDependencySlider->SetTooltip("Adjust wind contribution");
windDependencySlider->OnSlide([&](wiEventArgs args) {
params.wind_dependency = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck(), params);
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.wind_dependency = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck());
}
});
oceanWindow->AddWidget(windDependencySlider);
timeScaleSlider = new wiSlider(0, 4, 1000, 100000, "Time scale: ");
timeScaleSlider->SetSize(XMFLOAT2(100, 30));
timeScaleSlider->SetPos(XMFLOAT2(x, y += inc));
timeScaleSlider->SetValue(params.time_scale);
timeScaleSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.time_scale);
timeScaleSlider->SetTooltip("Adjust simulation speed");
timeScaleSlider->OnSlide([&](wiEventArgs args) {
params.time_scale = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck(), params);
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.time_scale = args.fValue;
wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck());
}
});
oceanWindow->AddWidget(timeScaleSlider);
@@ -88,8 +111,11 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
heightSlider->SetValue(0);
heightSlider->SetTooltip("Adjust water level");
heightSlider->OnSlide([&](wiEventArgs args) {
if (wiRenderer::GetOcean() != nullptr)
wiRenderer::GetOcean()->waterHeight = args.fValue;
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.waterHeight = args.fValue;
}
});
oceanWindow->AddWidget(heightSlider);
@@ -99,8 +125,11 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
detailSlider->SetValue(4);
detailSlider->SetTooltip("Adjust surface tessellation resolution. High values can decrease performance.");
detailSlider->OnSlide([&](wiEventArgs args) {
if (wiRenderer::GetOcean() != nullptr)
wiRenderer::GetOcean()->surfaceDetail = (uint32_t)args.iValue;
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.surfaceDetail = (uint32_t)args.iValue;
}
});
oceanWindow->AddWidget(detailSlider);
@@ -110,8 +139,11 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
toleranceSlider->SetValue(2);
toleranceSlider->SetTooltip("Big waves can introduce glitches on screen borders, this can fix that but surface detail will decrease.");
toleranceSlider->OnSlide([&](wiEventArgs args) {
if (wiRenderer::GetOcean() != nullptr)
wiRenderer::GetOcean()->surfaceDisplacementTolerance = args.fValue;
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.surfaceDisplacementTolerance = args.fValue;
}
});
oceanWindow->AddWidget(toleranceSlider);
@@ -122,8 +154,11 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
colorPicker->SetVisible(true);
colorPicker->SetEnabled(true);
colorPicker->OnColorChanged([&](wiEventArgs args) {
if (wiRenderer::GetOcean() != nullptr)
wiRenderer::GetOcean()->waterColor = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f));
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
weather.oceanParameters.waterColor = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f));
}
});
oceanWindow->AddWidget(colorPicker);
-4
View File
@@ -1,7 +1,5 @@
#pragma once
#include "wiOcean.h"
class wiGUI;
class wiWindow;
class wiLabel;
@@ -15,8 +13,6 @@ public:
OceanWindow(wiGUI* gui);
~OceanWindow();
wiOceanParameter params;
wiGUI* GUI;
wiWindow* oceanWindow;
+25 -25
View File
@@ -6,38 +6,38 @@
// Persistent buffers:
// These are bound once and are alive forever
#define CBSLOT_RENDERER_FRAME 1
#define CBSLOT_RENDERER_CAMERA 2
#define CBSLOT_RENDERER_MISC 3
#define CBSLOT_RENDERER_FRAME 0
#define CBSLOT_RENDERER_CAMERA 1
#define CBSLOT_RENDERER_MISC 2
#define CBSLOT_IMAGE_IMAGE 4
#define CBSLOT_IMAGE_POSTPROCESS 5
#define CBSLOT_IMAGE_IMAGE 3
#define CBSLOT_IMAGE_POSTPROCESS 4
#define CBSLOT_API 6
#define CBSLOT_API 5
// On demand buffers:
// These are bound on demand and alive until another is bound at the same slot
#define CBSLOT_RENDERER_MATERIAL 7
#define CBSLOT_RENDERER_CUBEMAPRENDER 8
#define CBSLOT_RENDERER_VOLUMELIGHT 8
#define CBSLOT_RENDERER_LENSFLARE 8
#define CBSLOT_RENDERER_DECAL 8
#define CBSLOT_RENDERER_TESSELLATION 8
#define CBSLOT_RENDERER_DISPATCHPARAMS 8
#define CBSLOT_RENDERER_VOXELIZER 8
#define CBSLOT_RENDERER_TRACED 8
#define CBSLOT_RENDERER_BVH 8
#define CBSLOT_RENDERER_UTILITY 8
#define CBSLOT_RENDERER_MATERIAL 6
#define CBSLOT_RENDERER_CUBEMAPRENDER 7
#define CBSLOT_RENDERER_VOLUMELIGHT 7
#define CBSLOT_RENDERER_LENSFLARE 7
#define CBSLOT_RENDERER_DECAL 7
#define CBSLOT_RENDERER_TESSELLATION 7
#define CBSLOT_RENDERER_DISPATCHPARAMS 7
#define CBSLOT_RENDERER_VOXELIZER 7
#define CBSLOT_RENDERER_TRACED 7
#define CBSLOT_RENDERER_BVH 7
#define CBSLOT_RENDERER_UTILITY 7
#define CBSLOT_OTHER_EMITTEDPARTICLE 8
#define CBSLOT_OTHER_HAIRPARTICLE 8
#define CBSLOT_OTHER_FFTGENERATOR 8
#define CBSLOT_OTHER_OCEAN_SIMULATION_IMMUTABLE 8
#define CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME 9
#define CBSLOT_OTHER_OCEAN_RENDER 8
#define CBSLOT_OTHER_CLOUDGENERATOR 8
#define CBSLOT_OTHER_GPUSORTLIB 9
#define CBSLOT_OTHER_EMITTEDPARTICLE 7
#define CBSLOT_OTHER_HAIRPARTICLE 7
#define CBSLOT_OTHER_FFTGENERATOR 7
#define CBSLOT_OTHER_OCEAN_SIMULATION_IMMUTABLE 7
#define CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME 8
#define CBSLOT_OTHER_OCEAN_RENDER 7
#define CBSLOT_OTHER_CLOUDGENERATOR 7
#define CBSLOT_OTHER_GPUSORTLIB 8
+2 -1
View File
@@ -4,9 +4,10 @@ float4 main(PixelInputType input) : SV_Target0
{
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 = g_xMat_baseColor * xBaseColorMap.Sample(sampler_objectshader, UV);
ALPHATEST(color.a);
color.a = 1;
color.rgb = DEGAMMA(color.rgb);
return color;
}
+8 -3
View File
@@ -3,9 +3,14 @@
struct VSOut
{
float4 pos : SV_POSITION;
float3 tex : TEXCOORD;
nointerpolation float dither : DITHER;
float4 pos : SV_POSITION;
float3 tex : TEXCOORD;
nointerpolation float dither : DITHER;
float3 pos3D : WORLDPOSITION;
uint instanceColor : INSTANCECOLOR;
float3 nor : NORMAL;
float4 pos2D : SCREENPOSITION;
float4 pos2DPrev : SCREENPOSITIONPREV;
};
TEXTURE2DARRAY(impostorTex, float4, TEXSLOT_ONDEMAND0);
+10 -10
View File
@@ -15,19 +15,19 @@ GBUFFEROutputType main(VSOut input)
ALPHATEST(color.a);
float4 normal_roughness = impostorTex.Sample(sampler_linear_clamp, uv_nor);
float4 surface = impostorTex.Sample(sampler_linear_clamp, uv_sur);
float4 surfaceparams = impostorTex.Sample(sampler_linear_clamp, uv_sur);
float3 N = normal_roughness.rgb;
float roughness = normal_roughness.a;
float reflectance = surface.r;
float metalness = surface.g;
float emissive = surface.b;
float reflectance = surfaceparams.r;
float metalness = surfaceparams.g;
float emissive = surfaceparams.b;
GBUFFEROutputType Out;
Out.g0 = float4(color.rgb, 1); /*FORMAT_R8G8B8A8_UNORM*/
Out.g1 = float4(encode(N), 0, 0); /*FORMAT_R16G16B16A16_FLOAT*/
Out.g2 = float4(0, 0, 0, emissive); /*FORMAT_R8G8B8A8_UNORM*/
Out.g3 = float4(roughness, reflectance, metalness, 1); /*FORMAT_R8G8B8A8_UNORM*/
return Out;
Surface surface = CreateSurface(0, input.nor, 0, color, roughness, reflectance, metalness);
surface.emissive = emissive;
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);
}
+30 -4
View File
@@ -1,8 +1,8 @@
#include "globals.hlsli"
#include "impostorHF.hlsli"
#include "ditherHF.hlsli"
#include "objectHF.hlsli"
float4 main(VSOut input) : SV_TARGET
GBUFFEROutputType_Thin main(VSOut input)
{
clip(dither(input.pos.xy + GetTemporalAASampleRotation()) - input.dither);
@@ -14,7 +14,33 @@ float4 main(VSOut input) : SV_TARGET
ALPHATEST(color.a);
float4 normal_roughness = impostorTex.Sample(sampler_linear_clamp, uv_nor);
float4 surface = impostorTex.Sample(sampler_linear_clamp, uv_sur);
float4 surfaceparams = impostorTex.Sample(sampler_linear_clamp, uv_sur);
return color;
float3 N = normal_roughness.rgb;
float roughness = normal_roughness.a;
float reflectance = surfaceparams.r;
float metalness = surfaceparams.g;
float emissive = surfaceparams.b;
float3 V = g_xCamera_CamPos - input.pos3D;
float dist = length(V);
V /= dist;
Surface surface = CreateSurface(input.pos3D, input.nor, V, color, roughness, reflectance, metalness);
float ao = 1;
float sss = 0;
float2 pixel = input.pos.xy;
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);
ApplyLighting(surface, diffuse, specular, ao, color);
ApplyFog(dist, color);
return CreateGbuffer_Thin(color, surface, velocity);
}
+31 -3
View File
@@ -1,7 +1,9 @@
#include "globals.hlsli"
#include "impostorHF.hlsli"
#include "objectHF.hlsli"
float4 main(VSOut input) : SV_TARGET
[earlydepthstencil]
GBUFFEROutputType_Thin main(VSOut input)
{
float3 uv_col = input.tex;
float3 uv_nor = uv_col + impostorCaptureAngles;
@@ -9,7 +11,33 @@ float4 main(VSOut input) : SV_TARGET
float4 color = impostorTex.Sample(sampler_linear_clamp, uv_col);
float4 normal_roughness = impostorTex.Sample(sampler_linear_clamp, uv_nor);
float4 surface = impostorTex.Sample(sampler_linear_clamp, uv_sur);
float4 surfaceparams = impostorTex.Sample(sampler_linear_clamp, uv_sur);
return color;
float3 N = normal_roughness.rgb;
float roughness = normal_roughness.a;
float reflectance = surfaceparams.r;
float metalness = surfaceparams.g;
float emissive = surfaceparams.b;
float3 V = g_xCamera_CamPos - input.pos3D;
float dist = length(V);
V /= dist;
Surface surface = CreateSurface(input.pos3D, input.nor, V, color, roughness, reflectance, metalness);
float ao = 1;
float sss = 0;
float2 pixel = input.pos.xy;
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);
ApplyLighting(surface, diffuse, specular, ao, color);
ApplyFog(dist, color);
return CreateGbuffer_Thin(color, surface, velocity);
}
+12 -7
View File
@@ -3,12 +3,12 @@
#include "objectInputLayoutHF.hlsli"
static const float3 BILLBOARD[] = {
float3(-1, -1, 0), // 0
float3(1, -1, 0), // 1
float3(-1, 1, 0), // 2
float3(-1, 1, 0), // 3
float3(1, -1, 0), // 4
float3(1, 1, 0), // 5
float3(-1, -1, 0),
float3(1, -1, 0),
float3(-1, 1, 0),
float3(-1, 1, 0),
float3(1, -1, 0),
float3(1, 1, 0),
};
RAWBUFFER(instanceBuffer, TEXSLOT_ONDEMAND0);
@@ -45,9 +45,14 @@ VSOut main(uint fakeIndex : SV_VERTEXID)
tex.z += impostorCaptureAngles * angle;
VSOut Out;
Out.pos = mul(mul(float4(pos, 1), WORLD), g_xCamera_VP);
Out.pos3D = mul(float4(pos, 1), WORLD).xyz;
Out.pos = mul(float4(Out.pos3D, 1), g_xCamera_VP);
Out.tex = tex;
Out.dither = instance.color_dither.a;
Out.instanceColor = 0xFFFFFFFF; // todo
Out.nor = face;
Out.pos2D = Out.pos;
Out.pos2DPrev = mul(float4(Out.pos3D, 1), g_xFrame_MainCamera_PrevVP);
return Out;
}
+1 -1
View File
@@ -571,7 +571,7 @@ void wiEmittedParticle::Draw(const CameraComponent& camera, const MaterialCompon
}
else
{
device->BindGraphicsPSO(&PSO[material.blendFlag][shaderType], threadID);
device->BindGraphicsPSO(&PSO[material.blendMode][shaderType], threadID);
device->BindResource(PS, material.GetBaseColorMap(), TEXSLOT_ONDEMAND0, threadID);
}
+2
View File
@@ -324,6 +324,8 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("HairParticle - Draw", threadID);
device->BindStencilRef(STENCILREF_DEFAULT, threadID);
if (wiRenderer::IsWireRender())
{
if (transparent || shaderType == SHADERTYPE_DEPTHONLY)
+33 -32
View File
@@ -106,15 +106,15 @@ void createTextureAndViews(UINT width, UINT height, FORMAT format, Texture2D** p
wiOcean::wiOcean(const wiOceanParameter& params)
wiOcean::wiOcean(const WeatherComponent& weather)
{
m_param = params;
auto& params = weather.oceanParameters;
// Height map H(0)
int height_map_size = (params.dmap_dim + 4) * (params.dmap_dim + 1);
XMFLOAT2* h0_data = new XMFLOAT2[height_map_size * sizeof(XMFLOAT2)];
float* omega_data = new float[height_map_size * sizeof(float)];
initHeightMap(h0_data, omega_data);
initHeightMap(weather, h0_data, omega_data);
int hmap_dim = params.dmap_dim;
int input_full_size = (hmap_dim + 4) * (hmap_dim + 1);
@@ -155,7 +155,7 @@ wiOcean::wiOcean(const wiOceanParameter& params)
// Constant buffers
UINT actual_dim = m_param.dmap_dim;
UINT actual_dim = params.dmap_dim;
UINT input_width = actual_dim + 4;
// We use full sized data here. The value "output_width" should be actual_dim/2+1 though.
UINT output_width = actual_dim;
@@ -205,19 +205,21 @@ wiOcean::~wiOcean()
// Initialize the vector field.
// wlen_x: width of wave tile, in meters
// wlen_y: length of wave tile, in meters
void wiOcean::initHeightMap(XMFLOAT2* out_h0, float* out_omega)
void wiOcean::initHeightMap(const WeatherComponent& weather, XMFLOAT2* out_h0, float* out_omega)
{
auto& params = weather.oceanParameters;
int i, j;
XMFLOAT2 K;
XMFLOAT2 wind_dir;
XMStoreFloat2(&wind_dir, XMVector2Normalize(XMLoadFloat2(&m_param.wind_dir)));
float a = m_param.wave_amplitude * 1e-7f; // It is too small. We must scale it for editing.
float v = m_param.wind_speed;
float dir_depend = m_param.wind_dependency;
XMStoreFloat2(&wind_dir, XMVector2Normalize(XMLoadFloat2(&params.wind_dir)));
float a = params.wave_amplitude * 1e-7f; // It is too small. We must scale it for editing.
float v = params.wind_speed;
float dir_depend = params.wind_dependency;
int height_map_dim = m_param.dmap_dim;
float patch_length = m_param.patch_length;
int height_map_dim = params.dmap_dim;
float patch_length = params.patch_length;
for (i = 0; i <= height_map_dim; i++)
@@ -247,8 +249,10 @@ void wiOcean::initHeightMap(XMFLOAT2* out_h0, float* out_omega)
}
}
void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
void wiOcean::UpdateDisplacementMap(const WeatherComponent& weather, float time, GRAPHICSTHREAD threadID)
{
auto& params = weather.oceanParameters;
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("Ocean Simulation", threadID);
@@ -268,17 +272,17 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
device->BindUAVs(CS, cs0_uavs, 0, ARRAYSIZE(cs0_uavs), threadID);
Ocean_Simulation_PerFrameCB perFrameData;
perFrameData.g_Time = time * m_param.time_scale;
perFrameData.g_ChoppyScale = m_param.choppy_scale;
perFrameData.g_GridLen = m_param.dmap_dim / m_param.patch_length;
perFrameData.g_Time = time * params.time_scale;
perFrameData.g_ChoppyScale = params.choppy_scale;
perFrameData.g_GridLen = params.dmap_dim / params.patch_length;
device->UpdateBuffer(m_pPerFrameCB, &perFrameData, threadID);
device->BindConstantBuffer(CS, m_pImmutableCB, CB_GETBINDSLOT(Ocean_Simulation_ImmutableCB), threadID);
device->BindConstantBuffer(CS, m_pPerFrameCB, CB_GETBINDSLOT(Ocean_Simulation_PerFrameCB), threadID);
// Run the CS
UINT group_count_x = (m_param.dmap_dim + OCEAN_COMPUTE_TILESIZE - 1) / OCEAN_COMPUTE_TILESIZE;
UINT group_count_y = (m_param.dmap_dim + OCEAN_COMPUTE_TILESIZE - 1) / OCEAN_COMPUTE_TILESIZE;
UINT group_count_x = (params.dmap_dim + OCEAN_COMPUTE_TILESIZE - 1) / OCEAN_COMPUTE_TILESIZE;
UINT group_count_y = (params.dmap_dim + OCEAN_COMPUTE_TILESIZE - 1) / OCEAN_COMPUTE_TILESIZE;
device->Dispatch(group_count_x, group_count_y, 1, threadID);
device->UAVBarrier(cs0_uavs, ARRAYSIZE(cs0_uavs), threadID);
@@ -301,7 +305,7 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
device->BindUAVs(CS, cs_uavs, 0, 1, threadID);
GPUResource* cs_srvs[1] = { m_pBuffer_Float_Dxyz };
device->BindResources(CS, cs_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
device->Dispatch(m_param.dmap_dim / OCEAN_COMPUTE_TILESIZE, m_param.dmap_dim / OCEAN_COMPUTE_TILESIZE, 1, threadID);
device->Dispatch(params.dmap_dim / OCEAN_COMPUTE_TILESIZE, params.dmap_dim / OCEAN_COMPUTE_TILESIZE, 1, threadID);
device->UAVBarrier(cs_uavs, ARRAYSIZE(cs_uavs), threadID);
// Update gradient map:
@@ -310,7 +314,7 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
device->BindUAVs(CS, cs_uavs, 0, 1, threadID);
cs_srvs[0] = m_pDisplacementMap;
device->BindResources(CS, cs_srvs, TEXSLOT_ONDEMAND0, 1, threadID);
device->Dispatch(m_param.dmap_dim / OCEAN_COMPUTE_TILESIZE, m_param.dmap_dim / OCEAN_COMPUTE_TILESIZE, 1, threadID);
device->Dispatch(params.dmap_dim / OCEAN_COMPUTE_TILESIZE, params.dmap_dim / OCEAN_COMPUTE_TILESIZE, 1, threadID);
device->UAVBarrier(cs_uavs, ARRAYSIZE(cs_uavs), threadID);
// Unbind
@@ -325,8 +329,10 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
}
void wiOcean::Render(const CameraComponent& camera, float time, GRAPHICSTHREAD threadID)
void wiOcean::Render(const CameraComponent& camera, const WeatherComponent& weather, float time, GRAPHICSTHREAD threadID)
{
auto& params = weather.oceanParameters;
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("Ocean Rendering", threadID);
@@ -343,16 +349,16 @@ void wiOcean::Render(const CameraComponent& camera, float time, GRAPHICSTHREAD t
}
const uint2 dim = uint2(160 * surfaceDetail, 90 * surfaceDetail);
const uint2 dim = uint2(160 * params.surfaceDetail, 90 * params.surfaceDetail);
Ocean_RenderCB cb;
cb.xOceanWaterColor = waterColor;
cb.xOceanTexelLength = m_param.patch_length / m_param.dmap_dim;
cb.xOceanWaterColor = params.waterColor;
cb.xOceanTexelLength = params.patch_length / params.dmap_dim;
cb.xOceanScreenSpaceParams = XMFLOAT4((float)dim.x, (float)dim.y, 1.0f / (float)dim.x, 1.0f / (float)dim.y);
cb.xOceanPatchSizeRecip = 1.0f / m_param.patch_length;
cb.xOceanMapHalfTexel = 0.5f / m_param.dmap_dim;
cb.xOceanWaterHeight = waterHeight;
cb.xOceanSurfaceDisplacementTolerance = max(1, surfaceDisplacementTolerance);
cb.xOceanPatchSizeRecip = 1.0f / params.patch_length;
cb.xOceanMapHalfTexel = 0.5f / params.dmap_dim;
cb.xOceanWaterHeight = params.waterHeight;
cb.xOceanSurfaceDisplacementTolerance = max(1, params.surfaceDisplacementTolerance);
device->UpdateBuffer(g_pShadingCB, &cb, threadID);
@@ -489,11 +495,6 @@ void wiOcean::CleanUp()
SAFE_DELETE(g_pShadingCB);
}
const wiOceanParameter& wiOcean::getParameters()
{
return m_param;
}
Texture2D* wiOcean::getDisplacementMap()
{
return m_pDisplacementMap;
+4 -60
View File
@@ -8,84 +8,28 @@
#include <vector>
struct wiOceanParameter
{
// Must be power of 2.
int dmap_dim;
// Typical value is 1000 ~ 2000
float patch_length;
// Adjust the time interval for simulation.
float time_scale;
// Amplitude for transverse wave. Around 1.0
float wave_amplitude;
// Wind direction. Normalization not required.
XMFLOAT2 wind_dir;
// Around 100 ~ 1000
float wind_speed;
// This value damps out the waves against the wind direction.
// Smaller value means higher wind dependency.
float wind_dependency;
// The amplitude for longitudinal wave. Must be positive.
float choppy_scale;
wiOceanParameter()
{
// Original version:
//dmap_dim = 512;
//patch_length = 2000.0f;
//time_scale = 0.8f;
//wave_amplitude = 0.35f;
//wind_dir = XMFLOAT2(0.8f, 0.6f);
//wind_speed = 600.0f;
//wind_dependency = 0.07f;
//choppy_scale = 1.3f;
// Scaled version:
dmap_dim = 512;
patch_length = 50.0f;
time_scale = 0.3f;
wave_amplitude = 1000.0f;
wind_dir = XMFLOAT2(0.8f, 0.6f);
wind_speed = 600.0f;
wind_dependency = 0.07f;
choppy_scale = 1.3f;
}
};
class wiOcean
{
public:
wiOcean(const wiOceanParameter& params);
wiOcean(const wiSceneSystem::WeatherComponent& weather);
~wiOcean();
void UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID);
void Render(const wiSceneSystem::CameraComponent& camera, float time, GRAPHICSTHREAD threadID);
void UpdateDisplacementMap(const wiSceneSystem::WeatherComponent& weather, float time, GRAPHICSTHREAD threadID);
void Render(const wiSceneSystem::CameraComponent& camera, const wiSceneSystem::WeatherComponent& weather, float time, GRAPHICSTHREAD threadID);
wiGraphicsTypes::Texture2D* getDisplacementMap();
wiGraphicsTypes::Texture2D* getGradientMap();
const wiOceanParameter& getParameters();
static void Initialize();
static void CleanUp();
static void LoadShaders();
XMFLOAT3 waterColor = XMFLOAT3(powf(0.07f, 1.0f / 2.2f), powf(0.15f, 1.0f / 2.2f), powf(0.2f, 1.0f / 2.2f));
float waterHeight = 0.0f;
uint32_t surfaceDetail = 4;
float surfaceDisplacementTolerance = 2;
protected:
wiOceanParameter m_param;
wiGraphicsTypes::Texture2D* m_pDisplacementMap; // (RGBA32F)
wiGraphicsTypes::Texture2D* m_pGradientMap; // (RGBA16F)
void initHeightMap(XMFLOAT2* out_h0, float* out_omega);
void initHeightMap(const wiSceneSystem::WeatherComponent& weather, XMFLOAT2* out_h0, float* out_omega);
// Initial height field H(0) generated by Phillips spectrum & Gauss distribution.
+54 -61
View File
@@ -1268,14 +1268,15 @@ void RenderMeshes(const XMFLOAT3& eye, const RenderQueue& renderQueue, SHADERTYP
instancedBatchArray[instancedBatchCount - 1].forceAlphatestForDithering = 1;
}
Entity objectEntity = scene.objects.GetEntity(instanceIndex);
const TransformComponent& transform = *scene.transforms.GetComponent(objectEntity);
const TransformComponent& transform = scene.transforms[instance.transformComponentIndex];
// Write into actual GPU-buffer:
if (advancedVBRequest)
{
((volatile InstBuf*)instances)[batchID].instance.Create(transform.world, instance.color, dither);
// The following GetComponent() is going to be a map lookup in this hot loop, but ideally just once per frame per object. Might need to optimize later if it becomes a problem:
Entity objectEntity = scene.objects.GetEntity(instanceIndex);
const PreviousFrameTransformComponent& prev_transform = *scene.prev_transforms.GetComponent(objectEntity);
((volatile InstBuf*)instances)[batchID].instancePrev.Create(prev_transform.world_prev);
}
@@ -1467,12 +1468,11 @@ void RenderMeshes(const XMFLOAT3& eye, const RenderQueue& renderQueue, SHADERTYP
}
boundVBType_Prev = boundVBType;
device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
device->BindStencilRef(material.GetStencilRef(), threadID);
device->BindGraphicsPSO(pso, threadID);
device->BindConstantBuffer(PS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID);
GPUResource* res[] = {
material.GetBaseColorMap(),
material.GetNormalMap(),
@@ -1555,6 +1555,7 @@ void RenderImpostors(const CameraComponent& camera, SHADERTYPE shaderType, GRAPH
}
device->InvalidateBufferAccess(&dynamicVertexBufferPools[threadID], threadID); // close buffer, ready to draw all!
device->BindStencilRef(STENCILREF_DEFAULT, threadID);
device->BindGraphicsPSO(impostorRequest, threadID);
SetAlphaRef(0.75f, threadID);
@@ -3347,7 +3348,7 @@ void UpdatePerFrameData(float dt)
if (ocean != nullptr)
{
requestReflectionRendering = true;
XMVECTOR _refPlane = XMPlaneFromPointNormal(XMVectorSet(0, ocean->waterHeight, 0, 0), XMVectorSet(0, 1, 0, 0));
XMVECTOR _refPlane = XMPlaneFromPointNormal(XMVectorSet(0, scene.weather.oceanParameters.waterHeight, 0, 0), XMVectorSet(0, 1, 0, 0));
XMStoreFloat4(&waterPlane, _refPlane);
}
@@ -3657,14 +3658,12 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
{
MeshComponent& mesh = scene.meshes[i];
if (mesh.IsSkinned())
if (mesh.IsSkinned() && scene.armatures.Contains(mesh.armatureID))
{
ArmatureComponent& armature = *scene.armatures.GetComponent(mesh.armatureID);
if (armature.boneBuffer == nullptr)
{
armature.boneData.resize(armature.boneCollection.size());
GPUBufferDesc bd;
bd.Usage = USAGE_DYNAMIC;
bd.CPUAccessFlags = CPU_ACCESS_WRITE;
@@ -3695,7 +3694,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
CSTYPES targetCS = CSTYPE_SKINNING_LDS;
if (!GetLDSSkinningEnabled() || armature.skinningMatrices.size() > SKINNING_COMPUTE_THREADCOUNT)
if (!GetLDSSkinningEnabled() || armature.boneData.size() > SKINNING_COMPUTE_THREADCOUNT)
{
// If we have more bones that can fit into LDS, we switch to a skinning shader which loads from device memory:
targetCS = CSTYPE_SKINNING;
@@ -3708,10 +3707,6 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
}
// Upload bones for skinning to shader
for (size_t k = 0; k < armature.skinningMatrices.size(); k++)
{
armature.boneData[k].Create(armature.skinningMatrices[k]);
}
device->UpdateBuffer(armature.boneBuffer.get(), armature.boneData.data(), threadID, (int)(sizeof(ArmatureComponent::ShaderBoneType) * armature.boneData.size()));
device->BindResource(CS, armature.boneBuffer.get(), SKINNINGSLOT_IN_BONEBUFFER, threadID);
@@ -3778,7 +3773,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
// Compute water simulation:
if (ocean != nullptr)
{
ocean->UpdateDisplacementMap(renderTime, threadID);
ocean->UpdateDisplacementMap(scene.weather, renderTime, threadID);
}
// Generate cloud layer:
@@ -4902,7 +4897,7 @@ void DrawWorldTransparent(const CameraComponent& camera, SHADERTYPE shaderType,
if (ocean != nullptr)
{
ocean->Render(camera, renderTime, threadID);
ocean->Render(camera, scene.weather, renderTime, threadID);
}
if (grass && GetAlphaCompositionEnabled())
@@ -6852,7 +6847,7 @@ void BuildSceneBVH(GRAPHICSTHREAD threadID)
{
const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
Entity entity = scene.objects.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
const TransformComponent& transform = scene.transforms[object.transformComponentIndex];
BVHCB cb;
cb.xTraceBVHWorld = transform.world;
@@ -7205,19 +7200,17 @@ void DrawTracedScene(const CameraComponent& camera, Texture2D* result, GRAPHICST
{
const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID);
MaterialCB mat;
// Copy base params:
materialArray[totalMaterials].baseColor = mat.g_xMat_baseColor;
materialArray[totalMaterials].texMulAdd = mat.g_xMat_texMulAdd;
materialArray[totalMaterials].roughness = mat.g_xMat_roughness;
materialArray[totalMaterials].reflectance = mat.g_xMat_reflectance;
materialArray[totalMaterials].metalness = mat.g_xMat_metalness;
materialArray[totalMaterials].emissive = mat.g_xMat_emissive;
materialArray[totalMaterials].refractionIndex = mat.g_xMat_refractionIndex;
materialArray[totalMaterials].subsurfaceScattering = mat.g_xMat_subsurfaceScattering;
materialArray[totalMaterials].normalMapStrength = mat.g_xMat_normalMapStrength;
materialArray[totalMaterials].parallaxOcclusionMapping = mat.g_xMat_normalMapStrength;
materialArray[totalMaterials].baseColor = material.baseColor;
materialArray[totalMaterials].texMulAdd = material.texMulAdd;
materialArray[totalMaterials].roughness = material.roughness;
materialArray[totalMaterials].reflectance = material.reflectance;
materialArray[totalMaterials].metalness = material.metalness;
materialArray[totalMaterials].emissive = material.emissive;
materialArray[totalMaterials].refractionIndex = material.refractionIndex;
materialArray[totalMaterials].subsurfaceScattering = material.subsurfaceScattering;
materialArray[totalMaterials].normalMapStrength = material.normalMapStrength;
materialArray[totalMaterials].parallaxOcclusionMapping = material.parallaxOcclusionMapping;
// Add extended properties:
const TextureDesc& desc = atlasTexture->GetDesc();
@@ -7993,7 +7986,7 @@ RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, u
{
const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
const TransformComponent& transform = scene.transforms[object.transformComponentIndex];
const XMMATRIX objectMat = XMLoadFloat4x4(&transform.world);
const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat);
@@ -8001,23 +7994,23 @@ RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, u
const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse);
const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse));
const ArmatureComponent* armature = mesh.IsSkinned() ? scene.armatures.GetComponent(mesh.armatureID) : nullptr;
int subsetCounter = 0;
for (auto& subset : mesh.subsets)
{
for (size_t i = 0; i < subset.indexCount; i += 3)
{
uint32_t i0 = mesh.indices[subset.indexOffset + i + 0];
uint32_t i1 = mesh.indices[subset.indexOffset + i + 1];
uint32_t i2 = mesh.indices[subset.indexOffset + i + 2];
const uint32_t i0 = mesh.indices[subset.indexOffset + i + 0];
const uint32_t i1 = mesh.indices[subset.indexOffset + i + 1];
const uint32_t i2 = mesh.indices[subset.indexOffset + i + 2];
XMVECTOR p0 = XMLoadFloat3(&mesh.vertex_positions[i0]);
XMVECTOR p1 = XMLoadFloat3(&mesh.vertex_positions[i1]);
XMVECTOR p2 = XMLoadFloat3(&mesh.vertex_positions[i2]);
if (mesh.IsSkinned())
if (armature != nullptr)
{
const ArmatureComponent& armature = *scene.armatures.GetComponent(mesh.armatureID);
const XMUINT4& ind0 = mesh.vertex_boneindices[i0];
const XMUINT4& ind1 = mesh.vertex_boneindices[i1];
const XMUINT4& ind2 = mesh.vertex_boneindices[i2];
@@ -8028,24 +8021,24 @@ RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, u
XMMATRIX sump;
sump = XMLoadFloat4x4(&armature.skinningMatrices[ind0.x]) * wei0.x;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind0.y]) * wei0.y;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind0.z]) * wei0.z;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind0.w]) * wei0.w;
sump = armature->boneData[ind0.x].Load() * wei0.x;
sump += armature->boneData[ind0.y].Load() * wei0.y;
sump += armature->boneData[ind0.z].Load() * wei0.z;
sump += armature->boneData[ind0.w].Load() * wei0.w;
p0 = XMVector3Transform(p0, sump);
sump = XMLoadFloat4x4(&armature.skinningMatrices[ind1.x]) * wei1.x;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind1.y]) * wei1.y;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind1.z]) * wei1.z;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind1.w]) * wei1.w;
sump = armature->boneData[ind1.x].Load() * wei1.x;
sump += armature->boneData[ind1.y].Load() * wei1.y;
sump += armature->boneData[ind1.z].Load() * wei1.z;
sump += armature->boneData[ind1.w].Load() * wei1.w;
p1 = XMVector3Transform(p1, sump);
sump = XMLoadFloat4x4(&armature.skinningMatrices[ind2.x]) * wei2.x;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind2.y]) * wei2.y;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind2.z]) * wei2.z;
sump += XMLoadFloat4x4(&armature.skinningMatrices[ind2.w]) * wei2.w;
sump = armature->boneData[ind2.x].Load() * wei2.x;
sump += armature->boneData[ind2.y].Load() * wei2.y;
sump += armature->boneData[ind2.z].Load() * wei2.z;
sump += armature->boneData[ind2.w].Load() * wei2.w;
p2 = XMVector3Transform(p2, sump);
}
@@ -8053,12 +8046,12 @@ RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, u
float distance;
if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, p0, p1, p2, distance))
{
XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat);
const XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat);
distance = wiMath::Distance(pos, rayOrigin);
if (distance < result.distance)
{
XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(p2, p1), XMVectorSubtract(p1, p0))), objectMat));
const XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Cross(XMVectorSubtract(p2, p1), XMVectorSubtract(p1, p0)), objectMat));
result.entity = entity;
XMStoreFloat3(&result.position, pos);
@@ -8097,16 +8090,6 @@ void AddDeferredMIPGen(Texture2D* tex)
void SetOceanEnabled(bool enabled, const wiOceanParameter& params)
{
SAFE_DELETE(ocean);
if (enabled)
{
ocean = new wiOcean(params);
}
}
void SetResolutionScale(float value) { RESOLUTIONSCALE = value; }
@@ -8210,6 +8193,16 @@ void SetEnviromentMap(wiGraphicsTypes::Texture2D* tex) { enviroMap = tex; }
Texture2D* GetEnviromentMap() { return enviroMap; }
void SetGameSpeed(float value) { GameSpeed = max(0, value); }
float GetGameSpeed() { return GameSpeed; }
wiOcean* GetOcean() { return ocean; }
void SetOceanEnabled(bool enabled)
{
SAFE_DELETE(ocean);
if (enabled)
{
Scene& scene = GetScene();
ocean = new wiOcean(scene.weather);
}
}
bool GetOceanEnabled() { return ocean != nullptr; }
}
+2 -4
View File
@@ -5,8 +5,6 @@
#include "wiSceneSystem_Decl.h"
#include "wiECS.h"
class wiOcean;
struct wiOceanParameter;
struct RAY;
namespace wiRenderer
@@ -220,8 +218,8 @@ namespace wiRenderer
const XMFLOAT4& GetWaterPlane();
void SetGameSpeed(float value);
float GetGameSpeed();
void SetOceanEnabled(bool enabled, const wiOceanParameter& params);
wiOcean* GetOcean();
void SetOceanEnabled(bool enabled);
bool GetOceanEnabled();
RAY GetPickRay(long cursorX, long cursorY);
+18 -19
View File
@@ -60,7 +60,7 @@ namespace wiSceneSystem
XMStoreFloat4x4(&world, W);
}
}
void TransformComponent::UpdateParentedTransform(const TransformComponent& parent, const XMFLOAT4X4& inverseParentBindMatrix)
void TransformComponent::UpdateTransform_Parented(const TransformComponent& parent, const XMFLOAT4X4& inverseParentBindMatrix)
{
XMMATRIX W;
@@ -1157,13 +1157,13 @@ namespace wiSceneSystem
names.Create(entity) = name;
emitters.Create(entity);
emitters.Create(entity).count = 10;
TransformComponent& transform = transforms.Create(entity);
transform.Translate(position);
transform.UpdateTransform();
materials.Create(entity).blendFlag = BLENDMODE_ALPHA;
materials.Create(entity).blendMode = BLENDMODE_ALPHA;
return entity;
}
@@ -1224,7 +1224,7 @@ namespace wiSceneSystem
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parentcomponent.world_parent_inverse_bind);
transform_child->UpdateTransform_Parented(*transform_parent, parentcomponent.world_parent_inverse_bind);
}
}
@@ -1406,14 +1406,10 @@ namespace wiSceneSystem
animation.timer += dt;
}
const float animationLength = animation.GetLength();
if (animation.IsLooped() && animation.timer > animationLength)
if (animation.IsLooped() && animation.timer > animation.end)
{
animation.timer = 0.0f;
animation.timer = animation.start;
}
animation.timer = min(animation.timer, animationLength);
}
}
void RunTransformUpdateSystem(ComponentManager<TransformComponent>& transforms)
@@ -1439,7 +1435,7 @@ namespace wiSceneSystem
TransformComponent* transform_parent = transforms.GetComponent(parentcomponent.parentID);
if (transform_child != nullptr && transform_parent != nullptr)
{
transform_child->UpdateParentedTransform(*transform_parent, parentcomponent.world_parent_inverse_bind);
transform_child->UpdateTransform_Parented(*transform_parent, parentcomponent.world_parent_inverse_bind);
}
@@ -1461,9 +1457,9 @@ namespace wiSceneSystem
{
ArmatureComponent& armature = armatures[i];
if (armature.skinningMatrices.size() != armature.boneCollection.size())
if (armature.boneData.size() != armature.boneCollection.size())
{
armature.skinningMatrices.resize(armature.boneCollection.size());
armature.boneData.resize(armature.boneCollection.size());
}
XMMATRIX R = XMLoadFloat4x4(&armature.remapMatrix);
@@ -1477,7 +1473,7 @@ namespace wiSceneSystem
XMMATRIX W = XMLoadFloat4x4(&bone.world);
XMMATRIX M = B * W * R;
XMStoreFloat4x4(&armature.skinningMatrices[boneIndex++], M);
armature.boneData[boneIndex++].Store(M);
}
}
@@ -1544,17 +1540,20 @@ namespace wiSceneSystem
if (object.meshID != INVALID_ENTITY)
{
Entity entity = objects.GetEntity(i);
const TransformComponent* transform = transforms.GetComponent(entity);
object.transformComponentIndex = transforms.GetIndex(entity);
const TransformComponent& transform = transforms[object.transformComponentIndex];
const MeshComponent* mesh = meshes.GetComponent(object.meshID);
if (mesh != nullptr && transform != nullptr)
if (mesh != nullptr)
{
aabb = mesh->aabb.get(transform->world);
aabb = mesh->aabb.get(transform.world);
sceneBounds = AABB::Merge(sceneBounds, aabb);
// This is instance bounding box matrix:
XMFLOAT4X4 meshMatrix;
XMStoreFloat4x4(&meshMatrix, mesh->aabb.getAsBoxMatrix() * XMLoadFloat4x4(&transform->world));
XMStoreFloat4x4(&meshMatrix, mesh->aabb.getAsBoxMatrix() * XMLoadFloat4x4(&transform.world));
// We need sometimes the center of the instance bounding box, not the transform position (which can be outside the bounding box)
object.center = *((XMFLOAT3*)&meshMatrix._41);
@@ -1583,7 +1582,7 @@ namespace wiSceneSystem
{
object.rendertypeMask |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER;
XMVECTOR _refPlane = XMPlaneFromPointNormal(transform->GetPositionV(), XMVectorSet(0, 1, 0, 0));
XMVECTOR _refPlane = XMPlaneFromPointNormal(transform.GetPositionV(), XMVectorSet(0, 1, 0, 0));
XMStoreFloat4(&waterPlane, _refPlane);
}
+55 -7
View File
@@ -66,7 +66,7 @@ namespace wiSceneSystem
XMVECTOR GetRotationV() const;
XMVECTOR GetScaleV() const;
void UpdateTransform();
void UpdateParentedTransform(const TransformComponent& parent, const XMFLOAT4X4& inverseParentBindMatrix = IDENTITYMATRIX);
void UpdateTransform_Parented(const TransformComponent& parent, const XMFLOAT4X4& inverseParentBindMatrix = IDENTITYMATRIX);
void ApplyTransform();
void ClearTransform();
void Translate(const XMFLOAT3& value);
@@ -112,7 +112,7 @@ namespace wiSceneSystem
STENCILREF engineStencilRef = STENCILREF_DEFAULT;
uint8_t userStencilRef = 0;
BLENDMODE blendFlag = BLENDMODE_OPAQUE;
BLENDMODE blendMode = BLENDMODE_OPAQUE;
XMFLOAT4 baseColor = XMFLOAT4(1, 1, 1, 1);
XMFLOAT4 texMulAdd = XMFLOAT4(1, 1, 0, 0);
@@ -409,6 +409,9 @@ namespace wiSceneSystem
float impostorFadeThresholdRadius;
float impostorSwapDistance;
// single frame-lifetime, to directly index transform component:
uint32_t transformComponentIndex;
// occlusion result history bitfield (32 bit->32 frame history)
uint32_t occlusionHistory = ~0;
// occlusion query pool index
@@ -503,7 +506,6 @@ namespace wiSceneSystem
XMFLOAT4X4 remapMatrix = IDENTITYMATRIX; // Use this to eg. mirror the armature
// Non-serialized attributes:
std::vector<XMFLOAT4X4> skinningMatrices;
GFX_STRUCT ShaderBoneType
{
@@ -511,11 +513,22 @@ namespace wiSceneSystem
XMFLOAT4A pose1;
XMFLOAT4A pose2;
void Create(const XMFLOAT4X4& matIn)
inline void Store(const XMMATRIX& M)
{
pose0 = XMFLOAT4A(matIn._11, matIn._21, matIn._31, matIn._41);
pose1 = XMFLOAT4A(matIn._12, matIn._22, matIn._32, matIn._42);
pose2 = XMFLOAT4A(matIn._13, matIn._23, matIn._33, matIn._43);
XMFLOAT4X4 mat;
XMStoreFloat4x4(&mat, M);
pose0 = XMFLOAT4A(mat._11, mat._21, mat._31, mat._41);
pose1 = XMFLOAT4A(mat._12, mat._22, mat._32, mat._42);
pose2 = XMFLOAT4A(mat._13, mat._23, mat._33, mat._43);
}
inline XMMATRIX Load() const
{
return XMMATRIX(
pose0.x, pose1.x, pose2.x, 0,
pose0.y, pose1.y, pose2.y, 0,
pose0.z, pose1.z, pose2.z, 0,
pose0.w, pose1.w, pose2.w, 1
);
}
ALIGN_16
@@ -879,6 +892,12 @@ namespace wiSceneSystem
struct WeatherComponent
{
enum FLAGS
{
EMPTY = 0,
};
uint32_t _flags = EMPTY;
XMFLOAT3 sunColor = XMFLOAT3(0, 0, 0);
XMFLOAT3 sunDirection = XMFLOAT3(0, 1, 0);
XMFLOAT3 horizon = XMFLOAT3(0.0f, 0.0f, 0.0f);
@@ -894,6 +913,35 @@ namespace wiSceneSystem
float windRandomness = 5;
float windWaveSize = 1;
struct OceanParameters
{
// Must be power of 2.
int dmap_dim = 512;
// Typical value is 1000 ~ 2000
float patch_length = 50.0f;
// Adjust the time interval for simulation.
float time_scale = 0.3f;
// Amplitude for transverse wave. Around 1.0
float wave_amplitude = 1000.0f;
// Wind direction. Normalization not required.
XMFLOAT2 wind_dir = XMFLOAT2(0.8f, 0.6f);
// Around 100 ~ 1000
float wind_speed = 600.0f;
// This value damps out the waves against the wind direction.
// Smaller value means higher wind dependency.
float wind_dependency = 0.07f;
// The amplitude for longitudinal wave. Must be positive.
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));
float waterHeight = 0.0f;
uint32_t surfaceDetail = 4;
float surfaceDisplacementTolerance = 2;
};
OceanParameters oceanParameters;
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
+30 -2
View File
@@ -81,7 +81,7 @@ namespace wiSceneSystem
archive >> _flags;
archive >> (uint8_t&)engineStencilRef;
archive >> userStencilRef;
archive >> (uint8_t&)blendFlag;
archive >> (uint8_t&)blendMode;
archive >> baseColor;
archive >> texMulAdd;
archive >> roughness;
@@ -132,7 +132,7 @@ namespace wiSceneSystem
archive << _flags;
archive << (uint8_t)engineStencilRef;
archive << userStencilRef;
archive << (uint8_t)blendFlag;
archive << (uint8_t)blendMode;
archive << baseColor;
archive << texMulAdd;
archive << roughness;
@@ -476,6 +476,7 @@ namespace wiSceneSystem
{
if (archive.IsReadMode())
{
archive >> _flags;
archive >> sunDirection;
archive >> sunColor;
archive >> horizon;
@@ -490,9 +491,23 @@ namespace wiSceneSystem
archive >> windDirection;
archive >> windRandomness;
archive >> windWaveSize;
archive >> oceanParameters.dmap_dim;
archive >> oceanParameters.patch_length;
archive >> oceanParameters.time_scale;
archive >> oceanParameters.wave_amplitude;
archive >> oceanParameters.wind_dir;
archive >> oceanParameters.wind_speed;
archive >> oceanParameters.wind_dependency;
archive >> oceanParameters.choppy_scale;
archive >> oceanParameters.waterColor;
archive >> oceanParameters.waterHeight;
archive >> oceanParameters.surfaceDetail;
archive >> oceanParameters.surfaceDisplacementTolerance;
}
else
{
archive << _flags;
archive << sunDirection;
archive << sunColor;
archive << horizon;
@@ -507,6 +522,19 @@ namespace wiSceneSystem
archive << windDirection;
archive << windRandomness;
archive << windWaveSize;
archive << oceanParameters.dmap_dim;
archive << oceanParameters.patch_length;
archive << oceanParameters.time_scale;
archive << oceanParameters.wave_amplitude;
archive << oceanParameters.wind_dir;
archive << oceanParameters.wind_speed;
archive << oceanParameters.wind_dependency;
archive << oceanParameters.choppy_scale;
archive << oceanParameters.waterColor;
archive << oceanParameters.waterHeight;
archive << oceanParameters.surfaceDetail;
archive << oceanParameters.surfaceDisplacementTolerance;
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ void wiWidget::Update(wiGUI* gui, float dt)
if (parent != nullptr)
{
this->UpdateParentedTransform(*parent, world_parent_bind);
this->UpdateTransform_Parented(*parent, world_parent_bind);
}
XMVECTOR S, R, T;