Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Replacement Shaders and Projectors

Discussion in 'Shaders' started by MaT227, Jan 15, 2015.

  1. MaT227


    Jul 3, 2012
    Hey everyone,

    I am trying to render only the Projectors of my scene but I can't, all I have is a black image and it seems logical as Projectors need other objects to be projected on.
    For this I am using replaced shaders but it doesn't work and to be honest, I don't have any idea on how to render only my projectors of my scene... Is there a way to do that ?

    Thanks a lot !
  2. MaT227


    Jul 3, 2012
    Even with Unity 5 and the framedebugger, I can't retrieve the projector pass, it's always combined with other objects. It doesn't seem that it's possible but maybe I am wrong. Any idea @Aras ?
  3. Aras


    Unity Technologies

    Nov 7, 2005
    I think more details are needed to answer your question. For example, the shaders that you use, what exactly goes wrong etc.
  4. MaT227


    Jul 3, 2012
    Thank you @Aras, I'll try to improve my question

    The aim is to use a post process effect on some projectors with a specific shader.
    For that I would like to exclude any other object from the camera and render only some specified projectors inside a rendertexture.
    First, I am using a disabled camera with a script and a target rendertexture. In that rendertexture I only want to retrieve the MainTex of some projectors with a black background.
    Code (CSharp):
    1. // Done OnPreCull
    2. RenderWithShader(myShader, ",myReplacementTag");
    The shader on my projectors has myReplacementTag.

    Here is myShader used for the post process effect.
    Code (CSharp):
    1. Shader "Custom/Projector"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Diffuse (RGBA)", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "myReplacementTag"="anything" }
    10.         Pass
    11.         {
    12.             Blend SrcAlpha OneMinusSrcAlpha
    13.             ZWrite Off
    14.             Offset -1, -1
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.              sampler2D            _MainTex;
    19.              uniform float4x4    _Projector;
    20.               struct vertexInput
    21.               {
    22.                 float4 vertex : POSITION;
    23.                 float3 normal : NORMAL;
    24.              };
    25.              struct vertexOutput
    26.              {
    27.                 float4 pos : SV_POSITION;
    28.                 float4 posProj : TEXCOORD0;
    29.              };
    31.              vertexOutput vert(vertexInput input)
    32.              {
    33.                 vertexOutput output;
    34.                 output.posProj = mul(_Projector, input.vertex);
    35.                 output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
    36.                 return output;
    37.              }
    39.              float4 frag(vertexOutput input) : COLOR
    40.              {
    41.                  if (input.posProj.w > 0.0)
    42.                 { return tex2D(_MainTex, input.posProj.xy / input.posProj.w); }
    43.                 else
    44.                 { return float4(0.0, 0.0, 0.0, 0.0); }
    45.              }
    46.              ENDCG
    47.          }
    48.    }
    49.     Fallback Off
    50. }
    After that I want to send my rendertexture to the specified projector and apply it but this should not be a problem except maybe for the projection.

    For the moment, I have a simple setup scene with two projectors and a plane and my rendertexture is all black.
    The first thing would be to fill the rendertexture with black and the specified projectors with their MainTex colors. But I don't know what I am doing wrong...and I don't know if what I want to do is possible.

    Tell me if you need more informations.
  5. MaT227


    Jul 3, 2012
    @Aras I take the liberty to remember you my question, I would like to know if you have an idea if there is an issue or if it's not possible.
    Of course, any other idea is also welcome ! :)

    Thank you !
    Last edited: Jan 20, 2015
  6. MaT227


    Jul 3, 2012
    Any idea ?
  7. Tralafgar-Law


    Jul 6, 2017
    I only know is in Unity5.6.4, Unity Don't support projectors when doing shader replacement. I found it in the unity source code.