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
1
Question by Thaggis · Mar 24, 2014 at 09:38 PM · shadercgpointshlslcircles

How do you render points as circles rather than squares?

Currently I have a script that I attach to a parent mesh object that essentially runs the mesh.topology command and sets the mesh to points at run time. The points show up as squares (planes, not cubes) that are "view-plane" aligned horizontally not vertically. I looked at the HLSL Microsoft docs,and it makes sense as to why they're showing up as squares. How would I render them as circles (or spheres), rather than squares?

I also have a basic shader attached to the meshes that colors the points by vertex (the imported models have per vertex colors). I'm feeling like this is a shader question based on the research I've done so far, so I can add a solution to my existing one if need be.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Thaggis · Dec 29, 2014 at 03:33 PM

The only thing reasonable answer I figured out was to use a geometry shader to render a billboard quad at each vertex with a texture. The texture was a square image, with a circle in the middle, and alpha values around it. It works but the performance is poor, and there is weird behavior where I can actually see the outline of the quad off-axis where it is supposed to be transparent. I will try to post images to demonstrate the behavior.

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

Answer by pancymon2 · Dec 19, 2017 at 10:51 PM

I've also tried to render points as circles. I used the VPOS semantics, which is similar to gl_Fragcoord in my understanding: https://docs.unity3d.com/560/Documentation/Manual/SL-ShaderSemantics.html

Here is a snippet of the shader I'm using:

         // It's hard to have both the SV_POSITION and VPOS in the same vertex-to-fragment structure.
         // So the vertex shader outputS the SV_POSITION as a separate “out” variable.
         v2f vert(appdata v, out float4 vertex : SV_POSITION)
         {
             v2f o;
             vertex = UnityObjectToClipPos(v.vertex);
             o.center = ComputeScreenPos(vertex);
             o.size = _PointSize;

             return o;
         }

         // vpos contains the integer coordinates of the current pixel, which is used
         // to caculate the distance between current pixel and center of the point.
         fixed4 frag(v2f i, UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
         {
             float4 center = i.center;

             // Converts center.xy into [0,1] range then mutiplies them with screen size.
             center.xy /= center.w;
             center.x *= _ScreenWidth;
             center.y *= _ScreenHeight;

             float dis = distance(vpos.xy, center.xy);
             if (dis > _PointSize / 2)
             {
                 discard;
             }

             return _Color;
         }
Comment
Add comment · Show 2 · 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 pesch2 · Feb 26, 2018 at 04:02 PM 0
Share

Hi pancymon2 ,

could you please post the complete shader code? I need some similar functionality and try to learn how to do it. But I am not able to compile your shader snippet..

Would be very helpful. Thanks!

avatar image pancymon2 pesch2 · Jun 14, 2018 at 10:35 AM 0
Share

Hi pesch2, I may not be able to share the complete shader with you at the moment due to confidentiality. We are planning on release this as open source, once it's released I'll point you to the code!

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

22 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

Related Questions

Access to svPosition in fragment shader 1 Answer

Can a CG shader fail to work on hardware? 1 Answer

cg to unitycg : Glowing shader 1 Answer

how to approach instanceID in shader? 0 Answers

How do you change Point Size in Direct3d 11 shader? 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