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 0tacun · Apr 06, 2014 at 04:16 PM · shaderimagecgblur

Stippled Shader?

I am trying to generate a stippled texture with a shader. My goal is that every second pixel is transparent. Unfortunatly my result looks like this:

alt text

My shader is applied on a fullscreen quad. I was wondering how I could achive stippling and furthermore define the boarder around a stippled pixel. Anyone has a hint?

 Shader "IndieEffects/Alpha-Blended Motion Blur Stippling" {
     Properties {
         _MainTex ("Texture(RGB)", 2D) = "black" {}
         _FrameAccumulation ("Accumulation", float) = 0.65
     }
     
     SubShader {
     
         ZTest Always Cull Off ZWrite Off
         Pass {
             Blend SrcAlpha OneMinusSrcAlpha
             //ColorMask RGB
             
                         CGPROGRAM
             #include "UnityCG.cginc"
             #pragma vertex vert
             #pragma fragment frag
             //#pragma fragmentoption ARB_precision_hint_fastest
             #pragma target 3.0
             
             struct v2f {
                 float4 pos : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             v2f vert (appdata_img v)
             {
                 v2f o;
                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.uv = v.texcoord.xy;
                 
                 return o;
             }
             
             sampler2D _MainTex;
             float _FrameAccumulation;
             
             float4 col;
             
             half4 frag (v2f i) : COLOR
             {
                 col = tex2D(_MainTex, i.uv);
 
             
                 if((int(i.uv.x + i.uv.y)/i.uv.x == i.uv.y))
                     discard;
                 else
                     col.a = _FrameAccumulation;
                     
                 col.r = 1.0;
                 col.g = 1.0;
                 col.b = 1.0;
                     
 
                 return col;
             }
             
             
             ENDCG
             /*
             SetTexture [_MainTex] {
                 ConstantColor(1,1,1,[_FrameAccumulation])
                 Combine texture, constant
             }*/
         }
         Pass {
             Blend One Zero
             ColorMask A
             SetTexture [_MainTex] {
                 Combine texture
             }
         }
     }
     Fallback off
 }


stippled.jpg (178.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by RC-1290 · Apr 06, 2014 at 04:50 PM

The texture coordinates don't tell you which pixel you're editing. You can find out by using TexelSize.

A float4 with _TexelSize appended to the texture name, will automagically be filled with information about the dimensions of each texel in uv space. So for _MainTex that would be:

 sampler2D _MainTex;
 float4 _MainTex_TexelSize;

where _MainTex_TexelSize.xy would be texel size (1 divided by texture size), and .zw would be texture size (resolution).

Keep in mind that in some cases, the texel size will have a negative y.

That should probably give you enough information to make your shader work.

Comment
Add comment · Show 5 · 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 0tacun · Apr 06, 2014 at 05:50 PM 0
Share

Thank you for your help! It works now to capture the whole screen, but I have a feeling that my if-statement is wrong, because there aren't pixel left which are not transparent. I also tried this one: "if((int($$anonymous$$ainTex_TexelSize.x + $$anonymous$$ainTex_TexelSize.y)%2 == 0)) discard;" but no result. It looks like every pixel is discarded.

avatar image RC-1290 · Apr 06, 2014 at 07:56 PM 1
Share

The _TexelSize values are the same for every fragment. You can find out which pixel you're currently processing by dividing the current uv coordinate, by the texelSize.

For a texture of 512 by 512, the u coordinate of 0.5 (halfway) would give you 256.

avatar image 0tacun · Apr 06, 2014 at 08:15 PM 1
Share

Ah now I understand. Thank you for clearing me up!

avatar image MattG54321 · Dec 08, 2017 at 03:36 AM 0
Share

Hey, I know this post is quite old, but I just wanted to thank you. I've been banging my head against the wall for the past few hours trying to get a simple sprite outline shader to work, and you've provided me with that last bit of knowledge that I needed.

Thank you so much! $$anonymous$$eep making the Unity community awesome!

avatar image RC-1290 MattG54321 · Dec 11, 2017 at 05:02 PM 0
Share

@$$anonymous$$attG54321 Glad to hear it :)

avatar image
1

Answer by Cherno · Dec 08, 2017 at 09:50 AM

I found this cool stipple shader some time ago:

https://ocias.com/blog/unity-stipple-transparency-shader/

Comment
Add comment · Show 1 · 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 Bunny83 · Dec 08, 2017 at 06:43 PM 0
Share

I converted your comment into an answer since this shader seems to directly answer the question ^^.

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

25 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

Related Questions

How to force the compilation of a shader in Unity? 5 Answers

How to determine shader center? 0 Answers

Shader to a Camera 1 Answer

How to blur the corners of the screen? 3 Answers

Why does this IOS / OGLES shader not match PC version? 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