Skip to content

Instantly share code, notes, and snippets.

@sugi-cho
Last active August 25, 2019 19:05
Show Gist options
  • Save sugi-cho/99f6d043ed7b568e702c to your computer and use it in GitHub Desktop.
Save sugi-cho/99f6d043ed7b568e702c to your computer and use it in GitHub Desktop.
ato de matomeru!!!
Shader "Custom/CheckUV" {
CGINCLUDE
sampler2D _MainTex;
struct Input {
float4 vColor;
float2 tex;
};
void vert (inout appdata_full v, out Input o){
UNITY_INITIALIZE_OUTPUT(Input,o);
o.vColor = v.color;
o.tex = v.texcoord.xy;
}
void surf (Input IN, inout SurfaceOutput o) {
half3 c = half3(
IN.tex,
ceil((fmod(IN.tex.x*10,1)-0.5)*(fmod(IN.tex.y*10,1)-0.5))/2
);
o.Emission = c;
}
ENDCG
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert noforwardadd
ENDCG
}
FallBack "Diffuse"
}
using UnityEngine;
using System.Collections;
public class Tex2VertColor : MonoBehaviour
{
public Texture2D tex;
// Use this for initialization
void Awake ()
{
Mesh mesh = GetComponent<MeshFilter> ().mesh;
if (mesh == null || tex == null) {
Destroy (this);
return;
}
Color[] colors = new Color[mesh.vertexCount];
for (int i = 0; i < colors.Length; i++) {
int
x = Mathf.FloorToInt ((mesh.uv [i].x % 1f) * tex.width),
y = Mathf.FloorToInt ((mesh.uv [i].y % 1f) * tex.height);
colors [i] = tex.GetPixel (x, y);
}
mesh.colors = colors;
Destroy (this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment