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 /
avatar image
0
Question by JamesGryphon · Jul 15, 2017 at 06:38 PM · 2dtexturesspriterenderertilingpattern

Tiling/Pattern Filling a Sprite

I've spent hours beating my head against the wall so I thought maybe asking here could help.

I'm wondering if there's a quick way to apply a pattern/texture to a sprite. I wanted to texture a 2D white sprite circle (not a sphere) with a repeating 2x2 pattern, resulting in something like this picture: alt text

Everything I've done so far seems to suggest that this isn't readily possible. I hope that's not the case, because it'll make everything messier. Thanks for any help you can provide.

e.png (569 B)
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
Best Answer

Answer by Cherno · Jul 15, 2017 at 08:29 PM

Here is a "stipple/screen door transparency" shader that does what you need.

Alex Ocias Blog

Download link

 Shader "Ocias/Diffuse (Stipple Transparency)" {
 Properties {
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _Transparency ("Transparency", Range(0,1)) = 1.0
 }
 SubShader {
     Tags { "RenderType"="Opaque" }
     LOD 150
 CGPROGRAM
 #pragma surface surf Lambert noforwardadd
 sampler2D _MainTex;
 struct Input {
     float2 uv_MainTex;
     float4 screenPos;
 };
 half _Transparency;
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
     o.Albedo = c.rgb;
     o.Alpha = c.a;
     // Screen-door transparency: Discard pixel if below threshold.
     float4x4 thresholdMatrix =
     {  1.0 / 17.0,  9.0 / 17.0,  3.0 / 17.0, 11.0 / 17.0,
       13.0 / 17.0,  5.0 / 17.0, 15.0 / 17.0,  7.0 / 17.0,
        4.0 / 17.0, 12.0 / 17.0,  2.0 / 17.0, 10.0 / 17.0,
       16.0 / 17.0,  8.0 / 17.0, 14.0 / 17.0,  6.0 / 17.0
     };
     float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
     float2 pos = IN.screenPos.xy / IN.screenPos.w;
     pos *= _ScreenParams.xy; // pixel position
     clip(_Transparency - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
 }
 ENDCG
 }
 Fallback "Mobile/VertexLit"
 }


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 toddisarockstar · Jul 15, 2017 at 11:39 PM

run this:

     int i;
     int i2;
     bool b;
     public int size = 64;
     public int center;
 
     public Texture2D image;
 
     void Start(){
         center=(int)(size*.5f);
     image = new Texture2D (size, size);
     image.filterMode = FilterMode.Point;
      i = image.width;
         while(i>0){i--;b=!b;
             i2=image.height;
             while(i2>0){i2--;b=!b;
                 if(dist(i,i2)<center){
                 if(b){image.SetPixel(i,i2,Color.black);}
                  else{image.SetPixel(i,i2,Color.white);}
                 }
                 else{image.SetPixel(i,i2,Color.clear);}}}
         image.Apply ();
     }
     public float dist (int x, int y){
         int f1 = (center - x) * (center - x);
         int f2 = (center - y) * (center - y);
         
         return Mathf.Sqrt(f1+f2);}
 
     void OnGUI(){
         GUI.DrawTexture(new Rect(10,10,400,400),image);
     }
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

124 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

Related Questions

What are the best settings for a tileable animated texture using a Texture Sheet Animation in Shuriken? 0 Answers

What is the best way of creating a modular texture? 0 Answers

Texture Tiling broken in Unity 2019.2 LWRP 1 Answer

How to nine slice a 2D SpriteRenderer? 0 Answers

Floor tiles - one big texture or many different prefabs? 4 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