Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

> Need help with shader, Unity / CGPROGRAM

views
     
TSnarf03
post Jan 29 2019, 03:01 PM, updated 5 months ago

Look at all my stars!!
*******
Senior Member
3,891 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


I am not sure if the terms i use will be correct, i am very inexperienced in shader, i found some code online and changed them so i able to use them. The code below should draw a red border over an image and the border thickness should be 3% off the image width and height. so with bigger image, the border will increase in size and also decrease if the image become smaller. I want to change that behavior of the border, instead of 3% of image width and height, i want to change to a fixed 3 pixels. Any idea which direction or how should i do it ?

CODE
Shader "Custom/shaderThumbnail"
{
Properties
{
 _MainTex("Texture", 2D) = "Black" {}
 _Red("HighlightRed", Float) = 0.0
}
SubShader
{
 Tags { "RenderType"="Opaque" }
 LOD 100
 Pass
 {
  CGPROGRAM
  #pragma vertex vert
  #pragma fragment frag
  // make fog work
  #pragma multi_compile_fog
 
  #include "UnityCG.cginc"

  struct appdata
  {
   float4 vertex : POSITION;
   float2 uv : TEXCOORD0;
  };

  struct v2f
  {
   float2 uv : TEXCOORD0;
   UNITY_FOG_COORDS(1)
   float4 vertex : SV_POSITION;
  };
  float4 _MainTex_ST;
  sampler2D _MainTex;
  float _Red = 0;
  v2f vert (appdata v)
  {
   v2f o;
   o.vertex = UnityObjectToClipPos(v.vertex);
   o.uv = TRANSFORM_TEX(v.uv, _MainTex);
   UNITY_TRANSFER_FOG(o,o.vertex);
   return o;
  }
  fixed4 frag (v2f i) : SV_Target
  {
   fixed4 col = tex2D(_MainTex, i.uv);
   fixed4 col2;
   col2.r = col.b;
   col2.g = col.g;
   col2.b = col.r;
   //here
   if (i.uv.x < 0.03f || i.uv.y < 0.03f || i.uv.x > 0.97f || i.uv.y > 0.97f) {
    col2.r = max(col2.r, _Red);
    col2.g = col2.g - _Red;
    col2.b = col2.b - _Red;
   }
   return col2;
  }
  ENDCG
 }
}
}


user posted image
turnmoil
post Mar 5 2019, 10:25 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003
From: The Miau Miaw Niau Miow Land


maybe this can help u

http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html
LucasAllcot P
post Apr 2 2019, 10:54 PM

New Member
*
Probation
3 posts

Joined: Apr 2019
I don't know if this is relevant, but I've had similar problem when working on this website. I could ask my system administrator how he fixed it, if you're still unable to find the solution.
TSnarf03
post Apr 3 2019, 03:48 PM

Look at all my stars!!
*******
Senior Member
3,891 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


nvm, ive solved it using other method
turnmoil
post Apr 4 2019, 11:11 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003
From: The Miau Miaw Niau Miow Land


QUOTE(narf03 @ Apr 3 2019, 03:48 PM)
nvm, ive solved it using other method
*
can share with us how you solved it?
might be useful to others in the future
TSnarf03
post Apr 4 2019, 12:46 PM

Look at all my stars!!
*******
Senior Member
3,891 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


QUOTE(turnmoil @ Apr 4 2019, 11:11 AM)
can share with us how you solved it?
might be useful to others in the future
*
instead of the shader decide on the size of the border, the app tell the shader whats the size of the border it supposed to draw. so the shader dont make the decision.
turnmoil
post Apr 8 2019, 11:09 AM

Casual
***
Junior Member
401 posts

Joined: Jan 2003
From: The Miau Miaw Niau Miow Land


thanks for sharing the info narf03

 

Switch to:
| Lo-Fi Version
0.0743sec    1.86    5 queries    GZIP Disabled
Time is now: 20th August 2019 - 10:47 AM