Хочу получить шейдер который имел бы два варианта techniques. И чтобы мог переключаться между ними в интерфейсе Unity.
Возможно ли вообще такое в Unity.
Привожу мои эксперементы в юнити конечно threshold.shader techniques неработают - незнаю как включить или где почитать посмотреть применительно к юнити.
Синтаксис:
Используется glsl
Shader "threshold" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_ReplaceColor ("Color Replace", Color) = (1,1,1,1)
_FillColor ("Color Fill", Color) = (1,1,1,1)
_Threshold ("Threshold", Range (0, 1)) = 0.01
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _ReplaceColor;
float4 _FillColor;
float _Threshold;
struct v2f {
float4 pos : POSITION;
float2 uv_MainTex : TEXCOORD0;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
float4 _MainTex_ST;
// VERTEXSHADERS
v2f vert( appdata v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv_MainTex = TRANSFORM_TEX (v.texcoord, _MainTex);
return o;
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// PIXELSHADERS:tresholded
half4 frag(v2f i) : COLOR {
half4 color = tex2D(_MainTex, i.uv_MainTex);
if (color.r > _Threshold && color.g > _Threshold && color.b > _Threshold)
{
color = _ReplaceColor;
}
return color;
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// PIXELSHADERS:tresholded2
half4 frag(v2f i) : COLOR {
half4 color = tex2D(_MainTex, i.uv_MainTex);
if (color.r > _Threshold && color.g > _Threshold && color.b > _Threshold)
{
color = _ReplaceColor;
} else {
color = _FillColor;
}
return color;
}
ENDCG
}
}
}
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_ReplaceColor ("Color Replace", Color) = (1,1,1,1)
_FillColor ("Color Fill", Color) = (1,1,1,1)
_Threshold ("Threshold", Range (0, 1)) = 0.01
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _ReplaceColor;
float4 _FillColor;
float _Threshold;
struct v2f {
float4 pos : POSITION;
float2 uv_MainTex : TEXCOORD0;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
float4 _MainTex_ST;
// VERTEXSHADERS
v2f vert( appdata v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv_MainTex = TRANSFORM_TEX (v.texcoord, _MainTex);
return o;
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// PIXELSHADERS:tresholded
half4 frag(v2f i) : COLOR {
half4 color = tex2D(_MainTex, i.uv_MainTex);
if (color.r > _Threshold && color.g > _Threshold && color.b > _Threshold)
{
color = _ReplaceColor;
}
return color;
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// PIXELSHADERS:tresholded2
half4 frag(v2f i) : COLOR {
half4 color = tex2D(_MainTex, i.uv_MainTex);
if (color.r > _Threshold && color.g > _Threshold && color.b > _Threshold)
{
color = _ReplaceColor;
} else {
color = _FillColor;
}
return color;
}
ENDCG
}
}
}
А вот threshold.fx работает как надо (исходник). Могу выбрать либо Tresholded либо Tresholded2
Синтаксис:
Используется glsl
// PARAMETERS:
//transforms
float4x4 tW: WORLD;
float4x4 tV: VIEW;
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;
//texture
texture _MainTex <string uiname="Base (RGB)";>;
sampler Samp = sampler_state
{
Texture = (_MainTex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;
float4 _ReplaceColor : COLOR <string uiname="Color Replace";> = { 0.0, 0.0, 0.0, 1.00000 };
float4 _FillColor : COLOR <string uiname="Color Fill";> = { 1, 1, 1, 1.00000 };
float _Threshold <string uiname="Threshold";> = 0.01;
struct vs2ps
{
float4 Pos : POSITION;
float4 TexCd : TEXCOORD0;
};
// VERTEXSHADERS
vs2ps VS(
float4 Pos : POSITION,
float4 TexCd : TEXCOORD0)
{
vs2ps Out = (vs2ps)0;
Out.Pos = mul(Pos, tWVP);
Out.TexCd = mul(TexCd, tTex);
return Out;
}
// PIXELSHADERS:
float4 tresholded(vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd);
if (col.r > _Threshold && col.g > _Threshold && col.b > _Threshold)
{
col = _ReplaceColor;
}
return col;
}
float4 tresholded2(vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd);
if (col.r > _Threshold && col.g > _Threshold && col.b > _Threshold)
{
col = _ReplaceColor;
} else {
col = _FillColor;
}
return col;
}
// TECHNIQUES:
technique Tresholded2 //name for the technique
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 tresholded2();
}
}
technique Tresholded //name for the technique
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 tresholded();
}
}
//transforms
float4x4 tW: WORLD;
float4x4 tV: VIEW;
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;
//texture
texture _MainTex <string uiname="Base (RGB)";>;
sampler Samp = sampler_state
{
Texture = (_MainTex);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
float4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;
float4 _ReplaceColor : COLOR <string uiname="Color Replace";> = { 0.0, 0.0, 0.0, 1.00000 };
float4 _FillColor : COLOR <string uiname="Color Fill";> = { 1, 1, 1, 1.00000 };
float _Threshold <string uiname="Threshold";> = 0.01;
struct vs2ps
{
float4 Pos : POSITION;
float4 TexCd : TEXCOORD0;
};
// VERTEXSHADERS
vs2ps VS(
float4 Pos : POSITION,
float4 TexCd : TEXCOORD0)
{
vs2ps Out = (vs2ps)0;
Out.Pos = mul(Pos, tWVP);
Out.TexCd = mul(TexCd, tTex);
return Out;
}
// PIXELSHADERS:
float4 tresholded(vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd);
if (col.r > _Threshold && col.g > _Threshold && col.b > _Threshold)
{
col = _ReplaceColor;
}
return col;
}
float4 tresholded2(vs2ps In): COLOR
{
float4 col = tex2D(Samp, In.TexCd);
if (col.r > _Threshold && col.g > _Threshold && col.b > _Threshold)
{
col = _ReplaceColor;
} else {
col = _FillColor;
}
return col;
}
// TECHNIQUES:
technique Tresholded2 //name for the technique
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 tresholded2();
}
}
technique Tresholded //name for the technique
{
pass P0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_0 tresholded();
}
}
работает только glsl поэтому пока подсвечиваю так.