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 abbsimoga · Sep 25, 2021 at 10:49 AM · rotationbillboardbillboards

Billboard shader does not support rotation of object

Why does this billboard shader not face the camera if the object is to be rotated. With zero world rotation this shader works as expected.

 #include "/Assets/Graphics/CGincFiles/BillboardSetup.cginc"
 
 float _TilePixelSize;
 float _ExtrudeDistance;
 float3 _UniformDisplacementRandom;
 
 struct g2f
 {
     float4 pos : SV_POSITION;
     float light : TEXCOORD0;
     float2 uv : TEXCOORD2;
 };
 
 g2f VertexOutput(float3 pos, float directionalLightValue)
 {
     g2f o;
     o.pos = UnityObjectToClipPos(pos);
     o.light = directionalLightValue;
     return o;
 }
 
 fixed rand(float3 co)
 {
     return sin(dot(co.xyz, float3(12.9898, 78.233, 53.539)));
 }
 
 [maxvertexcount(4)]
 void geo(triangle vertexOutput IN[3], inout TriangleStream<g2f> outStream)
 {
     float3 flatNormal = normalize(cross(IN[1].vertex - IN[0].vertex, IN[2].vertex - IN[0].vertex));
     float3 center = (IN[0].vertex + IN[1].vertex + IN[1].vertex) / 3;
 
     fixed lightValue = LightCalculation(center, flatNormal);
     
     fixed3 uniform_displacement = float3(rand(center), rand(center.yzx), rand(center.xzy)) * _UniformDisplacementRandom;
     center += uniform_displacement + flatNormal * _ExtrudeDistance;
 
     fixed pixelSize = _TilePixelSize / (5.4 * 2);
     float4 vectors[4];
     Get4Vectors(center, pixelSize, vectors);
  
     g2f idealVertexOutput = VertexOutput(center, lightValue);
 
     // Only change SV_POSITION and append to outStream
     idealVertexOutput.pos = UnityObjectToClipPos(vectors[0]);
     idealVertexOutput.uv = float2(1, 0);
     outStream.Append(idealVertexOutput);
 
     idealVertexOutput.pos = UnityObjectToClipPos(vectors[1]);
     idealVertexOutput.uv = float2(1, 1);
     outStream.Append(idealVertexOutput);
 
     idealVertexOutput.pos = UnityObjectToClipPos(vectors[2]);
     idealVertexOutput.uv = float2(0, 0);
     outStream.Append(idealVertexOutput);
 
     idealVertexOutput.pos = UnityObjectToClipPos(vectors[3]);
     idealVertexOutput.uv = float2(0, 1);
     outStream.Append(idealVertexOutput);
 }
 

Get4Vectors function are in BillboardSetup.cginc:

 fixed3 GetLookVector()
 {
     float3 look = mul(mul((float3x3)unity_CameraToWorld, float3(0,0,-1)), unity_ObjectToWorld);
     return normalize(look);
 }
 
 fixed3 GetRightVector(fixed3 look)
 {
     fixed3 world_up = float3(0, 1, 0);
     fixed3 right = normalize(cross(world_up, look));
     return right;
 }
 
 void Get4Vectors(float3 center, fixed pixelSize, out float4 vectors[4])
 {
     fixed3 look = GetLookVector();
     fixed3 right = GetRightVector(look) * pixelSize;
     fixed3 up = fixed3(0, pixelSize, 0);
     
     vectors[0] = float4(center + right - up, 1.0f);
     vectors[1] = float4(center + right + up, 1.0f);
     vectors[2] = float4(center - right - up, 1.0f);
     vectors[3] = float4(center - right + up, 1.0f);
 }

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

170 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with unity tree billboarding 0 Answers

Trying to make the player/npcs be a billboard of a sprite but can't find a way for it to cast and receive shadows 0 Answers

Stop Billboard Texture Rotation in Triplanar Shader 0 Answers

Problem with a Billboard script 0 Answers

Flip over an object (smooth transition) 3 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