Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by STGroves · Jun 12, 2017 at 08:46 AM · shadersgridshaderlabshader writinggradient

Is it possible to have a grid shader with gradient lines? (Without external assets)

Hey! I'm currently using the following Grid Shader:

 Shader "Custom/Grid"
 {
     Properties
     {
         gridThickness ("Grid Thickness", Float) = 0.01
         gridSpaceX ("Grid Spacing X", Float) = 1.0
         gridSpaceY ("Grid Spacing Y", Float) = 1.0
         gridOffsetX ("Grid Offset X", Float) = 0
         gridOffsetY ("Grid Offset Y", Float) = 0
         gridCol ("Grid Colour", Color) = (0.5, 1.0, 1.0, 1.0)
         baseCol ("Base Tint", Color) = (0.0, 0.0, 0.0, 0.0)
     }
 
     SubShader
     {
         Tags { "Queue" = "Transparent" }
         Pass
         {
             ZWrite Off
             Blend SrcAlpha OneMinusSrcAlpha
  
             CGPROGRAM
  
             // Define the vertex and fragment shader functions
             #pragma vertex Vert
             #pragma fragment Frag
  
             // Access Shaderlab properties
             uniform float gridThickness;
             uniform float gridSpaceX;
             uniform float gridSpaceY;
             uniform float gridOffsetX;
             uniform float gridOffsetY;
             uniform float4 gridCol;
             uniform float4 baseCol;
  
             // Input into the vertex shader
             struct VertexInput { float4 vertex : POSITION; };
  
             // Output from vertex shader into fragment shader
             struct VertexOutput
             {
                 float4 pos : SV_POSITION;
                 float4 worldPos : TEXCOORD0;
             };
 
             // VERTEX SHADER
             VertexOutput Vert(VertexInput input)
             {
                 VertexOutput output;
                 output.pos = UnityObjectToClipPos(input.vertex);
 
                 // Calculate the world position coordinates to pass to the fragment shader
                 output.worldPos = mul(unity_ObjectToWorld, input.vertex);
  
                 return output;
             }
 
             // FRAGMENT SHADER
             float4 Frag(VertexOutput input) : COLOR
             {
                 if (frac((input.worldPos.x + gridOffsetX) / gridSpaceX) < (gridThickness) ||
                   frac((input.worldPos.y + gridOffsetY) / gridSpaceY) < (gridThickness / gridSpaceY))
                 {
                     return gridCol;
                 }
  
                 else
                     return baseCol;
             }
  
             ENDCG
         }
     }
 }

Is it possible to have something like this, without using a grayscale texture?:

alt text

(I'm only allowed to use what Unity offers... No external assets)

Any help will be appreciated. Code even more so as I am fairly new to ShaderLab.

Thank you!!!

grid.jpg (19.1 kB)
Comment
Add comment · Show 1
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
avatar image bluemike · Jun 19, 2017 at 05:45 AM 0
Share

Yes this is definitely a good case for procedural texture. I think the cg function smoothstep will help you.

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.

Follow this Question

Answers Answers and Comments

112 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

Related Questions

_Time in Image Effects 0 Answers

Shader optimization: 3 color gradient with 2 middle points 0 Answers

Fog not working in my own Vertext Shader 2 Answers

Operate the shader, rotate the material 90 degrees 0 Answers

Is it possible to set the 'ForceNoShadowCasting' SubShader Tag via shader properties or a custom material editor? 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