Skip to content

Instantly share code, notes, and snippets.

@yty
Created May 12, 2017 14:27
Show Gist options
  • Save yty/59142ecb2973969ff2cdccfec0621d5c to your computer and use it in GitHub Desktop.
Save yty/59142ecb2973969ff2cdccfec0621d5c to your computer and use it in GitHub Desktop.
Zoom shader
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/Zoom" {
Properties {
_MainTex("Base (RGB)", 2D) = "white" {}
_LWTex("LieWen (RGB)", 2D) = "white" {}
_ForceVector("ForceVector", Vector) = (0,0,0)
_length("len", float) = 0
}
SubShader {
pass{
CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _LWTex;
float4 _MainTex_ST;
float _length;
float4 _ForceVector;
struct v2f
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
struct Input
{
float2 uv_MainTex;
float2 uv_Bump;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
//输入uv返回映射之后的uv,xLength为边框的大小
float2 mapuv(float2 uv,float xLength)
{
float2 newuv;
float rate = (1 - 2 * xLength ) / 1;
if(uv.x > xLength && uv.x < (1-xLength) && uv.y > xLength && uv.y < (1-xLength))
{
newuv.x = (uv.x-xLength)/rate;
newuv.y = (uv.y-xLength)/rate;
}
else
{
newuv.x=uv.x;
newuv.y=uv.y;
}
return newuv;
}
float4 frag(v2f i):COLOR
{
float4 outp;
float2 newuv;
if (distance(_ForceVector.xyz, i.pos.xyz) < 0.5)
{
newuv = mapuv(i.uv, _length);
}
else
{
newuv = mapuv(i.uv, 0.5);
}
outp = tex2D(_LWTex, newuv);
return outp;
}
ENDCG
}
}
}
我想要在输入的点周围0.5的范围内 显示 _LWTex的图,
这么写没有效果,求指导
两个vec不在一个几何空间里
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment