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 /
This question was closed Sep 13, 2015 at 10:52 AM by ritefall for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ritefall · Sep 13, 2015 at 10:19 AM · shadersmaterialstextures

Set Material Texture Border

So, I was looking through the Unity GUI system and noticed there's a pixel border you can set of the image that isn't scaled with the content inside it. Is there any way to do this with textures on say a scaled cube? I have found outline shaders but they only display the furthest edges, which in my case will be mostly hidden.

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

  • Sort: 
avatar image
0
Best Answer

Answer by ritefall · Sep 13, 2015 at 02:02 PM

Came up with this, it gets the job done on cubes well enough

    using UnityEngine;
     using System.Collections;
     
     public class addTextureBorderByScale : MonoBehaviour {
         public Texture2D t;
         public int x;
         public int y;
         public bool useTransformScale = true;
         public enum scaleTypes {XY,XZ,YZ};
         public scaleTypes scaleAxis = scaleTypes.XZ;
         public int scaleMod = 2;
         // Use this for initialization
         void Start () {
         if(useTransformScale) { 
                 switch(scaleAxis) {
                 default:
                 case scaleTypes.XY:
                     x = (int)transform.localScale.x;
                     y = (int)transform.localScale.y;
                     break;
     
                 case scaleTypes.XZ:
                     x = (int)transform.localScale.x;
                     y = (int)transform.localScale.z;
                     break;
     
                 case scaleTypes.YZ:
                     x = (int)transform.localScale.y;
                     y = (int)transform.localScale.z;
                     break;
     
                 }
             }
     
             x = x*scaleMod;
             y = y*scaleMod;
     
             t = new Texture2D(x,y);
             t.filterMode = FilterMode.Point;
     
             for(int i = 0; i < y; i++) {
                 t.SetPixel(0,i,Color.clear);
                 t.SetPixel(x-1,i,Color.clear);
             }
             
     
             for(int i = 0; i < x; i++) {
                 t.SetPixel(i,0,Color.clear);
                 t.SetPixel(i,y-1,Color.clear);
             }
     
             t.Apply();
             //TextureScale.Point(t,1000,1000);
             GetComponent<Renderer>().material.EnableKeyword("_EMISSION");
             GetComponent<Renderer>().material.SetTexture("_EmissionMap",t);
         }
         
         // Update is called once per frame
         void Update () {
         
         }
     }
     
     
     

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

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

alpha mask on a 0 Answers

Changing HDRP Material's Texture At Runtime Not Working? 2 Answers

How to apply a color to the second texture in this shader? 1 Answer

Multiple Shaders vs. Single Texture - Please help me overthink this. 2 Answers

How can I have a transparent ring around a transparent planet? 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