public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { var _evt = CameraEvent.AfterForwardAlpha; var _cmdBuf = GetCommandBufferForEvent(_cam, _evt, "MGFX.VolLine"); _cmdBuf.Clear(); var system = VolumetricLineSystem.instance; var propPt0 = Shader.PropertyToID("_VolLinePoint0"); var propPt1 = Shader.PropertyToID("_VolLinePoint1"); var propCol = Shader.PropertyToID("_VolLineColor"); var propRad = Shader.PropertyToID("_VolLineRadius"); Vector3 valPt0 = Vector3.zero; Vector3 valPt1 = Vector3.zero; Color valCol = Color.white; float valRad = 0; Matrix4x4 _m, _p; var _lut = m_LookUpTable; m_MaterialVolLine.SetTexture("_VolLineLUT", _lut); foreach (var _line in system.m_Lines) { valRad = _line.GetRenderMatrics(out _m, out _p); _line.GetPoints(_p, out valPt0, out valPt1); valCol = _line.GetLinearColor(); _cmdBuf.SetGlobalVector(propPt0, valPt0); _cmdBuf.SetGlobalVector(propPt1, valPt1); _cmdBuf.SetGlobalColor(propCol, valCol); _cmdBuf.SetGlobalFloat(propRad, valRad); _cmdBuf.DrawMesh(m_CubeMesh, _m, m_MaterialVolLine, 0, 0); } }
// http://docs.unity3d.com/540/Documentation/Manual/GraphicsCommandBuffers.html // http://docs.unity3d.com/540/Documentation/ScriptReference/Rendering.BuiltinRenderTextureType.html public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { RenderGeomBuffer(_cam, MaterialVertexColorSelect.shader, "RenderType", new Color(0, 0, 0, 0)); UpdateMaterialProperties(_cam); var _cmdBuf = GetCommandBufferForEvent(_cam, CameraEvent.BeforeImageEffects, "MGFX.VertexColorDisplay"); _cmdBuf.Clear(); _cmdBuf.Blit(GetGeomBuffer(_cam) as Texture, BuiltinRenderTextureType.CameraTarget, MaterialVertexColorDisplay, showAlpha ? 1 : 0); }
public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { var _mtl = MaterialBloom; int divider = resolution == Resolution.Low ? 4 : 2; float widthMod = resolution == Resolution.Low ? 0.5f : 1.0f; var _rtW = _cam.pixelWidth / divider; var _rtH = _cam.pixelHeight / divider; // update command buffers var _cmdBuf = GetCommandBufferForEvent(_cam, CameraEvent.BeforeImageEffects, "MGFX.Bloom"); _cmdBuf.Clear(); var _idCurr = Shader.PropertyToID ("_CurrTexture"); _cmdBuf.GetTemporaryRT (_idCurr, -1, -1); _cmdBuf.Blit (BuiltinRenderTextureType.CameraTarget, _idCurr); var _idBloom1 = Shader.PropertyToID("_MudBloomTex1"); var _idBloom2 = Shader.PropertyToID("_MudBloomTex2"); _cmdBuf.GetTemporaryRT(_idBloom1, _rtW, _rtH, 0, FilterMode.Bilinear); _cmdBuf.GetTemporaryRT(_idBloom2, _rtW, _rtH, 0, FilterMode.Bilinear); var _idSrc = _idBloom1; var _idDst = _idBloom2; // downsample _cmdBuf.SetGlobalVector("_BloomParameter", new Vector4(blurSize * widthMod, 0.0f, threshold, intensity)); _cmdBuf.Blit (_idCurr, _idSrc, _mtl, 1); // blur var passOffs = blurType == BlurType.Standard ? 0 : 2; for (int i = 0; i < blurIterations; i++) { _cmdBuf.SetGlobalVector("_BloomParameter", new Vector4(blurSize * widthMod + (i * 1.0f), 0.0f, threshold, intensity)); // vertical blur _cmdBuf.Blit (_idSrc, _idDst, _mtl, 2 + passOffs); Swap(ref _idSrc, ref _idDst); // horizontal blur _cmdBuf.Blit (_idSrc, _idDst, _mtl, 3 + passOffs); Swap(ref _idSrc, ref _idDst); } SetFlip (_cmdBuf, _cam); _cmdBuf.SetGlobalTexture("_MudBloomTex", _idSrc); _cmdBuf.Blit (_idCurr, BuiltinRenderTextureType.CameraTarget, _mtl, 0); _cmdBuf.ReleaseTemporaryRT(_idBloom1); _cmdBuf.ReleaseTemporaryRT(_idBloom2); _cmdBuf.ReleaseTemporaryRT(_idCurr); }
// http://docs.unity3d.com/540/Documentation/Manual/GraphicsCommandBuffers.html // http://docs.unity3d.com/540/Documentation/ScriptReference/Rendering.BuiltinRenderTextureType.html public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { UpdateMaterialProperties(_cam); // update command buffers var _cmdBuf = GetCommandBufferForEvent (_cam, CameraEvent.BeforeImageEffects, "MGFX.ColorBlend"); _cmdBuf.Clear (); var _idCurr = Shader.PropertyToID("_CurrTexture"); _cmdBuf.GetTemporaryRT(_idCurr, -1, -1); _cmdBuf.Blit(BuiltinRenderTextureType.CameraTarget, _idCurr); SetFlip(_cmdBuf, _cam); _cmdBuf.Blit(_idCurr, BuiltinRenderTextureType.CameraTarget, MaterialColorBlend, (int)mode); _cmdBuf.ReleaseTemporaryRT(_idCurr); }
public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { RenderGeomBuffer(_cam, MaterialNPR2GeomBuffer.shader, "RenderType", new Color(0.5f, 0.5f, 0.0f, 0.0f)); UpdateMaterialProperties(true); var _rtMask = Shader.PropertyToID ("_MudSSAOTex"); var _m = MaterialNPREffects; int _scale = ultraQuality ? 2 : 1; // update command buffers { var _cmdBuf = GetCommandBufferForEvent (_cam, CameraEvent.AfterDepthTexture, "MGFX.NPR2.Setup"); _cmdBuf.Clear (); var tw = _cam.pixelWidth; var th = _cam.pixelHeight; var format = RenderTextureFormat.ARGB32; var rwMode = RenderTextureReadWrite.Linear; if (downsampling) { tw /= 2; th /= 2; } tw = ((tw / 4) + 1) * 4 * _scale; th = ((th / 4) + 1) * 4 * _scale; _cmdBuf.GetTemporaryRT (_rtMask, tw, th, 0, FilterMode.Bilinear, format, rwMode); _cmdBuf.SetGlobalTexture("_MudGeomTex", GetGeomBuffer(_cam)); // AO estimation _cmdBuf.Blit (BuiltinRenderTextureType.None, _rtMask, _m, 0); //if (blurIterations > 0) { // Blur buffer var _rtBlur = Shader.PropertyToID ("_BlurTexture"); _cmdBuf.GetTemporaryRT (_rtBlur, tw, th, 0, FilterMode.Bilinear, format, rwMode); var _blurRight = new Vector2 ((float)_scale / tw, 0); var _blurUp = new Vector2 (0, (float)_scale / th); // Blur iterations for (var i = 0; i < blurIterations; i++) { _cmdBuf.SetGlobalVector ("_BlurVector", _blurRight); _cmdBuf.Blit (_rtMask, _rtBlur, _m, 1); _cmdBuf.SetGlobalVector ("_BlurVector", _blurUp); _cmdBuf.Blit (_rtBlur, _rtMask, _m, 1); } // AA //_cmdBuf.Blit (_rtMask, _rtBlur, _m, 2); //_cmdBuf.Blit (_rtBlur, _rtMask, _m, 2); //Swap(ref _rtBlur, ref _rtMask); _cmdBuf.ReleaseTemporaryRT (_rtBlur); } _cmdBuf.SetGlobalTexture ("_MudSSAOTex", _rtMask); } { var _cmdBuf = GetCommandBufferForEvent (_cam, CameraEvent.AfterForwardOpaque, "MGFX.NPR2.Final"); _cmdBuf.Clear (); bool _applyToScreen = edgeIntensity > 0; if (_applyToScreen) { var _idCurr = Shader.PropertyToID("_CurrTexture"); _cmdBuf.GetTemporaryRT(_idCurr, -1, -1); _cmdBuf.Blit (BuiltinRenderTextureType.CameraTarget, _idCurr); SetFlip(_cmdBuf, _cam); _cmdBuf.Blit(_idCurr, BuiltinRenderTextureType.CameraTarget, _m, 3); _cmdBuf.ReleaseTemporaryRT (_idCurr); } _cmdBuf.ReleaseTemporaryRT(_rtMask); } }
public override void SetupCameraEvents(Camera _cam, RenderSystem _system) { UpdateMaterialProperties(true); var _idMask = Shader.PropertyToID ("_MudSSAOTex"); // update command buffers { var _cmdBuf = GetCommandBufferForEvent (_cam, CameraEvent.AfterDepthNormalsTexture, "MGFX.SSAO"); _cmdBuf.Clear (); var tw = _cam.pixelWidth; var th = _cam.pixelHeight; var format = RenderTextureFormat.R8; var rwMode = RenderTextureReadWrite.Linear; if (downsampling) { tw /= 2; th /= 2; } tw = ((tw / 4) + 1) * 4; th = ((th / 4) + 1) * 4; // AO buffer var _m = MaterialSSAO; _cmdBuf.GetTemporaryRT (_idMask, tw, th, 0, FilterMode.Bilinear, format, rwMode); //var _idCurr = Shader.PropertyToID("_CurrTexture"); //_cmdBuf.GetTemporaryRT(_idCurr, -1, -1); //_cmdBuf.Blit (BuiltinRenderTextureType.CameraTarget, _idCurr); // AO estimation _cmdBuf.Blit (BuiltinRenderTextureType.None, _idMask, _m, 0); if (blurIterations > 0) { // Blur buffer var rtBlur = Shader.PropertyToID ("_ObscuranceBlurTexture"); _cmdBuf.GetTemporaryRT ( rtBlur, tw, th, 0, FilterMode.Bilinear, format, rwMode ); var _blurRight = new Vector2 (1.0f / tw, 0); var _blurUp = new Vector2 (0, 1.0f / th); // Blur iterations for (var i = 0; i < blurIterations; i++) { _cmdBuf.SetGlobalVector ("_BlurVector", _blurRight); _cmdBuf.Blit (_idMask, rtBlur, _m, 1); _cmdBuf.SetGlobalVector ("_BlurVector", _blurUp); _cmdBuf.Blit (rtBlur, _idMask, _m, 1); } _cmdBuf.ReleaseTemporaryRT (rtBlur); } _cmdBuf.SetGlobalTexture ("_MudSSAOTex", _idMask); /* SetFlip(_cmdBuf, _cam); _cmdBuf.Blit(_idCurr, BuiltinRenderTextureType.CameraTarget, _m, 2); _cmdBuf.ReleaseTemporaryRT (_idCurr); */ } { var _cmdBuf = GetCommandBufferForEvent (_cam, CameraEvent.AfterForwardOpaque, "MGFX.SSAO"); _cmdBuf.Clear (); _cmdBuf.ReleaseTemporaryRT (_idMask); } }