Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
n5
URasterizer
提交
c265fe7b
URasterizer
项目概览
n5
/
URasterizer
通知
21
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
URasterizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c265fe7b
编写于
1月 28, 2022
作者:
H
happyfire
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
vertex colors
上级
0850a8e6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
45 addition
and
29 deletion
+45
-29
URasterizer/Assembly-CSharp.csproj
URasterizer/Assembly-CSharp.csproj
+5
-2
URasterizer/Assets/Samples/Scenes/URasterizerScene.unity
URasterizer/Assets/Samples/Scenes/URasterizerScene.unity
+0
-12
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
+33
-12
URasterizer/Assets/URasterizer/Codes/RenderingConfig.cs
URasterizer/Assets/URasterizer/Codes/RenderingConfig.cs
+3
-0
URasterizer/Assets/URasterizer/Codes/RenderingObject.cs
URasterizer/Assets/URasterizer/Codes/RenderingObject.cs
+0
-3
URasterizer/Assets/URasterizer/RenderingConfig.asset
URasterizer/Assets/URasterizer/RenderingConfig.asset
+4
-0
未找到文件。
URasterizer/Assembly-CSharp.csproj
浏览文件 @
c265fe7b
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<PropertyGroup>
<LangVersion>
latest
</LangVersion>
<LangVersion>
8.0
</LangVersion>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
...
@@ -52,14 +52,17 @@
...
@@ -52,14 +52,17 @@
<UnityBuildTarget>
StandaloneWindows64:19
</UnityBuildTarget>
<UnityBuildTarget>
StandaloneWindows64:19
</UnityBuildTarget>
<UnityVersion>
2020.3.25f1c1
</UnityVersion>
<UnityVersion>
2020.3.25f1c1
</UnityVersion>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Analyzer
Include=
"C:\Program Files (x86)\Microsoft Visual Studio Tools for Unity\16.0\Analyzers\Microsoft.Unity.Analyzers.dll"
/>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"Assets\URasterizer\Codes\RenderingObject.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\RenderingObject.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\RenderingConfig.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\StatsPanel.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\StatsPanel.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\CameraRenderer.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\CameraRenderer.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\Triangle.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\Triangle.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\Rasterizer.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\Rasterizer.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\TransformTool.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\TransformTool.cs"
/>
<Compile
Include=
"Assets\URasterizer\Codes\RenderingConfig.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"UnityEngine"
>
<Reference
Include=
"UnityEngine"
>
...
...
URasterizer/Assets/Samples/Scenes/URasterizerScene.unity
浏览文件 @
c265fe7b
...
@@ -305,9 +305,6 @@ MonoBehaviour:
...
@@ -305,9 +305,6 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
mesh
:
{
fileID
:
0
}
mesh
:
{
fileID
:
0
}
DoubleSideRendering
:
0
DoubleSideRendering
:
0
Color0
:
{
r
:
1
,
g
:
0
,
b
:
0
,
a
:
1
}
Color1
:
{
r
:
0
,
g
:
1
,
b
:
0
,
a
:
1
}
Color2
:
{
r
:
0
,
g
:
0
,
b
:
1
,
a
:
1
}
---
!u!1
&264331597
---
!u!1
&264331597
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
@@ -662,9 +659,6 @@ MonoBehaviour:
...
@@ -662,9 +659,6 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
mesh
:
{
fileID
:
0
}
mesh
:
{
fileID
:
0
}
DoubleSideRendering
:
0
DoubleSideRendering
:
0
Color0
:
{
r
:
1
,
g
:
0
,
b
:
0
,
a
:
1
}
Color1
:
{
r
:
0
,
g
:
1
,
b
:
0
,
a
:
1
}
Color2
:
{
r
:
0
,
g
:
0
,
b
:
1
,
a
:
1
}
---
!u!95
&963210800
---
!u!95
&963210800
Animator
:
Animator
:
serializedVersion
:
3
serializedVersion
:
3
...
@@ -874,9 +868,6 @@ MonoBehaviour:
...
@@ -874,9 +868,6 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
mesh
:
{
fileID
:
0
}
mesh
:
{
fileID
:
0
}
DoubleSideRendering
:
0
DoubleSideRendering
:
0
Color0
:
{
r
:
1
,
g
:
0
,
b
:
0
,
a
:
1
}
Color1
:
{
r
:
0
,
g
:
1
,
b
:
0
,
a
:
1
}
Color2
:
{
r
:
0
,
g
:
0
,
b
:
1
,
a
:
1
}
---
!u!1
&1825649040
---
!u!1
&1825649040
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
@@ -993,9 +984,6 @@ MonoBehaviour:
...
@@ -993,9 +984,6 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
mesh
:
{
fileID
:
0
}
mesh
:
{
fileID
:
0
}
DoubleSideRendering
:
0
DoubleSideRendering
:
0
Color0
:
{
r
:
1
,
g
:
0
,
b
:
0
,
a
:
1
}
Color1
:
{
r
:
0
,
g
:
1
,
b
:
0
,
a
:
1
}
Color2
:
{
r
:
0
,
g
:
0
,
b
:
1
,
a
:
1
}
---
!u!1
&1899433433
---
!u!1
&1899433433
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
...
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
浏览文件 @
c265fe7b
...
@@ -143,9 +143,11 @@ namespace URasterizer
...
@@ -143,9 +143,11 @@ namespace URasterizer
//1. z轴反转
//1. z轴反转
//2. 三角形顶点环绕方向从顺时针改成逆时针
//2. 三角形顶点环绕方向从顺时针改成逆时针
int
idx0
=
indices
[
i
];
//注意这儿对调了v0和v1的索引,因为原来的 0,1,2是顺时针的,对调后是 1,0,2是逆时针的
int
idx1
=
indices
[
i
+
2
];
//注意这儿对调了v1和v2的索引,因为原来的 0,1,2是顺时针的,对调后是 0,2,1,是逆时针的
//Unity Quard模型的两个三角形索引分别是 0,3,1,3,0,2 转换后为 3,0,1,0,3,2
int
idx2
=
indices
[
i
+
1
];
int
idx0
=
indices
[
i
+
1
];
int
idx1
=
indices
[
i
];
int
idx2
=
indices
[
i
+
2
];
//vertex shader
//vertex shader
...
@@ -181,7 +183,7 @@ namespace URasterizer
...
@@ -181,7 +183,7 @@ namespace URasterizer
Vector3
e01
=
v1
-
v0
;
Vector3
e01
=
v1
-
v0
;
Vector3
e02
=
v2
-
v0
;
Vector3
e02
=
v2
-
v0
;
Vector3
cross
=
Vector3
.
Cross
(
e01
,
e02
);
Vector3
cross
=
Vector3
.
Cross
(
e01
,
e02
);
if
(
cross
.
z
<
=
0
)
if
(
cross
.
z
<
0
)
{
{
continue
;
continue
;
}
}
...
@@ -208,9 +210,21 @@ namespace URasterizer
...
@@ -208,9 +210,21 @@ namespace URasterizer
{
{
t
.
SetPosition
(
k
,
v
[
k
]);
t
.
SetPosition
(
k
,
v
[
k
]);
}
}
t
.
SetColor
(
0
,
ro
.
Color0
);
t
.
SetColor
(
1
,
ro
.
Color1
);
//设置顶点色,使用config中的颜色数组循环设置
t
.
SetColor
(
2
,
ro
.
Color2
);
int
vertexColorCount
=
_config
.
VertexColors
.
Length
;
if
(
vertexColorCount
>
0
)
{
t
.
SetColor
(
0
,
_config
.
VertexColors
[
idx0
%
vertexColorCount
]);
t
.
SetColor
(
1
,
_config
.
VertexColors
[
idx1
%
vertexColorCount
]);
t
.
SetColor
(
2
,
_config
.
VertexColors
[
idx2
%
vertexColorCount
]);
}
else
{
t
.
SetColor
(
0
,
Color
.
white
);
t
.
SetColor
(
1
,
Color
.
white
);
t
.
SetColor
(
2
,
Color
.
white
);
}
//Rasterization
//Rasterization
if
(
_config
.
WireframeMode
)
if
(
_config
.
WireframeMode
)
...
@@ -251,7 +265,7 @@ namespace URasterizer
...
@@ -251,7 +265,7 @@ namespace URasterizer
}
}
#
region
Wireframe
mode
#
region
Wireframe
mode
private
void
DrawLine
(
Vector3
begin
,
Vector3
end
,
Color
line_color
)
private
void
DrawLine
(
Vector3
begin
,
Vector3
end
,
Color
colorBegin
,
Color
colorEnd
)
{
{
int
x1
=
Mathf
.
FloorToInt
(
begin
.
x
);
int
x1
=
Mathf
.
FloorToInt
(
begin
.
x
);
int
y1
=
Mathf
.
FloorToInt
(
begin
.
y
);
int
y1
=
Mathf
.
FloorToInt
(
begin
.
y
);
...
@@ -265,7 +279,7 @@ namespace URasterizer
...
@@ -265,7 +279,7 @@ namespace URasterizer
dx1
=
Math
.
Abs
(
dx
);
dx1
=
Math
.
Abs
(
dx
);
dy1
=
Math
.
Abs
(
dy
);
dy1
=
Math
.
Abs
(
dy
);
px
=
2
*
dy1
-
dx1
;
px
=
2
*
dy1
-
dx1
;
py
=
2
*
dx1
-
dy1
;
py
=
2
*
dx1
-
dy1
;
if
(
dy1
<=
dx1
)
if
(
dy1
<=
dx1
)
{
{
...
@@ -282,6 +296,7 @@ namespace URasterizer
...
@@ -282,6 +296,7 @@ namespace URasterizer
xe
=
x1
;
xe
=
x1
;
}
}
Vector3
point
=
new
Vector3
(
x
,
y
,
1.0f
);
Vector3
point
=
new
Vector3
(
x
,
y
,
1.0f
);
Color
line_color
=
dx
>=
0
?
colorBegin
:
colorEnd
;
SetPixel
(
point
,
line_color
);
SetPixel
(
point
,
line_color
);
for
(
i
=
0
;
x
<
xe
;
i
++)
for
(
i
=
0
;
x
<
xe
;
i
++)
{
{
...
@@ -304,6 +319,8 @@ namespace URasterizer
...
@@ -304,6 +319,8 @@ namespace URasterizer
}
}
Vector3
pt
=
new
Vector3
(
x
,
y
,
1.0f
);
Vector3
pt
=
new
Vector3
(
x
,
y
,
1.0f
);
float
t
=
(
float
)(
xe
-
x
)
/
dx1
;
line_color
=
Color
.
Lerp
(
colorBegin
,
colorEnd
,
t
);
SetPixel
(
pt
,
line_color
);
SetPixel
(
pt
,
line_color
);
}
}
}
}
...
@@ -322,7 +339,9 @@ namespace URasterizer
...
@@ -322,7 +339,9 @@ namespace URasterizer
ye
=
y1
;
ye
=
y1
;
}
}
Vector3
point
=
new
Vector3
(
x
,
y
,
1.0f
);
Vector3
point
=
new
Vector3
(
x
,
y
,
1.0f
);
Color
line_color
=
dy
>=
0
?
colorBegin
:
colorEnd
;
SetPixel
(
point
,
line_color
);
SetPixel
(
point
,
line_color
);
for
(
i
=
0
;
y
<
ye
;
i
++)
for
(
i
=
0
;
y
<
ye
;
i
++)
{
{
y
++;
y
++;
...
@@ -343,6 +362,8 @@ namespace URasterizer
...
@@ -343,6 +362,8 @@ namespace URasterizer
py
+=
2
*
(
dx1
-
dy1
);
py
+=
2
*
(
dx1
-
dy1
);
}
}
Vector3
pt
=
new
Vector3
(
x
,
y
,
1.0f
);
Vector3
pt
=
new
Vector3
(
x
,
y
,
1.0f
);
float
t
=
(
float
)(
ye
-
y
)
/
dy1
;
line_color
=
Color
.
Lerp
(
colorBegin
,
colorEnd
,
t
);
SetPixel
(
pt
,
line_color
);
SetPixel
(
pt
,
line_color
);
}
}
}
}
...
@@ -350,9 +371,9 @@ namespace URasterizer
...
@@ -350,9 +371,9 @@ namespace URasterizer
private
void
RasterizeWireframe
(
Triangle
t
)
private
void
RasterizeWireframe
(
Triangle
t
)
{
{
DrawLine
(
t
.
Positions
[
0
],
t
.
Positions
[
1
],
t
.
Colors
[
0
]);
DrawLine
(
t
.
Positions
[
0
],
t
.
Positions
[
1
],
t
.
Colors
[
0
]
,
t
.
Colors
[
1
]
);
DrawLine
(
t
.
Positions
[
1
],
t
.
Positions
[
2
],
t
.
Colors
[
1
]);
DrawLine
(
t
.
Positions
[
1
],
t
.
Positions
[
2
],
t
.
Colors
[
1
]
,
t
.
Colors
[
2
]
);
DrawLine
(
t
.
Positions
[
2
],
t
.
Positions
[
0
],
t
.
Colors
[
2
]);
DrawLine
(
t
.
Positions
[
2
],
t
.
Positions
[
0
],
t
.
Colors
[
2
]
,
t
.
Colors
[
0
]
);
}
}
#
endregion
#
endregion
...
...
URasterizer/Assets/URasterizer/Codes/RenderingConfig.cs
浏览文件 @
c265fe7b
...
@@ -9,4 +9,7 @@ public class RenderingConfig : ScriptableObject
...
@@ -9,4 +9,7 @@ public class RenderingConfig : ScriptableObject
public
bool
WireframeMode
=
false
;
public
bool
WireframeMode
=
false
;
public
bool
BackfaceCulling
=
true
;
public
bool
BackfaceCulling
=
true
;
public
bool
MSAA
=
false
;
public
bool
MSAA
=
false
;
[
Header
(
"Vertex Color Setting"
)]
public
Color
[]
VertexColors
;
}
}
URasterizer/Assets/URasterizer/Codes/RenderingObject.cs
浏览文件 @
c265fe7b
...
@@ -7,9 +7,6 @@ namespace URasterizer
...
@@ -7,9 +7,6 @@ namespace URasterizer
{
{
public
Mesh
mesh
;
public
Mesh
mesh
;
public
bool
DoubleSideRendering
;
public
bool
DoubleSideRendering
;
public
Color
Color0
=
Color
.
red
;
public
Color
Color1
=
Color
.
green
;
public
Color
Color2
=
Color
.
blue
;
private
void
Awake
()
private
void
Awake
()
{
{
...
...
URasterizer/Assets/URasterizer/RenderingConfig.asset
浏览文件 @
c265fe7b
...
@@ -16,3 +16,7 @@ MonoBehaviour:
...
@@ -16,3 +16,7 @@ MonoBehaviour:
WireframeMode
:
0
WireframeMode
:
0
BackfaceCulling
:
1
BackfaceCulling
:
1
MSAA
:
0
MSAA
:
0
VertexColors
:
-
{
r
:
1
,
g
:
0
,
b
:
0
,
a
:
1
}
-
{
r
:
0
,
g
:
1
,
b
:
0
,
a
:
1
}
-
{
r
:
0
,
g
:
0
,
b
:
1
,
a
:
1
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录