@@ -58,13 +58,6 @@ public static void SetTexelsPerMeter(float newTexelsPerMeter) {
5858 private const string defaultTextureName = "_DecalColorMap" ;
5959 public static Material GetDilationMaterial ( ) => instance . dilationMaterial ;
6060 public static float GetTexelsPerMeter ( ) => instance . texelsPerMeter ;
61- private static void GetComponentsInChildrenNoAlloc < T > ( Transform t , List < T > temp , List < T > result ) {
62- t . GetComponents < T > ( temp ) ;
63- result . AddRange ( temp ) ;
64- for ( int i = 0 ; i < t . childCount ; i ++ ) {
65- GetComponentsInChildrenNoAlloc < T > ( t . GetChild ( i ) , temp , result ) ;
66- }
67- }
6861
6962 private int InternalMemoryInUse ( ) {
7063 int memoryInUse = 0 ;
@@ -139,49 +132,18 @@ public static void RemoveDecalableInfo(MonoBehaviourHider.DecalableInfo info) {
139132 }
140133 }
141134
142- public static void RenderDecalForCollider ( Collider c , Material projector , Vector3 position , Quaternion rotation , Vector2 size , float depth = 0.5f , string textureName = defaultTextureName ) {
143- LODGroup group = c . GetComponentInParent < LODGroup > ( ) ;
144- if ( group != null ) {
145- instance . staticRenderers . Clear ( ) ;
146- GetComponentsInChildrenNoAlloc < Renderer > ( group . transform , instance . staticTempRenderers , instance . staticRenderers ) ;
147- foreach ( Renderer renderer in instance . staticRenderers ) {
148- RenderDecal ( renderer , projector , position , rotation , size , depth , textureName ) ;
149- }
150- return ;
151- }
152- Renderer parentRenderer = c . GetComponentInParent < Renderer > ( ) ;
153- if ( parentRenderer != null ) {
154- RenderDecal ( parentRenderer , projector , position , rotation , size , depth , textureName ) ;
155- }
156-
157- instance . staticRenderers . Clear ( ) ;
158- GetComponentsInChildrenNoAlloc < Renderer > ( c . transform , instance . staticTempRenderers , instance . staticRenderers ) ;
159- foreach ( Renderer renderer in instance . staticRenderers ) {
160- RenderDecal ( renderer , projector , position , rotation , size , depth , textureName ) ;
161- }
162- }
163- public static void RenderDecalInSphere ( Vector3 position , float radius , Material projector , Quaternion rotation , LayerMask hitMask , string textureName = defaultTextureName ) {
164- int hits = Physics . OverlapSphereNonAlloc ( position , radius , instance . colliders , hitMask , QueryTriggerInteraction . UseGlobal ) ;
165- for ( int i = 0 ; i < hits ; i ++ ) {
166- Collider c = instance . colliders [ i ] ;
167- RenderDecalForCollider ( c , projector , position - rotation * Vector3 . forward * radius , rotation , Vector2 . one * radius , radius * 2f , textureName ) ;
168- }
169- }
170- public static void RenderDecalInBox ( Vector3 boxHalfExtents , Vector3 position , Material projector , Quaternion boxOrientation , LayerMask hitMask , string textureName = defaultTextureName ) {
171- int hits = Physics . OverlapBoxNonAlloc ( position , boxHalfExtents , instance . colliders , boxOrientation , hitMask , QueryTriggerInteraction . UseGlobal ) ;
172- for ( int i = 0 ; i < hits ; i ++ ) {
173- Collider c = instance . colliders [ i ] ;
174- RenderDecalForCollider ( c , projector , position - boxOrientation * Vector3 . forward * boxHalfExtents . z , boxOrientation , new Vector2 ( boxHalfExtents . x , boxHalfExtents . y ) * 2f , boxHalfExtents . z * 2f , textureName ) ;
175- }
176- }
177- public static void RenderDecalForCollision ( Collider c , Material projector , Vector3 position , Vector3 normal , float rotationAboutNormal , Vector2 size , float halfDepth = 0.5f , string textureName = defaultTextureName ) {
178- RenderDecalForCollider ( c , projector , position + normal * halfDepth , Quaternion . AngleAxis ( rotationAboutNormal , normal ) * Quaternion . FromToRotation ( Vector3 . forward , - normal ) , size , halfDepth * 2f , textureName ) ;
179- }
180- public static void RenderDecal ( Renderer r , Material projector , Vector3 position , Quaternion rotation , Vector2 size , float depth = 0.5f , string textureName = defaultTextureName ) {
135+ public static void RenderDecal ( Renderer r , Material projector , Vector3 position , Quaternion rotation , Vector2 size , float depth = 0.5f , string textureName = defaultTextureName , RenderTextureFormat renderTextureFormat = RenderTextureFormat . Default , RenderTextureReadWrite renderTextureReadWrite = RenderTextureReadWrite . Default ) {
181136 // Only can draw on meshes.
182137 if ( ! ( r is SkinnedMeshRenderer ) && ! ( r is MeshRenderer ) ) {
183138 return ;
184139 }
140+
141+ #if UNITY_EDITOR
142+ if ( r . localToWorldMatrix . determinant < 0f ) {
143+ Debug . LogError (
144+ "Tried to render a decal on an inside-out object, this isn't supported! Make sure scales aren't negative." , r . gameObject ) ;
145+ }
146+ #endif
185147
186148 if ( ! r . TryGetComponent ( out MonoBehaviourHider . DecalableInfo info ) ) {
187149 info = r . gameObject . AddComponent < MonoBehaviourHider . DecalableInfo > ( ) ;
@@ -194,7 +156,7 @@ public static void RenderDecal(Renderer r, Material projector, Vector3 position,
194156 // We just queue up the commands, paintdecal will send them all together when its ready.
195157 instance . commandBuffer . Clear ( ) ;
196158 instance . commandBuffer . SetViewProjectionMatrices ( view , projection ) ;
197- info . Render ( instance . commandBuffer , projector , textureName ) ;
159+ info . Render ( instance . commandBuffer , projector , textureName , renderTextureFormat , renderTextureReadWrite ) ;
198160 Graphics . ExecuteCommandBuffer ( instance . commandBuffer ) ;
199161 }
200162
0 commit comments