Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Image Effect help

Discussion in 'Scripting' started by User340, Sep 3, 2008.

  1. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I'm trying to make a script which can be placed onto a camera to make the camera render only the reds of a scene. Here's what I have so far:

    Script placed onto camera
    Code (csharp):
    1. var redMat : Material;
    2.  
    3. function OnRenderImage (source : RenderTexture, destination : RenderTexture)
    4. {
    5.     RenderTexture.active = destination;
    6.     redMat.SetTexture ("_MainTex", source);
    7. }
    8.  
    And this is the shader applied to the redMat:
    Code (csharp):
    1. Shader "Red Filter" {
    2.     Properties {
    3.         _MainTex ("Texture", RECT) = ""
    4.     }
    5.     SubShader {
    6.         Pass {
    7.             ColorMask R
    8.             Blend One One
    9.             SetTexture [_MainTex]
    10.         }
    11.     }
    12. }
    All this seems to do is create thick soft lines around the edge of the screen. Anyone know what I'm doing wrong?

    Thanks
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    You're not rendering anything into destination render texture. Take a look at Material.SetPass documentation for quite small image effect to get your started.

    Next step should be: change the shader to select only the red channel of the input texture. This would probably be easiest with a small Cg fragment program (instead of trying to do that via SetTexture).