From e419ce849e9a72df70c30b7cb201dfcee40b4c75 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Wed, 30 Aug 2023 21:46:22 +0900 Subject: [PATCH] [NUI.Scene3D] Add Shadow for a Directional Light Signed-off-by: seungho baek --- .../src/internal/Interop/Interop.Light.cs | 28 +++++- src/Tizen.NUI.Scene3D/src/public/Light/Light.cs | 104 +++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Light.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Light.cs index db80aea..c320a17 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Light.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Light.cs @@ -43,8 +43,34 @@ namespace Tizen.NUI.Scene3D [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] public static extern bool IsEnabled(global::System.Runtime.InteropServices.HandleRef light); - [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_SceneView_GetMaximumEnabledLightCount")] + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_GetMaximumEnabledLightCount")] public static extern uint GetMaximumEnabledLightCount(); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_EnableShadow")] + public static extern void EnableShadow(global::System.Runtime.InteropServices.HandleRef light, bool enable); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_IsShadowEnabled")] + [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] + public static extern bool IsShadowEnabled(global::System.Runtime.InteropServices.HandleRef light); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_EnableShadowSoftFiltering")] + public static extern void EnableShadowSoftFiltering(global::System.Runtime.InteropServices.HandleRef light, bool enable); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_IsShadowSoftFilteringEnabled")] + [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] + public static extern bool IsShadowSoftFilteringEnabled(global::System.Runtime.InteropServices.HandleRef light); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_SetShadowIntensity")] + public static extern void SetShadowIntensity(global::System.Runtime.InteropServices.HandleRef light, float shadowIntensity); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_GetShadowIntensity")] + public static extern float GetShadowIntensity(global::System.Runtime.InteropServices.HandleRef light); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_SetShadowBias")] + public static extern void SetShadowBias(global::System.Runtime.InteropServices.HandleRef light, float shadowIntensity); + + [global::System.Runtime.InteropServices.DllImport(Libraries.Scene3D, EntryPoint = "CSharp_Dali_Light_GetShadowBias")] + public static extern float GetShadowBias(global::System.Runtime.InteropServices.HandleRef light); } } } diff --git a/src/Tizen.NUI.Scene3D/src/public/Light/Light.cs b/src/Tizen.NUI.Scene3D/src/public/Light/Light.cs index 52ffc74..2c35416 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Light/Light.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Light/Light.cs @@ -118,5 +118,109 @@ namespace Tizen.NUI.Scene3D if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } + + /// + /// Make the light enable shadow for this light or not. + /// NUI.Scene3D generates shadow by using shadow map. + /// For the Directional Light, the shadow map is created to cover view frustum of current selected camera. + /// This means that if the distance between the near and far planes is too large, + /// the shadow map has to cover an unnecessarily large area. This results in lower shadow quality. + /// + /// + /// This light should be already turned on in the SceneView. + /// (When true) If there is previous light already enabled shadow in the SceneView, this function call is ignored. + /// (When false, and this light is currently used for shader) + /// If there are other lights those are turned on and shadow enabled, one of the light will be used for shadow automatically. + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsShadowEnabled + { + get + { + + bool isEnabled = Interop.Light.IsShadowEnabled(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return isEnabled; + } + set + { + Interop.Light.EnableShadow(SwigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + /// + /// Make the shadow edge soften or not. + /// Basically the shadow is hard shadow that has sharp edge. + /// This method enables soft filtering to make the sharp edge to smoothing. + /// + /// + /// This soft filtering requires expensive computation power. + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsShadowSoftFilteringEnabled + { + get + { + + bool isEnabled = Interop.Light.IsShadowSoftFilteringEnabled(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return isEnabled; + } + set + { + Interop.Light.EnableShadowSoftFiltering(SwigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + /// + /// Sets and gets shadow intensity. + /// If the intensity is larger, the shadow area will be darker. + /// The intensity value is between [0, 1]. + /// Default value is 0.5 + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public float ShadowIntensity + { + get + { + + float shadowIntensity = Interop.Light.GetShadowIntensity(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return shadowIntensity; + } + set + { + Interop.Light.SetShadowIntensity(SwigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + /// + /// Sets and gets shadow bias. + /// Shadow bias is an offset value to remove shadow acne that is a visual artifact can be shown on the Shadow + /// Default value is 0.001 + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public float ShadowBias + { + get + { + + float shadowBias = Interop.Light.GetShadowBias(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return shadowBias; + } + set + { + Interop.Light.SetShadowBias(SwigCPtr, value); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } } } -- 2.7.4