Last active
September 10, 2018 03:01
-
-
Save TheStoneBook/89578338e1d3e00fea2086e9819045e8 to your computer and use it in GitHub Desktop.
【Unity】ポリゴンの拡大縮小【Shader】
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Geometry/PolygonScaling" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_MainColor("Color",Color)=(1,1,1,1) | |
_ScaleFactor("Scale Factor", Range(0.0, 1.0)) = 1.0 | |
//_ScaleFactor("Scale Factor", Range(0.0, 2.0)) = 1.0 | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma geometry geom | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct g2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
fixed4 _MainColor; | |
fixed _ScaleFactor; | |
//float4 _MainTex_ST; | |
appdata vert (appdata v) | |
{ | |
return v; | |
} | |
[maxvertexcount(3)] | |
void geom(triangle appdata input[3], inout TriangleStream<g2f> outStream) | |
{ | |
//ポリゴンの中心を計算。 | |
float3 center = (input[0].vertex + input[1].vertex + input[2].vertex).xyz / 3; | |
[unroll] | |
for(int i=0;i<3;i++) | |
{ | |
appdata v=input[i]; | |
g2f o; | |
//v.vertex.xyz = (v.vertex.xyz - center) * (1.0 - _ScaleFactor) + center; | |
v.vertex.xyz = (v.vertex.xyz - center) * _ScaleFactor + center; | |
o.vertex=UnityObjectToClipPos(v.vertex); | |
o.uv=v.uv; | |
outStream.Append(o); | |
} | |
outStream.RestartStrip(); | |
} | |
fixed4 frag (g2f i) : SV_Target | |
{ | |
fixed4 col=tex2D(_MainTex, i.uv)*_MainColor; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment