xingwei.zhu
6 年前
当前提交
0eff16e9
共有 10 个文件被更改,包括 236 次插入 和 9 次删除
-
2Runtime/editor/surface.cs
-
4Runtime/ui/renderer/cmdbufferCanvas/command_buffer_canvas.cs
-
12Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
-
11Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
-
2Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs
-
27Runtime/Resources/UIWidgets_canvas_cb.cginc
-
58Runtime/Resources/UIWidgets_canvas_convexFill_cb.shader
-
9Runtime/Resources/UIWidgets_canvas_convexFill_cb.shader.meta
-
109Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_computebuffer_utils.cs
-
11Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_computebuffer_utils.cs.meta
|
|||
struct vdata |
|||
{ |
|||
float2 vertex; |
|||
float2 uv; |
|||
}; |
|||
|
|||
struct psInput |
|||
{ |
|||
float4 position : SV_POSITION; |
|||
}; |
|||
|
|||
StructuredBuffer<vdata> databuffer; |
|||
StructuredBuffer<int> indexbuffer; |
|||
float4 _viewport; |
|||
int _startVertex; |
|||
|
|||
psInput vert (uint vertex_id: SV_VertexID, uint instance_id: SV_InstanceID) |
|||
{ |
|||
psInput o = (psInput)0; |
|||
o.position = float4(databuffer[indexbuffer[_startVertex + vertex_id]].vertex.x * 2.0 / _viewport.z - 1.0, databuffer[indexbuffer[_startVertex + vertex_id]].vertex.y * 2.0 / _viewport.w - 1.0, 0, 1); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (psInput i) : SV_Target |
|||
{ |
|||
return float4(0, 1, 0, 1); |
|||
} |
|
|||
Shader "UIWidgets/canvas_convexFill_cb" |
|||
{ |
|||
Properties |
|||
{ |
|||
_SrcBlend("_SrcBlend", Int) = 1 // One |
|||
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
_StencilComp("_StencilComp", Float) = 3 // - Equal, 8 - Always |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
Pass { // 0, color |
|||
CGPROGRAM |
|||
#define UIWIDGETS_COLOR |
|||
#include "UIWidgets_canvas_cb.cginc" |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 1, linear |
|||
CGPROGRAM |
|||
#define UIWIDGETS_LINEAR |
|||
#include "UIWidgets_canvas_cb.cginc" |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 2, radial |
|||
CGPROGRAM |
|||
#define UIWIDGETS_RADIAL |
|||
#include "UIWidgets_canvas_cb.cginc" |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 3, sweep |
|||
CGPROGRAM |
|||
#define UIWIDGETS_SWEEP |
|||
#include "UIWidgets_canvas_cb.cginc" |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 4, image |
|||
CGPROGRAM |
|||
#define UIWIDGETS_IMAGE |
|||
#include "UIWidgets_canvas_cb.cginc" |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f33f0775754654febaf49dbb596c8927 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Runtime.InteropServices; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using Random = System.Random; |
|||
|
|||
namespace Unity.UIWidgets.ui { |
|||
public partial class PictureFlusher { |
|||
|
|||
struct TVertex |
|||
{ |
|||
public Vector2 position; |
|||
public Vector2 uv; |
|||
} |
|||
|
|||
ComputeBuffer computeBuffer; |
|||
List<TVertex> tvertexes; |
|||
|
|||
ComputeBuffer indexBuffer; |
|||
List<int> indexes; |
|||
|
|||
int startVertex; |
|||
int startIndex; |
|||
|
|||
Material material; |
|||
|
|||
public void DrawBuffer(CommandBuffer cmdBuf) |
|||
{ |
|||
if (this.computeBuffer == null) |
|||
{ |
|||
var stride = Marshal.SizeOf(typeof(TVertex)); |
|||
this.computeBuffer = new ComputeBuffer(1024 * 1024, stride); |
|||
this.tvertexes = new List<TVertex>(); |
|||
|
|||
this.indexBuffer = new ComputeBuffer(1024 * 1024, Marshal.SizeOf(typeof(int))); |
|||
this.indexes = new List<int>(); |
|||
} |
|||
|
|||
this.tvertexes.Clear(); |
|||
this.indexes.Clear(); |
|||
this.startVertex = 0; |
|||
this.startIndex = 0; |
|||
|
|||
if (this.material == null) { |
|||
this.material = new Material(Shader.Find("UIWidgets/canvas_convexFill_cb")); |
|||
this.material.SetVector("_viewport", new Vector4(0, 0, 500, 500)); |
|||
} |
|||
|
|||
var random = new Random(); |
|||
var num = 5; |
|||
var size = 30; |
|||
|
|||
for (var i = 0; i < num; i++) |
|||
{ |
|||
for (var j = 0; j < num; j++) |
|||
{ |
|||
var offsetY = i * size; |
|||
var offsetX = j * size; |
|||
var centerX = offsetX + size / 2; |
|||
var centerY = offsetY + size / 2; |
|||
var width = size; |
|||
var height = size; |
|||
|
|||
this.startVertex = this.tvertexes.Count; |
|||
this.startIndex = this.indexes.Count; |
|||
|
|||
|
|||
this.tvertexes.AddRange(new[] |
|||
{ |
|||
new TVertex |
|||
{ |
|||
position = new Vector2(centerX - width / 2, centerY - height / 2), |
|||
uv = new Vector2(0, 0) |
|||
}, |
|||
new TVertex |
|||
{ |
|||
position = new Vector2(centerX + width / 2, centerY - height / 2), |
|||
uv = new Vector2(0, 0) |
|||
}, |
|||
new TVertex |
|||
{ |
|||
position = new Vector2(centerX + width / 2, centerY + height / 2), |
|||
uv = new Vector2(0, 0) |
|||
}, |
|||
new TVertex |
|||
{ |
|||
position = new Vector2(centerX - width / 2, centerY + height / 2), |
|||
uv = new Vector2(0, 0) |
|||
} |
|||
}); |
|||
|
|||
this.indexes.AddRange(new [] |
|||
{ |
|||
this.startVertex, this.startVertex + 1, this.startVertex + 2, this.startVertex, this.startVertex + 2, this.startVertex + 3 |
|||
}); |
|||
|
|||
var mpb = new MaterialPropertyBlock(); |
|||
mpb.SetBuffer("databuffer", this.computeBuffer); |
|||
mpb.SetBuffer("indexbuffer", this.indexBuffer); |
|||
mpb.SetInt("_startVertex", this.startIndex); |
|||
cmdBuf.DrawProcedural(Matrix4x4.identity, this.material, 0, MeshTopology.Triangles, 6, 1, mpb); |
|||
} |
|||
} |
|||
|
|||
this.computeBuffer.SetData(this.tvertexes); |
|||
this.indexBuffer.SetData(this.indexes); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 88f2ad2c8ab504c5d95b1f70539f8d86 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue