private void OnGUI_DrawRTs(JCDSRenderTexture rt, ref Rect rect, bool isNewColumn) { int numRTs = rt.numRTs; for (int i = 0; i < numRTs; ++i) { GUI.DrawTexture(rect, rt.GetRenderTexture(i), ScaleMode.ScaleToFit, false); rect.y += rect.height; } if (isNewColumn) { rect.x += rect.width; rect.y = 0; } }
private void OnPostRender() { doubleFaceDepthRT.SetActiveRenderTexture(0); JCDSRenderTexture.ClearActiveRenderTexture(true, true, Color.black, 1.0f); JCDSRenderTexture.SetMultipleRenderTargets(doubleFaceDepthCam, doubleFaceDepthRT, doubleFaceDepthRT, 0); doubleFaceDepthCam.RenderWithShader(frontFaceDepthShader, null); JCDSRenderTexture.ClearActiveRenderTexture(true, false, Color.black, 1.0f); doubleFaceDepthCam.RenderWithShader(backFaceDepthShader, null); resultRT.SetActiveRenderTexture(0); JCDSRenderTexture.ClearActiveRenderTexture(true, true, Color.black, 0.0f); compositeResultBufferMtrl.SetTexture(shaderPropId_diffuseBuffer, mrtGBuffer.GetRenderTexture(0)); compositeResultBufferMtrl.SetTexture(shaderPropId_normalBuffer, mrtGBuffer.GetRenderTexture(1)); compositeResultBufferMtrl.SetTexture(shaderPropId_positionBuffer, mrtGBuffer.GetRenderTexture(2)); compositeResultBufferMtrl.SetTexture(shaderPropId_resultBuffer, resultRT.GetRenderTexture(0)); compositeResultBufferMtrl.SetTexture(shaderPropId_ssrBuffer, ssrRT.GetRenderTexture(0)); int numDirLights = dirLights == null ? 0 : dirLights.Length; for (int i = 0; i < numDirLights; ++i) { Light light = dirLights[i]; if (light != null && light.enabled && light.gameObject.activeSelf) { Vector3 dir = -light.transform.forward; compositeResultBufferMtrl.SetVector(shaderPropId_dirLightDir, new Vector4(dir.x, dir.y, dir.z, light.intensity)); compositeResultBufferMtrl.SetColor(shaderPropId_dirLightColor, light.color); DrawScreenQuad(compositeResultBufferMtrl, 0, false, false); } } int numPointLights = pointLights == null ? 0 : pointLights.Length; for (int i = 0; i < numPointLights; ++i) { Light light = pointLights[i]; if (light != null && light.enabled && light.gameObject.activeSelf) { compositeResultBufferMtrl.SetVector(shaderPropId_pointLightPos, light.transform.position); compositeResultBufferMtrl.SetColor(shaderPropId_pointLightColor, light.color); compositeResultBufferMtrl.SetVector(shaderPropId_pointLightRange, new Vector4(1.0f / light.range, light.intensity, 0, 0)); compositeResultBufferMtrl.SetPass(2); Graphics.DrawMeshNow(pointLightMesh, Matrix4x4.TRS(light.transform.position, Quaternion.identity, Vector3.one * light.range * 2)); } } ssrMtrl.SetTexture(shaderPropId_diffuseBuffer, mrtGBuffer.GetRenderTexture(0)); ssrMtrl.SetTexture(shaderPropId_normalBuffer, mrtGBuffer.GetRenderTexture(1)); ssrMtrl.SetTexture(shaderPropId_positionBuffer, mrtGBuffer.GetRenderTexture(2)); ssrMtrl.SetTexture(shaderPropId_resultBuffer, resultRT.GetRenderTexture(0)); ssrMtrl.SetTexture(shaderPropId_doubleFaceDepthBuffer, doubleFaceDepthRT.GetRenderTexture(0)); ssrMtrl.SetMatrix(shaderPropId_ssrVMatrix, cam.worldToCameraMatrix); ssrMtrl.SetMatrix(shaderPropId_ssrPMatrix, cam.projectionMatrix); ssrMtrl.SetVector(shaderPropId_screenPixelSize, new Vector2(Screen.width, Screen.height)); ssrRT.SetActiveRenderTexture(0); JCDSRenderTexture.ClearActiveRenderTexture(true, true, Color.black, 1.0f); DrawScreenQuad(ssrMtrl, 0, false, false); JCDSRenderTexture.ResetActiveRenderTexture(); DrawScreenQuad(compositeResultBufferMtrl, 3, true, true); JCDSRenderTexture.RestoreCurrentActiveBuffers(cam); }