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 /
  • Help Room /
avatar image
0
Question by Rockrono · Feb 28, 2017 at 05:06 PM · shadertransparencygeometry shadertransparent texture

Problem rendering textured quads with transparent areas

I'm working on a project in which i have to load and visualize point clouds (so around millions of points at a time). The best solution i found was to generate, in runtime, a series of meshes using the cloud's points as vertices, with the mesh topology property set to "points". This, though, got the points/vertices to be rendered ALWAYS as a single pixel on the screen, so kinda unusable. Then, as i started studying shader writing, i got that a good solution for my problem would've been to use a geometry shader that could generate a textured quad for each of the points, with a billboarding effect to make the quads always face the camera, and including a shader property that could allow me to increase or decrease the size of these quads at will. Being a noob at writing shaders, i looked around on the web for some example to use as a base, then i modified it to get a proper billboard effect and to use color data from the mesh vertices. I ended up with this:

 Shader "Custom/GS Billboard" 
 {
     Properties 
     {
         _SpriteTex ("Base (RGB)", 2D) = "white" {}
         _Size ("Size", Range(0, 3)) = 0.5
     }
 
     SubShader 
     {
         Pass
         {
             Tags { "Queue" = "Transparent" "RenderType" = "Transparent"}
             LOD 200
 
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
                 #pragma target 4.0
                 #pragma vertex VS_Main
                 #pragma fragment FS_Main
                 #pragma geometry GS_Main
                 #include "UnityCG.cginc" 
 
                 // **************************************************************
                 // Data structures                                                *
                 // **************************************************************
                 struct GS_INPUT
                 {
                     float4    pos        : POSITION;
                     float3    normal    : NORMAL;
                     float2  tex0    : TEXCOORD0;
                     
                     fixed4    color    : COLOR;
                 };
 
                 struct FS_INPUT
                 {
                     float4    pos        : POSITION;
                     float2  tex0    : TEXCOORD0;
                     
                     fixed4    color    : COLOR;
                 };
 
 
                 // **************************************************************
                 // Vars                                                            *
                 // **************************************************************
 
                 float _Size;
                 float4x4 _VP;
                 Texture2D _SpriteTex;
                 SamplerState sampler_SpriteTex;
 
                 // **************************************************************
                 // Shader Programs                                                *
                 // **************************************************************
 
                 // Vertex Shader ------------------------------------------------
                 GS_INPUT VS_Main(appdata_full v)
                 {
                     GS_INPUT output = (GS_INPUT)0;
 
                     output.pos =  mul(unity_ObjectToWorld, v.vertex);
                     output.normal = v.normal;
                     output.tex0 = float2(0, 0);
                 
                     output.color = v.color;
 
                     return output;
                 }
 
 
                 // Geometry Shader -----------------------------------------------------
                 [maxvertexcount(4)]
                 void GS_Main(point GS_INPUT p[1], inout TriangleStream<FS_INPUT> triStream)
                 {
                     float3 up = UNITY_MATRIX_V[1].xyz;
                     float3 right = UNITY_MATRIX_V[0].xyz * -1;
                     
                     float halfS = 0.5f * _Size;
                             
                     float4 v[4];
                     v[0] = float4(p[0].pos + halfS * right - halfS * up, 1.0f);
                     v[1] = float4(p[0].pos + halfS * right + halfS * up, 1.0f);
                     v[2] = float4(p[0].pos - halfS * right - halfS * up, 1.0f);
                     v[3] = float4(p[0].pos - halfS * right + halfS * up, 1.0f);
 
                     float4x4 vp = mul(UNITY_MATRIX_MVP, unity_WorldToObject);
                     FS_INPUT pIn;
                     
                     pIn.color = p[0].color;
                     pIn.pos = mul(vp, v[0]);
                     pIn.tex0 = float2(1.0f, 0.0f);
                     triStream.Append(pIn);
 
                     pIn.pos =  mul(vp, v[1]);
                     pIn.tex0 = float2(1.0f, 1.0f);
                     triStream.Append(pIn);
 
                     pIn.pos =  mul(vp, v[2]);
                     pIn.tex0 = float2(0.0f, 0.0f);
                     triStream.Append(pIn);
 
                     pIn.pos =  mul(vp, v[3]);
                     pIn.tex0 = float2(0.0f, 1.0f);
                     triStream.Append(pIn);
                 }
 
                 // Fragment Shader -----------------------------------------------
                 float4 FS_Main(FS_INPUT input) : COLOR
                 {
                     return input.color * _SpriteTex.Sample(sampler_SpriteTex, input.tex0);
                 }
 
             ENDCG
         }
     } 
 }

The quads are rendered and can be resized, but there is something wrong with the blending, since the transparent area of the texture of a quad seems to often "cover" the quad behind it. What am i doing wrong?

Here is a screen of what i get:

alt text

game-screen03.jpg (74.8 kB)
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

119 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

Related Questions

Something wrong with the cut out feature of the standard shader? 0 Answers

Transparent water shader and problems with render queue 0 Answers

how to add transparency to a cross-section-shader? 2 Answers

Transitioning decals with masks on a character 1 Answer

Water shader change 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