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 sakuraplus · Nov 08, 2018 at 12:50 PM · shaderscaleuvmapping

Scale and repeat texture without tilling

I need to separate the UV to grids and draw a texture in each grid.
It looks like using tilling and offset to make a texture repeat. But I want to make the texture scale in its grid.
alt text

 Shader "Custom/NewSurfaceShader" {
     Properties {
         _MainTex ("Albedo (RGB)", 2D) = "white" {}                        
         _Scale ("Scale", Range(0,5)) = 1.0      
         _SegmentX("Segment x", Float )=5
         _SegmentY("Segment y", Float )=5
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
 
         #pragma surface surf Standard fullforwardshadows
         #pragma target 3.0
 
         sampler2D _MainTex;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         float _SegmentX;
         float _SegmentY;        
         float _Scale;    
         
         void surf (Input IN, inout SurfaceOutputStandard o) {        
         
                     float2 _Diameter=fixed2(1/ceil(_SegmentX),1/ceil(_SegmentY));
                     float2 center = float2(_Diameter.x*floor(IN.uv_MainTex.x/_Diameter.x), _Diameter.y*floor(IN.uv_MainTex.y/_Diameter.y));
                     center+=_Diameter/2;
 
                     float2 _rd=_Scale*_Diameter/2;
         
                     fixed2 uvMask=fixed2((IN.uv_MainTex.x-center.x),(IN.uv_MainTex.y-center.y));
                                         
                     uvMask=(uvMask+_rd)/(2*_rd);
                     uvMask=saturate(uvMask);                        
                     o.Albedo =  tex2D (_MainTex, uvMask);    
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

when I change the scale, a strange line appears at the edge of grids, which the value of uvmask jumps from 1 to 0. The lines are more clear when the scale is less than 1. It works well when drawing colors in each grid.
alt text The only way I found to remove that line is to mirror the UV in every other grid.

                     fixed2 uvMask=fixed2((IN.uv_MainTex.x-center.x),(IN.uv_MainTex.y-center.y));
                     
                     fixed2 indexXY=fixed2(floor(IN.uv_MainTex.x/_Diameter.x),floor(IN.uv_MainTex.y/_Diameter.y));
                     fixed2 dir=1-step(fmod(indexXY,2),0.1)*2;
                     uvMask*=dir;
                     
                     uvMask=(uvMask+_rd)/(2*_rd);    

Have you guys get some other ideas?
Does a fragment shader really run in each pixel?

s22222.jpg (487.1 kB)
s11111.jpg (39.3 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hectorux · Nov 08, 2018 at 03:08 PM

It may sound clumsy, but do you have your texture in repeat?, maybe, if it is in clamp it may be tearing it

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 sakuraplus · Nov 09, 2018 at 08:04 AM 0
Share

alt text

The strange line exists no matter the texture is repeat or clamp. It seems that the UV of these pixels near the edge lerp from 0 to 1, so I guess the strange line is actually a narrow mirror texture. Is that right? or how can I deal with it :( Really confused.

s22223.jpg (504.4 kB)

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

156 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 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

Seamless Water Material on a Plane using Shader Graph 3 Answers

Shader Outline scale problem since U5 1 Answer

CG shader tile issue 1 Answer

Non scale texture? 1 Answer

How to make a localToWorld matrix for shader parameters? 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