diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index a12cea86f..325f5f879 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -17,224 +17,270 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); materialWindow = new wiWindow(GUI, "Material Window"); - materialWindow->SetSize(XMFLOAT2(760, 700)); + materialWindow->SetSize(XMFLOAT2(760, 720)); materialWindow->SetEnabled(false); GUI->AddWidget(materialWindow); - //materialNameField = new wiTextInputField("MaterialName"); - //materialNameField->SetPos(XMFLOAT2(10, 30)); - //materialNameField->SetSize(XMFLOAT2(300, 20)); - //materialNameField->OnInputAccepted([&](wiEventArgs args) { - // if (material != nullptr) - // material->name = args.sValue; - //}); - //materialWindow->AddWidget(materialNameField); + materialNameField = new wiTextInputField("MaterialName"); + materialNameField->SetPos(XMFLOAT2(10, 30)); + materialNameField->SetSize(XMFLOAT2(300, 20)); + materialNameField->OnInputAccepted([&](wiEventArgs args) { + NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + if (name != nullptr) + { + *name = args.sValue; + } + }); + materialWindow->AddWidget(materialNameField); - //float x = 540, y = 0; - //float step = 35; + float x = 540, y = 0; + float step = 35; - //waterCheckBox = new wiCheckBox("Water: "); - //waterCheckBox->SetTooltip("Set material as special water material."); - //waterCheckBox->SetPos(XMFLOAT2(570, y += step)); - //waterCheckBox->OnClick([&](wiEventArgs args) { - // if (material != nullptr) - // material->water = args.bValue; - //}); - //materialWindow->AddWidget(waterCheckBox); + waterCheckBox = new wiCheckBox("Water: "); + waterCheckBox->SetTooltip("Set material as special water material."); + waterCheckBox->SetPos(XMFLOAT2(570, y += step)); + waterCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->water = args.bValue; + }); + materialWindow->AddWidget(waterCheckBox); - //planarReflCheckBox = new wiCheckBox("Planar Reflections: "); - //planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); - //planarReflCheckBox->SetPos(XMFLOAT2(570, y += step)); - //planarReflCheckBox->OnClick([&](wiEventArgs args) { - // if (material != nullptr) - // material->planar_reflections = args.bValue; - //}); - //materialWindow->AddWidget(planarReflCheckBox); + planarReflCheckBox = new wiCheckBox("Planar Reflections: "); + planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); + planarReflCheckBox->SetPos(XMFLOAT2(570, y += step)); + planarReflCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->planar_reflections = args.bValue; + }); + materialWindow->AddWidget(planarReflCheckBox); - //shadowCasterCheckBox = new wiCheckBox("Cast Shadow: "); - //shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); - //shadowCasterCheckBox->SetPos(XMFLOAT2(570, y += step)); - //shadowCasterCheckBox->OnClick([&](wiEventArgs args) { - // if (material != nullptr) - // material->cast_shadow = args.bValue; - //}); - //materialWindow->AddWidget(shadowCasterCheckBox); + shadowCasterCheckBox = new wiCheckBox("Cast Shadow: "); + shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); + shadowCasterCheckBox->SetPos(XMFLOAT2(570, y += step)); + shadowCasterCheckBox->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->cast_shadow = args.bValue; + }); + materialWindow->AddWidget(shadowCasterCheckBox); - //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)); - //normalMapSlider->SetPos(XMFLOAT2(x, y += step)); - //normalMapSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->normalMapStrength = args.fValue; - //}); - //materialWindow->AddWidget(normalMapSlider); + 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)); + normalMapSlider->SetPos(XMFLOAT2(x, y += step)); + normalMapSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetNormalMapStrength(args.fValue); + }); + materialWindow->AddWidget(normalMapSlider); - //roughnessSlider = new wiSlider(0, 1, 0.5f, 1000, "Roughness: "); - //roughnessSlider->SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); - //roughnessSlider->SetSize(XMFLOAT2(100, 30)); - //roughnessSlider->SetPos(XMFLOAT2(x, y += step)); - //roughnessSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->roughness = args.fValue; - //}); - //materialWindow->AddWidget(roughnessSlider); + roughnessSlider = new wiSlider(0, 1, 0.5f, 1000, "Roughness: "); + roughnessSlider->SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); + roughnessSlider->SetSize(XMFLOAT2(100, 30)); + roughnessSlider->SetPos(XMFLOAT2(x, y += step)); + roughnessSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetRoughness(args.fValue); + }); + materialWindow->AddWidget(roughnessSlider); - //reflectanceSlider = new wiSlider(0, 1, 0.5f, 1000, "Reflectance: "); - //reflectanceSlider->SetTooltip("Adjust the overall surface reflectivity."); - //reflectanceSlider->SetSize(XMFLOAT2(100, 30)); - //reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); - //reflectanceSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->reflectance = args.fValue; - //}); - //materialWindow->AddWidget(reflectanceSlider); + reflectanceSlider = new wiSlider(0, 1, 0.5f, 1000, "Reflectance: "); + reflectanceSlider->SetTooltip("Adjust the overall surface reflectivity."); + reflectanceSlider->SetSize(XMFLOAT2(100, 30)); + reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); + reflectanceSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetReflectance(args.fValue); + }); + materialWindow->AddWidget(reflectanceSlider); - //metalnessSlider = new wiSlider(0, 1, 0.0f, 1000, "Metalness: "); - //metalnessSlider->SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); - //metalnessSlider->SetSize(XMFLOAT2(100, 30)); - //metalnessSlider->SetPos(XMFLOAT2(x, y += step)); - //metalnessSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->metalness = args.fValue; - //}); - //materialWindow->AddWidget(metalnessSlider); + metalnessSlider = new wiSlider(0, 1, 0.0f, 1000, "Metalness: "); + metalnessSlider->SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); + metalnessSlider->SetSize(XMFLOAT2(100, 30)); + metalnessSlider->SetPos(XMFLOAT2(x, y += step)); + metalnessSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetMetalness(args.fValue); + }); + materialWindow->AddWidget(metalnessSlider); - //alphaSlider = new wiSlider(0, 1, 1.0f, 1000, "Alpha: "); - //alphaSlider->SetTooltip("Adjusts the overall transparency of the surface."); - //alphaSlider->SetSize(XMFLOAT2(100, 30)); - //alphaSlider->SetPos(XMFLOAT2(x, y += step)); - //alphaSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->alpha = args.fValue; - //}); - //materialWindow->AddWidget(alphaSlider); + alphaSlider = new wiSlider(0, 1, 1.0f, 1000, "Alpha: "); + alphaSlider->SetTooltip("Adjusts the overall transparency of the surface."); + alphaSlider->SetSize(XMFLOAT2(100, 30)); + alphaSlider->SetPos(XMFLOAT2(x, y += step)); + alphaSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetOpacity(args.fValue); + }); + materialWindow->AddWidget(alphaSlider); - //alphaRefSlider = new wiSlider(0, 1, 1.0f, 1000, "AlphaRef: "); - //alphaRefSlider->SetTooltip("Adjust the alpha cutoff threshold. This disables some optimizations so performance can be affected."); - //alphaRefSlider->SetSize(XMFLOAT2(100, 30)); - //alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); - //alphaRefSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->alphaRef = args.fValue; - //}); - //materialWindow->AddWidget(alphaRefSlider); + alphaRefSlider = new wiSlider(0, 1, 1.0f, 1000, "AlphaRef: "); + alphaRefSlider->SetTooltip("Adjust the alpha cutoff threshold. This disables some optimizations so performance can be affected."); + alphaRefSlider->SetSize(XMFLOAT2(100, 30)); + alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); + alphaRefSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetAlphaRef(args.fValue); + }); + materialWindow->AddWidget(alphaRefSlider); - //refractionIndexSlider = new wiSlider(0, 1.0f, 0.02f, 1000, "Refraction Index: "); - //refractionIndexSlider->SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object."); - //refractionIndexSlider->SetSize(XMFLOAT2(100, 30)); - //refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); - //refractionIndexSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->refractionIndex = args.fValue; - //}); - //materialWindow->AddWidget(refractionIndexSlider); + refractionIndexSlider = new wiSlider(0, 1.0f, 0.02f, 1000, "Refraction Index: "); + refractionIndexSlider->SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object."); + refractionIndexSlider->SetSize(XMFLOAT2(100, 30)); + refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); + refractionIndexSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetRefractionIndex(args.fValue); + }); + materialWindow->AddWidget(refractionIndexSlider); - //emissiveSlider = new wiSlider(0, 1, 0.0f, 1000, "Emissive: "); - //emissiveSlider->SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); - //emissiveSlider->SetSize(XMFLOAT2(100, 30)); - //emissiveSlider->SetPos(XMFLOAT2(x, y += step)); - //emissiveSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->emissive = args.fValue; - //}); - //materialWindow->AddWidget(emissiveSlider); + emissiveSlider = new wiSlider(0, 1, 0.0f, 1000, "Emissive: "); + emissiveSlider->SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); + emissiveSlider->SetSize(XMFLOAT2(100, 30)); + emissiveSlider->SetPos(XMFLOAT2(x, y += step)); + emissiveSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetEmissive(args.fValue); + }); + materialWindow->AddWidget(emissiveSlider); - //sssSlider = new wiSlider(0, 1, 0.0f, 1000, "Subsurface Scattering: "); - //sssSlider->SetTooltip("Adjust how much the light is scattered when entered inside the surface of the object. (SSS postprocess must be enabled)"); - //sssSlider->SetSize(XMFLOAT2(100, 30)); - //sssSlider->SetPos(XMFLOAT2(x, y += step)); - //sssSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->subsurfaceScattering = args.fValue; - //}); - //materialWindow->AddWidget(sssSlider); + sssSlider = new wiSlider(0, 1, 0.0f, 1000, "Subsurface Scattering: "); + sssSlider->SetTooltip("Adjust how much the light is scattered when entered inside the surface of the object. (SSS postprocess must be enabled)"); + sssSlider->SetSize(XMFLOAT2(100, 30)); + sssSlider->SetPos(XMFLOAT2(x, y += step)); + sssSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetSubsurfaceScattering(args.fValue); + }); + materialWindow->AddWidget(sssSlider); - //pomSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); - //pomSlider->SetTooltip("Adjust how much the bump map should affect the object (slow)."); - //pomSlider->SetSize(XMFLOAT2(100, 30)); - //pomSlider->SetPos(XMFLOAT2(x, y += step)); - //pomSlider->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->parallaxOcclusionMapping = args.fValue; - //}); - //materialWindow->AddWidget(pomSlider); + pomSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); + pomSlider->SetTooltip("Adjust how much the bump map should affect the object (slow)."); + pomSlider->SetSize(XMFLOAT2(100, 30)); + pomSlider->SetPos(XMFLOAT2(x, y += step)); + pomSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->parallaxOcclusionMapping = args.fValue; + }); + materialWindow->AddWidget(pomSlider); - //movingTexSliderU = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); - //movingTexSliderU->SetTooltip("Adjust the texture animation speed along the U direction in texture space."); - //movingTexSliderU->SetSize(XMFLOAT2(100, 30)); - //movingTexSliderU->SetPos(XMFLOAT2(x, y += step)); - //movingTexSliderU->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->movingTex.x = args.fValue; - //}); - //materialWindow->AddWidget(movingTexSliderU); + texAnimFrameRateSlider = new wiSlider(0, 60, 0, 60, "Texcoord anim FPS: "); + texAnimFrameRateSlider->SetTooltip("Adjust the texture animation frame rate (frames per second). Any value above 0 will make the material dynamic."); + texAnimFrameRateSlider->SetSize(XMFLOAT2(100, 30)); + texAnimFrameRateSlider->SetPos(XMFLOAT2(x, y += step)); + texAnimFrameRateSlider->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->texAnimFrameRate = args.fValue; + } + }); + materialWindow->AddWidget(texAnimFrameRateSlider); - //movingTexSliderV = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); - //movingTexSliderV->SetTooltip("Adjust the texture animation speed along the V direction in texture space."); - //movingTexSliderV->SetSize(XMFLOAT2(100, 30)); - //movingTexSliderV->SetPos(XMFLOAT2(x, y += step)); - //movingTexSliderV->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->movingTex.y = args.fValue; - //}); - //materialWindow->AddWidget(movingTexSliderV); + texAnimDirectionSliderU = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); + texAnimDirectionSliderU->SetTooltip("Adjust the texture animation speed along the U direction in texture space."); + texAnimDirectionSliderU->SetSize(XMFLOAT2(100, 30)); + texAnimDirectionSliderU->SetPos(XMFLOAT2(x, y += step)); + texAnimDirectionSliderU->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->texAnimDirection.x = args.fValue; + } + }); + materialWindow->AddWidget(texAnimDirectionSliderU); - //texMulSliderX = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); - //texMulSliderX->SetTooltip("Adjust the texture mapping size."); - //texMulSliderX->SetSize(XMFLOAT2(100, 30)); - //texMulSliderX->SetPos(XMFLOAT2(x, y += step)); - //texMulSliderX->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->texMulAdd.x = args.fValue; - //}); - //materialWindow->AddWidget(texMulSliderX); + texAnimDirectionSliderV = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); + texAnimDirectionSliderV->SetTooltip("Adjust the texture animation speed along the V direction in texture space."); + texAnimDirectionSliderV->SetSize(XMFLOAT2(100, 30)); + texAnimDirectionSliderV->SetPos(XMFLOAT2(x, y += step)); + texAnimDirectionSliderV->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->texAnimDirection.y = args.fValue; + } + }); + materialWindow->AddWidget(texAnimDirectionSliderV); - //texMulSliderY = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); - //texMulSliderY->SetTooltip("Adjust the texture mapping size."); - //texMulSliderY->SetSize(XMFLOAT2(100, 30)); - //texMulSliderY->SetPos(XMFLOAT2(x, y += step)); - //texMulSliderY->OnSlide([&](wiEventArgs args) { - // if (material != nullptr) - // material->texMulAdd.y = args.fValue; - //}); - //materialWindow->AddWidget(texMulSliderY); + texMulSliderX = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); + texMulSliderX->SetTooltip("Adjust the texture mapping size."); + texMulSliderX->SetSize(XMFLOAT2(100, 30)); + texMulSliderX->SetPos(XMFLOAT2(x, y += step)); + texMulSliderX->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->dirty = true; + material->texMulAdd.x = args.fValue; + } + }); + materialWindow->AddWidget(texMulSliderX); + + texMulSliderY = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); + texMulSliderY->SetTooltip("Adjust the texture mapping size."); + texMulSliderY->SetSize(XMFLOAT2(100, 30)); + texMulSliderY->SetPos(XMFLOAT2(x, y += step)); + texMulSliderY->OnSlide([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->dirty = true; + material->texMulAdd.y = args.fValue; + } + }); + 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) { - // if (material != nullptr) - // material->baseColor = 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)); - //}); - //materialWindow->AddWidget(colorPicker); + colorPicker = new wiColorPicker(GUI, "Material Color"); + colorPicker->SetPos(XMFLOAT2(10, 400)); + colorPicker->RemoveWidgets(); + colorPicker->SetVisible(true); + colorPicker->SetEnabled(true); + colorPicker->OnColorChanged([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr) + material->SetBaseColor(XMFLOAT4(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f), material->GetOpacity())); + }); + materialWindow->AddWidget(colorPicker); - //blendModeComboBox = new wiComboBox("Blend mode: "); - //blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); - //blendModeComboBox->SetSize(XMFLOAT2(100, 25)); - //blendModeComboBox->OnSelect([&](wiEventArgs args) { - // if (material != nullptr && args.iValue >= 0) - // { - // material->blendFlag = static_cast(args.iValue); - // } - //}); - //blendModeComboBox->AddItem("Opaque"); - //blendModeComboBox->AddItem("Alpha"); - //blendModeComboBox->AddItem("Premultiplied"); - //blendModeComboBox->AddItem("Additive"); - //blendModeComboBox->SetEnabled(false); - //blendModeComboBox->SetTooltip("Set the blend mode of the material."); - //materialWindow->AddWidget(blendModeComboBox); + blendModeComboBox = new wiComboBox("Blend mode: "); + blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); + blendModeComboBox->SetSize(XMFLOAT2(100, 25)); + blendModeComboBox->OnSelect([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material != nullptr && args.iValue >= 0) + { + material->blendFlag = static_cast(args.iValue); + } + }); + blendModeComboBox->AddItem("Opaque"); + blendModeComboBox->AddItem("Alpha"); + blendModeComboBox->AddItem("Premultiplied"); + blendModeComboBox->AddItem("Additive"); + blendModeComboBox->SetEnabled(false); + blendModeComboBox->SetTooltip("Set the blend mode of the material."); + materialWindow->AddWidget(blendModeComboBox); //shaderTypeComboBox = new wiComboBox("Custom Shader: "); //shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); //shaderTypeComboBox->SetSize(XMFLOAT2(100, 25)); //shaderTypeComboBox->OnSelect([&](wiEventArgs args) { + // MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); // if (material != nullptr) // { // if (args.iValue == 0) @@ -257,212 +303,216 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) //materialWindow->AddWidget(shaderTypeComboBox); - //// Textures: + // Textures: - //x = 10; - //y = 60; + x = 10; + y = 60; - //texture_baseColor_Label = new wiLabel("BaseColorMap: "); - //texture_baseColor_Label->SetPos(XMFLOAT2(x, y += step)); - //texture_baseColor_Label->SetSize(XMFLOAT2(120, 20)); - //materialWindow->AddWidget(texture_baseColor_Label); + texture_baseColor_Label = new wiLabel("BaseColorMap: "); + texture_baseColor_Label->SetPos(XMFLOAT2(x, y += step)); + texture_baseColor_Label->SetSize(XMFLOAT2(120, 20)); + materialWindow->AddWidget(texture_baseColor_Label); - //texture_baseColor_Button = new wiButton("BaseColor"); - //texture_baseColor_Button->SetText(""); - //texture_baseColor_Button->SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); - //texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); - //texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); - //texture_baseColor_Button->OnClick([&](wiEventArgs args) { - // if (material == nullptr) - // return; + texture_baseColor_Button = new wiButton("BaseColor"); + texture_baseColor_Button->SetText(""); + texture_baseColor_Button->SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); + texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); + texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); + texture_baseColor_Button->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material == nullptr) + return; - // if (material->texture != nullptr) - // { - // material->texture = nullptr; - // material->textureName = ""; - // texture_baseColor_Button->SetText(""); - // } - // else - // { - // char szFile[260]; + if (material->baseColorMap != nullptr) + { + material->baseColorMap = nullptr; + material->baseColorMapName = ""; + texture_baseColor_Button->SetText(""); + } + else + { + char szFile[260]; - // OPENFILENAMEA ofn; - // ZeroMemory(&ofn, sizeof(ofn)); - // ofn.lStructSize = sizeof(ofn); - // ofn.hwndOwner = nullptr; - // ofn.lpstrFile = szFile; - // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // // use the contents of szFile to initialize itself. - // ofn.lpstrFile[0] = '\0'; - // ofn.nMaxFile = sizeof(szFile); - // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - // ofn.nFilterIndex = 1; - // ofn.lpstrFileTitle = NULL; - // ofn.nMaxFileTitle = 0; - // ofn.lpstrInitialDir = NULL; - // ofn.Flags = 0; - // if (GetSaveFileNameA(&ofn) == TRUE) { - // string fileName = ofn.lpstrFile; - // material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - // material->textureName = fileName; - // texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); - // } - // } - //}); - //materialWindow->AddWidget(texture_baseColor_Button); + OPENFILENAMEA ofn; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = nullptr; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = 0; + if (GetSaveFileNameA(&ofn) == TRUE) { + string fileName = ofn.lpstrFile; + material->baseColorMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->baseColorMapName = fileName; + texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName)); + } + } + }); + materialWindow->AddWidget(texture_baseColor_Button); - //texture_normal_Label = new wiLabel("NormalMap: "); - //texture_normal_Label->SetPos(XMFLOAT2(x, y += step)); - //texture_normal_Label->SetSize(XMFLOAT2(120, 20)); - //materialWindow->AddWidget(texture_normal_Label); + texture_normal_Label = new wiLabel("NormalMap: "); + texture_normal_Label->SetPos(XMFLOAT2(x, y += step)); + texture_normal_Label->SetSize(XMFLOAT2(120, 20)); + materialWindow->AddWidget(texture_normal_Label); - //texture_normal_Button = new wiButton("NormalMap"); - //texture_normal_Button->SetText(""); - //texture_normal_Button->SetTooltip("Load the normalmap texture. RGB: Normal, A: Roughness"); - //texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); - //texture_normal_Button->SetSize(XMFLOAT2(260, 20)); - //texture_normal_Button->OnClick([&](wiEventArgs args) { - // if (material == nullptr) - // return; + texture_normal_Button = new wiButton("NormalMap"); + texture_normal_Button->SetText(""); + texture_normal_Button->SetTooltip("Load the normalmap texture. RGB: Normal, A: Roughness"); + texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); + texture_normal_Button->SetSize(XMFLOAT2(260, 20)); + texture_normal_Button->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material == nullptr) + return; - // if (material->normalMap != nullptr) - // { - // material->normalMap = nullptr; - // material->normalMapName = ""; - // texture_normal_Button->SetText(""); - // } - // else - // { - // char szFile[260]; + if (material->normalMap != nullptr) + { + material->normalMap = nullptr; + material->normalMapName = ""; + texture_normal_Button->SetText(""); + } + else + { + char szFile[260]; - // OPENFILENAMEA ofn; - // ZeroMemory(&ofn, sizeof(ofn)); - // ofn.lStructSize = sizeof(ofn); - // ofn.hwndOwner = nullptr; - // ofn.lpstrFile = szFile; - // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // // use the contents of szFile to initialize itself. - // ofn.lpstrFile[0] = '\0'; - // ofn.nMaxFile = sizeof(szFile); - // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - // ofn.nFilterIndex = 1; - // ofn.lpstrFileTitle = NULL; - // ofn.nMaxFileTitle = 0; - // ofn.lpstrInitialDir = NULL; - // ofn.Flags = 0; - // if (GetSaveFileNameA(&ofn) == TRUE) { - // string fileName = ofn.lpstrFile; - // material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - // material->normalMapName = fileName; - // texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - // } - // } - //}); - //materialWindow->AddWidget(texture_normal_Button); + OPENFILENAMEA ofn; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = nullptr; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = 0; + if (GetSaveFileNameA(&ofn) == TRUE) { + string fileName = ofn.lpstrFile; + material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->normalMapName = fileName; + texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); + } + } + }); + materialWindow->AddWidget(texture_normal_Button); - //texture_surface_Label = new wiLabel("SurfaceMap: "); - //texture_surface_Label->SetPos(XMFLOAT2(x, y += step)); - //texture_surface_Label->SetSize(XMFLOAT2(120, 20)); - //materialWindow->AddWidget(texture_surface_Label); + texture_surface_Label = new wiLabel("SurfaceMap: "); + texture_surface_Label->SetPos(XMFLOAT2(x, y += step)); + texture_surface_Label->SetSize(XMFLOAT2(120, 20)); + materialWindow->AddWidget(texture_surface_Label); - //texture_surface_Button = new wiButton("SurfaceMap"); - //texture_surface_Button->SetText(""); - //texture_surface_Button->SetTooltip("Load the surface property texture: R: Reflectance, G: Metalness, B: Emissive, A: SSS"); - //texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); - //texture_surface_Button->SetSize(XMFLOAT2(260, 20)); - //texture_surface_Button->OnClick([&](wiEventArgs args) { - // if (material == nullptr) - // return; + texture_surface_Button = new wiButton("SurfaceMap"); + texture_surface_Button->SetText(""); + texture_surface_Button->SetTooltip("Load the surface property texture: R: Reflectance, G: Metalness, B: Emissive, A: SSS"); + texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); + texture_surface_Button->SetSize(XMFLOAT2(260, 20)); + texture_surface_Button->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material == nullptr) + return; - // if (material->surfaceMap != nullptr) - // { - // material->surfaceMap = nullptr; - // material->surfaceMapName = ""; - // texture_surface_Button->SetText(""); - // } - // else - // { - // char szFile[260]; + if (material->surfaceMap != nullptr) + { + material->surfaceMap = nullptr; + material->surfaceMapName = ""; + texture_surface_Button->SetText(""); + } + else + { + char szFile[260]; - // OPENFILENAMEA ofn; - // ZeroMemory(&ofn, sizeof(ofn)); - // ofn.lStructSize = sizeof(ofn); - // ofn.hwndOwner = nullptr; - // ofn.lpstrFile = szFile; - // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // // use the contents of szFile to initialize itself. - // ofn.lpstrFile[0] = '\0'; - // ofn.nMaxFile = sizeof(szFile); - // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - // ofn.nFilterIndex = 1; - // ofn.lpstrFileTitle = NULL; - // ofn.nMaxFileTitle = 0; - // ofn.lpstrInitialDir = NULL; - // ofn.Flags = 0; - // if (GetSaveFileNameA(&ofn) == TRUE) { - // string fileName = ofn.lpstrFile; - // material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - // material->surfaceMapName = fileName; - // texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - // } - // } - //}); - //materialWindow->AddWidget(texture_surface_Button); + OPENFILENAMEA ofn; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = nullptr; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = 0; + if (GetSaveFileNameA(&ofn) == TRUE) { + string fileName = ofn.lpstrFile; + material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->surfaceMapName = fileName; + texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); + } + } + }); + materialWindow->AddWidget(texture_surface_Button); - //texture_displacement_Label = new wiLabel("DisplacementMap: "); - //texture_displacement_Label->SetPos(XMFLOAT2(x, y += step)); - //texture_displacement_Label->SetSize(XMFLOAT2(120, 20)); - //materialWindow->AddWidget(texture_displacement_Label); + texture_displacement_Label = new wiLabel("DisplacementMap: "); + texture_displacement_Label->SetPos(XMFLOAT2(x, y += step)); + texture_displacement_Label->SetSize(XMFLOAT2(120, 20)); + materialWindow->AddWidget(texture_displacement_Label); - //texture_displacement_Button = new wiButton("DisplacementMap"); - //texture_displacement_Button->SetText(""); - //texture_displacement_Button->SetTooltip("Load the displacement map texture."); - //texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); - //texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); - //texture_displacement_Button->OnClick([&](wiEventArgs args) { - // if (material == nullptr) - // return; + texture_displacement_Button = new wiButton("DisplacementMap"); + texture_displacement_Button->SetText(""); + texture_displacement_Button->SetTooltip("Load the displacement map texture."); + texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); + texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); + texture_displacement_Button->OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + if (material == nullptr) + return; - // if (material->displacementMap != nullptr) - // { - // material->displacementMap = nullptr; - // material->displacementMapName = ""; - // texture_displacement_Button->SetText(""); - // } - // else - // { - // char szFile[260]; + if (material->displacementMap != nullptr) + { + material->displacementMap = nullptr; + material->displacementMapName = ""; + texture_displacement_Button->SetText(""); + } + else + { + char szFile[260]; - // OPENFILENAMEA ofn; - // ZeroMemory(&ofn, sizeof(ofn)); - // ofn.lStructSize = sizeof(ofn); - // ofn.hwndOwner = nullptr; - // ofn.lpstrFile = szFile; - // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // // use the contents of szFile to initialize itself. - // ofn.lpstrFile[0] = '\0'; - // ofn.nMaxFile = sizeof(szFile); - // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - // ofn.nFilterIndex = 1; - // ofn.lpstrFileTitle = NULL; - // ofn.nMaxFileTitle = 0; - // ofn.lpstrInitialDir = NULL; - // ofn.Flags = 0; - // if (GetSaveFileNameA(&ofn) == TRUE) { - // string fileName = ofn.lpstrFile; - // material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - // material->displacementMapName = fileName; - // texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - // } - // } - //}); - //materialWindow->AddWidget(texture_displacement_Button); + OPENFILENAMEA ofn; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = nullptr; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = 0; + if (GetSaveFileNameA(&ofn) == TRUE) { + string fileName = ofn.lpstrFile; + material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + material->displacementMapName = fileName; + texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); + } + } + }); + materialWindow->AddWidget(texture_displacement_Button); materialWindow->Translate(XMFLOAT3(screenW - 760, 50, 0)); @@ -482,55 +532,57 @@ MaterialWindow::~MaterialWindow() void MaterialWindow::SetEntity(Entity entity) { + if (this->entity == entity) + return; + this->entity = entity; - //if (this->material == mat) - // return; + Scene& scene = wiRenderer::GetScene(); + MaterialComponent* material = scene.materials.GetComponent(entity); - //if (material != nullptr) - //{ - // material->SetUserStencilRef(0); - //} + if (material != nullptr) + { + material->SetUserStencilRef(0); - //material = mat; - //if (material != nullptr) - //{ - // materialNameField->SetValue(material->name); - // waterCheckBox->SetCheck(material->water); - // planarReflCheckBox->SetCheck(material->planar_reflections); - // shadowCasterCheckBox->SetCheck(material->cast_shadow); - // normalMapSlider->SetValue(material->normalMapStrength); - // roughnessSlider->SetValue(material->roughness); - // reflectanceSlider->SetValue(material->reflectance); - // metalnessSlider->SetValue(material->metalness); - // alphaSlider->SetValue(material->alpha); - // refractionIndexSlider->SetValue(material->refractionIndex); - // emissiveSlider->SetValue(material->emissive); - // sssSlider->SetValue(material->subsurfaceScattering); - // pomSlider->SetValue(material->parallaxOcclusionMapping); - // movingTexSliderU->SetValue(material->movingTex.x); - // movingTexSliderU->SetValue(material->movingTex.x); - // texMulSliderX->SetValue(material->texMulAdd.x); - // texMulSliderY->SetValue(material->texMulAdd.y); - // alphaRefSlider->SetValue(material->alphaRef); - // materialWindow->SetEnabled(true); - // colorPicker->SetEnabled(true); - // blendModeComboBox->SetSelected((int)material->blendFlag); + const NameComponent& name = *scene.names.GetComponent(entity); - // texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); - // texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - // texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - // texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - //} - //else - //{ - // materialNameField->SetValue("No material selected"); - // materialWindow->SetEnabled(false); - // colorPicker->SetEnabled(false); + materialNameField->SetValue(name.name); + waterCheckBox->SetCheck(material->water); + planarReflCheckBox->SetCheck(material->planar_reflections); + shadowCasterCheckBox->SetCheck(material->cast_shadow); + 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); + sssSlider->SetValue(material->subsurfaceScattering); + pomSlider->SetValue(material->parallaxOcclusionMapping); + texAnimFrameRateSlider->SetValue(material->texAnimFrameRate); + texAnimDirectionSliderU->SetValue(material->texAnimDirection.x); + texAnimDirectionSliderV->SetValue(material->texAnimDirection.y); + texMulSliderX->SetValue(material->texMulAdd.x); + texMulSliderY->SetValue(material->texMulAdd.y); + alphaRefSlider->SetValue(material->alphaRef); + materialWindow->SetEnabled(true); + colorPicker->SetEnabled(true); + blendModeComboBox->SetSelected((int)material->blendFlag); - // texture_baseColor_Button->SetText(""); - // texture_normal_Button->SetText(""); - // texture_surface_Button->SetText(""); - // texture_displacement_Button->SetText(""); - //} + 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)); + } + else + { + materialNameField->SetValue("No material selected"); + materialWindow->SetEnabled(false); + colorPicker->SetEnabled(false); + + texture_baseColor_Button->SetText(""); + texture_normal_Button->SetText(""); + texture_surface_Button->SetText(""); + texture_displacement_Button->SetText(""); + } } diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index 71d86bc44..f36892b8b 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -35,8 +35,9 @@ public: wiSlider* emissiveSlider; wiSlider* sssSlider; wiSlider* pomSlider; - wiSlider* movingTexSliderU; - wiSlider* movingTexSliderV; + wiSlider* texAnimFrameRateSlider; + wiSlider* texAnimDirectionSliderU; + wiSlider* texAnimDirectionSliderV; wiSlider* texMulSliderX; wiSlider* texMulSliderY; wiColorPicker* colorPicker; diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 8d81a043c..ed64b63ac 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -30,19 +30,16 @@ Entity ImportModel_OBJ(const std::string& fileName) if (success) { - //Model* model = new Model; - //model->name = name; - Entity modelEntity = scene.Entity_CreateModel(name); ModelComponent& model = *scene.models.GetComponent(modelEntity); + TransformComponent& model_transform = *scene.transforms.GetComponent(modelEntity); + model_transform.UpdateTransform(); // everything will be attached to this, so values need to be up to date // Load material library: vector materialLibrary = {}; for (auto& obj_material : obj_materials) { - //Material* material = new Material(obj_material.name); - Entity materialEntity = scene.Entity_CreateMaterial(obj_material.name); MaterialComponent& material = *scene.materials.GetComponent(materialEntity); @@ -54,17 +51,11 @@ Entity ImportModel_OBJ(const std::string& fileName) material.displacementMapName = obj_material.bump_texname; } material.emissive = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); - //obj_material.emissive_texname; material.refractionIndex = obj_material.ior; material.metalness = obj_material.metallic; - //obj_material.metallic_texname; material.normalMapName = obj_material.normal_texname; material.surfaceMapName = obj_material.reflection_texname; material.roughness = obj_material.roughness; - //obj_material.roughness_texname; - //material.specular_power = (int)obj_material.shininess; - //material.specular = XMFLOAT4(obj_material.specular[0], obj_material.specular[1], obj_material.specular[2], 1); - //material.specularMapName = obj_material.specular_texname; if (!material.surfaceMapName.empty()) { @@ -86,17 +77,9 @@ Entity ImportModel_OBJ(const std::string& fileName) material.displacementMapName = directory + material.displacementMapName; material.displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.displacementMapName); } - //if (!material.specularMapName.empty()) - //{ - // material.specularMapName = directory + material.specularMapName; - // material.specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.specularMapName); - //} - - //material.ConvertToPhysicallyBasedMaterial(); materialLibrary.push_back(materialEntity); // for subset-indexing... model.materials.insert(materialEntity); - //model->materials.insert(make_pair(material.name, material)); } if (materialLibrary.empty()) @@ -106,23 +89,17 @@ Entity ImportModel_OBJ(const std::string& fileName) MaterialComponent& material = *scene.materials.GetComponent(materialEntity); materialLibrary.push_back(materialEntity); // for subset-indexing... model.materials.insert(materialEntity); - //Material* material = new Material("OBJImport_defaultMaterial"); - //materialLibrary.push_back(material); - //model->materials.insert(make_pair(material.name, material)); } // Load objects, meshes: for (auto& shape : obj_shapes) { - //Object* object = new Object(shape.name); - //Mesh* mesh = new Mesh(shape.name + "_mesh"); - Entity objectEntity = scene.Entity_CreateObject(shape.name); Entity meshEntity = scene.Entity_CreateMesh(shape.name + "_mesh"); ObjectComponent& object = *scene.objects.GetComponent(objectEntity); MeshComponent& mesh = *scene.meshes.GetComponent(meshEntity); - //scene.Component_Attach(objectEntity, modelEntity); + scene.Component_Attach(objectEntity, modelEntity); object.meshID = meshEntity; mesh.renderable = true; @@ -184,9 +161,7 @@ Entity ImportModel_OBJ(const std::string& fileName) { registered_materialIndices[materialIndex] = (int)mesh.subsets.size(); mesh.subsets.push_back(MeshComponent::MeshSubset()); - //MaterialComponent* material = materialLibrary[materialIndex]; mesh.subsets.back().materialID = materialLibrary[materialIndex]; - //mesh.materialNames.push_back(material.name); } vert.tex.z = (float)registered_materialIndices[materialIndex]; // this indexes a mesh subset @@ -221,30 +196,10 @@ Entity ImportModel_OBJ(const std::string& fileName) mesh.aabb.create(min, max); mesh.CreateRenderData(); - //// We need to eliminate colliding mesh names, because objects can reference them by names: - //// Note: in engine, object is decoupled from mesh, for instancing support. OBJ file have only meshes and names can collide there. - //string meshName = mesh->name; - //uint32_t unique_counter = 0; - //bool meshNameCollision = model->meshes.count(meshName) != 0; - //while (meshNameCollision) - //{ - // meshName = mesh->name + to_string(unique_counter); - // meshNameCollision = model->meshes.count(meshName) != 0; - // unique_counter++; - //} - //mesh->name = meshName; - - //object->meshName = mesh->name; - model.objects.insert(objectEntity); model.meshes.insert(meshEntity); - - //model->objects.insert(object); - //model->meshes.insert(make_pair(mesh->name, mesh)); } - //model->FinishLoading(); - return modelEntity; } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 2c3be7ffb..c52e9d4f7 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3119,40 +3119,13 @@ void wiRenderer::UpdatePerFrameData(float dt) const ObjectComponent* object = scene.objects.GetComponent(entity); if (object != nullptr) { - const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID); - if (mesh != nullptr) + if (object->GetRenderTypes() & RENDERTYPE_OPAQUE) { - UINT renderTypes = 0; - for (auto& subset : mesh->subsets) - { - const MaterialComponent* material = scene.materials.GetComponent(subset.materialID); - if (material != nullptr) - { - if (material->IsTransparent()) - { - renderTypes |= RENDERTYPE_TRANSPARENT; - } - else - { - renderTypes |= RENDERTYPE_OPAQUE; - } - - if (material->IsWater()) - { - renderTypes |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER; - } - } - } - - if (renderTypes & RENDERTYPE_OPAQUE) - { - culling.culledRenderer_opaque[object->meshID].push_back(entity); - } - if (renderTypes & RENDERTYPE_TRANSPARENT) - { - culling.culledRenderer_transparent[object->meshID].push_back(entity); - } - + culling.culledRenderer_opaque[object->meshID].push_back(entity); + } + if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT) + { + culling.culledRenderer_transparent[object->meshID].push_back(entity); } } @@ -5141,7 +5114,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle tessellation = tessellation && device->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION); const XMFLOAT4X4 __identityMat = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - XMFLOAT4X4 tempMat; struct InstBuf { @@ -5211,6 +5183,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle const TransformComponent& transform = *scene.transforms.GetComponent(objectEntity); + XMFLOAT4X4 tempMat; XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&transform.world)); if (advancedVBRequest) @@ -5309,13 +5282,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle continue; } - bool softbody = false; - - const PhysicsComponent* physicscomponent = scene.physicscomponents.GetComponent(meshEntity); - if (physicscomponent != nullptr) - { - softbody = physicscomponent->softBody; - } + const bool dynamicVB = mesh.IsDynamicVB(); const auto& visibleInstances = iter->second; @@ -5366,24 +5333,14 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle const TransformComponent& transform = *scene.transforms.GetComponent(objectEntity); - if (softbody) - tempMat = __identityMat; - else - tempMat = transform.world; - if (advancedVBRequest || tessellatorRequested) { - ((volatile InstBuf*)instances)[k].instance.Create(tempMat, instance.color); - - if (softbody) - tempMat = __identityMat; - else - tempMat = transform.world_prev; - ((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat); + ((volatile InstBuf*)instances)[k].instance.Create(dynamicVB ? __identityMat : transform.world, instance.color); + ((volatile InstBuf*)instances)[k].instancePrev.Create(dynamicVB ? __identityMat : transform.world_prev); } else { - ((volatile Instance*)instances)[k].Create(tempMat, instance.color, dither); + ((volatile Instance*)instances)[k].Create(dynamicVB ? __identityMat : transform.world, instance.color, dither); } ++k; @@ -5489,7 +5446,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::POSITION: { GPUBuffer* vbs[] = { - softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), + dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), dynamicVertexBufferPool }; UINT strides[] = { @@ -5497,7 +5454,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle sizeof(Instance) }; UINT offsets[] = { - softbody ? mesh.bufferOffset_POS : 0, + dynamicVB ? mesh.bufferOffset_POS : 0, instancesOffset }; device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); @@ -5506,7 +5463,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD: { GPUBuffer* vbs[] = { - softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), + dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), mesh.vertexBuffer_TEX, dynamicVertexBufferPool }; @@ -5516,7 +5473,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle sizeof(Instance) }; UINT offsets[] = { - softbody ? mesh.bufferOffset_POS : 0, + dynamicVB ? mesh.bufferOffset_POS : 0, 0, instancesOffset }; @@ -5526,9 +5483,9 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::EVERYTHING: { GPUBuffer* vbs[] = { - softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), + dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS), mesh.vertexBuffer_TEX, - softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_PRE != nullptr ? mesh.streamoutBuffer_PRE : mesh.vertexBuffer_POS), + dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_PRE != nullptr ? mesh.streamoutBuffer_PRE : mesh.vertexBuffer_POS), dynamicVertexBufferPool }; UINT strides[] = { @@ -5538,9 +5495,9 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle sizeof(InstBuf) }; UINT offsets[] = { - softbody ? mesh.bufferOffset_POS : 0, + dynamicVB ? mesh.bufferOffset_POS : 0, 0, - softbody ? mesh.bufferOffset_PRE : 0, + dynamicVB ? mesh.bufferOffset_PRE : 0, instancesOffset }; device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); @@ -7989,112 +7946,129 @@ RAY wiRenderer::getPickRay(long cursorX, long cursorY) { wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask, bool dynamicObjects, bool onlyVisible) { + Scene& scene = GetScene(); + RayIntersectWorldResult result; //if (spTree != nullptr) - //{ - // CulledList culledObjects; - // spTree->getVisible(ray, culledObjects); + { + //CulledList culledObjects; + //spTree->getVisible(ray, culledObjects); - // if (culledObjects.empty()) - // { - // return result; - // } + //if (culledObjects.empty()) + //{ + // return result; + //} - // const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); - // const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); + const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); + const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); - // // pre allocate helper vector array: - // static size_t _arraySize = 10000; - // static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); + // pre allocate helper vector array: + static size_t _arraySize = 10000; + static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); - // for (Cullable* culled : culledObjects) - // { - // Object* object = (Object*)culled; + for (size_t i = 0; i < scene.objects.GetCount(); ++i) + { + Entity entity = scene.objects.GetEntity(i); + const LayerComponent& layer = *scene.layers.GetComponent(entity); - // const uint32_t objectLayerMask = object->GetLayerMask(); - // if (objectLayerMask & layerMask) - // { + const uint32_t objectLayerMask = layer.GetLayerMask(); + if (objectLayerMask & layerMask) + { + const ObjectComponent& object = scene.objects[i]; - // if (!(renderTypeMask & object->GetRenderTypes())) - // { - // continue; - // } - // if (!dynamicObjects && object->isDynamic()) - // { - // continue; - // } - // if (onlyVisible && object->IsOccluded() && GetOcclusionCullingEnabled()) - // { - // continue; - // } + if (object.meshID == INVALID_ENTITY) + { + continue; + } + if (!(renderTypeMask & object.GetRenderTypes())) + { + continue; + } + if (!dynamicObjects && object.IsDynamic()) + { + continue; + } + if (onlyVisible && object.IsOccluded() && GetOcclusionCullingEnabled()) + { + continue; + } - // Mesh* mesh = object->mesh; - // if (mesh->vertices_POS.size() >= _arraySize) - // { - // // grow preallocated vector helper array - // _mm_free(_vertices); - // _arraySize = (mesh->vertices_POS.size() + 1) * 2; - // _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); - // } + const CullableComponent& cullable = *scene.cullables.GetComponent(entity); + if (!ray.intersects(cullable.aabb)) + { + continue; + } - // const XMMATRIX objectMat = object->getMatrix(); - // const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); + const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID); + if (mesh.vertices_POS.size() >= _arraySize) + { + // grow preallocated vector helper array + _mm_free(_vertices); + _arraySize = (mesh.vertices_POS.size() + 1) * 2; + _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); + } - // const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); - // const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); + const TransformComponent& transform = *scene.transforms.GetComponent(entity); - // MeshComponent::Vertex_FULL _tmpvert; + const XMMATRIX objectMat = XMLoadFloat4x4(&transform.world); + const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); - // if (object->isArmatureDeformed() && !object->mesh->armature->boneCollection.empty()) - // { - // for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) - // { - // _tmpvert = mesh->TransformVertex((int)i); - // _vertices[i] = XMLoadFloat4(&_tmpvert.pos); - // } - // } - // else if (mesh->hasDynamicVB()) - // { - // for (size_t i = 0; i < mesh->vertices_Transformed_POS.size(); ++i) - // { - // _vertices[i] = mesh->vertices_Transformed_POS[i].LoadPOS(); - // } - // } - // else - // { - // for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) - // { - // _vertices[i] = mesh->vertices_POS[i].LoadPOS(); - // } - // } + const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); + const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); - // for (size_t i = 0; i < mesh->indices.size(); i += 3) - // { - // int i0 = mesh->indices[i], i1 = mesh->indices[i + 1], i2 = mesh->indices[i + 2]; - // float distance; - // if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance)) - // { - // XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); - // distance = wiMath::Distance(pos, rayOrigin); + MeshComponent::Vertex_FULL _tmpvert; - // if (distance < result.distance) - // { - // XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat)); + if (mesh.IsSkinned()) + { + //for (size_t i = 0; i < mesh.vertices_POS.size(); ++i) + //{ + // _tmpvert = mesh.TransformVertex((int)i); + // _vertices[i] = XMLoadFloat4(&_tmpvert.pos); + //} + assert(0); // todo + } + else if (mesh.IsDynamicVB()) + { + for (size_t i = 0; i < mesh.vertices_Transformed_POS.size(); ++i) + { + _vertices[i] = mesh.vertices_Transformed_POS[i].LoadPOS(); + } + } + else + { + for (size_t i = 0; i < mesh.vertices_POS.size(); ++i) + { + _vertices[i] = mesh.vertices_POS[i].LoadPOS(); + } + } - // result.object = object; - // XMStoreFloat3(&result.position, pos); - // XMStoreFloat3(&result.normal, nor); - // result.distance = distance; - // result.subsetIndex = (int)mesh->vertices_POS[i0].GetMaterialIndex(); - // } - // } - // } + for (size_t i = 0; i < mesh.indices.size(); i += 3) + { + int i0 = mesh.indices[i], i1 = mesh.indices[i + 1], i2 = mesh.indices[i + 2]; + float distance; + if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance)) + { + 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(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat)); - // } - //} + result.entity = entity; + XMStoreFloat3(&result.position, pos); + XMStoreFloat3(&result.normal, nor); + result.distance = distance; + result.subsetIndex = (int)mesh.vertices_POS[i0].GetMaterialIndex(); + } + } + } + + } + + } + } return result; } diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index a9bc19b17..fed7620ae 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -578,6 +578,13 @@ namespace wiSceneSystem for (size_t i = 0; i < physicscomponents.GetCount(); ++i) { PhysicsComponent& physicscomponent = physicscomponents[i]; + Entity entity = physicscomponents.GetEntity(i); + + if (physicscomponent.softBody) + { + MeshComponent& mesh = *meshes.GetComponent(entity); + mesh.dynamicVB = true; + } } // Update Material components: @@ -585,17 +592,14 @@ namespace wiSceneSystem { MaterialComponent& material = materials[i]; - if (material.texAnimFrameRate > 0) - { - material.dirty = true; // will trigger contant buffer update! - } - material.texAnimSleep -= dt * material.texAnimFrameRate; if (material.texAnimSleep <= 0) { material.texMulAdd.z = fmodf(material.texMulAdd.z + material.texAnimDirection.x, 1); material.texMulAdd.w = fmodf(material.texMulAdd.w + material.texAnimDirection.y, 1); material.texAnimSleep = 1.0f; + + material.dirty = true; // will trigger constant buffer update! } material.engineStencilRef = STENCILREF_DEFAULT; @@ -614,6 +618,8 @@ namespace wiSceneSystem CullableComponent& cullable = *cullables.GetComponent(entity); cullable.aabb.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(0, 0, 0)); + object.rendertypeMask = 0; + object.dynamic = false; if (object.meshID != INVALID_ENTITY) { @@ -623,6 +629,33 @@ namespace wiSceneSystem if (mesh != nullptr && transform != nullptr) { cullable.aabb = mesh->aabb.get(transform->world); + + if (mesh->IsSkinned() || mesh->IsDynamicVB()) + { + object.dynamic = true; + } + + for (auto& subset : mesh->subsets) + { + const MaterialComponent* material = materials.GetComponent(subset.materialID); + + if (material != nullptr) + { + if (material->IsTransparent()) + { + object.rendertypeMask |= RENDERTYPE_TRANSPARENT; + } + else + { + object.rendertypeMask |= RENDERTYPE_OPAQUE; + } + + if (material->IsWater()) + { + object.rendertypeMask |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER; + } + } + } } } } diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 44832404b..2170219e2 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -68,7 +68,7 @@ namespace wiSceneSystem struct MaterialComponent { - bool dirty = true; + bool dirty = true; // can trigger constant buffer update STENCILREF engineStencilRef = STENCILREF_DEFAULT; uint8_t userStencilRef = 0; @@ -124,11 +124,25 @@ namespace wiSceneSystem wiGraphicsTypes::Texture2D* GetSurfaceMap() const; wiGraphicsTypes::Texture2D* GetDisplacementMap() const; - inline bool IsTransparent() const { return baseColor.w < 1.0f; } + inline float GetOpacity() const { return baseColor.w; } + + inline bool IsTransparent() const { return GetOpacity() < 1.0f; } inline bool IsWater() const { return water; } inline bool HasPlanarReflection() const { return planar_reflections || IsWater(); } inline bool IsCastingShadow() const { return cast_shadow; } inline bool IsAlphaTestEnabled() const { return alphaRef <= 1.0f - 1.0f / 256.0f; } + + inline void SetBaseColor(const XMFLOAT4& value) { dirty = true; baseColor = value; } + inline void SetRoughness(float value) { dirty = true; roughness = value; } + inline void SetReflectance(float value) { dirty = true; reflectance = value; } + inline void SetMetalness(float value) { dirty = true; metalness = value; } + inline void SetEmissive(float value) { dirty = true; emissive = value; } + inline void SetRefractionIndex(float value) { dirty = true; refractionIndex = value; } + inline void SetSubsurfaceScattering(float value) { dirty = true; subsurfaceScattering = value; } + inline void SetNormalMapStrength(float value) { dirty = true; normalMapStrength = value; } + inline void SetParallaxOcclusionMapping(float value) { dirty = true; parallaxOcclusionMapping = value; } + inline void SetOpacity(float value) { dirty = true; baseColor.w = value; } + inline void SetAlphaRef(float value) { alphaRef = value; } }; struct MeshComponent @@ -282,6 +296,7 @@ namespace wiSceneSystem wiGraphicsTypes::GPUBuffer* streamoutBuffer_PRE = nullptr; // Dynamic vertexbuffers write into a global pool, these will be the offsets into that: + bool dynamicVB = false; UINT bufferOffset_POS; UINT bufferOffset_PRE; @@ -308,8 +323,9 @@ namespace wiSceneSystem bool HasImpostor() const { return impostorTarget.IsInitialized(); } inline float GetTessellationFactor() const { return tessellationFactor; } - inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() { return indexFormat; } - inline bool IsSkinned() { return armatureID != wiECS::INVALID_ENTITY; } + inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() const { return indexFormat; } + inline bool IsSkinned() const { return armatureID != wiECS::INVALID_ENTITY; } + inline bool IsDynamicVB() const { return dynamicVB; } void CreateRenderData(); }; @@ -323,9 +339,12 @@ namespace wiSceneSystem { wiECS::Entity meshID = wiECS::INVALID_ENTITY; bool renderable = true; + bool dynamic = false; int cascadeMask = 0; // which shadow cascades to skip (0: skip none, 1: skip first, etc...) XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1); + uint32_t rendertypeMask = 0; + // occlusion result history bitfield (32 bit->32 frame history) uint32_t occlusionHistory = ~0; // occlusion query pool index @@ -339,7 +358,9 @@ namespace wiSceneSystem // If it pops up for a frame after occluded, it is visible again for some frames return ((occlusionQueryID >= 0) && (occlusionHistory & 0xFFFFFFFF) == 0); } + inline bool IsDynamic() const { return dynamic; } inline float GetTransparency() const { return 1 - color.w; } + inline uint32_t GetRenderTypes() const { return rendertypeMask; } }; struct PhysicsComponent