xingwei.zhu
6 年前
当前提交
61a56230
共有 14 个文件被更改,包括 365 次插入 和 65 次删除
-
2Runtime/engine/UIWidgetsPanel.cs
-
6Runtime/ui/painting/painting.cs
-
25Runtime/ui/painting/path.cs
-
6Runtime/ui/painting/shadow_utils.cs
-
8Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
-
86Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
-
32Runtime/ui/renderer/common/geometry/path/path.cs
-
6Samples/UIWidgetSample/MaterialSample.cs
-
85Runtime/Resources/UIWidgets_canvas_shadowBox.shader
-
9Runtime/Resources/UIWidgets_canvas_shadowBox.shader.meta
-
100Runtime/Resources/UIWidgets_canvas_shadowRBox.shader
-
9Runtime/Resources/UIWidgets_canvas_shadowRBox.shader.meta
-
37Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs
-
19Runtime/ui/renderer/common/geometry/path/path_extension.cs
|
|||
Shader "UIWidgets/ShadowBox" |
|||
{ |
|||
//originally from http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/ |
|||
Properties |
|||
{ |
|||
_SrcBlend("_SrcBlend", Int) = 1 // One |
|||
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
_StencilComp("_StencilComp", Float) = 8 // - Equal, 8 - Always |
|||
} |
|||
SubShader |
|||
{ |
|||
ZTest Always |
|||
ZWrite Off |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
|
|||
Stencil { |
|||
Ref 128 |
|||
Comp [_StencilComp] |
|||
} |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
|
|||
float4 box; |
|||
float4 _viewport; |
|||
float sigma; |
|||
float4 color; |
|||
float _mat[9]; |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 coord : TEXCOORD0; |
|||
}; |
|||
|
|||
float4 erf(float4 x) |
|||
{ |
|||
float4 s = sign(x); |
|||
float4 a = abs(x); |
|||
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a; |
|||
x = x * x; |
|||
return s - s / (x * x); |
|||
return s; |
|||
} |
|||
|
|||
float boxShadow(float2 lower, float2 upper, float2 pnt, float sigma) |
|||
{ |
|||
float4 query = float4(pnt - lower, pnt - upper); |
|||
float4 integral = 0.5 + 0.5 * erf(query * (sqrt(0.5) / sigma)); |
|||
return (integral.z - integral.x) * (integral.w - integral.y); |
|||
} |
|||
|
|||
v2f vert(appdata v){ |
|||
v2f o; |
|||
float padding = 3.0 * sigma; |
|||
o.coord = lerp(box.xy - padding, box.zw + padding, v.vertex.xy); |
|||
float3x3 mat = float3x3(_mat[0], _mat[1], _mat[2], _mat[3], _mat[4], _mat[5], 0, 0, 1); |
|||
float2 p = mul(mat, float3(o.coord.xy, 1.0)).xy - _viewport.xy; |
|||
|
|||
#if UNITY_UV_STARTS_AT_TOP |
|||
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 2.0 * p.y / _viewport.w - 1.0, 0, 1); |
|||
#else |
|||
o.vertex = float4(2.0 * p.x / _viewport.z - 1.0, 1.0 - 2.0 * p.y / _viewport.w, 0, 1); |
|||
#endif |
|||
return o; |
|||
} |
|||
|
|||
float4 frag(v2f i) : SV_TARGET { |
|||
float4 fragColor = color; |
|||
fragColor.a = fragColor.a * boxShadow(box.xy, box.zw, i.coord, sigma); |
|||
return fragColor; |
|||
} |
|||
|
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 105f52491741049d88708e718c749e34 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "UIWidgets/ShadowRBox" |
|||
{ |
|||
//originally from http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/ |
|||
Properties |
|||
{ |
|||
_SrcBlend("_SrcBlend", Int) = 1 // One |
|||
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
} |
|||
SubShader |
|||
{ |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
Pass { |
|||
CGPROGRAM |
|||
|
|||
float4 box; |
|||
float2 window; |
|||
float sigma; |
|||
float4 color; |
|||
float corner; |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 coord : TEXCOORD0; |
|||
}; |
|||
|
|||
float gaussian(float x, float sigma) |
|||
{ |
|||
float pi = 3.141592653589793; |
|||
return exp(-(x*x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * pi) * sigma); |
|||
} |
|||
|
|||
float2 erf(float2 x) |
|||
{ |
|||
float2 s = sign(x); |
|||
float2 a = abs(x); |
|||
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a; |
|||
x = x * x; |
|||
return s - s / (x * x); |
|||
return s; |
|||
} |
|||
|
|||
float roundedBoxShadowX(float x, float y, float sigma, float corner, float2 halfSize) |
|||
{ |
|||
float delta = min(halfSize.y - corner - abs(y), 0.0); |
|||
float curved = halfSize.x - corner + sqrt(max(0.0, corner * corner - delta * delta)); |
|||
float2 integral = 0.5 + 0.5 * erf((x + float2(-curved, curved)) * (sqrt(0.5)/sigma)); |
|||
return integral.y - integral.x; |
|||
} |
|||
|
|||
float roundedBoxShadow(float2 lower, float2 upper, float2 pnt, float sigma, float corner) |
|||
{ |
|||
float2 center = (lower + upper) * 0.5; |
|||
float2 halfSize = (upper - lower) * 0.5; |
|||
pnt -= center; |
|||
|
|||
float low = pnt.y - halfSize.y; |
|||
float high = pnt.y + halfSize.y; |
|||
float start = clamp(-3.0 * sigma, low, high); |
|||
float end = clamp(3.0 * sigma, low, high); |
|||
|
|||
float step = (end - start) / 4.0; |
|||
float y = start + step * 0.5; |
|||
float value = 0.0; |
|||
|
|||
for(int i=0; i<4;i++) |
|||
{ |
|||
value += roundedBoxShadowX(pnt.x, pnt.y - y, sigma, corner, halfSize) * gaussian(y, sigma) * step; |
|||
y += step; |
|||
} |
|||
|
|||
return value; |
|||
} |
|||
|
|||
v2f vert(appdata v){ |
|||
v2f o; |
|||
float padding = 3.0 * sigma; |
|||
o.coord = lerp(box.xy - padding, box.zw + padding, v.vertex.xy); |
|||
o.vertex = float4(o.coord.x * 2.0 /window.x - 1.0, o.coord.y * 2.0/window.y - 1.0, 0, 1); |
|||
return o; |
|||
} |
|||
|
|||
float4 frag(v2f i) : SV_TARGET { |
|||
float4 fragColor = color; |
|||
fragColor.a = fragColor.a * roundedBoxShadow(box.xy, box.zw, i.coord, sigma, corner); |
|||
return fragColor; |
|||
} |
|||
|
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 77c8565b9b449434490473ef8f7f0e91 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.ui { |
|||
public partial class PictureFlusher { |
|||
|
|||
void _drawRRectShadow(uiPath path, uiPaint paint) { |
|||
D.assert(path.isRRect, () => "Cannot draw Shadow for non-RRect shapes"); |
|||
D.assert(paint.style == PaintingStyle.fill, () => "Cannot draw Shadow for stroke lines"); |
|||
|
|||
var layer = this._currentLayer; |
|||
var state = layer.currentState; |
|||
|
|||
var vertices = ObjectPool<uiList<Vector3>>.alloc(); |
|||
vertices.SetCapacity(4); |
|||
vertices.Add(new Vector2(0, 0)); |
|||
vertices.Add(new Vector2(1, 0)); |
|||
vertices.Add(new Vector2(0, 1)); |
|||
vertices.Add(new Vector2(1, 1)); |
|||
|
|||
var _triangles = ObjectPool<uiList<int>>.alloc(); |
|||
_triangles.SetCapacity(6); |
|||
_triangles.Add(0); |
|||
_triangles.Add(1); |
|||
_triangles.Add(2); |
|||
_triangles.Add(2); |
|||
_triangles.Add(1); |
|||
_triangles.Add(3); |
|||
|
|||
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles); |
|||
var bound = path.getBounds(); |
|||
Debug.Log("Draw shadow>>> " + bound.top); |
|||
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, path.isRect, new Vector4(bound.left, bound.top, bound.right, bound.bottom))); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
namespace Unity.UIWidgets.ui { |
|||
public partial class uiPath { |
|||
|
|||
public enum uiPathShapeHint { |
|||
Rect, |
|||
Oval, |
|||
RRect, |
|||
Other |
|||
} |
|||
|
|||
public bool isRect { |
|||
get { return this._shapeHint == uiPathShapeHint.Rect; } |
|||
} |
|||
|
|||
public bool isOval { |
|||
get { return this._shapeHint == uiPathShapeHint.Oval; } |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue