public void CalculateStarData()
        {
            if (m_starlinesCount == 0)
            {
                return;
            }

            m_starLinesArr = new StarLineData[m_starlinesCount];
            float fInc = (m_customIncrement > 0) ? m_customIncrement : (180.0f / ( float )m_starlinesCount);

            fInc *= Mathf.Deg2Rad;
            for (int i = 0; i < m_starlinesCount; i++)
            {
                m_starLinesArr[i]              = new StarLineData();
                m_starLinesArr[i].PassCount    = m_passCount;
                m_starLinesArr[i].SampleLength = m_sampleLength;
                if (m_longAttenuation > 0)
                {
                    m_starLinesArr[i].Attenuation = ((i % 2) == 0) ? m_longAttenuation : m_attenuation;
                }
                else
                {
                    m_starLinesArr[i].Attenuation = m_attenuation;
                }
                m_starLinesArr[i].Inclination = fInc * ( float )i;
            }
        }
Пример #2
0
 public unsafe void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot)
 {
     Graphics.Blit(Texture2D.blackTexture, dest);
     if (!this.m_isDirty && ((this.m_currentWidth == source.width) && (this.m_currentHeight == source.height)))
     {
         this.OnRenderFromCache(source, dest, material, this.m_intensity, cameraRot);
     }
     else
     {
         this.m_isDirty       = false;
         this.m_currentWidth  = source.width;
         this.m_currentHeight = source.height;
         GlareDefData data = null;
         bool         flag = false;
         if (this.m_currentGlareType != GlareLibType.Custom)
         {
             data = this.m_glareDefArr[this.m_currentGlareIdx];
         }
         else if ((this.m_customGlareDef == null) || (this.m_customGlareDef.Length <= 0))
         {
             data = this.m_glareDefArr[0];
         }
         else
         {
             data = this.m_customGlareDef[this.m_customGlareDefIdx];
             flag = true;
         }
         this.m_amplifyGlareCache.GlareDef = data;
         float       width  = source.width;
         float       height = source.height;
         StarDefData data2  = !flag ? this.m_starDefArr[(int)data.StarType] : data.CustomStarData;
         this.m_amplifyGlareCache.StarDef = data2;
         int num3 = (this.m_glareMaxPassCount >= data2.PassCount) ? data2.PassCount : this.m_glareMaxPassCount;
         this.m_amplifyGlareCache.CurrentPassCount = num3;
         float num4 = data.StarInclination + data2.Inclination;
         int   num5 = 0;
         while (num5 < this.m_glareMaxPassCount)
         {
             float t    = ((float)(num5 + 1)) / ((float)this.m_glareMaxPassCount);
             int   num7 = 0;
             while (true)
             {
                 if (num7 >= 8)
                 {
                     num5++;
                     break;
                 }
                 Color b = this._overallTint * Color.Lerp(this.m_cromaticAberrationGrad.Evaluate(((float)num7) / 7f), this.m_whiteReference, t);
                 *(this.m_amplifyGlareCache.CromaticAberrationMat[num5, num7]) = Color.Lerp(this.m_whiteReference, b, data.ChromaticAberration);
                 num7++;
             }
         }
         this.m_amplifyGlareCache.TotalRT = data2.StarlinesCount * num3;
         for (int i = 0; i < this.m_amplifyGlareCache.TotalRT; i++)
         {
             this._rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height);
         }
         int index = 0;
         int num10 = 0;
         while (num10 < data2.StarlinesCount)
         {
             StarLineData data3  = data2.StarLinesArr[num10];
             float        f      = num4 + data3.Inclination;
             float        num12  = Mathf.Sin(f);
             float        num13  = Mathf.Cos(f);
             Vector2      vector = new Vector2 {
                 x = (num13 / width) * (data3.SampleLength * this.m_overallStreakScale),
                 y = (num12 / height) * (data3.SampleLength * this.m_overallStreakScale)
             };
             float num14 = (((this.m_aTanFoV + 0.1f) * 280f) / (width + height)) * 1.2f;
             int   num15 = 0;
             while (true)
             {
                 if (num15 >= num3)
                 {
                     num10++;
                     break;
                 }
                 int num16 = 0;
                 while (true)
                 {
                     if (num16 >= 8)
                     {
                         int num18 = 8;
                         while (true)
                         {
                             if (num18 >= 0x10)
                             {
                                 this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets, this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights, this.m_intensity, data2.CameraRotInfluence * cameraRot);
                                 if (num15 == 0)
                                 {
                                     Graphics.Blit(source, this._rtBuffer[index], material, 2);
                                 }
                                 else
                                 {
                                     Graphics.Blit(this._rtBuffer[index - 1], this._rtBuffer[index], material, 2);
                                 }
                                 index++;
                                 vector *= this.m_perPassDisplacement;
                                 num14  *= this.m_perPassDisplacement;
                                 num15++;
                                 break;
                             }
                             this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num18] = -this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num18 - 8];
                             this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num18] = this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num18 - 8];
                             num18++;
                         }
                         break;
                     }
                     float num17 = Mathf.Pow(data3.Attenuation, num14 * num16);
                     this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num16]   = ((this.m_amplifyGlareCache.CromaticAberrationMat[(num3 - 1) - num15, num16] * num17) * (num15 + 1f)) * 0.5f;
                     this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x = vector.x * num16;
                     this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y = vector.y * num16;
                     if ((Mathf.Abs(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x) >= 0.9f) || (Mathf.Abs(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y) >= 0.9f))
                     {
                         this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x = 0f;
                         this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y = 0f;
                         Vector4 *vectorPtr1 = &(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num16]);
                         vectorPtr1[0] *= 0f;
                     }
                     num16++;
                 }
             }
         }
         this.m_amplifyGlareCache.AverageWeight = Vector4.one / ((float)data2.StarlinesCount);
         for (int j = 0; j < data2.StarlinesCount; j++)
         {
             material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[j], this.m_amplifyGlareCache.AverageWeight);
             int num20 = ((j + 1) * num3) - 1;
             material.SetTexture(AmplifyUtils.AnamorphicRTS[j], this._rtBuffer[num20]);
         }
         int pass = (0x13 + data2.StarlinesCount) - 1;
         dest.DiscardContents();
         Graphics.Blit(this._rtBuffer[0], dest, material, pass);
         for (index = 0; index < this._rtBuffer.Length; index++)
         {
             AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[index]);
             this._rtBuffer[index] = null;
         }
     }
 }
Пример #3
0
        public void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot)
        {
            //NEED TO SET DESTINATION RENDER TARGET TO COMPLETELLY BLACK SO WE CAN SUM ALL THE GLARE/STAR PASSES ON IT
            Graphics.Blit(Texture2D.blackTexture, dest);

            if (m_isDirty ||
                m_currentWidth != source.width ||
                m_currentHeight != source.height)
            {
                m_isDirty       = false;
                m_currentWidth  = source.width;
                m_currentHeight = source.height;
            }
            else
            {
                OnRenderFromCache(source, dest, material, m_intensity, cameraRot);
                return;
            }

            GlareDefData glareDef    = null;
            bool         validCustom = false;

            if (m_currentGlareType == GlareLibType.Custom)
            {
                if (m_customGlareDef != null && m_customGlareDef.Length > 0)
                {
                    glareDef    = m_customGlareDef[m_customGlareDefIdx];
                    validCustom = true;
                }
                else
                {
                    glareDef = m_glareDefArr[0];
                }
            }
            else
            {
                glareDef = m_glareDefArr[m_currentGlareIdx];
            }


            m_amplifyGlareCache.GlareDef = glareDef;

            float srcW = source.width;
            float srcH = source.height;

            StarDefData starDef = (validCustom) ? glareDef.CustomStarData : m_starDefArr[( int )glareDef.StarType];


            m_amplifyGlareCache.StarDef = starDef;
            int currPassCount = (m_glareMaxPassCount < starDef.PassCount) ? m_glareMaxPassCount : starDef.PassCount;

            m_amplifyGlareCache.CurrentPassCount = currPassCount;
            float radOffset = glareDef.StarInclination + starDef.Inclination;

            for (int p = 0; p < m_glareMaxPassCount; p++)
            {
                float ratio = ( float )(p + 1) / ( float )m_glareMaxPassCount;

                for (int s = 0; s < MaxLineSamples; s++)
                {
                    Color chromaticAberrColor = _overallTint * Color.Lerp(m_cromaticAberrationGrad.Evaluate(( float )s / ( float )(MaxLineSamples - 1)), m_whiteReference, ratio);
                    m_amplifyGlareCache.CromaticAberrationMat[p, s] = Color.Lerp(m_whiteReference, chromaticAberrColor, glareDef.ChromaticAberration);
                }
            }
            m_amplifyGlareCache.TotalRT = starDef.StarlinesCount * currPassCount;

            for (int i = 0; i < m_amplifyGlareCache.TotalRT; i++)
            {
                _rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height);
            }

            int rtIdx = 0;

            for (int d = 0; d < starDef.StarlinesCount; d++)
            {
                StarLineData starLine = starDef.StarLinesArr[d];
                float        angle    = radOffset + starLine.Inclination;
                float        sinAngle = Mathf.Sin(angle);
                float        cosAngle = Mathf.Cos(angle);
                Vector2      vtStepUV = new Vector2();
                vtStepUV.x = cosAngle / srcW * (starLine.SampleLength * m_overallStreakScale);
                vtStepUV.y = sinAngle / srcH * (starLine.SampleLength * m_overallStreakScale);

                float attnPowScale = (m_aTanFoV + 0.1f) * (280.0f) / (srcW + srcH) * 1.2f;

                for (int p = 0; p < currPassCount; p++)
                {
                    for (int i = 0; i < MaxLineSamples; i++)
                    {
                        float lum = Mathf.Pow(starLine.Attenuation, attnPowScale * i);

                        m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i] = m_amplifyGlareCache.CromaticAberrationMat[currPassCount - 1 - p, i] * lum * (p + 1.0f) * 0.5f;

                        // OFFSET OF SAMPLING COORDINATE
                        m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x = vtStepUV.x * i;
                        m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y = vtStepUV.y * i;
                        if (Mathf.Abs(m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x) >= 0.9f ||
                            Mathf.Abs(m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y) >= 0.9f)
                        {
                            m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x = 0.0f;
                            m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y = 0.0f;
                            m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i]  *= 0.0f;
                        }
                    }

                    // MIRROR STARLINE
                    for (int i = MaxLineSamples; i < MaxTotalSamples; i++)
                    {
                        m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i] = -m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i - MaxLineSamples];
                        m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i] = m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i - MaxLineSamples];
                    }

                    // APPLY SHADER
                    UpdateMatrixesForPass(material, m_amplifyGlareCache.Starlines[d].Passes[p].Offsets, m_amplifyGlareCache.Starlines[d].Passes[p].Weights, m_intensity, starDef.CameraRotInfluence * cameraRot);

                    //CREATED WEIGHTED TEXTURE
                    if (p == 0)
                    {
                        Graphics.Blit(source, _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare);
                    }
                    else
                    {
                        Graphics.Blit(_rtBuffer[rtIdx - 1], _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare);
                    }

                    rtIdx        += 1;
                    vtStepUV     *= m_perPassDisplacement;
                    attnPowScale *= m_perPassDisplacement;
                }
            }

            //ADD TO MAIN RT
            m_amplifyGlareCache.AverageWeight = Vector4.one / starDef.StarlinesCount;
            for (int i = 0; i < starDef.StarlinesCount; i++)
            {
                material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[i], m_amplifyGlareCache.AverageWeight);
                int idx = (i + 1) * currPassCount - 1;
                material.SetTexture(AmplifyUtils.AnamorphicRTS[i], _rtBuffer[idx]);
            }

            int passId = ( int )BloomPasses.WeightedAddPS1 + starDef.StarlinesCount - 1;

            dest.DiscardContents();
            Graphics.Blit(_rtBuffer[0], dest, material, passId);

            //RELEASE RT's
            for (rtIdx = 0; rtIdx < _rtBuffer.Length; rtIdx++)
            {
                AmplifyUtils.ReleaseTempRenderTarget(_rtBuffer[rtIdx]);
                _rtBuffer[rtIdx] = null;
            }
        }
Пример #4
0
 public void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot)
 {
     Graphics.Blit(Texture2D.blackTexture, dest);
     if (this.m_isDirty || this.m_currentWidth != source.width || this.m_currentHeight != source.height)
     {
         this.m_isDirty       = false;
         this.m_currentWidth  = source.width;
         this.m_currentHeight = source.height;
         bool         flag = false;
         GlareDefData glareDefData;
         if (this.m_currentGlareType == GlareLibType.Custom)
         {
             if (this.m_customGlareDef != null && this.m_customGlareDef.Length != 0)
             {
                 glareDefData = this.m_customGlareDef[this.m_customGlareDefIdx];
                 flag         = true;
             }
             else
             {
                 glareDefData = this.m_glareDefArr[0];
             }
         }
         else
         {
             glareDefData = this.m_glareDefArr[this.m_currentGlareIdx];
         }
         this.m_amplifyGlareCache.GlareDef = glareDefData;
         float       num         = (float)source.width;
         float       num2        = (float)source.height;
         StarDefData starDefData = flag ? glareDefData.CustomStarData : this.m_starDefArr[(int)glareDefData.StarType];
         this.m_amplifyGlareCache.StarDef = starDefData;
         int num3 = (this.m_glareMaxPassCount < starDefData.PassCount) ? this.m_glareMaxPassCount : starDefData.PassCount;
         this.m_amplifyGlareCache.CurrentPassCount = num3;
         float num4 = glareDefData.StarInclination + starDefData.Inclination;
         for (int i = 0; i < this.m_glareMaxPassCount; i++)
         {
             float t = (float)(i + 1) / (float)this.m_glareMaxPassCount;
             for (int j = 0; j < 8; j++)
             {
                 Color b = this._overallTint * Color.Lerp(this.m_cromaticAberrationGrad.Evaluate((float)j / 7f), this.m_whiteReference, t);
                 this.m_amplifyGlareCache.CromaticAberrationMat[i, j] = Color.Lerp(this.m_whiteReference, b, glareDefData.ChromaticAberration);
             }
         }
         this.m_amplifyGlareCache.TotalRT = starDefData.StarlinesCount * num3;
         for (int k = 0; k < this.m_amplifyGlareCache.TotalRT; k++)
         {
             this._rtBuffer[k] = AmplifyUtils.GetTempRenderTarget(source.width, source.height);
         }
         int l = 0;
         for (int m = 0; m < starDefData.StarlinesCount; m++)
         {
             StarLineData starLineData = starDefData.StarLinesArr[m];
             float        f            = num4 + starLineData.Inclination;
             float        num5         = Mathf.Sin(f);
             float        num6         = Mathf.Cos(f);
             Vector2      vector       = default(Vector2);
             vector.x = num6 / num * (starLineData.SampleLength * this.m_overallStreakScale);
             vector.y = num5 / num2 * (starLineData.SampleLength * this.m_overallStreakScale);
             float num7 = (this.m_aTanFoV + 0.1f) * 280f / (num + num2) * 1.2f;
             for (int n = 0; n < num3; n++)
             {
                 for (int num8 = 0; num8 < 8; num8++)
                 {
                     float d = Mathf.Pow(starLineData.Attenuation, num7 * (float)num8);
                     this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num8]   = this.m_amplifyGlareCache.CromaticAberrationMat[num3 - 1 - n, num8] * d * ((float)n + 1f) * 0.5f;
                     this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x = vector.x * (float)num8;
                     this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y = vector.y * (float)num8;
                     if (Mathf.Abs(this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x) >= 0.9f || Mathf.Abs(this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y) >= 0.9f)
                     {
                         this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x = 0f;
                         this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y = 0f;
                         this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num8]  *= 0f;
                     }
                 }
                 for (int num9 = 8; num9 < 16; num9++)
                 {
                     this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num9] = -this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num9 - 8];
                     this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num9] = this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num9 - 8];
                 }
                 this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets, this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights, this.m_intensity, starDefData.CameraRotInfluence * cameraRot);
                 if (n == 0)
                 {
                     Graphics.Blit(source, this._rtBuffer[l], material, 2);
                 }
                 else
                 {
                     Graphics.Blit(this._rtBuffer[l - 1], this._rtBuffer[l], material, 2);
                 }
                 l++;
                 vector *= this.m_perPassDisplacement;
                 num7   *= this.m_perPassDisplacement;
             }
         }
         this.m_amplifyGlareCache.AverageWeight = Vector4.one / (float)starDefData.StarlinesCount;
         for (int num10 = 0; num10 < starDefData.StarlinesCount; num10++)
         {
             material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[num10], this.m_amplifyGlareCache.AverageWeight);
             int num11 = (num10 + 1) * num3 - 1;
             material.SetTexture(AmplifyUtils.AnamorphicRTS[num10], this._rtBuffer[num11]);
         }
         int pass = 19 + starDefData.StarlinesCount - 1;
         dest.DiscardContents();
         Graphics.Blit(this._rtBuffer[0], dest, material, pass);
         for (l = 0; l < this._rtBuffer.Length; l++)
         {
             AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[l]);
             this._rtBuffer[l] = null;
         }
         return;
     }
     this.OnRenderFromCache(source, dest, material, this.m_intensity, cameraRot);
 }