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 /
avatar image
0
Question by manikiran22 · Jul 29, 2019 at 06:44 AM · texturematerialshadersshader programming

Default Uniy Shader variables are not working.

Hey, i am trying to work on Unity shaders through script. However in order to achieve what i need i have to use the built in Unity shader variables such as _Time which represents the time since the level is loaded. And this default shader variable is not working. cause when i try to peek the definition from the MVS it says not defined.

Shader "Custom/ScrollingShaders" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _ScrollXSeed ("X Scroll Speed", Range(0,10)) = 2 _ScrollYSeed("Y Scroll Speed", Range(0,10)) = 2

 }
 SubShader
 {
     Tags { "RenderType"="Opaque" }
     LOD 200

     CGPROGRAM

     #include "Assets/CGIncludes/UnityShaderVariables.cginc"

     // Physically based Standard lighting model, and enable shadows on all light types
     #pragma surface surf Standard fullforwardshadows

     // Use shader model 3.0 target, to get nicer looking lighting
     #pragma target 3.0
     
     fixed4 _Color;
     fixed _ScrollXSpeed;
     fixed _ScrollYSpeed;
     sampler2D _MainTex;

     struct Input
     {
         float2 uv_MainTex;
     };

     // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
     // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
     // #pragma instancing_options assumeuniformscaling
     UNITY_INSTANCING_BUFFER_START(Props)
         // put more per-instance properties here
     UNITY_INSTANCING_BUFFER_END(Props)

     void surf (Input IN, inout SurfaceOutputStandard o)
     {

         //create a separate variable to store our UV's
         //before we pass them to the text2D() function
         fixed2 scrolledUV = IN.uv_MainTex;

         //create a variable that stores individual X and Y
         //components for the uv scaled by time
         fixed xScrollValue = _ScrollXSpeed * _Time;
         fixed yScrollValue = _ScrollYSpeed * _Time;

         //Apply final UV offset where scrolls are merged with UV
         scrolledUV += fixed2(xScrollValue, yScrollValue);

         // Albedo comes from a texture tinted by color
         half4 c = tex2D (_MainTex, scrolledUV);
         o.Albedo = c.rgb * _Color;
         
         // Metallic and smoothness come from slider variables
         o.Alpha = c.a;
     }
     ENDCG
 }
 FallBack "Diffuse"

}

[1]: /storage/temp/143682--time.png

-time.png (7.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Deathdefy · Jul 29, 2019 at 02:02 PM

_Time is stored as a float4. You need to access one of the floats within it to actually use it.

https://answers.unity.com/questions/266584/shaders-why-is-time-stored-in-a-vector4.html

Comment
Add comment · Show 1 · Share
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 manikiran22 · Jul 29, 2019 at 08:19 PM 0
Share

so does this mean this is how i should rewrite the code as @Deathdefy

fixed xScrollValue = _ScrollXSpeed mul _Time.x;
. fixed yScrollValue = _ScrollYSpeed mul _Time.y;

or may be change the variables from fixed to float as mentioned in the document in that case this is how it should be.

float xScrollValue = _ScrollXSpeed mul _Time.x;
. float yScrollValue = _ScrollYSpeed mul _Time.y;

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

165 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

Related Questions

RimLight Shader 0 Answers

Is it possible to make an image sequence into an animated normal map? 0 Answers

How can I pan a texture to specific location on a sheet? 1 Answer

There is an issue with texture wrapping around sphere's in unity 0 Answers

Shader: Modify XY Position of Texture 0 Answers


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