private void DrawNormal(Decal decal, Material material, ref int n) { if (decal.HighQualityBlending) { // Create of copy of GBuffer1 (specular / smoothness) and GBuffer 2 (normal) _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer1, _copy1ID); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, _copy2ID); _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloat("_MaskMultiplier", decal.Fade); _instancedBlock.SetFloat("_LimitTo", decal.LimitTo ? decal.LimitTo.GetInstanceID() : _noLimitToValue); _instancedBlock.SetVectorArray("_Color", _colors); _bufferDeferred.DrawMesh(_cubeMesh, decal.transform.localToWorldMatrix, material, 0, 1, _instancedBlock); } else { if (UseInstancing) { // Instanced drawing _matrices[n] = decal.transform.localToWorldMatrix; _fadeValues[n] = decal.Fade; _limitToValues[n] = decal.LimitTo ? decal.LimitTo.GetInstanceID() : _noLimitToValue; _colors[n] = decal.Color; ++n; if (n == 1023) { // Create of copy of GBuffer1 (specular / smoothness) and GBuffer 2 (normal) _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer1, _copy1ID); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, _copy2ID); _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloatArray("_MaskMultiplier", _fadeValues); _instancedBlock.SetFloatArray("_LimitTo", _limitToValues); _instancedBlock.SetVectorArray("_Color", _colors); _bufferDeferred.DrawMeshInstanced(_cubeMesh, 0, material, 1, _matrices, n, _instancedBlock); n = 0; } } else { if (n == 0) { // Create of copy of GBuffer1 (specular / smoothness) and GBuffer 2 (normal) _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer1, _copy1ID); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, _copy2ID); } _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloat("_MaskMultiplier", decal.Fade); _instancedBlock.SetFloat("_LimitTo", decal.LimitTo ? decal.LimitTo.GetInstanceID() : _noLimitToValue); _instancedBlock.SetVectorArray("_Color", _colors); _bufferDeferred.DrawMesh(_cubeMesh, decal.transform.localToWorldMatrix, material, 0, 1, _instancedBlock); ++n; } } }
public void Add(Decal decal, GameObject limitTo) { if (limitTo) { _limitToGameObjects.Add(limitTo); } switch (decal.RenderMode) { case Decal.DecalRenderMode.Deferred: AddDeferred(decal); break; case Decal.DecalRenderMode.Unlit: AddUnlit(decal); break; } }
private void AddUnlit(Decal decal) { if (!_unlitDecals.ContainsKey(decal.RenderOrder)) { _unlitDecals.Add(decal.RenderOrder, new Dictionary <Material, HashSet <Decal> >()); } var dict = _unlitDecals[decal.RenderOrder]; if (!dict.ContainsKey(decal.Material)) { dict.Add(decal.Material, new HashSet <Decal> { decal }); } else { dict[decal.Material].Add(decal); } }
private void DrawAlbedo(Decal decal, Material material, ref int n) { if (UseInstancing && !decal.UseLightProbes) { _matrices[n] = decal.transform.localToWorldMatrix; _fadeValues[n] = decal.Fade; _limitToValues[n] = decal.LimitTo ? decal.LimitTo.GetInstanceID() : _noLimitToValue; _colors[n] = decal.Color; ++n; if (n == 1023) { _instancedBlock.Clear(); _instancedBlock.SetFloatArray("_MaskMultiplier", _fadeValues); _instancedBlock.SetFloatArray("_LimitTo", _limitToValues); _instancedBlock.SetVectorArray("_Color", _colors); SetLightProbeOnBlock(RenderSettings.ambientProbe, _instancedBlock); _bufferDeferred.DrawMeshInstanced(_cubeMesh, 0, material, 0, _matrices, n, _instancedBlock); n = 0; } } else { // Fall back to non-instanced rendering _directBlock.Clear(); _directBlock.SetFloat("_MaskMultiplier", decal.Fade); _directBlock.SetFloat("_LimitTo", decal.LimitTo ? decal.LimitTo.GetInstanceID() : _noLimitToValue); _directBlock.SetVectorArray("_Color", _colors); // Interpolate a light probe for this probe, if requested if (decal.UseLightProbes) { LightProbes.GetInterpolatedProbe(decal.transform.position, decal.Mr, out var probe); SetLightProbeOnBlock(probe, _directBlock); } _bufferDeferred.DrawMesh(_cubeMesh, decal.transform.localToWorldMatrix, material, 0, 0, _directBlock); } }