void AddDecalToRenderer(OzoneDecal d) { if (d.Dec.Shared.DrawAlbedo) { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacs.Add(d); } else { _DecalsAlbedo.Add(d); } } else { if (!_Decals.ContainsKey(d.Material)) { _Decals.Add(d.Material, new HashSet <OzoneDecal>() { d }); } else { _Decals[d.Material].Add(d); } } }
void RemoveDecalFromRenderer(OzoneDecal d) { if (d.Dec.Shared.DrawAlbedo) { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacs.Remove(d); } else { _DecalsAlbedo.Remove(d); } } else { if (!_Decals.ContainsKey(d.Material)) { //_Decals.Remove(d.Material, new HashSet<OzoneDecal>() { d }); } else { _Decals[d.Material].Remove(d); if (_Decals[d.Material].Count == 0) { _Decals.Remove(d.Material); } } } }
public static void AddDecal(OzoneDecal d, Camera Cam) { if (Current == null || Cam == null) { return; } #if UNITY_EDITOR /* * if(false && Cam != Current.RenderCamera && Cam.name == "SceneCamera") * { * // Is Editor * OzoneDecalRenderer renderer = Cam.GetComponent<OzoneDecalRenderer>(); * if (renderer == null) * renderer = Cam.gameObject.AddComponent<OzoneDecalRenderer>(); * * renderer.AddDecalToRenderer(d); * } * else */ #endif { Current.AddDecalToRenderer(d); } }
public static void SnapToGround(Transform tr, GameObject Connected) { Vector3 Pos = tr.TransformPoint(PivotPointLocal); Pos.y = ScmapEditor.Current.Teren.SampleHeight(Pos); tr.localPosition = tr.TransformPoint(tr.InverseTransformPoint(Pos) - PivotPointLocal); if (Connected != null) { OzoneDecal OD = Connected.GetComponent <OzoneDecal>(); if (OD != null) { OD.tr.localPosition = tr.localPosition; OD.UpdateMatrix(); } } }
private void DrawDeferredDecals_Normals_Sorted(Camera cam) { _bufferDeferred.GetTemporaryRT(copy2id, -1, -1, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, copy2id); _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); OzoneDecal decal = null; for (int i = 0; i < NormalCount; i++) { if (NormalArray[i] == null) { continue; } decal = NormalArray[i]; if (decal.Dec.Shared.DrawNormal && decal.IsVisible) { _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 1, _directBlock); } } //Creation var decalListEnum = _DecalsNormal.GetEnumerator(); while (decalListEnum.MoveNext()) { decal = decalListEnum.Current; _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 1, _directBlock); } decalListEnum.Dispose(); }
private void DrawDeferredDecals_Albedo(Camera cam) { _bufferDeferred.SetRenderTarget(_albedoRenderTarget, BuiltinRenderTextureType.CameraTarget); OzoneDecal decal = null; for (int i = 0; i < AlbedoCount; i++) { if (AlbedoArray[i] == null) { continue; } decal = AlbedoArray[i]; if (decal.Dec.Shared.DrawAlbedo && decal.IsVisible) { _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 0, _directBlock); } } var decalListEnum = _DecalsAlbedo.GetEnumerator(); while (decalListEnum.MoveNext()) { decal = decalListEnum.Current; if (decal.Dec.Shared.DrawAlbedo) { _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 0, _directBlock); } } decalListEnum.Dispose(); }
private void DrawDeferredDecals_Tarmacs(Camera cam) { _bufferDeferred.SetRenderTarget(_albedoRenderTarget, BuiltinRenderTextureType.CameraTarget); var decalListEnum = _DecalsTarmacs.GetEnumerator(); while (decalListEnum.MoveNext()) { OzoneDecal decal = decalListEnum.Current; if (decal.Dec.Shared.DrawAlbedo) { _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 0, _directBlock); } } }
private void DrawDeferredDecals_Tarmacs_Normals(Camera cam) { _bufferDeferred.GetTemporaryRT(copy2id, -1, -1, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, copy2id); _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); var decalListEnum = _DecalsTarmacsNormals.GetEnumerator(); while (decalListEnum.MoveNext()) { OzoneDecal decal = decalListEnum.Current; //if (!decal.Dec.Shared.DrawAlbedo) { _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, decal.Material, 0, 1, _directBlock); } } decalListEnum.Dispose(); }
void RemoveDecalFromRenderer(OzoneDecal d) { if (d.Dec.Shared.DrawAlbedo) { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacs.Remove(d); } else { if (d.CreationObject) { _DecalsAlbedo.Remove(d); } else { if (d.Index >= MAX_DECAL_INSTANCES) { Debug.LogWarning("Wrong decal index: " + d.Index, d); } else if (d.Index < 0) { } else if (d == AlbedoArray[d.Index]) { if (d.Index + 1 == AlbedoCount) { AlbedoCount--; } AlbedoArray[d.Index] = null; } } } } else { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacsNormals.Remove(d); } else if (d.CreationObject) { _DecalsNormal.Remove(d); } else { if (d.Index >= MAX_DECAL_INSTANCES) { Debug.LogWarning("Wrong decal index: " + d.Index, d); } else if (d.Index < 0) { } else if (d == NormalArray[d.Index]) { if (d.Index + 1 == NormalCount) { NormalCount--; } NormalArray[d.Index] = null; } } /*if (!_Decals.ContainsKey(d.Material)) * { * //_Decals.Remove(d.Material, new HashSet<OzoneDecal>() { d }); * } * else * { * _Decals[d.Material].Remove(d); * if (_Decals[d.Material].Count == 0) * _Decals.Remove(d.Material); * }*/ } }
void AddDecalToRenderer(OzoneDecal d) { if (d.Dec.Shared.DrawAlbedo) { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacs.Add(d); } else { if (d.CreationObject) { _DecalsAlbedo.Add(d); } else { if (d.Index >= 0 && d.Index < MAX_DECAL_INSTANCES) { if (d.Index + 1 > AlbedoCount) { AlbedoCount = d.Index + 1; } AlbedoArray[d.Index] = d; } else { Debug.LogWarning("Wrong decal index! " + d.Index); } } } } else { if (d.Dec.Shared.IsTarmac) { _DecalsTarmacsNormals.Add(d); } else { if (d.CreationObject) { _DecalsNormal.Add(d); } else { if (d.Index >= 0 && d.Index < MAX_DECAL_INSTANCES) { if (d.Index + 1 > NormalCount) { NormalCount = d.Index + 1; } NormalArray[d.Index] = d; } else { Debug.LogWarning("Wrong decal index! " + d.Index); } } } /*if (!_Decals.ContainsKey(d.Material)) * { * _Decals.Add(d.Material, new HashSet<OzoneDecal>() { d }); * } * else * { * _Decals[d.Material].Add(d); * }*/ } }
public static void RemoveDecal(OzoneDecal d) { Current.RemoveDecalFromRenderer(d); }
private void DrawDeferredDecals_Normal(Camera cam) { int hqCount = 0; // Specular //var copy1id = Shader.PropertyToID("_CameraGBufferTexture1Copy"); //_bufferDeferred.GetTemporaryRT(copy1id, -1, -1, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); // Normal //var copy2id = Shader.PropertyToID("_CameraGBufferTexture2Copy"); _bufferDeferred.GetTemporaryRT(copy2id, -1, -1, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32); _bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, copy2id); var allDecalEnum = _Decals.GetEnumerator(); while (allDecalEnum.MoveNext()) { Material material = allDecalEnum.Current.Key; HashSet <OzoneDecal> decals = allDecalEnum.Current.Value; int n = 0; var decalListEnum = decals.GetEnumerator(); while (decalListEnum.MoveNext()) { OzoneDecal decal = decalListEnum.Current; if (decal.Dec.Shared.DrawNormal) { if (hqCount < HightQualityMaxCount) { // 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); _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, material, 0, 1, _directBlock); hqCount++; } else { if (UseInstancing) { // Instanced drawing _matrices[n] = decal.localToWorldMatrix; _CutOffLODValues[n] = decal.CutOff * CutoffMultiplier; _NearCutOffLODValues[n] = decal.NearCutOff; ++n; if (n == 1023) { //_bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer1, copy1id); //_bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer2, copy2id); _bufferDeferred.SetRenderTarget(_normalRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloatArray(_NearCutOffLOD, _NearCutOffLODValues); _instancedBlock.SetFloatArray(_CutOffLOD, _CutOffLODValues); _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); _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff * CutoffMultiplier); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, material, 0, 1, _directBlock); ++n; } } } } #if UNITY_5_5_OR_NEWER if (UseInstancing && 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.SetFloatArray(_NearCutOffLOD, _NearCutOffLODValues); _instancedBlock.SetFloatArray(_CutOffLOD, _CutOffLODValues); _bufferDeferred.DrawMeshInstanced(_cubeMesh, 0, material, 1, _matrices, n, _instancedBlock); } #endif } }
private void DrawDeferredDecals_AlbedoInstanced(Camera cam) { _bufferDeferred.SetRenderTarget(_albedoRenderTarget, BuiltinRenderTextureType.CameraTarget); //var copy1id = Shader.PropertyToID("_CameraGBufferTexture0Copy"); //_bufferDeferred.GetTemporaryRT(copy1id, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB32); //_bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer0, copy1id); //var copy2id = Shader.PropertyToID("_CameraGBufferTexture4Copy"); //_bufferDeferred.GetTemporaryRT(copy2id, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010); var allDecalEnum = _Decals.GetEnumerator(); while (allDecalEnum.MoveNext()) { Material material = allDecalEnum.Current.Key; HashSet <OzoneDecal> decals = allDecalEnum.Current.Value; int decalCount = decals.Count; int n = 0; var decalListEnum = decals.GetEnumerator(); while (decalListEnum.MoveNext()) { OzoneDecal decal = decalListEnum.Current; if (decal != null && decal.Dec.Shared.DrawAlbedo) { if (UseInstancing && AllowAlbedoInstancing) { _matrices[n] = decal.localToWorldMatrix; _NearCutOffLODValues[n] = decal.NearCutOff; _CutOffLODValues[n] = decal.CutOff * CutoffMultiplier; ++n; if (n == 1023) { //_bufferDeferred.Blit(BuiltinRenderTextureType.GBuffer0, copy1id); //_bufferDeferred.Blit(BuiltinRenderTextureType.CameraTarget, copy2id); //_bufferDeferred.SetRenderTarget(_albedoRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloatArray(_NearCutOffLOD, _NearCutOffLODValues); _instancedBlock.SetFloatArray(_CutOffLOD, _CutOffLODValues); _bufferDeferred.DrawMeshInstanced(_cubeMesh, 0, material, 0, _matrices, n, _instancedBlock); n = 0; } } else { //if(n == 0) //_bufferDeferred.Blit(BuiltinRenderTextureType.CameraTarget, copy2id); _directBlock.Clear(); _directBlock.SetFloat(_NearCutOffLOD, decal.NearCutOff); _directBlock.SetFloat(_CutOffLOD, decal.CutOff); _bufferDeferred.DrawMesh(_cubeMesh, decal.localToWorldMatrix, material, 0, 0, _directBlock); } } } if (UseInstancing && n > 0 && AllowAlbedoInstancing) { //_bufferDeferred.Blit(BuiltinRenderTextureType.CameraTarget, copy2id); //_bufferDeferred.SetRenderTarget(_albedoRenderTarget, BuiltinRenderTextureType.CameraTarget); _instancedBlock.Clear(); _instancedBlock.SetFloatArray(_NearCutOffLOD, _NearCutOffLODValues); _instancedBlock.SetFloatArray(_CutOffLOD, _CutOffLODValues); _bufferDeferred.DrawMeshInstanced(_cubeMesh, 0, material, 0, _matrices, n, _instancedBlock); } } }
public static void RemoveAlbedoDecal(OzoneDecal d) { //Current._DecalsAlbedo.Remove(d); }
public static void AddAlbedoDecal(OzoneDecal d) { //Current._DecalsAlbedo.Add(d); }