private void SetShaderParameters(LensFlareParameters lensFlareParams, RenderTexture downsampledScene, float downsamplingNormalizer) { if (lensFlareParams.lensColorTexture != null) { this.m_lensFlareMat.SetTexture("_LensColorTexture", lensFlareParams.lensColorTexture); } else { this.m_lensFlareMat.SetTexture("_LensColorTexture", ScionUtility.WhiteTexture); } Vector4 value = default(Vector4); value.x = lensFlareParams.ghostIntensity / (float)lensFlareParams.ghostSamples; value.y = lensFlareParams.ghostDispersal * 10f / (float)lensFlareParams.ghostSamples; value.z = lensFlareParams.ghostDistortion * 60f; value.w = lensFlareParams.ghostEdgeFade; this.m_lensFlareMat.SetVector("_LensFlareParams1", value); Vector4 value2 = default(Vector4); value2.x = lensFlareParams.haloIntensity; value2.y = lensFlareParams.haloWidth; value2.z = lensFlareParams.haloDistortion * 25f; value2.w = downsamplingNormalizer; this.m_lensFlareMat.SetVector("_LensFlareParams2", value2); Vector4 value3 = default(Vector4); value3.x = lensFlareParams.blurStrength * 50f * this.GetBlurNormalizer(lensFlareParams.blurSamples) * downsamplingNormalizer; this.m_lensFlareMat.SetVector("_LensFlareParams3", value3); Vector4 value4 = default(Vector4); value4.x = 1f / (float)downsampledScene.width; value4.y = 1f / (float)downsampledScene.height; this.m_lensFlareMat.SetVector("_TextureParams", value4); }
private void PrepareLensFlareSampling(LensFlareParameters lensFlareParams, RenderTexture lensFlareTexture, Transform cameraTransform) { Vector3 camLeft = -cameraTransform.right; Vector3 camForward = cameraTransform.forward; float camRotation = Vector3.Dot(camLeft, Vector3.forward) + Vector3.Dot(camForward, Vector3.up); Vector4 lensStarParams1 = new Vector4(); lensStarParams1.x = Mathf.Cos(camRotation * 2.0f * Mathf.PI); lensStarParams1.y = Mathf.Sin(camRotation * 2.0f * Mathf.PI); lensStarParams1.z = lensFlareParams.starUVScale; lensStarParams1.w = (1.0f - lensFlareParams.starUVScale) * 0.5f; m_combinationMat.SetVector("_LensStarParams1", lensStarParams1); if (lensFlareParams.starTexture != null) { m_combinationMat.SetTexture("_LensFlareStarTexture", lensFlareParams.starTexture); } else { m_combinationMat.SetTexture("_LensFlareStarTexture", ScionUtility.WhiteTexture); } m_combinationMat.SetTexture("_LensFlareTexture", lensFlareTexture); }
public RenderTexture RenderLensFlare(RenderTexture downsampledScene, LensFlareParameters lensFlareParams, int origSourceWidth) { float downsamplingNormalizer = this.GetDownsamplingNormalizer(origSourceWidth, downsampledScene.width); this.SetShaderParameters(lensFlareParams, downsampledScene, downsamplingNormalizer); downsampledScene.wrapMode = TextureWrapMode.Clamp; RenderTexture temporary = RenderTexture.GetTemporary(downsampledScene.width, downsampledScene.height, 0, downsampledScene.format, RenderTextureReadWrite.Linear); temporary.filterMode = FilterMode.Bilinear; temporary.wrapMode = TextureWrapMode.Clamp; Graphics.Blit(downsampledScene, temporary, this.m_lensFlareMat, (int)lensFlareParams.ghostSamples); this.HexagonalBlur(temporary, lensFlareParams.blurSamples); return(temporary); }
public RenderTexture RenderLensFlare(RenderTexture downsampledScene, LensFlareParameters lensFlareParams, int origSourceWidth) { float downsamplingNormalizer = GetDownsamplingNormalizer(origSourceWidth, downsampledScene.width); SetShaderParameters(lensFlareParams, downsampledScene, downsamplingNormalizer); downsampledScene.wrapMode = TextureWrapMode.Clamp; RenderTexture lensFlareTex = RenderTexture.GetTemporary(downsampledScene.width, downsampledScene.height, 0, downsampledScene.format, RenderTextureReadWrite.Linear); lensFlareTex.filterMode = FilterMode.Bilinear; lensFlareTex.wrapMode = TextureWrapMode.Clamp; Graphics.Blit(downsampledScene, lensFlareTex, m_lensFlareMat, (int)lensFlareParams.ghostSamples); HexagonalBlur(lensFlareTex, lensFlareParams.blurSamples); return lensFlareTex; }
private void SetShaderParameters(LensFlareParameters lensFlareParams, RenderTexture downsampledScene, float downsamplingNormalizer) { if (lensFlareParams.lensColorTexture != null) { m_lensFlareMat.SetTexture("_LensColorTexture", lensFlareParams.lensColorTexture); } else { m_lensFlareMat.SetTexture("_LensColorTexture", ScionUtility.WhiteTexture); } Vector4 lensFlareParams1 = new Vector4(); lensFlareParams1.x = lensFlareParams.ghostIntensity / (float)lensFlareParams.ghostSamples; //Normalize energy! lensFlareParams1.y = lensFlareParams.ghostDispersal * 10.0f / (float)lensFlareParams.ghostSamples; //Normalize reach! lensFlareParams1.z = lensFlareParams.ghostDistortion * 60.0f; lensFlareParams1.w = lensFlareParams.ghostEdgeFade; m_lensFlareMat.SetVector("_LensFlareParams1", lensFlareParams1); Vector4 lensFlareParams2 = new Vector4(); lensFlareParams2.x = lensFlareParams.haloIntensity; lensFlareParams2.y = lensFlareParams.haloWidth; lensFlareParams2.z = lensFlareParams.haloDistortion * 25.0f; lensFlareParams2.w = downsamplingNormalizer; m_lensFlareMat.SetVector("_LensFlareParams2", lensFlareParams2); Vector4 lensFlareParams3 = new Vector4(); //Normalize the value so all sample counts "reach" as far under all circumstances lensFlareParams3.x = lensFlareParams.blurStrength * 50.0f * GetBlurNormalizer(lensFlareParams.blurSamples) * downsamplingNormalizer; m_lensFlareMat.SetVector("_LensFlareParams3", lensFlareParams3); Vector4 textureParams = new Vector4(); textureParams.x = 1.0f / downsampledScene.width; textureParams.y = 1.0f / downsampledScene.height; m_lensFlareMat.SetVector("_TextureParams", textureParams); }
private void PrepareLensFlareSampling(LensFlareParameters lensFlareParams, RenderTexture lensFlareTexture, Transform cameraTransform) { Vector3 camLeft = -cameraTransform.right; Vector3 camForward = cameraTransform.forward; float camRotation = Vector3.Dot(camLeft, Vector3.forward) + Vector3.Dot(camForward, Vector3.up); Vector4 lensStarParams1 = new Vector4(); lensStarParams1.x = Mathf.Cos(camRotation * 2.0f * Mathf.PI); lensStarParams1.y = Mathf.Sin(camRotation * 2.0f * Mathf.PI); lensStarParams1.z = lensFlareParams.starUVScale; lensStarParams1.w = (1.0f - lensFlareParams.starUVScale) * 0.5f; m_combinationMat.SetVector("_LensStarParams1", lensStarParams1); if (lensFlareParams.starTexture != null) m_combinationMat.SetTexture("_LensFlareStarTexture", lensFlareParams.starTexture); else m_combinationMat.SetTexture("_LensFlareStarTexture", ScionUtility.WhiteTexture); m_combinationMat.SetTexture("_LensFlareTexture", lensFlareTexture); }
private void SetShaderParameters(LensFlareParameters lensFlareParams, RenderTexture downsampledScene, float downsamplingNormalizer) { if (lensFlareParams.lensColorTexture != null) m_lensFlareMat.SetTexture("_LensColorTexture", lensFlareParams.lensColorTexture); else m_lensFlareMat.SetTexture("_LensColorTexture", ScionUtility.WhiteTexture); Vector4 lensFlareParams1 = new Vector4(); lensFlareParams1.x = lensFlareParams.ghostIntensity / (float)lensFlareParams.ghostSamples; //Normalize energy! lensFlareParams1.y = lensFlareParams.ghostDispersal * 10.0f / (float)lensFlareParams.ghostSamples; //Normalize reach! lensFlareParams1.z = lensFlareParams.ghostDistortion * 60.0f; lensFlareParams1.w = lensFlareParams.ghostEdgeFade; m_lensFlareMat.SetVector("_LensFlareParams1", lensFlareParams1); Vector4 lensFlareParams2 = new Vector4(); lensFlareParams2.x = lensFlareParams.haloIntensity; lensFlareParams2.y = lensFlareParams.haloWidth; lensFlareParams2.z = lensFlareParams.haloDistortion * 25.0f; lensFlareParams2.w = downsamplingNormalizer; m_lensFlareMat.SetVector("_LensFlareParams2", lensFlareParams2); Vector4 lensFlareParams3 = new Vector4(); //Normalize the value so all sample counts "reach" as far under all circumstances lensFlareParams3.x = lensFlareParams.blurStrength * 50.0f * GetBlurNormalizer(lensFlareParams.blurSamples) * downsamplingNormalizer; m_lensFlareMat.SetVector("_LensFlareParams3", lensFlareParams3); Vector4 textureParams = new Vector4(); textureParams.x = 1.0f / downsampledScene.width; textureParams.y = 1.0f / downsampledScene.height; m_lensFlareMat.SetVector("_TextureParams", textureParams); }