BlitWithMaterial() публичный статический Метод

public static BlitWithMaterial ( Material material, RenderTexture source, RenderTexture destination ) : void
material Material
source RenderTexture
destination RenderTexture
Результат void
Пример #1
0
 // Called by camera to apply image effect
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     material.SetTexture("_RampTex", textureRamp);
     material.SetFloat("_Desat", desaturateAmount);
     material.SetVector("_RampOffset", new Vector4(rampOffsetR, rampOffsetG, rampOffsetB, 0));
     ImageEffects.BlitWithMaterial(material, source, destination);
 }
Пример #2
0
    // Called by camera to apply image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        // Create the accumulation texture
        if (accumTexture == null || accumTexture.width != source.width || accumTexture.height != source.height)
        {
            DestroyImmediate(accumTexture);
            accumTexture           = new RenderTexture(source.width, source.height, 0);
            accumTexture.hideFlags = HideFlags.HideAndDontSave;
            ImageEffects.Blit(source, accumTexture);
        }

        // If Extra Blur is selected, downscale the texture to 4x4 smaller resolution.
        if (extraBlur)
        {
            RenderTexture blurbuffer = RenderTexture.GetTemporary(source.width / 4, source.height / 4, 0);
            ImageEffects.Blit(accumTexture, blurbuffer);
            ImageEffects.Blit(blurbuffer, accumTexture);
            RenderTexture.ReleaseTemporary(blurbuffer);
        }

        // Clamp the motion blur variable, so it can never leave permanent trails in the image
        blurAmount = Mathf.Clamp(blurAmount, 0.0f, 0.92f);

        // Setup the texture and floating point values in the shader
        material.SetTexture("_MainTex", accumTexture);
        material.SetFloat("_AccumOrig", 1.0F - blurAmount);

        // Render the image using the motion blur shader
        ImageEffects.BlitWithMaterial(material, source, accumTexture);
        ImageEffects.Blit(accumTexture, destination);
    }
Пример #3
0
    public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
    {
        Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);

        material.SetMatrix("_RotationMatrix", rotationMatrix);
        material.SetVector("_CenterRadius", new Vector4(center.x, center.y, radius.x, radius.y));
        material.SetFloat("_Angle", angle * Mathf.Deg2Rad);

        ImageEffects.BlitWithMaterial(material, source, destination);
    }
Пример #4
0
    // Downsamples the texture to a set resolution.
    private void DownSample(RenderTexture source, RenderTexture dest)
    {
        downsampleMaterial.SetFloat("_DownsampleAmount", downsampleAmount);

        // Remove colors below the threshold.
        downsampleMaterial.SetFloat("_GlowThreshold", glowThreshold);

        downsampleMaterial.color = new Color(glowTint.r, glowTint.g, glowTint.b, glowTint.a / downsampleAmount);
        ImageEffects.BlitWithMaterial(downsampleMaterial, source, dest);
    }
Пример #5
0
    public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
    {
        Matrix4x4 matrix4x = Matrix4x4.TRS(Vector3.get_zero(), Quaternion.Euler(0f, 0f, angle), Vector3.get_one());

        material.SetMatrix("_RotationMatrix", matrix4x);
        string  arg_56_1 = "_CenterRadius";
        Vector4 vector   = new Vector4(center.x, center.y, radius.x, radius.y);

        material.SetVector(arg_56_1, vector);
        material.SetFloat("_Angle", angle * 0.0174532924f);
        ImageEffects.BlitWithMaterial(material, source, destination);
    }
Пример #6
0
    public override void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        RenderTexture temporary  = RenderTexture.GetTemporary(source.get_width() / 4, source.get_height() / 4, 0);
        RenderTexture temporary2 = RenderTexture.GetTemporary(source.get_width() / 4, source.get_height() / 4, 0);
        RenderTexture temporary3 = RenderTexture.GetTemporary(source.get_width() / 4, source.get_height() / 4, 0);

        this.DownSample4x(source, temporary);
        bool flag = true;
        int  num  = 0;

        while ((float)num < this.iterations + this.iterations2)
        {
            if (flag)
            {
                this.FourTapCone(temporary, temporary2, num);
            }
            else
            {
                this.FourTapCone(temporary2, temporary, num);
            }
            flag = !flag;
            if ((float)num == this.iterations - (float)1)
            {
                ImageEffects.Blit((!flag) ? temporary2 : temporary, temporary3);
            }
            checked
            {
                num++;
            }
        }
        Material compositeMaterial = this.GetCompositeMaterial();

        compositeMaterial.SetTexture("_BlurTex1", temporary3);
        compositeMaterial.SetTexture("_BlurTex2", (!flag) ? temporary2 : temporary);
        compositeMaterial.SetTexture("_DepthTex", this.renderTexture);
        Shader.SetGlobalVector("_FocalParams", new Vector4(this.focalDistance, 1f / this.focalDistance, this.focalRange, 1f / this.focalRange));
        ImageEffects.BlitWithMaterial(compositeMaterial, source, destination);
        RenderTexture.ReleaseTemporary(temporary);
        RenderTexture.ReleaseTemporary(temporary2);
        RenderTexture.ReleaseTemporary(temporary3);
        if (this.renderTexture != null)
        {
            RenderTexture.ReleaseTemporary(this.renderTexture);
            this.renderTexture = null;
        }
    }
Пример #7
0
    // Called by camera to apply image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        // Create the accumulation texture
        if (accumTexture == null || accumTexture.width != source.width || accumTexture.height != source.height)
        {
            if (accumTexture != null)
            {
                DestroyImmediate(accumTexture);
            }
            accumTexture           = new RenderTexture(source.width, source.height, 0);
            accumTexture.hideFlags = HideFlags.HideAndDontSave;
            ImageEffects.Blit(source, accumTexture);
        }

        if (this.debugView)
        {
            //ImageEffects.Blit( source, accumTexture );
            Shader.EnableKeyword("MOTIONBLUREDGE_DEBUG");
            Shader.DisableKeyword("MOTIONBLUREDGE_NORMAL");
        }
        else
        {
            Shader.EnableKeyword("MOTIONBLUREDGE_NORMAL");
            Shader.DisableKeyword("MOTIONBLUREDGE_DEBUG");
        }

        // Clamp the motion blur variable, so it can never leave permanent trails in the image
//		blurAmount = Mathf.Clamp( blurAmount, 0.0f, 0.92f );
        endRadius   = Mathf.Clamp(endRadius, 0.01f, 10f);
        startRadius = Mathf.Clamp(startRadius, 0.01f, 10f);
        float scaledEndRad   = endRadius * source.height * 0.5f;
        float scaledStartRad = startRadius * source.height * 0.5f;
        float increaseFactor = 1.0f / (scaledEndRad - scaledStartRad);
        float startOffset    = increaseFactor * scaledStartRad;

        Shader.SetGlobalVector("_WindowsCorrection", new Vector4(source.width, source.height, 0, 0));
        // Setup the texture and floating point values in the shader
        material.SetTexture("_MainTex", accumTexture);
        material.SetFloat("_AccumOrig", 1.0F - blurAmount * speedFactor);         // * speedFactor);
        material.SetVector("_CenterPos", new Vector4(source.width * (0.5f + centerOffsetX), source.height * (0.5f + centerOffsetY), increaseFactor, startOffset));
        material.SetFloat("_TransitionCurve", transitionCurve);
        // Render the image using the motion blur shader
        ImageEffects.BlitWithMaterial(material, source, accumTexture);
        ImageEffects.Blit(accumTexture, destination);
    }
Пример #8
0
    /// Apply the filter
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        // Blit to smaller RT and convert to luminance on the way
        const int     TEMP_RATIO = 1;     // 4x4 smaller
        RenderTexture rtTempSrc  = RenderTexture.GetTemporary(source.width / TEMP_RATIO, source.height / TEMP_RATIO);

        ImageEffects.BlitWithMaterial(materialLum, source, rtTempSrc);

        // Repeatedly reduce this image in size, computing min/max luminance values
        // In the end we'll have 1x1 image with min/max luminances found.
        const int FINAL_SIZE = 1;

        //const int FINAL_SIZE = 1;
        while (rtTempSrc.width > FINAL_SIZE || rtTempSrc.height > FINAL_SIZE)
        {
            const int REDUCE_RATIO = 2;             // our shader does 2x2 reduction
            int       destW        = rtTempSrc.width / REDUCE_RATIO;
            if (destW < FINAL_SIZE)
            {
                destW = FINAL_SIZE;
            }
            int destH = rtTempSrc.height / REDUCE_RATIO;
            if (destH < FINAL_SIZE)
            {
                destH = FINAL_SIZE;
            }
            RenderTexture rtTempDst = RenderTexture.GetTemporary(destW, destH);
            ImageEffects.BlitWithMaterial(materialReduce, rtTempSrc, rtTempDst);

            // Release old src temporary, and make new temporary the source
            RenderTexture.ReleaseTemporary(rtTempSrc);
            rtTempSrc = rtTempDst;
        }

        // Update viewer's adaptation level
        CalculateAdaptation(rtTempSrc);

        // Apply contrast strech to the original scene, using currently adapted parameters
        materialApply.SetTexture("_AdaptTex", adaptRenderTex[curAdaptIndex]);
        ImageEffects.BlitWithMaterial(materialApply, source, destination);

        RenderTexture.ReleaseTemporary(rtTempSrc);
    }
Пример #9
0
    // Called by the camera to apply the image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        int           sourceWidth  = source.width;
        int           sourceHeight = source.height;
        RenderTexture buffer       = RenderTexture.GetTemporary(sourceWidth / 4, sourceHeight / 4, 0);
        RenderTexture buffer2      = RenderTexture.GetTemporary(sourceWidth / 4, sourceHeight / 4, 0);

        // Copy things mask to the 4x4 smaller texture.
        DownSample4x(renderTexture, buffer);

        // Blur the small texture
        bool oddEven = true;

        for (int i = 0; i < iterations; i++)
        {
            if (oddEven)
            {
                FourTapCone(buffer, buffer2, i);
            }
            else
            {
                FourTapCone(buffer2, buffer, i);
            }
            oddEven = !oddEven;
        }
        Material compositeMat = GetCompositeMaterial();

        compositeMat.SetTexture("_BlurTex", oddEven ? buffer : buffer2);
        compositeMat.SetTexture("_ColorRamp", colorRamp);
        compositeMat.SetTexture("_BlurRamp", blurRamp);

        ImageEffects.BlitWithMaterial(compositeMat, source, destination);

        RenderTexture.ReleaseTemporary(buffer);
        RenderTexture.ReleaseTemporary(buffer2);

        if (renderTexture != null)
        {
            RenderTexture.ReleaseTemporary(renderTexture);
            renderTexture = null;
        }
    }
Пример #10
0
 private void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     if (GameScene.mainScene == null)
     {
         return;
     }
     GameScene.mainScene.mainRTT = source;
     if (this.shader == null)
     {
         this.shader = Shader.Find("Snail/PostEffect");
     }
     if (PostEffects.textureRamp == null)
     {
         PostEffects.textureRamp = (Resources.Load("Textures/Water/grayscaleRamp", typeof(Texture2D)) as Texture2D);
     }
     this.material.SetTexture("_RampTex", PostEffects.textureRamp);
     this.material.SetFloat("_Desat", PostEffects.desaturateAmount);
     this.material.SetVector("_RampOffset", new Vector4(PostEffects.rampOffsetR, PostEffects.rampOffsetG, PostEffects.rampOffsetB, 0f));
     ImageEffects.BlitWithMaterial(this.material, source, destination);
 }
Пример #11
0
    // Called by the camera to apply the image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        SanitizeParameters();

        if (scratchTimeLeft <= 0.0f)
        {
            scratchTimeLeft = Random.value * 2 / scratchFPS;             // we have sanitized it earlier, won't be zero
            scratchX        = Random.value;
            scratchY        = Random.value;
        }
        scratchTimeLeft -= Time.deltaTime;

        Material mat = material;

        mat.SetTexture("_GrainTex", grainTexture);
        mat.SetTexture("_ScratchTex", scratchTexture);
        float grainScale = 1.0f / grainSize;         // we have sanitized it earlier, won't be zero

        mat.SetVector("_GrainOffsetScale", new Vector4(
                          Random.value,
                          Random.value,
                          (float)Screen.width / (float)grainTexture.width * grainScale,
                          (float)Screen.height / (float)grainTexture.height * grainScale
                          ));
        mat.SetVector("_ScratchOffsetScale", new Vector4(
                          scratchX + Random.value * scratchJitter,
                          scratchY + Random.value * scratchJitter,
                          (float)Screen.width / (float)scratchTexture.width,
                          (float)Screen.height / (float)scratchTexture.height
                          ));
        mat.SetVector("_Intensity", new Vector4(
                          Random.Range(grainIntensityMin, grainIntensityMax),
                          Random.Range(scratchIntensityMin, scratchIntensityMax),
                          0, 0));
        ImageEffects.BlitWithMaterial(mat, source, destination);
    }
Пример #12
0
    public void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        RenderTexture temporary  = RenderTexture.GetTemporary(source.get_width() / 4, source.get_height() / 4, 0);
        RenderTexture temporary2 = RenderTexture.GetTemporary(source.get_width() / 4, source.get_height() / 4, 0);

        this.DownSample4x(this.renderTexture, temporary);
        bool flag = true;

        checked
        {
            for (int i = 0; i < this.iterations; i++)
            {
                if (flag)
                {
                    this.FourTapCone(temporary, temporary2, i);
                }
                else
                {
                    this.FourTapCone(temporary2, temporary, i);
                }
                flag = !flag;
            }
            Material compositeMaterial = this.GetCompositeMaterial();
            compositeMaterial.SetTexture("_BlurTex", (!flag) ? temporary2 : temporary);
            compositeMaterial.SetTexture("_ColorRamp", this.colorRamp);
            compositeMaterial.SetTexture("_BlurRamp", this.blurRamp);
            ImageEffects.BlitWithMaterial(compositeMaterial, source, destination);
            RenderTexture.ReleaseTemporary(temporary);
            RenderTexture.ReleaseTemporary(temporary2);
            if (this.renderTexture != null)
            {
                RenderTexture.ReleaseTemporary(this.renderTexture);
                this.renderTexture = null;
            }
        }
    }
Пример #13
0
    /// Helper function to do gradual adaptation to min/max luminances
    private void CalculateAdaptation(Texture curTexture)
    {
        int prevAdaptIndex = curAdaptIndex;

        curAdaptIndex = (curAdaptIndex + 1) % 2;

        // Adaptation speed is expressed in percents/frame, based on 30FPS.
        // Calculate the adaptation lerp, based on current FPS.
        float       adaptLerp     = 1.0f - Mathf.Pow(1.0f - adaptationSpeed, 30.0f * Time.deltaTime);
        const float kMinAdaptLerp = 0.01f;

        adaptLerp = Mathf.Clamp(adaptLerp, kMinAdaptLerp, 1);

        materialAdapt.SetTexture("_CurTex", curTexture);
        materialAdapt.SetVector("_AdaptParams", new Vector4(
                                    adaptLerp,
                                    limitMinimum,
                                    limitMaximum,
                                    0.0f
                                    ));
        ImageEffects.BlitWithMaterial(materialAdapt,
                                      adaptRenderTex[prevAdaptIndex],
                                      adaptRenderTex[curAdaptIndex]);
    }
Пример #14
0
 public void BlitGlow(RenderTexture source, RenderTexture dest)
 {
     compositeMaterial.color = new Color(1F, 1F, 1F, Mathf.Clamp01(glowIntensity));
     ImageEffects.BlitWithMaterial(compositeMaterial, source, dest);
 }
Пример #15
0
 // Downsamples the texture to a quarter resolution.
 private void DownSample4x(RenderTexture source, RenderTexture dest)
 {
     downsampleMaterial.color = new Color(glowTint.r, glowTint.g, glowTint.b, glowTint.a / 4.0f);
     ImageEffects.BlitWithMaterial(downsampleMaterial, source, dest);
 }
Пример #16
0
	// Called by camera to apply image effect
	void OnRenderImage (RenderTexture source, RenderTexture destination)
	{
		material.SetFloat("_Treshold", threshold * threshold);
		ImageEffects.BlitWithMaterial (material, source, destination);
	}
Пример #17
0
 // Called by camera to apply image effect
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     ImageEffects.BlitWithMaterial(material, source, destination);
 }
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     material.SetTexture("_DepthNormal", _depthNormalTex);
     ImageEffects.BlitWithMaterial(material, source, destination);
     CleanUpTextures();
 }
Пример #19
0
 public void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     ImageEffects.BlitWithMaterial(this.get_material(), source, destination);
 }
Пример #20
0
 // Called by camera to apply image effect
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     material.SetFloat("_Gamma", 1f / gamma);
     ImageEffects.BlitWithMaterial(material, source, destination);
 }
Пример #21
0
 // Called by camera to apply image effect
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     material.SetTexture("_RampTex", textureRamp);
     material.SetFloat("_RampOffset", rampOffset);
     ImageEffects.BlitWithMaterial(material, source, destination);
 }