private void OnGUI() { if (Event.current.type != EventType.Repaint) { return; } InternalStartMouseAction(Input.mousePosition, MouseButton.None, false, true); var commandBuffer = new CommandBuffer(); commandBuffer.SetRenderTarget(_renderTexture); commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor); var zoom = new Vector2(Screen.width / (float)_renderTexture.width, Screen.height / (float)_renderTexture.height); commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) * OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix); for (int i = 0; i < (int)ClothSlots.Hip; i++) { var @object = OpenTibiaUnity.ContainerStorage.BodyContainerView.Objects[i]; if (@object) { @object.SetClamping(true); @object.Animate(OpenTibiaUnity.TicksMillis); @object.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * i, 0), 0, 0, 0); } } Graphics.ExecuteCommandBuffer(commandBuffer); commandBuffer.Dispose(); }
private void DrawColorItem(CommandBuffer commandBuffer, int index, Vector2 margin, Vector2 padding) { var texScale = new Vector2(_colorTexture.width, _colorTexture.height); var colorScale = texScale - padding * 2; Texture texture; if (index == _activeColor || (index == _highlightedColor && !_cancelHighlight)) { texture = _colorTextureOn; } else { texture = _colorTexture; } int i = index % Core.Colors.HSI_H_STEPS; int j = index / Core.Colors.HSI_H_STEPS; var position = new Vector2 { x = i * (margin.x + _colorTexture.width), y = j * (margin.y + _colorTexture.height) }; var props = new MaterialPropertyBlock(); props.SetTexture("_MainTex", texture); props.SetVector("_MainTex_UV", new Vector4(1, 1, 0, 0)); GraphicsUtility.Draw(commandBuffer, position, texScale, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, props); position += padding; props = new MaterialPropertyBlock(); props.SetVector("_Color", Core.Colors.ColorFromHSI(index)); GraphicsUtility.Draw(commandBuffer, position, colorScale, OpenTibiaUnity.GameManager.ColoredMaterial, props); }
static int _m_RemoveCommandBuffer(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UnityEngine.Light gen_to_be_invoked = (UnityEngine.Light)translator.FastGetCSObj(L, 1); { UnityEngine.Rendering.LightEvent _evt; translator.Get(L, 2, out _evt); UnityEngine.Rendering.CommandBuffer _buffer = (UnityEngine.Rendering.CommandBuffer)translator.GetObject(L, 3, typeof(UnityEngine.Rendering.CommandBuffer)); gen_to_be_invoked.RemoveCommandBuffer( _evt, _buffer); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public void RemoveCommandBuffer(CameraEvent evt, CommandBuffer buffer) { if (buffer == null) { throw new NullReferenceException("buffer is null"); } RemoveCommandBufferImpl(evt, buffer); }
public void AddCommandBufferAsync(CameraEvent evt, CommandBuffer buffer, ComputeQueueType queueType) { if (buffer == null) { throw new NullReferenceException("buffer is null"); } AddCommandBufferAsyncImpl(evt, buffer, queueType); }
protected void OnGUI() { if (Event.current.type != EventType.Repaint || _minimized) { return; } InternalStartMouseAction(Input.mousePosition, MouseButton.None, false, true); if (!_slotsRenderTexture) { return; } var commandBuffer = new CommandBuffer(); commandBuffer.SetRenderTarget(_slotsRenderTexture); commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor); var zoom = new Vector2(Screen.width / (float)_slotsRenderTexture.width, Screen.height / (float)_slotsRenderTexture.height); commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) * OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix); for (int i = 0; i < 4; i++) { for (int j = 0; j < _rows; j++) { int index = j * 4 + i; if (index < _containerView.NumberOfTotalObjects) { var @object = _containerView.GetObject(index + _containerView.IndexOfFirstObject); if (@object) { if ([email protected]) { @object.ClampeToFieldSize = true; } @object.Animate(OpenTibiaUnity.TicksMillis); @object.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * i, Constants.FieldSize * j), 0, 0, 0); } } } } int iconColumn = _numberOfSlots % 4; int iconRow = _numberOfSlots / 4; if (!_containerView.Icon.ClampeToFieldSize) { _containerView.Icon.ClampeToFieldSize = true; } _containerView.Icon.Draw(commandBuffer, new Vector2Int(Constants.FieldSize * iconColumn, Constants.FieldSize * iconRow), 0, 0, 0); Graphics.ExecuteCommandBuffer(commandBuffer); commandBuffer.Dispose(); }
public static void DrawInstanced(CommandBuffer commandBuffer, Vector2[] positions, Vector3 scale, int count, Material mat, MaterialPropertyBlock props = null) { Matrix4x4[] matricies = new Matrix4x4[positions.Length]; for (int i = 0; i < positions.Length; i++) { matricies[i] = Matrix4x4.TRS(positions[i], DefaultRotation, scale); } commandBuffer.DrawMeshInstanced(s_texMesh, 0, mat, 0, matricies, count, props); }
public RenderError Render(RenderTexture renderTarget) { if (MiniMapStorage == null || !OpenTibiaUnity.GameManager.IsGameRunning || !WorldMapStorage.Valid) { return(RenderError.MiniMapNotValid); } var commandBuffer = new CommandBuffer(); commandBuffer.SetRenderTarget(renderTarget); commandBuffer.ClearRenderTarget(false, true, Color.black); var zoom = new Vector2() { x = Screen.width / (float)Constants.MiniMapSideBarViewWidth, y = Screen.height / (float)Constants.MiniMapSideBarViewHeight, }; zoom *= _zoomScale; var drawnSectors = new List <MiniMapSector>(); // 4 is the maximum number of sectors to be drawn (pre-calculated) // todo; provide a function to calculate it (if someone plans to use minimap differently) Vector3Int curPosition = new Vector3Int(0, 0, PositionZ); for (int i = 0; i < 4; i++) { curPosition.x = _positionRect.x + i % 2 * _positionRect.width; curPosition.y = _positionRect.y + (i / 2) * _positionRect.height; var sector = MiniMapStorage.AcquireSector(curPosition, false); if (sector == null || drawnSectors.IndexOf(sector) != -1) { continue; } drawnSectors.Add(sector); var sectorRect = new RectInt(sector.SectorX, sector.SectorY, Constants.MiniMapSectorSize, Constants.MiniMapSectorSize); var translation = sectorRect.position - _positionRect.position; Matrix4x4 transformation = Matrix4x4.TRS(translation * zoom, Quaternion.Euler(180, 0, 0), Constants.MiniMapSectorSize * zoom); var props = new MaterialPropertyBlock(); props.SetTexture("_MainTex", sector.SafeDrawTexture); props.SetVector("_MainTex_UV", new Vector4(1, 1, 0, 0)); props.SetFloat("_HighlightOpacity", 0); Utils.GraphicsUtility.Draw(commandBuffer, transformation, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, props); } Graphics.ExecuteCommandBuffer(commandBuffer); commandBuffer.Dispose(); return(RenderError.None); }
protected void OnGUI() { var e = Event.current; if (e.type != EventType.Repaint || !Visible) { return; } if (!_activeActionPanel) { if (_objectImage.enabled) { _objectImage.enabled = false; } return; } var objectAction = GetHotkeyActionForPanel <HotkeyObjectAction>(_activeActionPanel); if (objectAction == null || !objectAction.AppearanceType) { if (_objectImage.enabled) { _objectImage.enabled = false; } return; } if (s_renderTexture == null) { s_renderTexture = new RenderTexture(Constants.FieldSize, Constants.FieldSize, 0, RenderTextureFormat.ARGB32); s_renderTexture.filterMode = FilterMode.Bilinear; s_renderTexture.Create(); _objectImage.texture = s_renderTexture; } var commandBuffer = new CommandBuffer(); commandBuffer.SetRenderTarget(s_renderTexture); commandBuffer.ClearRenderTarget(false, true, Core.Utils.GraphicsUtility.TransparentColor); var zoom = new Vector2(Screen.width / (float)s_renderTexture.width, Screen.height / (float)s_renderTexture.height); commandBuffer.SetViewMatrix(Matrix4x4.TRS(Vector3.zero, Quaternion.identity, zoom) * OpenTibiaUnity.GameManager.MainCamera.worldToCameraMatrix); _objectInstance.Draw(commandBuffer, new Vector2Int(0, 0), 0, 0, 0); Graphics.ExecuteCommandBuffer(commandBuffer); commandBuffer.Dispose(); if (!_objectImage.enabled) { _objectImage.enabled = true; } }
public override void Draw(CommandBuffer commandBuffer, Vector2Int screenPosition, int patternX, int patternY, int patternZ, bool highlighted = false, float highlightOpacity = 0) { if (_hasSpecialPattern) { patternX = -1; patternY = -1; } base.Draw(commandBuffer, screenPosition, patternX, patternY, patternZ, highlighted, highlightOpacity); }
public void init(Camera camera) { mf_ = GetComponent <MeshFilter>(); mr_ = GetComponent <MeshRenderer>(); mr_.enabled = false; mf_.sharedMesh = Sight.Instance.getMesh(); mr_.sharedMaterial = Sight.Instance.getMaterial(); command_buffer_ = new UnityEngine.Rendering.CommandBuffer(); command_buffer_.DrawRenderer(mr_, Sight.Instance.getMaterial()); camera.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterImageEffects, command_buffer_); }
public void AddCommandBuffer(CameraEvent evt, CommandBuffer buffer) { if (!Enum.IsDefined(typeof(CameraEvent), evt)) { throw new ArgumentException(string.Format(@"Invalid CameraEvent value ""{0}"".", (int)evt), "evt"); } if (buffer == null) { throw new NullReferenceException("buffer is null"); } AddCommandBufferImpl(evt, buffer); }
public void Draw(CommandBuffer commandBuffer, int screenX, int screenY, int ticks) { Animate(ticks); var position = new Vector3(screenX, screenY, 0); var scale = new Vector3(Constants.FieldSize, Constants.FieldSize, 0); var uv = new Vector4(1f / s_cachedFrameCount, 1f, (float)_currentFrame / s_cachedFrameCount, 0); _props.SetVector("_MainTex_UV", uv); Utils.GraphicsUtility.Draw(commandBuffer, position, scale, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, _props); }
public void AddCommandBufferAsync(CameraEvent evt, CommandBuffer buffer, ComputeQueueType queueType) { if (!Rendering.CameraEventUtils.IsValid(evt)) { throw new ArgumentException(string.Format(@"Invalid CameraEvent value ""{0}"".", (int)evt), "evt"); } if (buffer == null) { throw new NullReferenceException("buffer is null"); } AddCommandBufferAsyncImpl(evt, buffer, queueType); }
public void RemoveCommandBuffer(CameraEvent evt, CommandBuffer buffer) { if (!Rendering.CameraEventUtils.IsValid(evt)) { throw new ArgumentException(string.Format(@"Invalid CameraEvent value ""{0}"".", (int)evt), "evt"); } if (buffer == null) { throw new NullReferenceException("buffer is null"); } RemoveCommandBufferImpl(evt, buffer); }
static int _m_AddCommandBufferAsync(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UnityEngine.Light gen_to_be_invoked = (UnityEngine.Light)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 4 && translator.Assignable <UnityEngine.Rendering.LightEvent>(L, 2) && translator.Assignable <UnityEngine.Rendering.CommandBuffer>(L, 3) && translator.Assignable <UnityEngine.Rendering.ComputeQueueType>(L, 4)) { UnityEngine.Rendering.LightEvent _evt; translator.Get(L, 2, out _evt); UnityEngine.Rendering.CommandBuffer _buffer = (UnityEngine.Rendering.CommandBuffer)translator.GetObject(L, 3, typeof(UnityEngine.Rendering.CommandBuffer)); UnityEngine.Rendering.ComputeQueueType _queueType; translator.Get(L, 4, out _queueType); gen_to_be_invoked.AddCommandBufferAsync( _evt, _buffer, _queueType); return(0); } if (gen_param_count == 5 && translator.Assignable <UnityEngine.Rendering.LightEvent>(L, 2) && translator.Assignable <UnityEngine.Rendering.CommandBuffer>(L, 3) && translator.Assignable <UnityEngine.Rendering.ShadowMapPass>(L, 4) && translator.Assignable <UnityEngine.Rendering.ComputeQueueType>(L, 5)) { UnityEngine.Rendering.LightEvent _evt; translator.Get(L, 2, out _evt); UnityEngine.Rendering.CommandBuffer _buffer = (UnityEngine.Rendering.CommandBuffer)translator.GetObject(L, 3, typeof(UnityEngine.Rendering.CommandBuffer)); UnityEngine.Rendering.ShadowMapPass _shadowPassMask; translator.Get(L, 4, out _shadowPassMask); UnityEngine.Rendering.ComputeQueueType _queueType; translator.Get(L, 5, out _queueType); gen_to_be_invoked.AddCommandBufferAsync( _evt, _buffer, _shadowPassMask, _queueType); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Light.AddCommandBufferAsync!")); }
private void DrawColorItems(CommandBuffer commandBuffer, int count, Vector2[] texPositions, Vector2[] colorPositions, Vector4[] uvs, Vector4[] colors, Vector2 padding) { var texScale = new Vector2(_colorTexture.width, _colorTexture.height); var colorScale = texScale - padding * 2; MaterialPropertyBlock props = new MaterialPropertyBlock(); props.SetTexture("_MainTex", _colorTexture); props.SetVectorArray("_MainTex_UV", uvs); GraphicsUtility.DrawInstanced(commandBuffer, texPositions, texScale, count, OpenTibiaUnity.GameManager.AppearanceTypeMaterial, props); props = new MaterialPropertyBlock(); props.SetVectorArray("_Color", colors); GraphicsUtility.DrawInstanced(commandBuffer, colorPositions, colorScale, count, OpenTibiaUnity.GameManager.ColoredMaterial, props); }
// Called by camera to apply image effect void OnRenderImage(RenderTexture source, RenderTexture destination) { NVIDIA.VRWorks.Feature feature = m_VRWorks.GetActiveFeature(); if (feature == NVIDIA.VRWorks.Feature.LensMatchedShading || feature == NVIDIA.VRWorks.Feature.MultiResolution) { UnityEngine.Rendering.CommandBuffer buf = new UnityEngine.Rendering.CommandBuffer(); buf.SetRenderTarget(destination); buf.IssuePluginCustomBlit(PluginExtGetIssueEventCallback(), kPluginExtCommandUpscale, source, destination, 0, VerticalFlip ? 1U : 0U); Graphics.ExecuteCommandBuffer(buf); } else { Graphics.Blit(source, destination); } }
public static void DrawRect(CommandBuffer commandBuffer, Rect rect, Vector3 scale, Color color) { _mesh.vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(rect.width, 0, 0), new Vector3(rect.width, rect.height, 0), new Vector3(0, rect.height, 0), }; _mesh.colors = Enumerable.Repeat(color, 4).ToArray(); _mesh.SetIndices(new int[] { 0, 1, 2, 3 }, MeshTopology.Quads, 0); Matrix4x4 matrix = Matrix4x4.TRS(rect.position, Quaternion.Euler(180, 0, 0), scale); commandBuffer.DrawMesh(_mesh, matrix, OpenTibiaUnity.GameManager.InternalColoredMaterial); }
static StackObject *ExecuteCommandBuffer_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.Rendering.CommandBuffer commandBuffer = (UnityEngine.Rendering.CommandBuffer) typeof(UnityEngine.Rendering.CommandBuffer).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.Experimental.Rendering.ScriptableRenderContext instance_of_this_method; instance_of_this_method = (UnityEngine.Experimental.Rendering.ScriptableRenderContext) typeof(UnityEngine.Experimental.Rendering.ScriptableRenderContext).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); instance_of_this_method.ExecuteCommandBuffer(commandBuffer); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); return(__ret); }
public void DrawMarks(CommandBuffer commandBuffer, Marks marks, int screenX, int screenY) { var texture = OpenTibiaUnity.GameManager.MarksViewTexture; var material = OpenTibiaUnity.GameManager.MarksViewMaterial; var position = new Vector2(screenX, screenY); var scale = new Vector2(Constants.FieldSize, Constants.FieldSize); var transformation = Matrix4x4.TRS(position, Quaternion.Euler(180, 0, 0), scale); var size = MarksStartSize; foreach (var information in _marksViewInformations) { if (!marks.IsMarkSet(information.MarkType)) { continue; } uint eightBit = marks.GetMarkColor(information.MarkType); if (eightBit > Marks.MarksNumTotal) { continue; } Color color = GetMarksColor(eightBit); var uv = new Vector4() { z = size * Constants.FieldSize / (float)texture.width, w = (Constants.MarkThicknessBold - information.MarkThickness) * Constants.FieldSize / (float)texture.height, x = Constants.FieldSize / (float)texture.width, y = Constants.FieldSize / (float)texture.height, }; var props = new MaterialPropertyBlock(); props.SetTexture("_MainTex", texture); props.SetVector("_MainTex_ST", uv); props.SetColor("_Color", color); Utils.GraphicsUtility.Draw(commandBuffer, transformation, material, props); } }
protected override void Load() { this.cameraEventHandler.OnPreCullEvents += this.OnPreCullEvent; if (this.commandBuffer == null) { this.commandBuffer = new UnityEngine.Rendering.CommandBuffer(); this.commandBuffer.name = this.name; if (this.DrawInLight) { this.AddCommandBuffer(this.LightEvent); } else { this.AddCommandBuffer(this.CameraEvent); } } base.Load(); }
static int _m_AddCommandBuffer(RealStatePtr L) { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); UnityEngine.Light __cl_gen_to_be_invoked = (UnityEngine.Light)translator.FastGetCSObj(L, 1); int __gen_param_count = LuaAPI.lua_gettop(L); try { if (__gen_param_count == 3 && translator.Assignable <UnityEngine.Rendering.LightEvent>(L, 2) && translator.Assignable <UnityEngine.Rendering.CommandBuffer>(L, 3)) { UnityEngine.Rendering.LightEvent evt; translator.Get(L, 2, out evt); UnityEngine.Rendering.CommandBuffer buffer = (UnityEngine.Rendering.CommandBuffer)translator.GetObject(L, 3, typeof(UnityEngine.Rendering.CommandBuffer)); __cl_gen_to_be_invoked.AddCommandBuffer(evt, buffer); return(0); } if (__gen_param_count == 4 && translator.Assignable <UnityEngine.Rendering.LightEvent>(L, 2) && translator.Assignable <UnityEngine.Rendering.CommandBuffer>(L, 3) && translator.Assignable <UnityEngine.Rendering.ShadowMapPass>(L, 4)) { UnityEngine.Rendering.LightEvent evt; translator.Get(L, 2, out evt); UnityEngine.Rendering.CommandBuffer buffer = (UnityEngine.Rendering.CommandBuffer)translator.GetObject(L, 3, typeof(UnityEngine.Rendering.CommandBuffer)); UnityEngine.Rendering.ShadowMapPass shadowPassMask; translator.Get(L, 4, out shadowPassMask); __cl_gen_to_be_invoked.AddCommandBuffer(evt, buffer, shadowPassMask); return(0); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Light.AddCommandBuffer!")); }
protected override void Unload() { base.Unload(); if (this.commandBuffer != null) { if (this.cameraEventHandler != null && this.cameraEventHandler.CameraComponent) { this.RemoveCommandBuffer(); } this.commandBuffer.Clear(); this.commandBuffer.Release(); this.commandBuffer = null; } // Here a tricks : a reference to a component that has been destroyed act as null on a comparaison. if (this.cameraEventHandler != null) { this.cameraEventHandler.OnPreCullEvents -= this.OnPreCullEvent; } this.cameraEventHandler = null; this.lightEventHandler = null; }
void EnsureHookedLightSource(Light light) { if (!light) { return; } if (light.commandBufferCount == 2) { return; } //Debug.Log("Hooking scattering command buffers on light source: " + light.name); // NOTE: This doesn't really play nicely with other users of light events. // Currently not an issue since this code was written pre-5.1 (and light events // are a new feature in 5.1), but might need a proper solution in the future. light.RemoveAllCommandBuffers(); if (m_occlusionCmdAfterShadows != null) { m_occlusionCmdAfterShadows.Dispose(); } if (m_occlusionCmdBeforeScreen != null) { m_occlusionCmdBeforeScreen.Dispose(); } m_occlusionCmdAfterShadows = new UnityEngine.Rendering.CommandBuffer(); m_occlusionCmdAfterShadows.name = "Scatter Occlusion Pass 1"; m_occlusionCmdAfterShadows.SetGlobalTexture("u_SMCascadedShadowMap", new UnityEngine.Rendering.RenderTargetIdentifier(UnityEngine.Rendering.BuiltinRenderTextureType.CurrentActive)); m_occlusionCmdBeforeScreen = new UnityEngine.Rendering.CommandBuffer(); m_occlusionCmdBeforeScreen.name = "Scatter Occlusion Pass 2"; light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.AfterShadowMap, m_occlusionCmdAfterShadows); light.AddCommandBuffer(UnityEngine.Rendering.LightEvent.BeforeScreenspaceMask, m_occlusionCmdBeforeScreen); }
protected void FillMaskBuffer(UnityEngine.Rendering.CommandBuffer cb, List <Renderer> rs, Material m) { for (int i = 0; i < rs.Count; ++i) { Renderer r = rs[i]; if (r is MeshRenderer) { MeshFilter mf = r.GetComponent <MeshFilter>(); if (!mf) { continue; } int sms = mf.sharedMesh.subMeshCount; for (int j = 0; j < sms; ++j) { cb.DrawRenderer(r, m, j); } } else { cb.DrawRenderer(r, m); } } }
[NativeName("RemoveCommandBuffer")] extern private void RemoveCommandBufferImpl(CameraEvent evt, [NotNull] CommandBuffer buffer);
[NativeName("AddCommandBufferAsync")] extern private void AddCommandBufferAsyncImpl(CameraEvent evt, [NotNull] CommandBuffer buffer, ComputeQueueType queueType);
/// <summary> /// Change the player transform and player camera sources, if they need to be changed or updated. /// UniStorm's weather type components will be moved to the new Player Transform's transform. /// Your previous Camera Component will be disabled as the clouds would be rendered twice. /// This function will alway enabled the CameraSource's Camera Component. /// </summary> public void ChangeCameraSource(Transform PlayerTransform, Camera CameraSource) { if (UniStormSystem.Instance.UniStormInitialized) { UniStormSystem.Instance.PlayerCamera.enabled = false; if (UniStormSystem.Instance.PlayerCamera.GetComponent <ScreenSpaceCloudShadows>() != null && UniStormSystem.Instance.CloudShadows == UniStormSystem.EnableFeature.Enabled) { UniStormSystem.Instance.PlayerCamera.GetComponent <ScreenSpaceCloudShadows>().enabled = false; } UniStormSystem.Instance.PlayerTransform = PlayerTransform; UniStormSystem.Instance.m_EffectsTransform.transform.SetParent(PlayerTransform); UniStormSystem.Instance.m_EffectsTransform.transform.localPosition = Vector3.zero; UniStormSystem.Instance.m_SoundTransform.transform.SetParent(PlayerTransform); UniStormSystem.Instance.m_SoundTransform.transform.localPosition = Vector3.zero; UniStormSystem.Instance.PlayerCamera = CameraSource; //Look to see if the Render Clouds CommandBuffer exists on the newly assignned camera source, if it doesn't add one as this is needed to properly render the clouds. UnityEngine.Rendering.CommandBuffer[] CommandBuffers = CameraSource.GetCommandBuffers(UnityEngine.Rendering.CameraEvent.AfterSkybox); if (CommandBuffers.Length > 0) { for (int i = 0; i < CommandBuffers.Length; i++) { if (CommandBuffers[i].name != "Render Clouds") { UnityEngine.Rendering.CommandBuffer cloudsCommBuff = FindObjectOfType <UniStormClouds>().cloudsCommBuff; CameraSource.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterSkybox, cloudsCommBuff); cloudsCommBuff.name = "Render Clouds"; } } } else if (CommandBuffers.Length == 0) { UnityEngine.Rendering.CommandBuffer cloudsCommBuff = FindObjectOfType <UniStormClouds>().cloudsCommBuff; CameraSource.AddCommandBuffer(UnityEngine.Rendering.CameraEvent.AfterSkybox, cloudsCommBuff); cloudsCommBuff.name = "Render Clouds"; } if (UniStormSystem.Instance.PlayerCamera.GetComponent <ScreenSpaceCloudShadows>() == null && UniStormSystem.Instance.CloudShadows == UniStormSystem.EnableFeature.Enabled) { ScreenSpaceCloudShadows m_CloudShadows = UniStormSystem.Instance.PlayerCamera.gameObject.AddComponent <ScreenSpaceCloudShadows>(); m_CloudShadows.CloudShadowTexture = FindObjectOfType <UniStormClouds>().PublicCloudShadowTexture; m_CloudShadows.BottomThreshold = 0.5f; m_CloudShadows.TopThreshold = 1; m_CloudShadows.CloudTextureScale = 0.001f; m_CloudShadows.ShadowIntensity = UniStormSystem.Instance.CurrentWeatherType.CloudShadowIntensity; } else { if (UniStormSystem.Instance.CloudShadows == UniStormSystem.EnableFeature.Enabled) { UniStormSystem.Instance.PlayerCamera.GetComponent <ScreenSpaceCloudShadows>().enabled = true; } } UniStormSystem.Instance.PlayerCamera.enabled = true; } }
extern public void RemoveCommandBuffer(UnityEngine.Rendering.LightEvent evt, UnityEngine.Rendering.CommandBuffer buffer);