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
1
Question by nipundavid · Sep 09, 2016 at 06:27 AM · shaderunity5graphicsshader programming

Replaced '_Object2World' with 'unity_ObjectToWorld'

Hi I just started learing unity shaders, - https://www.youtube.com/watch?v=epixwRw80MM

But when creating a difuse lightinig shader with single directional light

everytime _Object2World is replaced by unity_ObjectToWorld with a upgrade message on top

I tried searching for it but the bug is issue is closed in latest version of unity

My Unity ver - 5.4.0f3

 // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
 
 // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
 
 Shader "Unlit/Custom_Diffuse"
 {
     Properties {
         // Texture field in inspector where we assign texture to the model
         _MainTexture("Main Texture",2D) = "white"{}
     }
 
     SubShader {        
         PASS {
             CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
 
                 fixed4 _Color;
                 sampler2D _MainTexture;
                 float4 _LightColor0;
                 struct appData {
                     float4 vertex : POSITION;
                     float3 normal : NORMAL;
                     float2 texCoord : TEXCOORD0;
                 };
 
                 struct v2f {
                     float4 pos : SV_POSITION;
                     float3 normal : NORMAL;
                     float2 texCoord : TEXCOORD0;
                 };
 
                 v2f vert (appData IN) {
                     v2f OUT;
                     OUT.pos = mul(UNITY_MATRIX_MVP,IN.vertex);
 
                     // Directly used from model space to modelspace
                     // OUT.normal = IN.NORMAL;
                     // float4 (IN.normal,0.0) - normal is a float3 type variable declared in appData
                     // But we need float4 so this line converts float3 to float4 type casting we can say
                     //mul() to convert the normal from model space to world space as light is in world space
                     // _Object2World is a unity internal variable
                     //mul().xyz - swizling the resultant of mul is float4, this converts to float3
                     OUT.normal = mul(float4(IN.normal,0.0),unity_ObjectToWorld).xyz;
                     // just pass the texture coodinates of the UV map to the semantics in fragment
                     // Directly used from model space to modelspace
                     OUT.texCoord = IN.texCoord;
                     return OUT;
                 }
 
                 fixed4 frag(v2f IN) : COLOR{
                     // wraps the texture data to the UV coordinates recieved from the vertex function
                     float4 texColor = tex2D(_MainTexture,IN.texCoord);
 
                     float3 normalDirection = normalize(IN.normal);
                     float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
 
                     float3 diffuse = _LightColor0.rgb * max(0.0,dot(normalDirection,lightDirection));
 
                     return _Color * texColor * float4(diffuse,1);
                 }
             ENDCG
         }
     }
 }
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 Namey5 · Sep 09, 2016 at 06:45 AM 0
Share

What exactly is the problem? It does this automatically, most likely due to an updated library. It shouldn't change anything in the project except the name.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Wolfos · Nov 29, 2017 at 03:34 PM

I know it's a little late to respond, but this was pretty high up on Google so I'll answer; The _Object2World matrix was renamed to unity_ObjectToWorld in (I believe) Unity 5.4. When you use _Object2World it will automatically be replaced with the new name. The behaviour will remain the same.

Comment
Add comment · 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

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

100 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

Related Questions

How can I rotate Cubemap? 0 Answers

Issues when using Unity's new PBR Dissolve Shader 0 Answers

Is there any way to make a custom written shader with hdrp? 0 Answers

How do I get the exact values of the near and far planes in clip space, both in a shader and in C#? 0 Answers

Unity 2018 without shader 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