• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by MrRegalityBoom · 3 days ago · shader

Enabling lighting/shadow receiving on custom shader.

Hello, I've recently obtained a shader that I'm trying to modify to allow light/shadows. At the moment it renders unlit (I'm also using Universal Render Pipeline, if it helps)

I'm fairly competent in Shader Graph, but when it comes to shader code I'm unfortunately useless.

Is there something I'm missing here? I've tried a few things already, but nothing seems to be working. If someone could help point me in the right direction, I'd greatly appreciate it. Or, if someone can break this down into something I can recreate in Shader Graph, that would also be extremely helpful.

 Shader "LGPE/GroundTexture"
 {
     Properties
     {
         _TexA("TexA", 2D) = "white" {}
         _TexB("TexB", 2D) = "white" {}
         _TexC("TexC", 2D) = "white" {}
         _TexD("TexD", 2D) = "white" {}
         _TexNoise("TexNoise", 2D) = "white" {}
         _TexTransition("TexTransition", 2D) = "white" {}
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 100
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
                 float2 uv1 : TEXCOORD1;
             };
 
             struct v2f
             {
                 float2 uv_a : TEXCOORD0;
                 float2 uv_b : TEXCOORD1;
                 float2 uv_c : TEXCOORD2;
                 float2 uv_d : TEXCOORD3;
                 float2 uv_n : TEXCOORD4;
                 float2 uv_t : TEXCOORD5;
                 UNITY_FOG_COORDS(1)
                 float4 vertex : SV_POSITION;
             };
 
             sampler2D _TexA;
             sampler2D _TexB;
             sampler2D _TexC;
             sampler2D _TexD;
             sampler2D _TexNoise;
             sampler2D _TexTransition;
             float4 _TexA_ST;
             float4 _TexB_ST;
             float4 _TexC_ST;
             float4 _TexD_ST;
             float4 _TexNoise_ST;
             float4 _TexTransition_ST;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv_a = TRANSFORM_TEX(v.uv, _TexA);
                 o.uv_b = TRANSFORM_TEX(v.uv, _TexB);
                 o.uv_c = TRANSFORM_TEX(v.uv, _TexC);
                 o.uv_d = TRANSFORM_TEX(v.uv, _TexD);
                 o.uv_n = TRANSFORM_TEX(v.uv, _TexNoise);
                 o.uv_t = TRANSFORM_TEX(v.uv1, _TexTransition);
                 return o;
             }
             
             fixed4 func(fixed4 a, fixed4 b, fixed4 c)
             {
                 return a * (b - c) + c;
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 tex_a = tex2D(_TexA, i.uv_a);
                 fixed4 tex_b = tex2D(_TexB, i.uv_b);
                 fixed4 tex_c = tex2D(_TexC, i.uv_c);
                 fixed4 tex_d = tex2D(_TexD, i.uv_d);
                 fixed4 tex_noise = tex2D(_TexNoise, i.uv_n);
                 fixed4 tex_transition = tex2D(_TexTransition, i.uv_t);
                 float trans_alpha = tex_transition.w;
                 fixed4 col = tex_transition * func(trans_alpha,
                     func(tex_noise, tex_a, tex_b),
                     func(tex_noise, tex_c, tex_d));
                 return col;
             }
             ENDCG
         }
     }
 }
 

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

228 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

Exclude outline only, from fog, in custom toon shader. 1 Answer

Bring phong settings from cinema 4d into unity 1 Answer

shader blocking the color component 0 Answers

2d lighting effect 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges