private void UploadVariables(PostProcessParameters postProcessParams) { Vector4 postProcessParams1 = new Vector4(); postProcessParams1.x = postProcessParams.commonPostProcess.grainIntensity; postProcessParams1.y = postProcessParams.commonPostProcess.vignetteIntensity; postProcessParams1.z = postProcessParams.commonPostProcess.vignetteScale; postProcessParams1.w = postProcessParams.commonPostProcess.chromaticAberrationDistortion; m_combinationMat.SetVector("_PostProcessParams1", postProcessParams1); Vector4 postProcessParams2 = new Vector4(); postProcessParams2.x = postProcessParams.commonPostProcess.vignetteColor.r; postProcessParams2.y = postProcessParams.commonPostProcess.vignetteColor.g; postProcessParams2.z = postProcessParams.commonPostProcess.vignetteColor.b; postProcessParams2.w = postProcessParams.commonPostProcess.chromaticAberrationIntensity; m_combinationMat.SetVector("_PostProcessParams2", postProcessParams2); Vector4 postProcessParams3 = new Vector4(); postProcessParams3.x = Random.value; postProcessParams3.y = ScionUtility.GetWhitePointMultiplier(postProcessParams.commonPostProcess.whitePoint); postProcessParams3.z = 1.0f / postProcessParams.commonPostProcess.whitePoint; m_combinationMat.SetVector("_PostProcessParams3", postProcessParams3); }
private void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source) { this.focalDistance = ((this.focalDistance >= this.m_camera.nearClipPlane + 0.3f) ? this.focalDistance : (this.m_camera.nearClipPlane + 0.3f)); postProcessParams.halfResSource = null; postProcessParams.halfResDepth = this.m_downsampling.DownsampleDepthTexture(source.width, source.height); postProcessParams.width = source.width; postProcessParams.height = source.height; postProcessParams.halfWidth = source.width / 2; postProcessParams.halfHeight = source.height / 2; if (this.prevCamFoV != this.m_camera.fieldOfView) { postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(this.m_camera.fieldOfView * 0.5f * 0.0174532924f); this.prevCamFoV = this.m_camera.fieldOfView; } postProcessParams.DoFParams.useMedianFilter = true; if (!this.userControlledFocalLength) { postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV); } else { postProcessParams.cameraParams.focalLength = this.focalLength * 0.001f; } postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(this.fNumber, postProcessParams.cameraParams.focalLength); postProcessParams.cameraParams.fieldOfView = this.m_camera.fieldOfView; postProcessParams.cameraParams.aspect = this.m_camera.aspect; postProcessParams.cameraParams.nearPlane = this.m_camera.nearClipPlane; postProcessParams.cameraParams.farPlane = this.m_camera.farClipPlane; postProcessParams.isFirstRender = this.m_isFirstRender; this.m_isFirstRender = false; }
public void BindVirtualCameraParams(Material mat, CameraParameters cameraParams, float focalDistance, float halfResWidth, bool isFirstRender) { Vector4 shaderParams1 = new Vector4(); shaderParams1.x = 1.0f / (cameraParams.focalLength * 1000.0f); //From meter to millimeter shaderParams1.y = cameraParams.fNumber; shaderParams1.z = cameraParams.shutterSpeed; shaderParams1.w = isFirstRender == true ? 1.0f : 1.0f - Mathf.Exp(-Time.deltaTime * cameraParams.adaptionSpeed); #if UNITY_EDITOR if (UnityEditor.EditorApplication.isPlaying == false) { shaderParams1.w = 1.0f; } #endif mat.SetVector("_VirtualCameraParams1", shaderParams1); Vector4 shaderParams2 = new Vector4(); shaderParams2.x = cameraParams.exposureCompensation + BuiltinExposureCompensation; shaderParams2.y = cameraParams.focalLength; shaderParams2.z = focalDistance; shaderParams2.w = ScionUtility.CoCToPixels(halfResWidth); mat.SetVector("_VirtualCameraParams2", shaderParams2); Vector4 shaderParams3 = new Vector4(); shaderParams3.x = Mathf.Pow(2.0f, cameraParams.minMaxExposure.x); shaderParams3.y = Mathf.Pow(2.0f, cameraParams.minMaxExposure.y); mat.SetVector("_VirtualCameraParams3", shaderParams3); }
private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange, float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane) { int tileWidth = halfResDepth.width / 10 + (halfResDepth.width % 10 == 0 ? 0 : 1); int tileHeight = halfResDepth.height / 10 + (halfResDepth.height % 10 == 0 ? 0 : 1); float CoCScale = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength); float CoCBias = -apertureDiameter * focalLength / (focalDistance - focalLength); float toPixels = ScionUtility.CoCToPixels(halfResDepth.width); CoCScale *= toPixels; CoCBias *= toPixels; Vector4 CoCParams1 = new Vector4(); CoCParams1.x = CoCScale; CoCParams1.y = CoCBias; CoCParams1.z = focalDistance; CoCParams1.w = focalRange * 0.5f; m_DoFMat.SetVector("_CoCParams1", CoCParams1); Vector4 CoCParams2 = new Vector4(); CoCParams2.x = maxCoCRadius * 0.5f; //We're in half res, so halve it CoCParams2.y = 1.0f / maxCoCRadius; m_DoFMat.SetVector("_CoCParams2", CoCParams2); if (m_DoFMatDX11 != null) { m_DoFMatDX11.SetVector("_CoCParams1", CoCParams1); m_DoFMatDX11.SetVector("_CoCParams2", CoCParams2); } m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.width); //Width for horizontal RenderTexture tiledDataHorizontal = RenderTexture.GetTemporary(tileWidth, halfResDepth.height, 0, RenderTextureFormat.RHalf); tiledDataHorizontal.filterMode = FilterMode.Point; tiledDataHorizontal.wrapMode = TextureWrapMode.Clamp; RenderTexture tiledData = RenderTexture.GetTemporary(tileWidth, tileHeight, 0, RenderTextureFormat.RHalf); tiledData.filterMode = FilterMode.Point; tiledData.wrapMode = TextureWrapMode.Clamp; halfResDepth.filterMode = FilterMode.Point; ScionGraphics.Blit(tiledDataHorizontal, m_DoFMat, 0); m_DoFMat.SetTexture("_HorizontalTileResult", tiledDataHorizontal); m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.height); //Height for vertical ScionGraphics.Blit(tiledData, m_DoFMat, 1); RenderTexture.ReleaseTemporary(tiledDataHorizontal); return(tiledData); }
public void Fill(ScionPostProcessBase postProcess) { bloom = postProcess.bloom; lensDirt = postProcess.lensDirt && (postProcess.lensDirtTexture != null); lensDirtTexture = postProcess.lensDirtTexture; bloomTexture = null; dofTexture = null; exposure = postProcess.cameraMode != CameraMode.Off ? true : false; depthOfField = postProcess.depthOfField; halfResSource = null; //Done later bloomParams.intensity = ScionUtility.Square(postProcess.bloomIntensity); bloomParams.brightness = postProcess.bloomBrightness; bloomParams.distanceMultiplier = postProcess.bloomDistanceMultiplier; bloomParams.downsamples = postProcess.bloomDownsamples; lensDirtParams.intensity = ScionUtility.Square(postProcess.lensDirtIntensity); lensDirtParams.brightness = postProcess.lensDirtBrightness; DoFParams.depthFocusMode = postProcess.depthFocusMode; DoFParams.maxCoCRadius = postProcess.maxCoCRadius; DoFParams.quality = SystemInfo.graphicsShaderLevel < 40 ? DepthOfFieldQuality.Normal : postProcess.depthOfFieldQuality; DoFParams.pointAveragePosition = postProcess.pointAveragePosition; DoFParams.pointAverageRange = postProcess.pointAverageRange; DoFParams.visualizePointFocus = postProcess.visualizePointFocus; DoFParams.depthAdaptionSpeed = postProcess.depthAdaptionSpeed; DoFParams.focalDistance = postProcess.focalDistance; DoFParams.focalRange = postProcess.focalRange; colorGradingParams.colorGradingMode = postProcess.colorGradingTex1 == null ? ColorGradingMode.Off : postProcess.colorGradingMode; colorGradingParams.colorGradingTex1 = postProcess.colorGradingTex1; colorGradingParams.colorGradingTex2 = postProcess.colorGradingTex2; colorGradingParams.colorGradingBlendFactor = postProcess.colorGradingBlendFactor; cameraParams.cameraMode = postProcess.cameraMode; cameraParams.fNumber = postProcess.fNumber; cameraParams.ISO = postProcess.ISO; cameraParams.shutterSpeed = postProcess.shutterSpeed; cameraParams.adaptionSpeed = postProcess.adaptionSpeed; cameraParams.minMaxExposure = postProcess.minMaxExposure; cameraParams.exposureCompensation = postProcess.exposureCompensation; commonPostProcess.grainIntensity = postProcess.grain == true ? postProcess.grainIntensity : 0.0f; commonPostProcess.vignetteIntensity = postProcess.vignette == true ? postProcess.vignetteIntensity : 0.0f; commonPostProcess.vignetteScale = postProcess.vignetteScale; commonPostProcess.vignetteColor = postProcess.vignetteColor; commonPostProcess.chromaticAberration = postProcess.chromaticAberration; commonPostProcess.chromaticAberrationDistortion = postProcess.chromaticAberrationDistortion; commonPostProcess.chromaticAberrationIntensity = postProcess.chromaticAberrationIntensity; }
public void Fill(ScionPostProcess postProcess) { this.tonemapping = postProcess.tonemapping; this.bloom = postProcess.bloom; this.lensDirt = (postProcess.lensDirt && postProcess.lensDirtTexture != null); this.lensDirtTexture = postProcess.lensDirtTexture; this.bloomTexture = null; this.dofTexture = null; this.exposure = (postProcess.cameraMode != CameraMode.Off); this.depthOfField = postProcess.depthOfField; this.halfResSource = null; this.bloomParams.intensity = ScionUtility.Square(postProcess.bloomIntensity); this.bloomParams.brightness = postProcess.bloomBrightness; this.bloomParams.downsamples = postProcess.bloomDownsamples; this.lensDirtParams.intensity = ScionUtility.Square(postProcess.lensDirtIntensity); this.lensDirtParams.brightness = postProcess.lensDirtBrightness; this.DoFParams.depthFocusMode = postProcess.depthFocusMode; this.DoFParams.maxCoCRadius = postProcess.maxCoCRadius; this.DoFParams.quality = ((SystemInfo.graphicsShaderLevel >= 40) ? postProcess.depthOfFieldQuality : DepthOfFieldQuality.Normal); this.DoFParams.pointAveragePosition = postProcess.pointAveragePosition; this.DoFParams.pointAverageRange = postProcess.pointAverageRange; this.DoFParams.visualizePointFocus = postProcess.visualizePointFocus; this.DoFParams.depthAdaptionSpeed = postProcess.depthAdaptionSpeed; this.DoFParams.focalDistance = postProcess.focalDistance; this.DoFParams.focalRange = postProcess.focalRange; this.colorGradingParams.colorGradingMode = ((!(postProcess.colorGradingTex1 == null)) ? postProcess.colorGradingMode : ColorGradingMode.Off); this.colorGradingParams.colorGradingTex1 = postProcess.colorGradingTex1; this.colorGradingParams.colorGradingTex2 = postProcess.colorGradingTex2; this.colorGradingParams.colorGradingBlendFactor = postProcess.colorGradingBlendFactor; this.colorGradingParams.colorGradingCompatibility = postProcess.colorGradingCompatibility; this.cameraParams.cameraMode = postProcess.cameraMode; this.cameraParams.fNumber = postProcess.fNumber; this.cameraParams.ISO = postProcess.ISO; this.cameraParams.shutterSpeed = postProcess.shutterSpeed; this.cameraParams.adaptionSpeed = postProcess.adaptionSpeed; this.cameraParams.minMaxExposure = postProcess.minMaxExposure; this.cameraParams.exposureCompensation = postProcess.exposureCompensation; this.commonPostProcess.grainIntensity = ((!postProcess.grain) ? 0f : postProcess.grainIntensity); this.commonPostProcess.vignetteIntensity = ((!postProcess.vignette) ? 0f : postProcess.vignetteIntensity); this.commonPostProcess.vignetteScale = postProcess.vignetteScale; this.commonPostProcess.vignetteColor = postProcess.vignetteColor; this.commonPostProcess.chromaticAberration = postProcess.chromaticAberration; this.commonPostProcess.chromaticAberrationDistortion = postProcess.chromaticAberrationDistortion; this.commonPostProcess.chromaticAberrationIntensity = postProcess.chromaticAberrationIntensity; this.commonPostProcess.whitePoint = postProcess.whitePoint; }
private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange, float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane) { int width = halfResDepth.width / 10 + ((halfResDepth.width % 10 != 0) ? 1 : 0); int height = halfResDepth.height / 10 + ((halfResDepth.height % 10 != 0) ? 1 : 0); float num = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength); float num2 = -apertureDiameter * focalLength / (focalDistance - focalLength); float num3 = ScionUtility.CoCToPixels((float)halfResDepth.width); num *= num3; num2 *= num3; Vector4 value = default(Vector4); value.x = num; value.y = num2; value.z = focalDistance; value.w = focalRange * 0.5f; this.m_DoFMat.SetVector("_CoCParams1", value); Vector4 value2 = default(Vector4); value2.x = maxCoCRadius * 0.5f; value2.y = 1f / maxCoCRadius; this.m_DoFMat.SetVector("_CoCParams2", value2); if (this.m_DoFMatDX11 != null) { this.m_DoFMatDX11.SetVector("_CoCParams1", value); this.m_DoFMatDX11.SetVector("_CoCParams2", value2); } this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.width); RenderTexture temporary = RenderTexture.GetTemporary(width, halfResDepth.height, 0, RenderTextureFormat.RHalf); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; RenderTexture temporary2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.RHalf); temporary2.filterMode = FilterMode.Point; temporary2.wrapMode = TextureWrapMode.Clamp; halfResDepth.filterMode = FilterMode.Point; ScionGraphics.Blit(temporary, this.m_DoFMat, 0); this.m_DoFMat.SetTexture("_HorizontalTileResult", temporary); this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.height); ScionGraphics.Blit(temporary2, this.m_DoFMat, 1); RenderTexture.ReleaseTemporary(temporary); return(temporary2); }
protected void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source) { focalDistance = focalDistance < m_camera.nearClipPlane + 0.3f ? m_camera.nearClipPlane + 0.3f : focalDistance; postProcessParams.camera = m_camera; postProcessParams.cameraTransform = m_cameraTransform; //Done later postProcessParams.halfResSource = null; postProcessParams.halfResDepth = m_downsampling.DownsampleDepthTexture(source.width, source.height); postProcessParams.width = source.width; postProcessParams.height = source.height; postProcessParams.halfWidth = source.width / 2; postProcessParams.halfHeight = source.height / 2; if (prevCamFoV != m_camera.fieldOfView) { postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(m_camera.fieldOfView * 0.5f * Mathf.Deg2Rad); prevCamFoV = m_camera.fieldOfView; } postProcessParams.DoFParams.useMedianFilter = true; //This could technically be a user choice, but its a lot of quality for a low price if (userControlledFocalLength == false) { postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV); } else { postProcessParams.cameraParams.focalLength = focalLength * 0.001f; //Millimeter to meter } postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(fNumber, postProcessParams.cameraParams.focalLength); postProcessParams.cameraParams.fieldOfView = m_camera.fieldOfView; postProcessParams.cameraParams.aspect = m_camera.aspect; postProcessParams.cameraParams.nearPlane = m_camera.nearClipPlane; postProcessParams.cameraParams.farPlane = m_camera.farClipPlane; postProcessParams.isFirstRender = m_isFirstRender; m_isFirstRender = false; }
public void BindVirtualCameraParams(Material mat, CameraParameters cameraParams, float focalDistance, float halfResWidth, bool isFirstRender) { mat.SetVector("_VirtualCameraParams1", new Vector4 { x = 1f / (cameraParams.focalLength * 1000f), y = cameraParams.fNumber, z = cameraParams.shutterSpeed, w = ((!isFirstRender) ? (1f - Mathf.Exp(-Time.deltaTime * cameraParams.adaptionSpeed)) : 1f) }); mat.SetVector("_VirtualCameraParams2", new Vector4 { x = cameraParams.exposureCompensation + 1.8f, y = cameraParams.focalLength, z = focalDistance, w = ScionUtility.CoCToPixels(halfResWidth) }); mat.SetVector("_VirtualCameraParams3", new Vector4 { x = Mathf.Pow(2f, cameraParams.minMaxExposure.x), y = Mathf.Pow(2f, cameraParams.minMaxExposure.y) }); }
public void Fill(ScionPostProcessBase postProcess, bool forceFill) { if (isFilled == true && forceFill == false) { return; } isFilled = true; bloom = postProcess.bloom; lensFlare = postProcess.lensFlare; lensDirt = postProcess.lensDirt; lensDirtTexture = postProcess.lensDirtTexture; bloomTexture = null; dofTexture = null; exposure = postProcess.cameraMode != CameraMode.Off ? true : false; depthOfField = postProcess.depthOfField; halfResSource = null; //Done later glareParams.intensity = ScionUtility.Square(postProcess.bloomIntensity); glareParams.brightness = postProcess.bloomBrightness; glareParams.distanceMultiplier = postProcess.bloomDistanceMultiplier; glareParams.downsamples = postProcess.bloomDownsamples; lensFlareParams.ghostSamples = postProcess.lensFlareGhostSamples; lensFlareParams.ghostIntensity = postProcess.lensFlareGhostIntensity; lensFlareParams.ghostDispersal = postProcess.lensFlareGhostDispersal; lensFlareParams.ghostDistortion = postProcess.lensFlareGhostDistortion; lensFlareParams.ghostEdgeFade = postProcess.lensFlareGhostEdgeFade; lensFlareParams.haloIntensity = postProcess.lensFlareHaloIntensity; lensFlareParams.haloWidth = postProcess.lensFlareHaloWidth; lensFlareParams.haloDistortion = postProcess.lensFlareHaloDistortion; lensFlareParams.starUVScale = postProcess.lensFlareDiffractionUVScale; lensFlareParams.starTexture = postProcess.lensFlareDiffractionTexture; lensFlareParams.lensColorTexture = postProcess.lensFlareLensColorTexture; lensFlareParams.blurSamples = postProcess.lensFlareBlurSamples; lensFlareParams.blurStrength = postProcess.lensFlareBlurStrength; lensFlareParams.downsamples = postProcess.lensFlareDownsamples; //lensDirtParams.bloomEffect = ScionUtility.Square(postProcess.lensDirtBloomEffect); lensDirtParams.bloomEffect = postProcess.lensDirtBloomEffect; lensDirtParams.bloomBrightness = postProcess.lensDirtBloomBrightness; lensDirtParams.lensFlareEffect = postProcess.lensDirtLensFlareEffect; lensDirtParams.lensFlareBrightness = postProcess.lensDirtLensFlareBrightness; DoFParams.depthFocusMode = postProcess.depthFocusMode; DoFParams.maxCoCRadius = postProcess.maxCoCRadius; DoFParams.quality = SystemInfo.graphicsShaderLevel < 40 ? DepthOfFieldQuality.Normal : postProcess.depthOfFieldQuality; DoFParams.pointAveragePosition = postProcess.pointAveragePosition; DoFParams.pointAverageRange = postProcess.pointAverageRange; DoFParams.visualizePointFocus = postProcess.visualizePointFocus; DoFParams.depthAdaptionSpeed = postProcess.depthAdaptionSpeed; DoFParams.focalDistance = postProcess.focalDistance; DoFParams.focalRange = postProcess.focalRange; colorGradingParams.colorGradingMode = postProcess.colorGradingTex1 == null ? ColorGradingMode.Off : postProcess.colorGradingMode; colorGradingParams.colorGradingTex1 = postProcess.colorGradingTex1; colorGradingParams.colorGradingTex2 = postProcess.colorGradingTex2; colorGradingParams.colorGradingBlendFactor = postProcess.colorGradingBlendFactor; cameraParams.cameraMode = postProcess.cameraMode; cameraParams.fNumber = postProcess.fNumber; cameraParams.ISO = postProcess.ISO; cameraParams.shutterSpeed = postProcess.shutterSpeed; cameraParams.adaptionSpeed = postProcess.adaptionSpeed; cameraParams.minMaxExposure = postProcess.minMaxExposure; cameraParams.exposureCompensation = postProcess.exposureCompensation; commonPostProcess.grainIntensity = postProcess.grain == true ? postProcess.grainIntensity : 0.0f; commonPostProcess.vignetteIntensity = postProcess.vignette == true ? postProcess.vignetteIntensity : 0.0f; commonPostProcess.vignetteScale = postProcess.vignetteScale; commonPostProcess.vignetteColor = postProcess.vignetteColor; commonPostProcess.chromaticAberration = postProcess.chromaticAberration; commonPostProcess.chromaticAberrationDistortion = postProcess.chromaticAberrationDistortion; commonPostProcess.chromaticAberrationIntensity = postProcess.chromaticAberrationIntensity; }