Skip to content

Instantly share code, notes, and snippets.

@emilianavt
Created December 10, 2018 23:53
Show Gist options
  • Save emilianavt/289a3d160a74fae1b25e10b3285bc5fb to your computer and use it in GitHub Desktop.
Save emilianavt/289a3d160a74fae1b25e10b3285bc5fb to your computer and use it in GitHub Desktop.
Shader "PositionMapper" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_FactorX ("Object width scale factor (X)", Float) = 1.0
_FactorY ("Object height scale factor (Y)", Float) = 1.0
_FactorZ ("Object depth scale factor (Z)", Float) = 1.0
}
SubShader {
ColorMask RGBA
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0; // texture coordinate
float4 vertex : SV_POSITION; // clip space position
float4 pos : TEXCOORD1;
};
sampler2D _MainTex;
float _FactorX;
float _FactorY;
float _FactorZ;
v2f vert (appdata v) {
v2f o;
o.pos = v.vertex * float4(_FactorX, _FactorY, _FactorZ, 1.0);
v.vertex = mul(unity_WorldToObject, float4(v.uv, 0.0, 1.0));
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float4 frag (v2f i) : SV_Target {
float4 col = i.pos;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment