概要
表示したTextureを拡大して表示できるShaderです。
実装
Shader "Custom/Zoom"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Zoom ("Zoom", Range(0.5, 1)) = 0
}
SubShader
{
Tags {
"RenderType"="Transparent"
"Queue"="Transparent"
"LightMode"="ForwardBase"
"RenderPipeline"="UniversalPipeline"
}
LOD 100
Pass
{
Name "ForwardLit"
Tags { "LightMode"="UniversalForward" }
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 positionHCS : SV_POSITION;
};
sampler2D _MainTex;
half _Zoom;
CBUFFER_START(UnityPerMaterial)
float4 _MainTex_ST;
CBUFFER_END
Varyings vert (Attributes v)
{
Varyings o;
o.positionHCS = TransformObjectToHClip(v.positionOS.xyz);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
half4 frag (Varyings i) : SV_Target
{
float u = ceil(i.uv.x) * 0.5;
float v = ceil(i.uv.y) * 0.5;
float uLerp = lerp(u, i.uv.x, _Zoom);
float vLerp = lerp(v, i.uv.y, _Zoom);
half4 col = tex2D(_MainTex, float2(uLerp, vLerp));
return col;
}
ENDHLSL
}
}
}
あとがき
ゲーム内でズームする際は大体カメラ側を動かしそうなのであんまり使い道はないのかも