-5

How can I add a Texture to following shader given by Oculus API for fading :

Shader "Oculus/Unlit Transparent Color" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Texture", 2D) = "white" {} //  I added this property to apply Texture. Where can I use it?
}

SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 100
    Fog {Mode Off}
    Cull Off
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha
    Color [_Color]

    Pass {}
}
}
Umair M
  • 10,298
  • 6
  • 42
  • 74
  • 12
    **About all the downvoters** If you are sure that _This question does not show research effort;it is unclear and not useful._ then you should justify that by adding a proper comment. If you are down voting the question because of _meta effect_ and you can't downvote the answer because you don't want to lose the reputation then such herd behavior is not acceptable. – akash Aug 20 '16 at 07:33

2 Answers2

30

You can use the property you have added in the Pass {} which should contain at least a vertex and a fragment shader (or a surface shader).

In the pass you define a sampler2D with the same name as you property, so you can use it in your shader functions.

There are some examples shaders in unitys documentation: https://docs.unity3d.com/Manual/ShaderTut2.html
https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html

Edit
There is also an example for shaders that are structured like yours:
https://docs.unity3d.com/Manual/ShaderTut1.html
According to this, you can add something like

SetTexture [_MainTex] {
    // some properties
}

So in a similar fashion like setting the Color. (Sorry I haven't used shaders structured like that yet, only vertex/fragment shaders, so you will have to try if it works and/or read up the examples provided by unity or wait for another answer of someone with more expertise :) )

nyro_0
  • 1,135
  • 1
  • 7
  • 9
1

As xyLe_ suggested in his post, In Pass{}block I added following code and it worked:

  SetTexture [_MainTex] {
            constantColor [_Color]
            Combine texture * primary DOUBLE, texture * constant
        }
Community
  • 1
  • 1
Umair M
  • 10,298
  • 6
  • 42
  • 74
  • 22
    You should have marked his answer as correct. If it was lacking anything you only needed to tell him, or add it in an edit. –  Aug 18 '16 at 19:31
  • 1
    This answer has been discussed on meta: https://meta.stackoverflow.com/questions/332723/answer-your-question-copying-an-answer-and-mark-yours-as-accepted – user000001 Aug 19 '16 at 05:57