Depth of field no unit accurate

This commit is contained in:
antopilo
2024-12-01 13:06:13 -05:00
parent 15051a4eb7
commit b6c3220797
6 changed files with 55 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ namespace Nuake
Matrix4 Camera::GetPerspective()
{
//TODO: Add perspective options
m_Perspective = glm::perspectiveFov(glm::radians(Fov), 9.0f * AspectRatio, 9.0f, 0.001f, 400.0f);
m_Perspective = glm::perspectiveFov(glm::radians(Fov), 9.0f * AspectRatio, 9.0f, Near, Far);
return m_Perspective;
}

View File

@@ -27,6 +27,9 @@ namespace Nuake
Matrix4 m_Perspective;
Matrix4 m_View;
float Near = 0.001f;
float Far = 400.0f;
public:
float AspectRatio = 16.0f / 9.0f;
@@ -48,6 +51,9 @@ namespace Nuake
void SetDirection(Vector3 direction);
void SetDirection(const Quat& direction);
float GetNear() const { return Near; }
float GetFar() const { return Far; }
Vector3 GetTranslation();
Vector3 GetDirection();
Matrix4 GetPerspective();

View File

@@ -447,6 +447,9 @@ namespace Nuake
Shader* shader = ShaderManager::GetShader("Resources/Shaders/dof.shader");
shader->Bind();
auto cam = scene.GetCurrentCamera();
shader->SetUniform("znear", cam->GetNear());
shader->SetUniform("zfar", cam->GetFar());
shader->SetUniform("focalDepth", sceneEnv->DOFFocalDepth);
shader->SetUniform("focalLength", sceneEnv->DOFFocalLength);
shader->SetUniform("fstop", sceneEnv->DOFFstop);

View File

@@ -625,6 +625,16 @@ namespace Nuake {
}
}
void EnvironmentDepthOfFieldSetFocusDistanceIcall(float distance)
{
Engine::GetCurrentScene()->GetEnvironment()->DOFFocalDepth = distance;
}
float EnvironmentDepthOfFieldGetFocusDistanceIcall()
{
return Engine::GetCurrentScene()->GetEnvironment()->DOFFocalDepth;
}
void Nuake::SceneNetAPI::RegisterMethods()
{
// Entity
@@ -680,6 +690,9 @@ namespace Nuake {
// Audio Emitter
RegisterMethod("AudioEmitterComponent.GetIsPlayingIcall", &AudioEmitterGetIsPlaying);
RegisterMethod("AudioEmitterComponent.SetIsPlayingIcall", &AudioEmitterSetIsPlaying);
RegisterMethod("Environment.SetFocusDistanceIcall", &EnvironmentDepthOfFieldSetFocusDistanceIcall);
RegisterMethod("Environment.GetFocusDistanceIcall", &EnvironmentDepthOfFieldGetFocusDistanceIcall);
}
}

View File

@@ -0,0 +1,31 @@
using Coral.Managed.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nuake.Net
{
public class Environment
{
internal static unsafe delegate*<float, void> SetFocusDistanceIcall;
internal static unsafe delegate*<float> GetFocusDistanceIcall;
public static void SetFocusDistance(float distance)
{
unsafe
{
SetFocusDistanceIcall(distance);
}
}
public static float GetFocusDistance()
{
unsafe
{
return GetFocusDistanceIcall();
}
}
}
}

View File

@@ -83,7 +83,7 @@ uniform bool showFocus = false;
make sure that these two values are the same for your camera, otherwise distances will be wrong.
*/
uniform float znear = 0.1f; //camera clipping start
uniform float znear = 0.001f; //camera clipping start
uniform float zfar = 1000.0; //camera clipping end
//------------------------------------------