Okay. Did the temp registers error go away after adding that line? If no, quit Unity, and start it with the -force-opengl argument. The error should go away then (I use openGL [Mac] and don’t encounter that problem). The && problem is a tricky one. I managed to fix it by breaking the statement into individual booleans. Here, the shader throws no more errors on my system. Note that I haven’t tested it, so that’s up to you.
Shader "Custom/2xBR" {
Properties {
_Color ("Color", Color) = (1,1,1,1) //You should set this field in Unity scripting, material.SetColor
_MainTex ("Albedo (RGB)", 2D) = "white" {}
decal ("decal (RGB)", 2D) = "white" {} //you should also set this in scripting with material.SetTexture ("decal", yourDecalTexture)
}
SubShader {
Tags { "RenderType"="Opaque" }
///////////////////////////////////
Pass {
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex main_vertex
#pragma fragment main_fragment
uniform half4 _Color;
uniform sampler2D decal : TEXUNIT0;
uniform half2 video_size; //You should set this in Unity (your script) using material.SetVector("video_size", outputSize float); //note that the vector you set must be a vector4, smae as the remaining two below
uniform float2 texture_size; //You should set this in Unity (your script) using material.SetVector("texture_size", outputSize float);
uniform half2 output_size; //You should set this in Unity (your script) using material.SetVector("output_size", outputSize float);
const static float coef = 2.0;
const static float3 dtt = float3(65536,255,1);
const static half y_weight = 48.0;
const static half u_weight = 7.0;
const static half v_weight = 6.0;
const static half3x3 yuv = half3x3(0.299, 0.587, 0.114, -0.169, -0.331, 0.499, 0.499, -0.418, -0.0813);
const static half3x3 yuv_weighted = half3x3(y_weight*yuv[0], u_weight*yuv[1], v_weight*yuv[2]);
//const static half3x3 yuv_weighted = half3x3(14.352, 28.176, 5.472, -1.183, -2.317, 3.5, 3.0, -2.514, -0.486);
float4 RGBtoYUV(half4x4 mat_color) {
float a = abs(mul(yuv_weighted, mat_color[0].xyz));
float b = abs(mul(yuv_weighted, mat_color[1].xyz));
float c = abs(mul(yuv_weighted, mat_color[2].xyz));
float d = abs(mul(yuv_weighted, mat_color[3].xyz));
return float4(a, b, c, d);
}
float4 df(float4 A, float4 B) {
return float4(abs(A - B));
}
float4 weighted_distance(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h) {
return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
}
struct out_vertex {
half4 position : POSITION;
half4 color : COLOR;
float2 texCoord : TEXCOORD0;
half4 t1 : TEXCOORD1;
};
// VERTEX_SHADER
out_vertex main_vertex ( appdata_base v ) {
out_vertex OUT;
OUT.position = mul(UNITY_MATRIX_MVP, v.vertex);
OUT.color = _Color;
half2 ps = half2(1.0 / texture_size.x, 1.0 / texture_size.y);
half dx = ps.x;
half dy = ps.y;
OUT.texCoord = v.texcoord;
OUT.t1.xy = half2(dx, 0); // F
OUT.t1.zw = half2(0, dy); // H
return OUT;
}
// FRAGMENT SHADER
half4 main_fragment( out_vertex VAR ) : COLOR {
bool4 edr, edr_left, edr_up, px; // px = pixel, edr = edge detection rule
bool4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
float2 fp = frac(VAR.texCoord*texture_size);
half2 dx = VAR.t1.xy;
half2 dy = VAR.t1.zw;
half3 A = tex2D(decal, VAR.texCoord - dx - dy).xyz;
half3 B = tex2D(decal, VAR.texCoord - dy).xyz;
half3 C = tex2D(decal, VAR.texCoord + dx - dy).xyz;
half3 D = tex2D(decal, VAR.texCoord - dx).xyz;
half3 E = tex2D(decal, VAR.texCoord).xyz;
half3 F = tex2D(decal, VAR.texCoord + dx).xyz;
half3 G = tex2D(decal, VAR.texCoord - dx + dy).xyz;
half3 H = tex2D(decal, VAR.texCoord + dy).xyz;
half3 I = tex2D(decal, VAR.texCoord + dx + dy).xyz;
half3 A1 = tex2D(decal, VAR.texCoord - dx - 2.0*dy).xyz;
half3 C1 = tex2D(decal, VAR.texCoord + dx - 2.0*dy).xyz;
half3 A0 = tex2D(decal, VAR.texCoord - 2.0*dx - dy).xyz;
half3 G0 = tex2D(decal, VAR.texCoord - 2.0*dx + dy).xyz;
half3 C4 = tex2D(decal, VAR.texCoord + 2.0*dx - dy).xyz;
half3 I4 = tex2D(decal, VAR.texCoord + 2.0*dx + dy).xyz;
half3 G5 = tex2D(decal, VAR.texCoord - dx + 2.0*dy).xyz;
half3 I5 = tex2D(decal, VAR.texCoord + dx + 2.0*dy).xyz;
half3 B1 = tex2D(decal, VAR.texCoord - 2.0*dy).xyz;
half3 D0 = tex2D(decal, VAR.texCoord - 2.0*dx).xyz;
half3 H5 = tex2D(decal, VAR.texCoord + 2.0*dy).xyz;
half3 F4 = tex2D(decal, VAR.texCoord + 2.0*dx).xyz;
float4 a = RGBtoYUV(half4x4(half4(A,1), half4(G,1), half4(I,1), half4(C,1)));
float4 b = RGBtoYUV(half4x4(half4(B,1), half4(D,1), half4(H,1), half4(F,1)));
float4 c = RGBtoYUV(half4x4(half4(C,1), half4(A,1), half4(G,1), half4(I,1)));
float4 d = RGBtoYUV(half4x4(half4(D,1), half4(H,1), half4(F,1), half4(B,1)));
float4 e = RGBtoYUV(half4x4(half4(E,1), half4(E,1), half4(E,1), half4(E,1)));
float4 f = RGBtoYUV(half4x4(half4(F,1), half4(B,1), half4(D,1), half4(H,1)));
float4 g = RGBtoYUV(half4x4(half4(G,1), half4(I,1), half4(C,1), half4(A,1)));
float4 h = RGBtoYUV(half4x4(half4(H,1), half4(F,1), half4(B,1), half4(D,1)));
float4 i = RGBtoYUV(half4x4(half4(I,1), half4(C,1), half4(A,1), half4(G,1)));
float4 a1 = RGBtoYUV(half4x4(half4(A1,1), half4(G0,1), half4(I5,1), half4(C4,1)));
float4 c1 = RGBtoYUV(half4x4(half4(C1,1), half4(A0,1), half4(G5,1), half4(I4,1)));
float4 a0 = RGBtoYUV(half4x4(half4(A0,1), half4(G5,1), half4(I4,1), half4(C1,1)));
float4 g0 = RGBtoYUV(half4x4(half4(G0,1), half4(I5,1), half4(C4,1), half4(A1,1)));
float4 c4 = RGBtoYUV(half4x4(half4(C4,1), half4(A1,1), half4(G0,1), half4(I5,1)));
float4 i4 = RGBtoYUV(half4x4(half4(I4,1), half4(C1,1), half4(A0,1), half4(G5,1)));
float4 g5 = RGBtoYUV(half4x4(half4(G5,1), half4(I4,1), half4(C1,1), half4(A0,1)));
float4 i5 = RGBtoYUV(half4x4(half4(I5,1), half4(C4,1), half4(A1,1), half4(G0,1)));
float4 b1 = RGBtoYUV(half4x4(half4(B1,1), half4(D0,1), half4(H5,1), half4(F4,1)));
float4 d0 = RGBtoYUV(half4x4(half4(D0,1), half4(H5,1), half4(F4,1), half4(B1,1)));
float4 h5 = RGBtoYUV(half4x4(half4(H5,1), half4(F4,1), half4(B1,1), half4(D0,1)));
float4 f4 = RGBtoYUV(half4x4(half4(F4,1), half4(B1,1), half4(D0,1), half4(H5,1)));
//interp_restriction_lv1 = ((e != f) && (e != h)); //must break up into seperate conditions
bool iop1 = (e != f);
bool iop2 = (e != h);
interp_restriction_lv1 = iop1 && iop2;
//interp_restriction_lv2_left = ((e != g) && (d != g));
bool irp1 = (e != g);
bool irp2 = (d != g);
interp_restriction_lv2_left = irp1 && irp2;
//interp_restriction_lv2_up = ((e != c) && (b != c));
bool iru1 = (e != c);
bool iru2 = (b != c);
interp_restriction_lv2_up = iru1 && iru2;
//edr = (weighted_distance(e, c, g, i, h5, f4, h, f) < weighted_distance(h, d, i5, f, i4, b, e, i)) && interp_restriction_lv1;
bool ed1 = (weighted_distance(e, c, g, i, h5, f4, h, f) < weighted_distance(h, d, i5, f, i4, b, e, i));
edr = ed1 && (iop1 && iop2); //interp_restriction_lv1 here throws error, so I replaced it with it's assignment
//edr_left = ((coef*df(f,g)) <= df(h,c)) && interp_restriction_lv2_left;
bool edl1 = ((coef*df(f,g)) <= df(h,c));
edr_left = edl1 && (irp1 && irp2);
//edr_up = (df(f,g) >= (coef*df(h,c))) && interp_restriction_lv2_up;
bool edu1 = (df(f,g) >= (coef*df(h,c)));
edr_up = edu1 && (iru1 && iru2);
half3 E0 = E;
half3 E1 = E;
half3 E2 = E;
half3 E3 = E;
px = (df(e,f) <= df(e,h));
half3 P[4];
P[0] = px.x ? F : H;
P[1] = px.y ? B : F;
P[2] = px.z ? D : B;
P[3] = px.w ? H : D;
if (edr.x)
{
if (edr_left.x && edr_up.x)
{
E3 = lerp(E3 , P[0], 0.833333);
E2 = lerp(E2 , P[0], 0.25);
E1 = lerp(E1 , P[0], 0.25);
}
else if (edr_left.x)
{
E3 = lerp(E3 , P[0], 0.75);
E2 = lerp(E2 , P[0], 0.25);
}
else if (edr_up.x)
{
E3 = lerp(E3 , P[0], 0.75);
E1 = lerp(E1 , P[0], 0.25);
}
else
{
E3 = lerp(E3 , P[0], 0.5);
}
}
if (edr.y)
{
if (edr_left.y && edr_up.y)
{
E1 = lerp(E1 , P[1], 0.833333);
E3 = lerp(E3 , P[1], 0.25);
E0 = lerp(E0 , P[1], 0.25);
}
else if (edr_left.y)
{
E1 = lerp(E1 , P[1], 0.75);
E3 = lerp(E3 , P[1], 0.25);
}
else if (edr_up.y)
{
E1 = lerp(E1 , P[1], 0.75);
E0 = lerp(E0 , P[1], 0.25);
}
else
{
E1 = lerp(E1 , P[1], 0.5);
}
}
if (edr.z)
{
if (edr_left.z && edr_up.z)
{
E0 = lerp(E0 , P[2], 0.833333);
E1 = lerp(E1 , P[2], 0.25);
E2 = lerp(E2 , P[2], 0.25);
}
else if (edr_left.z)
{
E0 = lerp(E0 , P[2], 0.75);
E1 = lerp(E1 , P[2], 0.25);
}
else if (edr_up.z)
{
E0 = lerp(E0 , P[2], 0.75);
E2 = lerp(E2 , P[2], 0.25);
}
else
{
E0 = lerp(E0 , P[2], 0.5);
}
}
if (edr.w)
{
if (edr_left.w && edr_up.w)
{
E2 = lerp(E2 , P[3], 0.833333);
E0 = lerp(E0 , P[3], 0.25);
E3 = lerp(E3 , P[3], 0.25);
}
else if (edr_left.w)
{
E2 = lerp(E2 , P[3], 0.75);
E0 = lerp(E0 , P[3], 0.25);
}
else if (edr_up.w)
{
E2 = lerp(E2 , P[3], 0.75);
E3 = lerp(E3 , P[3], 0.25);
}
else
{
E2 = lerp(E2 , P[3], 0.5);
}
}
half3 res = (fp.x < 0.50) ? (fp.y < 0.50 ? E0 : E2) : (fp.y < 0.50 ? E1 : E3);
return half4(res, 1.0);
}
ENDCG
}
///////////////////////////////////
}
FallBack "Diffuse"
}