Last active
September 12, 2018 04:42
-
-
Save sugi-cho/16cd223604d1a2ac21758e3a240ecbf2 to your computer and use it in GitHub Desktop.
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 "Unlit/checkTexture" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
half4 frag (v2f i) : SV_Target | |
{ | |
// sample the texture | |
half4 col = tex2D(_MainTex, i.uv); | |
col = half4(1.0 < col.r, frac(col.g), col.b < -0.1, 1); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
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
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class TestCode : MonoBehaviour | |
{ | |
public TextureFormat format = TextureFormat.RGBAFloat; | |
public Texture2D tex; | |
public Material mat; | |
// Use this for initialization | |
void Start() | |
{ | |
tex = new Texture2D(512, 512, format, false); | |
for (var y = 0; y < tex.height; y++) | |
for (var x = 0; x < tex.width; x++) | |
tex.SetPixel(x, y, new Color((float)x / tex.width, (float)y / tex.height, (float)(x + y) / tex.width, 1) * 2.0f - Color.gray); | |
tex.Apply(); | |
mat.mainTexture = tex; | |
#if UNITY_EDITOR | |
AssetDatabase.CreateAsset(tex, "Assets/tex.asset"); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment