Projekt

Obecné

Profil

Stáhnout (2.22 KB) Statistiky
| Větev: | Tag: | Revize:
1
float2 UnpackUV(float uv)
2
{ 
3
	float2 output;
4
	output.x = floor(uv / 4096);
5
	output.y = uv - 4096 * output.x;
6

    
7
	return output * 0.001953125;
8
}
9

    
10
fixed4 GetColor(half d, fixed4 faceColor, fixed4 outlineColor, half outline, half softness)
11
{
12
	half faceAlpha = 1-saturate((d - outline * 0.5 + softness * 0.5) / (1.0 + softness));
13
	half outlineAlpha = saturate((d + outline * 0.5)) * sqrt(min(1.0, outline));
14

    
15
	faceColor.rgb *= faceColor.a;
16
	outlineColor.rgb *= outlineColor.a;
17

    
18
	faceColor = lerp(faceColor, outlineColor, outlineAlpha);
19

    
20
	faceColor *= faceAlpha;
21

    
22
	return faceColor;
23
}
24

    
25
float3 GetSurfaceNormal(float4 h, float bias)
26
{
27
	bool raisedBevel = step(1, fmod(_ShaderFlags, 2));
28

    
29
	h += bias+_BevelOffset;
30

    
31
	float bevelWidth = max(.01, _OutlineWidth+_BevelWidth);
32

    
33
  // Track outline
34
	h -= .5;
35
	h /= bevelWidth;
36
	h = saturate(h+.5);
37

    
38
	if(raisedBevel) h = 1 - abs(h*2.0 - 1.0);
39
	h = lerp(h, sin(h*3.141592/2.0), _BevelRoundness);
40
	h = min(h, 1.0-_BevelClamp);
41
	h *= _Bevel * bevelWidth * _GradientScale * -2.0;
42

    
43
	float3 va = normalize(float3(1.0, 0.0, h.y - h.x));
44
	float3 vb = normalize(float3(0.0, -1.0, h.w - h.z));
45

    
46
	return cross(va, vb);
47
}
48

    
49
float3 GetSurfaceNormal(float2 uv, float bias, float3 delta)
50
{
51
	// Read "height field"
52
  float4 h = {tex2D(_MainTex, uv - delta.xz).a,
53
				tex2D(_MainTex, uv + delta.xz).a,
54
				tex2D(_MainTex, uv - delta.zy).a,
55
				tex2D(_MainTex, uv + delta.zy).a};
56

    
57
	return GetSurfaceNormal(h, bias);
58
}
59

    
60
float3 GetSpecular(float3 n, float3 l)
61
{
62
	float spec = pow(max(0.0, dot(n, l)), _Reflectivity);
63
	return _SpecularColor.rgb * spec * _SpecularPower;
64
}
65

    
66
float4 GetGlowColor(float d, float scale)
67
{
68
	float glow = d - (_GlowOffset*_ScaleRatioB) * 0.5 * scale;
69
	float t = lerp(_GlowInner, (_GlowOuter * _ScaleRatioB), step(0.0, glow)) * 0.5 * scale;
70
	glow = saturate(abs(glow/(1.0 + t)));
71
	glow = 1.0-pow(glow, _GlowPower);
72
	glow *= sqrt(min(1.0, t)); // Fade off glow thinner than 1 screen pixel
73
	return float4(_GlowColor.rgb, saturate(_GlowColor.a * glow * 2));
74
}
75

    
76
float4 BlendARGB(float4 overlying, float4 underlying)
77
{
78
	overlying.rgb *= overlying.a;
79
	underlying.rgb *= underlying.a;
80
	float3 blended = overlying.rgb + ((1-overlying.a)*underlying.rgb);
81
	float alpha = underlying.a + (1-underlying.a)*overlying.a;
82
	return float4(blended, alpha);
83
}
84

    
(27-27/34)