Search Unity

Feedback URP decal bug.Error when last decal is in distance

Discussion in 'Universal Render Pipeline' started by gyx920820, Sep 6, 2022.

  1. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    DecalCreateDrawCallSystem.cs
    line 180 should be like this.Otherwise if last decal is in distance, all other decals will be discarded.

    Code (CSharp):
    1.                     float distanceToDecal = (cameraPosition - boundingSphere.position).magnitude;
    2.                     float cullDistance = math.min(drawDistance.x, maxDrawDistance) + boundingSphere.radius;
    3.                     if (distanceToDecal <= cullDistance)
    4.                     {
    5.  
    6.                         decalToWorldsDraw[instanceIndex] = decalToWorlds[decalIndex];
    7.  
    8.                         float fadeFactorScaler = fadeFactors[decalIndex];
    9.                         float2 angleFade = angleFades[decalIndex];
    10.                         float4 uvScaleBias = uvScaleBiases[decalIndex];
    11.  
    12.                         float4x4 normalToDecals = normalToWorlds[decalIndex];
    13.                         // NormalToWorldBatchis a Matrix4x4x but is a Rotation matrix so bottom row and last column can be used for other data to save space
    14.                         float fadeFactor = fadeFactorScaler * math.clamp((cullDistance - distanceToDecal) / (cullDistance * (1.0f - drawDistance.y)), 0.0f, 1.0f);
    15.                         normalToDecals.c0.w = uvScaleBias.x;
    16.                         normalToDecals.c1.w = uvScaleBias.y;
    17.                         normalToDecals.c2.w = uvScaleBias.z;
    18.                         normalToDecals.c3 = new float4(fadeFactor * 1.0f, angleFade.x, angleFade.y, uvScaleBias.w);
    19.                         normalToDecalsDraw[instanceIndex] = normalToDecals;
    20.  
    21.                         instanceIndex++;
    22.                     }
    23.  
    24.                     int instanceCount = instanceIndex - instanceStart;
    25.                     bool isReachedMaximumBatchSize = instanceCount >= 250;
    26.                     bool isLastDecal = i == visibleDecalCount - 1;
    27.                     if (isReachedMaximumBatchSize || isLastDecal)
    28.                     {
    29.                         subCalls[subCallIndex++] = new DecalSubDrawCall()
    30.                         {
    31.                             start = instanceStart,
    32.                             end = instanceIndex,
    33.                         };
    34.                         instanceStart = instanceIndex;
    35.                     }
    36.  
     
    pierre92nicot likes this.
  2. gyx920820

    gyx920820

    Joined:
    Oct 8, 2015
    Posts:
    35
    DecalDrawSystem.cs line 159 should change like this:
    Code (CSharp):
    1. Graphics.DrawMesh(mesh, decalDrawCallChunk.decalToWorlds[j], material, decalCachedChunk.layerMasks[j], cameraData.camera, 0, decalCachedChunk.propertyBlock);