Particle system improvements + Emissive materials

Added option for Global particle positions
Added material property for particles
Added Emissive rendering
This commit is contained in:
Antoine Pilote
2023-09-23 20:31:50 -04:00
parent 50bc020f6e
commit 2cb0ca4f29
17 changed files with 242 additions and 26 deletions

View File

@@ -38,6 +38,7 @@ uniform sampler2D m_Albedo;
uniform sampler2D m_Material;
uniform sampler2D m_Normal;
uniform sampler2D m_SSAO;
uniform sampler2D m_Emissive;
// Lights
const int MaxLight = 32;
@@ -223,10 +224,21 @@ void main()
// Convert from [0, 1] to [-1, 1].
vec3 albedo = texture(m_Albedo, UV).rgb;
vec3 normal = texture(m_Normal, UV).rgb * 2.0 - 1.0;
float metallic = texture(m_Material, UV).r;
float roughness = texture(m_Material, UV).b;
float ao = texture(m_Material, UV).g;
float ssao = texture(m_SSAO, UV).r;
vec4 materialSample = texture(m_Material, UV);
float metallic = materialSample.r;
float ao = materialSample.g;
float roughness = materialSample.b;
float unlit = materialSample.a;
float ssao = texture(m_SSAO, UV).r;
float emissive = texture(m_Emissive, UV).r;
if (unlit > 0.1f)
{
FragColor = vec4(albedo * ssao * emissive, 1.0);
return;
}
vec3 N = normal;
vec3 V = normalize(u_EyePosition - worldPos);
vec3 R = reflect(-V, N);
@@ -240,6 +252,7 @@ void main()
vec3 fog = vec3(0.0);
float shadow = 0.0f;
if (true)
{
vec3 L = normalize(u_DirectionalLight.Direction);

View File

@@ -40,6 +40,7 @@ layout(location = 0) out vec4 gAlbedo;
layout(location = 1) out vec4 gNormal;
layout(location = 2) out vec4 gMaterial;
layout(location = 3) out int gEntityID;
layout(location = 4) out float gEmissive;
in vec3 FragPos;
in vec2 UV;
@@ -67,6 +68,7 @@ layout(std140, binding = 32) uniform u_MaterialUniform
int u_HasNormal; // 56 byte
int u_HasDisplacement; // 60 byte
int u_Unlit;
float u_Emissive;
};
void main()
@@ -77,10 +79,10 @@ void main()
normal = texture(m_Normal, UV).rgb;
normal = normal * 2.0 - 1.0;
normal = TBN * normalize(normal);
gNormal = vec4(normal / 2.0 + 0.5, 1.0);
gNormal = vec4(normal / 2.0 + 0.5, 1.0f);
// Albedo
gAlbedo = vec4(m_AlbedoColor, 1.0);
gAlbedo = vec4(m_AlbedoColor, 1.0f);
if (u_HasAlbedo == 1)
{
vec4 albedoSample = texture(m_Albedo, UV);
@@ -106,10 +108,12 @@ void main()
if (u_HasRoughness == 1)
finalRoughness = texture(m_Roughness, UV).r;
gMaterial = vec4(0, 0, 0, 1);
gMaterial = vec4(0, 0, 0, u_Unlit);
gMaterial.r = finalMetalness;
gMaterial.g = finalAO;
gMaterial.b = finalRoughness;
gEntityID = int(u_EntityID);
gEmissive = u_Emissive;
}

View File

@@ -65,6 +65,7 @@ layout(location = 0) out vec4 gAlbedo;
layout(location = 1) out vec4 gNormal;
layout(location = 2) out vec4 gMaterial;
layout(location = 3) out int gEntityID;
layout(location = 4) out float gEmissive;
in vec3 FragPos;
in vec2 UV;
@@ -92,6 +93,7 @@ layout(std140, binding = 32) uniform u_MaterialUniform
int u_HasNormal; // 56 byte
int u_HasDisplacement; // 60 byte
int u_Unlit;
float u_Emissive;
};
void main()
@@ -102,10 +104,10 @@ void main()
normal = texture(m_Normal, UV).rgb;
normal = normal * 2.0 - 1.0;
normal = TBN * normalize(normal);
gNormal = vec4(normal / 2.0 + 0.5, 1.0);
gNormal = vec4(normal / 2.0 + 0.5, 1.0f);
// Albedo
gAlbedo = vec4(m_AlbedoColor, 1.0);
gAlbedo = vec4(m_AlbedoColor, 1.0f);
if (u_HasAlbedo == 1)
{
vec4 albedoSample = texture(m_Albedo, UV);
@@ -131,10 +133,11 @@ void main()
if (u_HasRoughness == 1)
finalRoughness = texture(m_Roughness, UV).r;
gMaterial = vec4(0, 0, 0, 1);
gMaterial = vec4(0, 0, 0, u_Unlit);
gMaterial.r = finalMetalness;
gMaterial.g = finalAO;
gMaterial.b = finalRoughness;
gEntityID = int(u_EntityID);
gEmissive = u_Emissive;
}

View File

@@ -5,10 +5,15 @@
#include <src/Core/Maths.h>
#include <src/Scene/Components/ParticleEmitterComponent.h>
#include <src/Scene/Entities/ImGuiHelper.h>
#include "MaterialEditor.h"
#include <src/Resource/ResourceLoader.h>
#include <src/Resource/ResourceLoader.h>
class ParticleEmitterPanel : ComponentPanel
{
public:
Scope<ModelResourceInspector> _modelInspector;
ParticleEmitterPanel() {}
void Draw(Nuake::Entity entity) override
@@ -30,6 +35,50 @@ public:
ImGui::TableNextColumn();
ComponentTableReset(component.ParticleColor, Nuake::Vector4(1, 1, 1, 1));
}
ImGui::TableNextColumn();
{
ImGui::Text("Particle Material");
ImGui::TableNextColumn();
std::string label = "Empty";
if (!component.ParticleMaterial->Path.empty())
{
label = component.ParticleMaterial->Path;
}
if (ImGui::Button(label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)))
{
}
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Material"))
{
char* file = (char*)payload->Data;
std::string fullPath = std::string(file, 256);
fullPath = Nuake::FileSystem::AbsoluteToRelative(fullPath);
Ref<Nuake::Material> material = Nuake::ResourceLoader::LoadMaterial(fullPath);
component.ParticleMaterial = material;
}
ImGui::EndDragDropTarget();
}
//std::string childId = "materialEditorParticle";
//ImGui::BeginChild(childId.c_str(), ImVec2(0, 0), false);
//{
// MaterialEditor editor;
// editor.Draw(component.ParticleMaterial);
//}
//ImGui::EndChild();
ImGui::TableNextColumn();
ComponentTableReset(component.ParticleColor, Nuake::Vector4(1, 1, 1, 1));
}
ImGui::TableNextColumn();
{
ImGui::Text("Amount");
@@ -40,6 +89,26 @@ public:
ComponentTableReset(component.Amount, 10.0f);
}
ImGui::TableNextColumn();
{
ImGui::Text("Particle Size");
ImGui::TableNextColumn();
ImGuiHelper::DrawVec3("##particleSize", &component.ParticleScale);
ImGui::TableNextColumn();
ComponentTableReset(component.ParticleScale, Nuake::Vector3(0.1, 0.1, 0.1));
}
ImGui::TableNextColumn();
{
ImGui::Text("Global Space");
ImGui::TableNextColumn();
ImGui::Checkbox("##globalSpace", &component.GlobalSpace);
ImGui::TableNextColumn();
ComponentTableReset(component.GlobalSpace, false);
}
ImGui::TableNextColumn();
{
ImGui::Text("Rate");
ImGui::TableNextColumn();