浏览代码

spot and point lights now render their geometry with front face culling and greater ztest if near clip is intersected, rather than fullscreen quad.

/main
Filip Iliescu 8 年前
当前提交
a44e4c7c
共有 3 个文件被更改,包括 252 次插入12 次删除
  1. 18
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs
  2. 240
      Assets/TestScenes/MobileDeferredTest/ClassicDeferredTest.unity
  3. 6
      Assets/TestScenes/MobileDeferredTest/ClassicDeferredTest/LightingData.asset

18
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs


private Material m_DirectionalDeferredLightingMaterial;
private Material m_FiniteDeferredLightingMaterial;
private Material m_FiniteNearDeferredLightingMaterial;
private Material m_ReflectionMaterial;
private Material m_ReflectionNearClipMaterial;

if (m_BlitMaterial) DestroyImmediate(m_BlitMaterial);
if (m_DirectionalDeferredLightingMaterial) DestroyImmediate(m_DirectionalDeferredLightingMaterial);
if (m_FiniteDeferredLightingMaterial) DestroyImmediate(m_FiniteDeferredLightingMaterial);
if (m_FiniteNearDeferredLightingMaterial) DestroyImmediate(m_FiniteNearDeferredLightingMaterial);
if (m_ReflectionMaterial) DestroyImmediate (m_ReflectionMaterial);
if (m_ReflectionNearClipMaterial) DestroyImmediate (m_ReflectionNearClipMaterial);
if (m_ReflectionNearAndFarClipMaterial) DestroyImmediate (m_ReflectionNearAndFarClipMaterial);

m_FiniteDeferredLightingMaterial.SetInt("_DstABlend", (int)BlendMode.Zero);
m_FiniteDeferredLightingMaterial.SetInt("_CullMode", (int)CullMode.Back);
m_FiniteDeferredLightingMaterial.SetInt("_CompareFunc", (int)CompareFunction.LessEqual);
m_FiniteNearDeferredLightingMaterial = new Material (deferredShader) { hideFlags = HideFlags.HideAndDontSave };
m_FiniteNearDeferredLightingMaterial.SetInt("_SrcBlend", (int)BlendMode.One);
m_FiniteNearDeferredLightingMaterial.SetInt("_DstBlend", (int)BlendMode.One);
m_FiniteNearDeferredLightingMaterial.SetInt("_SrcABlend", (int)BlendMode.One);
m_FiniteNearDeferredLightingMaterial.SetInt("_DstABlend", (int)BlendMode.Zero);
m_FiniteNearDeferredLightingMaterial.SetInt("_CullMode", (int)CullMode.Front);
m_FiniteNearDeferredLightingMaterial.SetInt("_CompareFunc", (int)CompareFunction.Greater);
m_ReflectionMaterial = new Material (deferredReflectionShader) { hideFlags = HideFlags.HideAndDontSave };
m_ReflectionMaterial.SetInt("_SrcBlend", (int)BlendMode.DstAlpha);

{
VisibleLight light = inputs.visibleLights[lightNum];
bool renderAsQuad = (light.flags & VisibleLightFlags.IntersectsNearPlane)!=0 || (light.flags & VisibleLightFlags.IntersectsFarPlane)!=0 || (light.lightType == LightType.Directional);
bool intersectsNear = (light.flags & VisibleLightFlags.IntersectsNearPlane) != 0;
bool intersectsFar = (light.flags & VisibleLightFlags.IntersectsFarPlane) != 0;
bool renderAsQuad = (intersectsNear && intersectsFar) || (light.lightType == LightType.Directional);
Vector3 lightPos = light.localToWorld.GetColumn (3); //position
Vector3 lightDir = light.localToWorld.GetColumn (2); //z axis

}
if (renderAsQuad) {
cmd.DrawMesh (m_QuadMesh, Matrix4x4.identity, m_DirectionalDeferredLightingMaterial, 0, 0, props);
} else if (intersectsNear) {
cmd.DrawMesh (m_PointLightMesh, matrix, m_FiniteNearDeferredLightingMaterial, 0, 0, props);
} else {
cmd.DrawMesh (m_PointLightMesh, matrix, m_FiniteDeferredLightingMaterial, 0, 0, props);
}

if (renderAsQuad) {
cmd.DrawMesh (m_QuadMesh, Matrix4x4.identity, m_DirectionalDeferredLightingMaterial, 0, 0, props);
} else if (intersectsNear) {
cmd.DrawMesh (m_SpotLightMesh, lightToWorld, m_FiniteNearDeferredLightingMaterial, 0, 0, props);
} else {
cmd.DrawMesh (m_SpotLightMesh, lightToWorld, m_FiniteDeferredLightingMaterial, 0, 0, props);
}

240
Assets/TestScenes/MobileDeferredTest/ClassicDeferredTest.unity


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 95697982}
m_LocalRotation: {x: 0.2164396, y: 0, z: 0, w: 0.97629607}
m_LocalPosition: {x: -32, y: 65.8, z: -160.3}
m_LocalRotation: {x: -0.170569, y: -0.12467795, z: 0.02176232, w: -0.97718376}
m_LocalPosition: {x: -59.316757, y: 70.361824, z: -168.81792}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 696494501}
m_LocalRotation: {x: 0.02170083, y: 0.0053889398, z: -0.00011697372, w: 0.99975}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalEulerAnglesHint: {x: 2.4870002, y: 0.61800003, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!215 &696494503
ReflectionProbe:
m_ObjectHideFlags: 0

- {fileID: 1021527292}
- {fileID: 1161912881}
- {fileID: 696494502}
- {fileID: 826396901}
--- !u!1 &826396900
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 826396901}
- component: {fileID: 826396902}
m_Layer: 0
m_Name: Sphere Reflection Probe (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &826396901
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 826396900}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -88.1, y: 16.8, z: -28.1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 797301775}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!215 &826396902
ReflectionProbe:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 826396900}
m_Enabled: 1
serializedVersion: 2
m_Type: 0
m_Mode: 1
m_RefreshMode: 1
m_TimeSlicingMode: 0
m_Resolution: 128
m_UpdateFrequency: 0
m_BoxSize: {x: 20, y: 20, z: 20}
m_BoxOffset: {x: 0, y: 0, z: 0}
m_NearClip: 0.3
m_FarClip: 1000
m_ShadowDistance: 100
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_IntensityMultiplier: 2
m_BlendDistance: 1
m_HDR: 1
m_BoxProjection: 0
m_RenderDynamicObjects: 0
m_UseOcclusionCulling: 1
m_Importance: 1
m_CustomBakedTexture: {fileID: 0}
--- !u!1 &912152365
GameObject:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 945195326}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -118.8, y: 1.3, z: 33.8}
m_LocalPosition: {x: -102.3, y: -1.6, z: -55.4}
m_LocalScale: {x: 20, y: 20, z: 20}
m_Children: []
m_Father: {fileID: 0}

- component: {fileID: 985220433}
- component: {fileID: 985220432}
m_Layer: 0
m_Name: ground (5)
m_Name: frontCenter
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1021527291}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -131.8, y: 17.5, z: 77.4}
m_LocalPosition: {x: -115.3, y: 14.6, z: -11.8}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 797301775}

m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_IntensityMultiplier: 5
m_IntensityMultiplier: 2.49
m_BlendDistance: 1
m_HDR: 1
m_BoxProjection: 0

m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1275902020
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1275902021}
- component: {fileID: 1275902022}
m_Layer: 0
m_Name: Spotlight
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1275902021
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1275902020}
m_LocalRotation: {x: 0.38268343, y: 0, z: 0, w: 0.92387956}
m_LocalPosition: {x: -10.2, y: 152.1, z: -257.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1436098192}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0}
--- !u!108 &1275902022
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1275902020}
m_Enabled: 1
serializedVersion: 8
m_Type: 0
m_Color: {r: 0.033975385, g: 0, b: 0.9852941, a: 1}
m_Intensity: 15.95
m_Range: 500
m_SpotAngle: 23
m_CookieSize: 10
m_Shadows:
m_Type: 0
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_FalloffTable:
m_Table[0]: 0
m_Table[1]: 0
m_Table[2]: 0
m_Table[3]: 0
m_Table[4]: 0
m_Table[5]: 0
m_Table[6]: 0
m_Table[7]: 0
m_Table[8]: 0
m_Table[9]: 0
m_Table[10]: 0
m_Table[11]: 0
m_Table[12]: 0
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1366809161
GameObject:
m_ObjectHideFlags: 0

- {fileID: 1719222741}
- {fileID: 480371294}
- {fileID: 1167670143}
- {fileID: 1275902021}
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!1 &1726338861
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1726338865}
- component: {fileID: 1726338864}
- component: {fileID: 1726338863}
- component: {fileID: 1726338862}
m_Layer: 0
m_Name: Reflective Ball (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &1726338862
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726338861}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: dd33fc7fd2c844efa8c209610ff06074, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
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
--- !u!135 &1726338863
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726338861}
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!33 &1726338864
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726338861}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1726338865
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1726338861}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -75.1, y: 2.3, z: -71.7}
m_LocalScale: {x: 20, y: 20, z: 20}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1729182546
GameObject:
m_ObjectHideFlags: 0

6
Assets/TestScenes/MobileDeferredTest/ClassicDeferredTest/LightingData.asset


12�102017.1.0b2�������Ƣ��^Ee��c���_��7���������� �� ��".�+���� ��".�+H��������1�1����� @���
1131P2017.1.0b3�������Ƣ��^Ee��c���_��7���������� �� ��".�+���� ��".�+H��������1�1����� @���
��j� ��� LightingDataAssetPPtr<EditorExtension>m_FileIDm_PathIDm_LightmapsLightmapDatam_Lightmapm_DirLightmapm_ShadowMaskPPtr<LightProbes>m_LightProbesm_LightmapsModeSphericalHarmonicsL2m_BakedAmbientProbeInLinearsh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_LightmappedRendererDataRendererDataPPtr<Mesh>uvMeshterrainDynamicUVSTxyzwterrainChunkDynamicUVSTlightmapIndexlightmapIndexDynamiclightmapSTlightmapSTDynamicm_LightmappedRendererDataIDsSceneObjectIdentifiertargetObjecttargetPrefabEnlightenSceneMappingm_EnlightenSceneMappingm_RenderersEnlightenRendererInformationrendererdynamicLightmapSTInSystemsystemIdHash128instanceHashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]geometryHashm_SystemsEnlightenSystemInformationrendererIndexrendererSizeatlasIndexatlasOffsetXatlasOffsetYinputSystemHashradiositySystemHashm_Probesetsm_SystemAtlasesEnlightenSystemAtlasInformationatlasSizeatlasHashfirstSystemIdm_TerrainChunksEnlightenTerrainChunksInformationnumChunksInXnumChunksInYm_EnlightenSceneMappingRendererIDsm_Lightsm_LightBakingOutputsLightBakingOutputprobeOcclusionLightIndexocclusionMaskChannellightmappingMaskm_BakedReflectionProbeCubemapsm_BakedReflectionProbesm_EnlightenDatam_EnlightenDataVersion@��H��Hd��3-�YH״�,��:�ͧb׫�EӺ�rhުĢS8���FR�+�b�O LightingData LightingData@����;>�I��h��;�L<�l<m�;���;��}<
=�lj>�L(=`+<�P�<�~<f�<��"<�K�<`K7=���>x��=��<�i =EQ�<�|q<��6<l=xa=�͇�͇�͇�D�<2bAE;UnityFS5.x.x2017.1.0b2;
��j� ��� LightingDataAssetPPtr<EditorExtension>m_FileIDm_PathIDm_LightmapsLightmapDatam_Lightmapm_DirLightmapm_ShadowMaskPPtr<LightProbes>m_LightProbesm_LightmapsModeSphericalHarmonicsL2m_BakedAmbientProbeInLinearsh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_LightmappedRendererDataRendererDataPPtr<Mesh>uvMeshterrainDynamicUVSTxyzwterrainChunkDynamicUVSTlightmapIndexlightmapIndexDynamiclightmapSTlightmapSTDynamicm_LightmappedRendererDataIDsSceneObjectIdentifiertargetObjecttargetPrefabEnlightenSceneMappingm_EnlightenSceneMappingm_RenderersEnlightenRendererInformationrendererdynamicLightmapSTInSystemsystemIdHash128instanceHashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]geometryHashm_SystemsEnlightenSystemInformationrendererIndexrendererSizeatlasIndexatlasOffsetXatlasOffsetYinputSystemHashradiositySystemHashm_Probesetsm_SystemAtlasesEnlightenSystemAtlasInformationatlasSizeatlasHashfirstSystemIdm_TerrainChunksEnlightenTerrainChunksInformationnumChunksInXnumChunksInYm_EnlightenSceneMappingRendererIDsm_Lightsm_LightBakingOutputsLightBakingOutputprobeOcclusionLightIndexocclusionMaskChannellightmappingMaskm_BakedReflectionProbeCubemapsm_BakedReflectionProbesm_EnlightenDatam_EnlightenDataVersion@��H��H���3-�YH״�,��:�ͧb׫�EӺ�rhުĢS8���FR�+�b�O�ʣ�Mϩ��j<J� LightingData LightingData@����;>�I��h��;�L<�l<m�;���;��}<
=�lj>�L(=`+<�P�<�~<f�<��"<�K�<`K7=���>x��=��<�i =EQ�<�|q<��6<l=xa=�͇�͇�͇�͇�D�<2bAE���);UnityFS5.x.x2017.1.0b2;
�Pk
正在加载...
取消
保存