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 Nishtana · Oct 16, 2019 at 12:21 PM · textureshadersmaterialsnormalsworldspace

World Space material Stretching when object is rotated.

I've pieced together a world space shader including a few extra textures like Normal/Bump, Specular, Emissions and a rotation variable for the top facing sides of our cubes. I'm running into an issue where when I rotate the mesh 90 and 270 degrees the faces on the x and z axis stretch the texture as if it is holding normals for those faces and not updating to the new axis for the world space. when I rotate to 180 it corrects the texture again, however I need it to work correctly on 90 and 270 as well. Any help would be appreciative, I'm sure I'm missing something I just can't see it as I've been staring at it too long.

https://imgur.com/pBBXhfy - Before Rotation

https://imgur.com/WkK0seu - After Rotation

 CGPROGRAM
 #pragma surface surf StandardSpecular vertex:vert
 
 sampler2D _MainTex;
 sampler2D _Bump;
 sampler2D _SpecMap;
 fixed4 _Emission;
 fixed4 _Color;
 float _Scale;
 float _Rotation;
 
 struct Input
 {
     float3 sworldNormal;
     float3 worldPos;
     float2 uv_Bump;
 
 };
 
 void vert (inout appdata_full v, out Input o)
         {
                UNITY_INITIALIZE_OUTPUT(Input,o);
        
             o.sworldNormal = abs(v.normal);
         }
 
 void surf (Input IN, inout SurfaceOutputStandardSpecular o)
 {
 
     float2 UV;
     fixed4 c;
     float r = _Rotation;
     float3 uv = IN.sworldNormal.xyz;
     half4 x;
     half4 y;
     half4 z;
     half4 n = float4(1,1,1,1);
     
 
     if(r<0.5)
     {
             if(abs(IN.sworldNormal.x)>0.5)
         {
                 UV = IN.worldPos.zy; // side
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 x = tex2D (_MainTex, uv.zy);
                 x = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,x,IN.sworldNormal.r);
         }
            else if(abs(IN.sworldNormal.z)>0.5)
         {
                 UV = IN.worldPos.xy; // front
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 z = tex2D (_MainTex, uv.xy);
                 z = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,z,IN.sworldNormal.b);
         }
             else
         {
                 UV = IN.worldPos.zx; // top
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 y = tex2D (_MainTex, uv.zx);
                 y = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,y,IN.sworldNormal.g);
         }
     }
     else
     {
                 if(abs(IN.sworldNormal.x)>0.5)
         {
                 UV = IN.worldPos.zy; // side
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 x = tex2D (_MainTex, uv.zy);
                 x = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,x,IN.sworldNormal.r);
         }
            else if(abs(IN.sworldNormal.z)>0.5)
         {
                 UV = IN.worldPos.xy; // front
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 z = tex2D (_MainTex, uv.xy);
                 z = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,z,IN.sworldNormal.b);
         }
             else
         {
                 UV = IN.worldPos.xz; // top
                 c = tex2D(_MainTex, UV* _Scale);
                 o.Specular = tex2D(_SpecMap, UV* _Scale).a;
                 half4 y = tex2D (_MainTex, uv.xz);
                 y = tex2D(_Bump, UV* _Scale);
                 n = lerp(n,y,IN.sworldNormal.g);
         }
     }
 
 
 
 
     o.Normal = UnpackNormal(n);
     o.Albedo = c.rgb * _Color;
     o.Emission = _Emission;
 
 }
 ENDCG
 }
 
 Fallback "VertexLit"
 }


[1]: https://imgur.com/pBBXhfy

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

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

157 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

Related Questions

Shader: get back scene pixel color? 1 Answer

The Best Way to Highlight An Enemy 0 Answers

A Shader to Duplicate and Flip a texture 0 Answers

is it possible adding text in realtime using shadergraph? 0 Answers

How do I properly apply a transparent texture to a mesh? 2 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