mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Terrible postprocessing and start of Editor GUI for lights
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
Texture2D CameraTarget : register(t0);
|
||||
SamplerState CameraTargetSampler : register(s0);
|
||||
|
||||
struct VS_IN
|
||||
{
|
||||
float2 Position : POSITION;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float2 TexCoord : TEXCOORD;
|
||||
};
|
||||
|
||||
PS_IN VS(VS_IN input)
|
||||
{
|
||||
PS_IN output;
|
||||
|
||||
output.Position = float4(input.Position, 0, 1);
|
||||
output.TexCoord = input.TexCoord;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_IN input) : SV_TARGET
|
||||
{
|
||||
float4 rawColor = CameraTarget.Sample(CameraTargetSampler, input.TexCoord);
|
||||
|
||||
float3 color = rawColor.rgb / (rawColor.rgb + 1.0f);
|
||||
|
||||
color = pow(color, 1.0f / 2.2f);
|
||||
|
||||
return float4(color, 1);
|
||||
}
|
||||
|
||||
#effect[VS = VS, PS = PS]
|
||||
@@ -108,16 +108,8 @@ float4 PS(PS_IN input) : SV_TARGET
|
||||
|
||||
float3 luminanceColor = LightColor * Illuminance;
|
||||
|
||||
float3 cook = (kd * diffuse + specular) * luminanceColor * n_dot_l;
|
||||
|
||||
float3 final = cook;
|
||||
|
||||
// Tone mapping // TODO: do in postprocessing
|
||||
final = final / (final + 1.0f);
|
||||
|
||||
// Gamma correction // TODO: do in postprocessing/hardware
|
||||
final = pow(final, 1.0f / 2.2f);
|
||||
|
||||
float3 final = (kd * diffuse + specular) * luminanceColor * n_dot_l;
|
||||
|
||||
#if OUTPUT == Inspect_NormalDistribution
|
||||
final = max(final - 10000000, nrmDist.xxx);
|
||||
#elif OUTPUT == Inspect_GeometryFunction
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace GlitchyEditor.EditWindows
|
||||
ShowComponentEditor<CameraComponent>("Camera", entity, => ShowCameraComponentEditor, => ShowComponentContextMenu<CameraComponent>);
|
||||
ShowComponentEditor<SpriterRendererComponent>("Sprite Renderer", entity, => ShowSpriteRendererComponentEditor, => ShowComponentContextMenu<SpriterRendererComponent>);
|
||||
ShowComponentEditor<MeshRendererComponent>("Mesh Renderer", entity, => ShowMeshRendererComponentEditor, => ShowComponentContextMenu<MeshRendererComponent>);
|
||||
ShowComponentEditor<LightComponent>("Mesh Renderer", entity, => ShowLightComponentEditor, => ShowComponentContextMenu<LightComponent>);
|
||||
|
||||
ShowAddComponentButton(entity);
|
||||
}
|
||||
@@ -349,6 +350,58 @@ namespace GlitchyEditor.EditWindows
|
||||
}
|
||||
}
|
||||
|
||||
private static void LabelColumn(StringView label)
|
||||
{
|
||||
ImGui.TextUnformatted(label);
|
||||
ImGui.NextColumn();
|
||||
}
|
||||
|
||||
private static void ShowLightComponentEditor(Entity entity, LightComponent* lightComponent)
|
||||
{
|
||||
ImGui.Columns(2);
|
||||
defer ImGui.Columns(1);
|
||||
|
||||
const String[?] strings = String[]("Directional", "Point", "Spot");
|
||||
|
||||
var light = ref lightComponent.SceneLight;
|
||||
|
||||
String typeName = strings[light.LightType.Underlying];
|
||||
|
||||
LabelColumn("Type");
|
||||
|
||||
if (ImGui.BeginCombo("##Type", typeName.CStr()))
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
bool isSelected = (typeName == strings[i]);
|
||||
|
||||
if (ImGui.Selectable(strings[i], isSelected))
|
||||
{
|
||||
light.LightType = (.)i;
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
ImGui.SetItemDefaultFocus();
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
ImGui.NextColumn();
|
||||
LabelColumn("Color");
|
||||
|
||||
ColorRGB color = light.Color;
|
||||
if (ImGui.ColorEdit3("##Color", ref color))
|
||||
light.Color = color;
|
||||
|
||||
ImGui.NextColumn();
|
||||
LabelColumn("Illuminance");
|
||||
|
||||
float illuminance = light.Illuminance;
|
||||
if (ImGui.DragFloat("##Illuminance", &illuminance, 0.1f, 0.0f, float.MaxValue))
|
||||
light.Illuminance = illuminance;
|
||||
}
|
||||
|
||||
private static void ShowAddComponentButton(Entity entity)
|
||||
{
|
||||
static char8[128] searchBuffer = .();
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace GlitchyEditor
|
||||
|
||||
Editor _editor ~ delete _;
|
||||
|
||||
RenderTarget2D _intermediateTarget ~ _?.ReleaseRef();
|
||||
RenderTarget2D _viewportTarget ~ _?.ReleaseRef();
|
||||
RenderTarget2D _cameraTarget ~ _.ReleaseRef();
|
||||
RenderTarget2D _viewportTarget ~ _.ReleaseRef();
|
||||
|
||||
SettingsWindow _settingsWindow = new .() ~ delete _;
|
||||
|
||||
@@ -87,16 +87,18 @@ namespace GlitchyEditor
|
||||
camera.Camera.SetPerspective(MathHelper.ToRadians(75), 0.1f, 10000.0f);
|
||||
camera.Primary = true;
|
||||
camera.FixedAspectRatio = false;
|
||||
camera.RenderTarget = _viewportTarget;
|
||||
camera.RenderTarget = _cameraTarget;
|
||||
let transform = _cameraEntity.GetComponent<TransformComponent>();
|
||||
transform.Position = .(-1.5f, 1.5f, -2.5f);
|
||||
transform.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0);
|
||||
//transform.Position = .(-1.5f, 1.5f, -2.5f);
|
||||
transform.Position = .(3.5f, 1.25f, 2.75f);
|
||||
//transform.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0);
|
||||
transform.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(40), 0);
|
||||
|
||||
_cameraEntity.AddComponent<NativeScriptComponent>().Bind<EditorCameraController>();
|
||||
_cameraEntity.AddComponent<EditorComponent>();
|
||||
}
|
||||
|
||||
{
|
||||
/*{
|
||||
_otherCameraEntity = _scene.CreateEntity("Other Camera Entity");
|
||||
let camera = _otherCameraEntity.AddComponent<CameraComponent>();
|
||||
camera.Camera.SetPerspective(MathHelper.ToRadians(45), 0.1f, 1000.0f);
|
||||
@@ -108,13 +110,13 @@ namespace GlitchyEditor
|
||||
|
||||
_otherCameraEntity.AddComponent<NativeScriptComponent>().Bind<EditorCameraController>();
|
||||
_otherCameraEntity.AddComponent<EditorComponent>();
|
||||
}
|
||||
}*/
|
||||
|
||||
{
|
||||
var lightNtt = _scene.CreateEntity("My Sexy Sun");
|
||||
let transform = lightNtt.GetComponent<TransformComponent>();
|
||||
transform.Position = .(0, 0, 0);
|
||||
transform.RotationEuler = .(MathHelper.ToRadians(45), MathHelper.ToRadians(-45), 0);
|
||||
transform.RotationEuler = .(MathHelper.ToRadians(45), MathHelper.ToRadians(-100), 0);
|
||||
|
||||
let light = lightNtt.AddComponent<LightComponent>();
|
||||
light.SceneLight.Illuminance = 10.0f;
|
||||
@@ -132,6 +134,17 @@ namespace GlitchyEditor
|
||||
light.SceneLight.Color = .(1.0f, 0.95f, 0.8f);
|
||||
}
|
||||
|
||||
{
|
||||
var lightNtt = _scene.CreateEntity("My Sexy Sun 3");
|
||||
let transform = lightNtt.GetComponent<TransformComponent>();
|
||||
transform.Position = .(0, 0, 0);
|
||||
transform.RotationEuler = .(MathHelper.ToRadians(20), MathHelper.ToRadians(-55), 0);
|
||||
|
||||
let light = lightNtt.AddComponent<LightComponent>();
|
||||
light.SceneLight.Illuminance = 10.0f;
|
||||
light.SceneLight.Color = .(1.0f, 0.95f, 0.8f);
|
||||
}
|
||||
|
||||
InitEditor();
|
||||
|
||||
TestEntitiesWithModels();
|
||||
@@ -160,8 +173,11 @@ namespace GlitchyEditor
|
||||
mat.SetTexture("NormalTexture", normal);
|
||||
mat.SetTexture("MetallicTexture", metal);
|
||||
mat.SetTexture("RoughnessTexture", rough);
|
||||
//mat.SetVariable("BaseColor", Vector4(1, 0, 1, 1));
|
||||
//mat.SetVariable("LightDir", Vector3(1, 1, 0).Normalized());
|
||||
|
||||
mat.SetVariable("AlbedoColor", ColorRGBA.White);
|
||||
mat.SetVariable("NormalScaling", Vector2.One);
|
||||
mat.SetVariable("MetallicFactor", 1.0f);
|
||||
mat.SetVariable("RoughnessFactor", 1.0f);
|
||||
|
||||
EcsEntity e = ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips, "Sphere 1");
|
||||
|
||||
@@ -239,8 +255,11 @@ namespace GlitchyEditor
|
||||
|
||||
DepthStencilStateDescription dsDesc = .();
|
||||
_depthStencilState = new DepthStencilState(dsDesc);
|
||||
|
||||
_cameraTarget = new RenderTarget2D(RenderTarget2DDescription(.R16G16B16A16_Float, 100, 100) {DepthStencilFormat = .D32_Float});
|
||||
_cameraTarget.SamplerState = SamplerStateManager.LinearClamp;
|
||||
|
||||
_viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100) {DepthStencilFormat = .D32_Float});
|
||||
_viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100));
|
||||
_viewportTarget.SamplerState = SamplerStateManager.LinearClamp;
|
||||
}
|
||||
|
||||
@@ -281,7 +300,7 @@ namespace GlitchyEditor
|
||||
|
||||
//Renderer.EndScene();
|
||||
|
||||
_scene.Update(gameTime);
|
||||
_scene.Update(gameTime, _viewportTarget);
|
||||
|
||||
RenderCommand.Clear(null, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0);
|
||||
|
||||
@@ -305,9 +324,9 @@ namespace GlitchyEditor
|
||||
|
||||
private bool OnImGuiRender(ImGuiRenderEvent event)
|
||||
{
|
||||
//viewer.ViewTexture(Renderer.[Friend]_gBuffer.Normal);
|
||||
viewer.ViewTexture(_cameraTarget);
|
||||
|
||||
ImGui.Begin("Test");
|
||||
/*ImGui.Begin("Test");
|
||||
|
||||
static bool cameraA = true;
|
||||
|
||||
@@ -317,7 +336,7 @@ namespace GlitchyEditor
|
||||
_otherCameraEntity.GetComponent<CameraComponent>().Primary = !cameraA;
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
ImGui.End();*/
|
||||
|
||||
ImGui.Viewport* viewport = ImGui.GetMainViewport();
|
||||
ImGui.DockSpaceOverViewport(viewport);
|
||||
@@ -383,6 +402,7 @@ namespace GlitchyEditor
|
||||
return;
|
||||
|
||||
_viewportTarget.Resize(sizeX, sizeY);
|
||||
_cameraTarget.Resize(sizeX, sizeY);
|
||||
|
||||
_scene.OnViewportResize(sizeX, sizeY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user