Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Exalia · Dec 04, 2013 at 11:31 PM · shadershadersviewmatrixinverse

accessing inverse view matrix

Hi, I'm writing a shader and would like to write my own billboarding, for this I need the inverse view matrix, I'm not sure if unity will let me have this information however.

Is there anyone with shader experience who can give me a hand? Thanks

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
1
Best Answer

Answer by Womrwood · Dec 05, 2013 at 12:37 AM

I did a research and I guess that Unity3d does not give you the inverse view matrix, but it gives you the UNITY_MATRIX_V that you can access in your shader, just transpose the upper 3x3 matrix and negate the translation vector to get the inverse.

Comment
Add comment · Show 4 · 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 Womrwood · Dec 05, 2013 at 12:50 AM 0
Share

If you are trying to transform vertices in modelview/world matrix into local space of the object I guess you can use _World2Object.

avatar image Exalia · Dec 05, 2013 at 02:34 PM 0
Share

I'm not sure if I should be multiplying/transposing matrices inside my vertex shader, is that a good idea?

$$anonymous$$y current shader :

 Shader "Custom/ParticleShader" 
 {
     Properties 
     {
         _Speed ("Particle Speed", Range (0,10)) = 1
         _Height ("Particle Height", Range (0,100)) = 1
     }
     
     SubShader 
     {
         Pass
         {    
             CGPROGRA$$anonymous$$
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
             
             sampler2D _$$anonymous$$ainTex;
             float _Speed;
             float _Height;
             
             struct v2f {
                 float4 pos : SV_POSITION;
                 float3 color : COLOR0;
             };
 
             v2f vert (appdata_base v)
             {
                 float t = frac(v.vertex.z + _Speed * _Time); 
                   float s = pow(t, 1);
                   float3 eyeVector = ObjSpaceViewDir( v.vertex );
                 float3 upVector = float3(0,1,0);
                 float3 sideVector = normalize(cross(eyeVector,upVector));
               
                 v2f o;
                 o.pos.x = 20 * s * sin(62.0 * v.vertex.z);
                    o.pos.z = 20 * s * cos(163.0 * v.vertex.z);
                    o.pos.y = t * _Height;
                 o.pos.xyz += 7.8 * (v.vertex.x * sideVector + v.vertex.y * upVector).xyz;
                    o.pos = mul (UNITY_$$anonymous$$ATRIX_VP, o.pos);
                 o.color = 1.0 - t;
                 return o;
             }
 
             half4 frag (v2f i) : COLOR
             {
                 return half4 (i.color, 1);
             }
             ENDCG
         }
     }
 }
avatar image Womrwood · Dec 05, 2013 at 03:33 PM 1
Share

No problem in doing it, cg programs have access to a function called transpose that you can use.

avatar image Exalia · Dec 05, 2013 at 03:36 PM 0
Share

Awesome I'll give it a go :)

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

17 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

Related Questions

UnityObjectToClipPos is inverted? 0 Answers

shader inverse(float4x4) function 2 Answers

Previous Model*View*Projection Matrix 0 Answers

Getting the forward position of an object in a vertex shader 0 Answers

Missing shader variants/features in asset bundles 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