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 Shinyclef · Mar 17, 2015 at 08:17 AM · shadergeometry shader

Why are my geometry shader output positions not rotated by object rotation?

Hello,

I've been struggling for the last couple of days with my geometry shader. It's meant to take a vertex position, and from that produce a square facing a particular direction in object space. It works great until I rotate my game objects. The squares always have the same orientation in world space when I'd like them to rotate with my object.

The vertex and geometry programs as well as their inputs are shown below.
Can anyone spot the problem? Thanks.

 /* --------------- */
 /* Data structures */
 /* --------------- */
 struct VSData
 {
     half4 Pos        : POSITION;
     half2 UVStart    : TEXCOORD0; 
     half2 UVLen      : TEXCOORD1;
     half2 TileLen    : TEXCOORD2; 
     float2 SizeDir   : TEXCOORD3; 
 };
 
 struct GSData
 {
     half4 Pos   : POSITION;
     half4 UV    : TEXCOORD0;
     half4 Face  : TEXCOORD1;
 };

 /* ------------- */
 /* Vertex Shader */
 /* ------------- */
 GSData VS_Main(VSData v)
 {
     GSData output = (GSData)0;
 
     output.Pos = v.Pos; // <- No Transform. Transform applied in geometry shader.
     output.UV = half4(v.UVStart.xy, v.UVLen.xy);
     output.Face = half4(v.TileLen.xy, v.SizeDir.xy);
 
     return output;
 }
 
 /* --------------- */
 /* Geometry Shader */
 /* --------------- */
 [maxvertexcount(4)]
 void GS_Main(point GSData p[1], inout TriangleStream<FSData> triStream)
 {
     half4 pos = p[0].Pos; <- this is the position passed in by the vertex shader.
     float halfSize = 2.0;
     half3 right = half3(1,0,0);
     half3 up = half3(0,1,0);
 
     // define the corner positions of this square
     half4 v[4];
     v[0] = half4(pos - (halfSize * right) - (halfSize * up), 1.0f); // 1 left bottom
     v[1] = half4(pos - (halfSize * right) + (halfSize * up), 1.0f); // 2 left top
     v[2] = half4(pos + (halfSize * right) - (halfSize * up), 1.0f); // 3 right bottom
     v[3] = half4(pos + (halfSize * right) + (halfSize * up), 1.0f); // 4 right top
 
     // create the vertices, passing in everything fragment shader needs to calculate fragment UV pos
     FSData o;
     o.Pos = mul(UNITY_MATRIX_MVP, v[0]); // left bottom <- THIS POSITION IS NOT ROTATED WITH OBJECT. WHY?
     o.UV  = p[0].UV;                        
     o.Len = half4(p[0].Face.xy, 0, 0);    
     triStream.Append(o);
 
     o.Pos = mul(UNITY_MATRIX_MVP, v[1]); // left top <- THIS POSITION IS NOT ROTATED WITH OBJECT. WHY?
     o.UV  = p[0].UV;
     o.Len = half4(p[0].Face.xy, 0, 1);
     triStream.Append(o);
 
     o.Pos = mul(UNITY_MATRIX_MVP, v[2]); // right bottom <- THIS POSITION IS NOT ROTATED WITH OBJECT. WHY?
     o.UV  = p[0].UV;                    
     o.Len = half4(p[0].Face.xy, 1, 0);
     triStream.Append(o);
 
     o.Pos = mul(UNITY_MATRIX_MVP, v[3]); // right top <- THIS POSITION IS NOT ROTATED WITH OBJECT. WHY?
     o.UV  = p[0].UV;
     o.Len = half4(p[0].Face.xy, 1, 1);
     triStream.Append(o);
 }


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 Shinyclef · Mar 17, 2015 at 01:14 PM

It turns out the problem is related to batching. It doesn't work when the object being viewed is batched, as batching affects the projection matrix (used in UNITY_MATRIX_MVP). The shader works as expected when the object views is the only object being viewed and there is no batching.

Or perhaps that is incorrect and what is really being affected is the concept of object space. When all objects are batched, they are all put into one 'space'. So translating from object to projection space doesn't make sense with multiple rotations anymore.

Anyway, batching is the issue!

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

20 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

Related Questions

How to rotate a triangle created in a geometry shader around its center 1 Answer

[Shader included] Geometry shader draw order reversed in vertices above camera y-position 1 Answer

Geometry Shader not writing to depth texture 0 Answers

Adjacency information in geometry shaders 3 Answers

(Bilboard Shader) Max Screen Size 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