Search Unity

Shader Syntax for #include shader.shader

Discussion in 'Shaders' started by TenBitNet, Jan 21, 2019.

  1. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    How do I include a shader without explicitly naming the passes?
    Code (CSharp):
    1. Shader "Custom/NewSurfaceShader"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Color", Color) = (1,1,1,1)
    6.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    7.     }
    8.     SubShader
    9.     {
    10.         #include "Lighting.shader"
    11.     }
    12.     FallBack "Diffuse"
    13. }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Not possible. You have to use UsePass, or Fallback.
     
  3. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    Can I atleast name a standard shader pass somehow? Maybe even put the passes just in a cginc file instead so I don't duplicate code
     
    Last edited: Jan 22, 2019
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    You should look at the code of the Standard.shader. You’ll see that there’s very little there to begin with for the same kind of goals you’re looking to achieve. Most of the code for the Standard Shader is in cginc files that are included. The passes mostly define those includes, setup some multi compile / shader feature pragma, and then define which function to use for the vertex / fragment stages.
     
  5. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    So I've found out you just have to write the passes in a cginc file in order to explicitly add them to the shader. Since the code in the compiler will completely copy and past everything in the file word for word. Where did you learn about shaders? I want to know so I don't keep asking simple questions.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    I learned from 15 years of trial and error, asking questions, and reading the various talks GPU vendors put out.

    Today there are resources like Alan Zucconi, Catlike Coding, Simon schreibt, and tons of youtube videos.
     
  7. TenBitNet

    TenBitNet

    Joined:
    Nov 9, 2017
    Posts:
    29
    Can
    I now found out you are right there is no way to do it other than use pass. That I can use the includes only between cg program and endcg. Thanks for your help.