From 1fcbec0d9d8cd4d0856a308f05aa31eae10a1830 Mon Sep 17 00:00:00 2001 From: teamclouday Date: Sun, 26 Dec 2021 19:39:07 -0500 Subject: [PATCH] support directional light (sun light) --- Assets/Materials/Box2.mat | 4 +- Assets/Materials/Light.mat | 2 +- .../CornellBox-Original-shortBox.mat | 15 +- .../sponza/Materials/sponza-ceiling.mat | 4 +- .../teapot/Materials/teapot-default.mat | 4 +- Assets/Scenes/Bunny.unity | 4 +- Assets/Scenes/Chrismas.unity | 4 +- Assets/Scenes/CornellBox.unity | 146 +------- Assets/Scenes/Dragon.unity | 14 +- Assets/Scenes/Room.unity | 347 +----------------- Assets/Scenes/Sponza.unity | 2 +- Assets/Scripts/Tracing.cs | 8 + Assets/Shaders/Tracing.compute | 23 +- Assets/Shaders/Tracing/global.hlsl | 1 + Assets/Shaders/Tracing/intersection.hlsl | 27 ++ ProjectSettings/EditorBuildSettings.asset | 4 +- 16 files changed, 95 insertions(+), 514 deletions(-) diff --git a/Assets/Materials/Box2.mat b/Assets/Materials/Box2.mat index 5fc2d7b..c48bce2 100644 --- a/Assets/Materials/Box2.mat +++ b/Assets/Materials/Box2.mat @@ -61,9 +61,9 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 0 - _GlossMapScale: 1 - - _Glossiness: 0.144 + - _Glossiness: 1 - _GlossyReflections: 1 - - _Metallic: 0.148 + - _Metallic: 1 - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 diff --git a/Assets/Materials/Light.mat b/Assets/Materials/Light.mat index 70242cb..252206a 100644 --- a/Assets/Materials/Light.mat +++ b/Assets/Materials/Light.mat @@ -74,5 +74,5 @@ Material: - _ZWrite: 1 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} - - _EmissionColor: {r: 0.7490196, g: 0.7490196, b: 0.7490196, a: 1} + - _EmissionColor: {r: 5.992157, g: 5.7411766, b: 4.737255, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Models/CornellBox/Materials/CornellBox-Original-shortBox.mat b/Assets/Models/CornellBox/Materials/CornellBox-Original-shortBox.mat index e3d10ab..936cc13 100644 --- a/Assets/Models/CornellBox/Materials/CornellBox-Original-shortBox.mat +++ b/Assets/Models/CornellBox/Materials/CornellBox-Original-shortBox.mat @@ -9,12 +9,13 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: CornellBox-Original-shortBox m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: + m_ShaderKeywords: _ALPHAPREMULTIPLY_ON m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} + m_CustomRenderQueue: 3000 + stringTagMap: + RenderType: Transparent disabledShaderPasses: [] m_SavedProperties: serializedVersion: 3 @@ -59,20 +60,20 @@ Material: - _BumpScale: 1 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 - - _DstBlend: 0 + - _DstBlend: 10 - _GlossMapScale: 1 - _Glossiness: 0 - _GlossyReflections: 1 - _Metallic: 0 - - _Mode: 0 + - _Mode: 3 - _OcclusionStrength: 1 - _Parallax: 0.02 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 - _UVSec: 0 - - _ZWrite: 1 + - _ZWrite: 0 m_Colors: - - _Color: {r: 0.725, g: 0.71, b: 0.68, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Models/sponza/Materials/sponza-ceiling.mat b/Assets/Models/sponza/Materials/sponza-ceiling.mat index 1706567..95725c7 100644 --- a/Assets/Models/sponza/Materials/sponza-ceiling.mat +++ b/Assets/Models/sponza/Materials/sponza-ceiling.mat @@ -9,8 +9,8 @@ Material: m_PrefabAsset: {fileID: 0} m_Name: sponza-ceiling m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: _EMISSION - m_LightmapFlags: 2 + m_ShaderKeywords: + m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 diff --git a/Assets/Models/teapot/Materials/teapot-default.mat b/Assets/Models/teapot/Materials/teapot-default.mat index 88fa2f3..cd8172a 100644 --- a/Assets/Models/teapot/Materials/teapot-default.mat +++ b/Assets/Models/teapot/Materials/teapot-default.mat @@ -62,9 +62,9 @@ Material: - _DetailNormalMapScale: 1 - _DstBlend: 10 - _GlossMapScale: 1 - - _Glossiness: 0.487 + - _Glossiness: 0.848 - _GlossyReflections: 1 - - _Metallic: 0.116 + - _Metallic: 0.525 - _Mode: 3 - _OcclusionStrength: 1 - _Parallax: 0.02 diff --git a/Assets/Scenes/Bunny.unity b/Assets/Scenes/Bunny.unity index d1cb192..3345415 100644 --- a/Assets/Scenes/Bunny.unity +++ b/Assets/Scenes/Bunny.unity @@ -291,7 +291,7 @@ Light: m_Type: 1 m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 0 + m_Intensity: 1 m_Range: 10 m_SpotAngle: 30 m_InnerSpotAngle: 21.80208 @@ -382,7 +382,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 855875881} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: -37.5, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 563345313} diff --git a/Assets/Scenes/Chrismas.unity b/Assets/Scenes/Chrismas.unity index da6561b..e57d0ea 100644 --- a/Assets/Scenes/Chrismas.unity +++ b/Assets/Scenes/Chrismas.unity @@ -407,7 +407,7 @@ MonoBehaviour: RayTracingShader: {fileID: 7200000, guid: 665d1ef5183a88c43ad98a3cf93e0ddd, type: 3} InfoShader: {fileID: 7200000, guid: b9568c70d14d4ae49a257b1843b38f9a, type: 3} DirectionalLight: {fileID: 523176987} - SkyboxTexture: {fileID: 8900000, guid: 992e1cc8f302dad45a03219eca9b2f59, type: 2} + SkyboxTexture: {fileID: 8900000, guid: 4dbc9c26cab64a242b32e55a02f630c8, type: 2} SkyboxIntensity: 1 TraceDepth: 5 CameraFocalDistance: 1 @@ -513,7 +513,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1594488316} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 18.5, z: 0} + m_LocalPosition: {x: 0, y: -17.9, z: 0} m_LocalScale: {x: 20, y: 1, z: 20} m_Children: [] m_Father: {fileID: 307151176} diff --git a/Assets/Scenes/CornellBox.unity b/Assets/Scenes/CornellBox.unity index 4ed78f2..ee2615e 100644 --- a/Assets/Scenes/CornellBox.unity +++ b/Assets/Scenes/CornellBox.unity @@ -123,102 +123,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &60095218 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 60095219} - - component: {fileID: 60095222} - - component: {fileID: 60095221} - - component: {fileID: 60095220} - m_Layer: 0 - m_Name: Quad - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &60095219 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 60095218} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 1300379386} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!64 &60095220 -MeshCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 60095218} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 4 - m_Convex: 0 - m_CookingOptions: 30 - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &60095221 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 60095218} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 2c1f8c6347b59f5458d2c1e42c7dc2cd, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &60095222 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 60095218} - m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 @@ -391,7 +295,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 2, z: -10} + m_LocalPosition: {x: 0, y: 2, z: -6} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -412,7 +316,7 @@ MonoBehaviour: RayTracingShader: {fileID: 7200000, guid: 665d1ef5183a88c43ad98a3cf93e0ddd, type: 3} InfoShader: {fileID: 7200000, guid: b9568c70d14d4ae49a257b1843b38f9a, type: 3} DirectionalLight: {fileID: 705507994} - SkyboxTexture: {fileID: 8900000, guid: 992e1cc8f302dad45a03219eca9b2f59, type: 2} + SkyboxTexture: {fileID: 8900000, guid: 4dbc9c26cab64a242b32e55a02f630c8, type: 2} SkyboxIntensity: 1 TraceDepth: 5 CameraFocalDistance: 1 @@ -434,50 +338,6 @@ MonoBehaviour: scrollSpeed: 0.5 dragSpeed: 0.1 keySpeed: 0.2 ---- !u!1 &1300379385 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1300379386} - - component: {fileID: 1300379387} - m_Layer: 0 - m_Name: Ground - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1300379386 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1300379385} - m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: -1.5, z: 0} - m_LocalScale: {x: 10, y: 10, z: 10} - m_Children: - - {fileID: 60095219} - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} ---- !u!114 &1300379387 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1300379385} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c62dccd56703b4e478d7ad78b4b896e6, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1448981423 GameObject: m_ObjectHideFlags: 0 @@ -508,7 +368,7 @@ Transform: m_Children: - {fileID: 1781954605} m_Father: {fileID: 0} - m_RootOrder: 4 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} --- !u!114 &1448981425 MonoBehaviour: diff --git a/Assets/Scenes/Dragon.unity b/Assets/Scenes/Dragon.unity index 413f954..5f695e5 100644 --- a/Assets/Scenes/Dragon.unity +++ b/Assets/Scenes/Dragon.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.44300318, g: 0.49219626, b: 0.57192606, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -248,7 +248,7 @@ Light: m_Type: 1 m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 0 + m_Intensity: 1 m_Range: 10 m_SpotAngle: 30 m_InnerSpotAngle: 21.80208 @@ -305,13 +305,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 776780037} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} - m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalRotation: {x: 0.5, y: 0, z: 0, w: 0.8660254} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} + m_LocalEulerAnglesHint: {x: 60, y: 0, z: 0} --- !u!1001 &1434804150 PrefabInstance: m_ObjectHideFlags: 0 @@ -345,7 +345,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 6464beefe2d727e4db8c1d2b946a29de, type: 3} propertyPath: m_LocalPosition.z - value: 0.0000013411045 + value: 0 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 6464beefe2d727e4db8c1d2b946a29de, type: 3} propertyPath: m_LocalRotation.w @@ -601,7 +601,7 @@ MonoBehaviour: RayTracingShader: {fileID: 7200000, guid: 665d1ef5183a88c43ad98a3cf93e0ddd, type: 3} InfoShader: {fileID: 7200000, guid: b9568c70d14d4ae49a257b1843b38f9a, type: 3} DirectionalLight: {fileID: 776780038} - SkyboxTexture: {fileID: 8900000, guid: 992e1cc8f302dad45a03219eca9b2f59, type: 2} + SkyboxTexture: {fileID: 8900000, guid: 4dbc9c26cab64a242b32e55a02f630c8, type: 2} SkyboxIntensity: 1 TraceDepth: 5 CameraFocalDistance: 1 diff --git a/Assets/Scenes/Room.unity b/Assets/Scenes/Room.unity index c211e5f..c3571da 100644 --- a/Assets/Scenes/Room.unity +++ b/Assets/Scenes/Room.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.4482345, g: 0.49425024, b: 0.55403584, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -123,242 +123,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &607599907 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 607599908} - - component: {fileID: 607599909} - m_Layer: 0 - m_Name: Lights - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &607599908 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 607599907} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.97, y: 1.8, z: 0.5} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 918176276} - - {fileID: 1397190298} - - {fileID: 1127498632} - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &607599909 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 607599907} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c62dccd56703b4e478d7ad78b4b896e6, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!1 &918176275 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 918176276} - - component: {fileID: 918176279} - - component: {fileID: 918176278} - - component: {fileID: 918176277} - m_Layer: 0 - m_Name: L1 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &918176276 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 918176275} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.4, y: 0.2, z: 0.4} - m_Children: [] - m_Father: {fileID: 607599908} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!135 &918176277 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 918176275} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &918176278 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 918176275} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 923d5e62af767244893abd35c4abf0f5, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &918176279 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 918176275} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!1 &1127498631 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1127498632} - - component: {fileID: 1127498635} - - component: {fileID: 1127498634} - - component: {fileID: 1127498633} - m_Layer: 0 - m_Name: Cube - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1127498632 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1127498631} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 2.25, y: 2.15, z: -0.75} - m_LocalScale: {x: 6, y: 0.1, z: 5} - m_Children: [] - m_Father: {fileID: 607599908} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!65 &1127498633 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1127498631} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &1127498634 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1127498631} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 5b124796ca2c7634794f3c1cb3579d66, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &1127498635 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1127498631} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!1001 &1225061402 PrefabInstance: m_ObjectHideFlags: 0 @@ -396,7 +160,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalRotation.w - value: 0.7071068 + value: 0 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalRotation.x @@ -404,7 +168,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalRotation.y - value: 0.7071068 + value: 1 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalRotation.z @@ -416,7 +180,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalEulerAnglesHint.y - value: 90 + value: 180 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} propertyPath: m_LocalEulerAnglesHint.z @@ -428,101 +192,6 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} ---- !u!1 &1397190297 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1397190298} - - component: {fileID: 1397190301} - - component: {fileID: 1397190300} - - component: {fileID: 1397190299} - m_Layer: 0 - m_Name: L2 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1397190298 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1397190297} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -1.6} - m_LocalScale: {x: 0.4, y: 0.2, z: 0.4} - m_Children: [] - m_Father: {fileID: 607599908} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!135 &1397190299 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1397190297} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &1397190300 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1397190297} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 923d5e62af767244893abd35c4abf0f5, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &1397190301 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1397190297} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} --- !u!1 &1407687244 stripped GameObject: m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: c12706641b51a1744abf9cc6bcb67952, type: 3} @@ -619,7 +288,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1849126419} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -1.5} + m_LocalPosition: {x: 0, y: 1, z: -3} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -691,7 +360,7 @@ Light: m_Type: 1 m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} - m_Intensity: 1 + m_Intensity: 2 m_Range: 10 m_SpotAngle: 30 m_InnerSpotAngle: 21.80208 @@ -748,10 +417,10 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2048758096} - m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalRotation: {x: 0.12575097, y: -0.58749944, z: 0.09305079, w: 0.79396015} m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} + m_LocalEulerAnglesHint: {x: 18, y: -73, z: 0} diff --git a/Assets/Scenes/Sponza.unity b/Assets/Scenes/Sponza.unity index 08074b0..6a8187d 100644 --- a/Assets/Scenes/Sponza.unity +++ b/Assets/Scenes/Sponza.unity @@ -558,7 +558,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1896617281} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: c62dccd56703b4e478d7ad78b4b896e6, type: 3} m_Name: diff --git a/Assets/Scripts/Tracing.cs b/Assets/Scripts/Tracing.cs index 132a50d..dc23478 100644 --- a/Assets/Scripts/Tracing.cs +++ b/Assets/Scripts/Tracing.cs @@ -51,6 +51,7 @@ public class Tracing : MonoBehaviour private int dispatchGroupX, dispatchGroupY; private Vector4 directionalLightInfo; + private Vector3 directionalLightColorInfo; private Denoise denoiser; @@ -149,6 +150,7 @@ private void SetShaderParameters(ComputeShader shader, int targetCount) shader.SetFloat("_SkyboxIntensity", SkyboxIntensity); // set directional light shader.SetVector("_DirectionalLight", directionalLightInfo); + shader.SetVector("_DirectionalLightColor", directionalLightColorInfo); // set objects info if (ObjectManager.VertexBuffer != null) shader.SetBuffer(0, "_Vertices", ObjectManager.VertexBuffer); if (ObjectManager.IndexBuffer != null) shader.SetBuffer(0, "_Indices", ObjectManager.IndexBuffer); @@ -280,6 +282,7 @@ private void Update() if(Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.R) && Application.isEditor) { ObjectManager.ReloadMaterials(); + UpdateDirectionalLight(); ResetSamples(); } } @@ -301,6 +304,11 @@ private void UpdateDirectionalLight() -dir.x, -dir.y, -dir.z, DirectionalLight.intensity ); + directionalLightColorInfo = new Vector3( + DirectionalLight.color.r, + DirectionalLight.color.g, + DirectionalLight.color.b + ); } private Vector2 GeneratePixelOffset() diff --git a/Assets/Shaders/Tracing.compute b/Assets/Shaders/Tracing.compute index 2b258ac..d0832a9 100644 --- a/Assets/Shaders/Tracing.compute +++ b/Assets/Shaders/Tracing.compute @@ -11,7 +11,8 @@ bool TraceHit(Ray ray, float targetDist) { HitInfo bestHit = CreateHitInfo(); // check tlas intersection - return IntersectTlasTreeFast(ray, bestHit, targetDist); + //return IntersectTlasTreeFast(ray, bestHit, targetDist); + return IntersectTlasFast(ray, bestHit, targetDist); } // trace a ray and detect nearest hit @@ -19,8 +20,8 @@ HitInfo Trace(Ray ray) { HitInfo bestHit = CreateHitInfo(); // check tlas intersection - IntersectTlasTree(ray, bestHit); - //IntersectTlas(ray, bestHit); + //IntersectTlasTree(ray, bestHit); + IntersectTlas(ray, bestHit); return bestHit; } @@ -32,6 +33,18 @@ float3 Shade(inout Ray ray, HitInfo hit) //ray.energy = 0.0; //return hit.norm * 0.5 + 0.5; + // sample directional light + Ray shadowRay = CreateRay(hit.pos + hit.norm * 1e-5, _DirectionalLight.xyz); + float3 lightContrib = _DirectionalLight.w; + if (_DirectionalLight.w <= 0.0 || TraceHit(shadowRay, 1.#INF)) + { + lightContrib = 0.0; + } + else + { + lightContrib *= hit.colors.albedo * saturate(dot(hit.norm, _DirectionalLight.xyz)) * _DirectionalLightColor; + } + float random = rand(); if(hit.mode >= 3.0) { @@ -44,12 +57,14 @@ float3 Shade(inout Ray ray, HitInfo hit) { ray.dir = normalize(SampleHemisphere3(reflect(ray.dir, hit.norm), 1e5 * kr)); ray.energy *= clamp(1.0 / kr, 0.0, 1e2) * hit.colors.specular * clamp(dot(hit.norm, ray.dir), 0.8, 1.0); + lightContrib *= saturate(kr); } else { kr = 1.0 - kr; ray.dir = normalize(SampleHemisphere3(refract(ray.dir, hit.norm, 1.0 / ior), 1e5 * kr)); ray.energy *= clamp(1.0 / kr, 0.0, 1e2) * hit.colors.albedo * clamp(dot(-hit.norm, ray.dir), 0.8, 1.0); + lightContrib *= saturate(kr); } } else @@ -73,7 +88,7 @@ float3 Shade(inout Ray ray, HitInfo hit) ray.energy *= 1.0 / diffChance * 2.0 * hit.colors.albedo * saturate(dot(hit.norm, ray.dir)); } } - return hit.colors.emission; + return hit.colors.emission + lightContrib; } else diff --git a/Assets/Shaders/Tracing/global.hlsl b/Assets/Shaders/Tracing/global.hlsl index 05ae484..0e9d4f0 100644 --- a/Assets/Shaders/Tracing/global.hlsl +++ b/Assets/Shaders/Tracing/global.hlsl @@ -23,6 +23,7 @@ float2 _PixelOffset; // directional light info float4 _DirectionalLight; +float3 _DirectionalLightColor; // trace depth int _TraceDepth; diff --git a/Assets/Shaders/Tracing/intersection.hlsl b/Assets/Shaders/Tracing/intersection.hlsl index 90ee9a1..036a783 100644 --- a/Assets/Shaders/Tracing/intersection.hlsl +++ b/Assets/Shaders/Tracing/intersection.hlsl @@ -247,11 +247,18 @@ bool IntersectBlasTreeFast(Ray ray, int startIdx, float targetDist) float3 v0 = _Vertices[_Indices[i]]; float3 v1 = _Vertices[_Indices[i + 1]]; float3 v2 = _Vertices[_Indices[i + 2]]; + float2 uv0 = _UVs[_Indices[i]]; + float2 uv1 = _UVs[_Indices[i + 1]]; + float2 uv2 = _UVs[_Indices[i + 2]]; float t, u, v; if (IntersectTriangle(ray, v0, v1, v2, t, u, v)) { if (t > 0.0 && t < targetDist) { + MaterialData mat = _Materials[node.materialIdx]; + float2 uv = uv1 * u + uv2 * v + uv0 * (1.0 - u - v); + if (mat.mode == 1.0 && GetColorAlpha(mat.color, mat.albedoIdx, uv) < 1.0) + continue; return true; } } @@ -355,4 +362,24 @@ bool IntersectTlasTreeFast(Ray ray, HitInfo bestHit, float targetDist) return false; } +bool IntersectTlasFast(Ray ray, HitInfo bestHit, float targetDist) +{ + uint size, stride; + _TNodesRaw.GetDimensions(size, stride); + for (uint i = 0; i < size; i++) + { + TLASNodeRaw node = _TNodesRaw[i]; + if (IntersectBox3(ray, bestHit, node.boundMax, node.boundMin)) + { + // intersect with BLAS tree + Ray localRay = PrepareTreeEnterRay(ray, node.transformIdx); + PrepareTreeEnterHit(localRay, bestHit, node.transformIdx); + if (IntersectBlasTreeFast(localRay, node.rootIdx, targetDist)) + return true; + PrepareTreeExit(ray, bestHit, node.transformIdx); + } + } + return false; +} + #endif \ No newline at end of file diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 3c09cc0..98a28e1 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -6,6 +6,6 @@ EditorBuildSettings: serializedVersion: 2 m_Scenes: - enabled: 1 - path: Assets/Scenes/Sponza.unity - guid: d8f4db3443f0b5f44b4ca7d99f8f6b07 + path: Assets/Scenes/Room.unity + guid: 16de311b445e859448951e15930167d8 m_configObjects: {}