Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
n5
URasterizer
提交
63113236
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 搜索 >>
提交
63113236
编写于
2月 06, 2022
作者:
H
happyfire
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
comments
上级
22c69985
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
10 deletion
+14
-10
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
+14
-10
未找到文件。
URasterizer/Assets/URasterizer/Codes/Rasterizer.cs
浏览文件 @
63113236
...
@@ -159,7 +159,7 @@ namespace URasterizer
...
@@ -159,7 +159,7 @@ namespace URasterizer
//2. 三角形顶点环绕方向从顺时针改成逆时针
//2. 三角形顶点环绕方向从顺时针改成逆时针
//
vertex shader
//
/ ------------- Vertex Shader -------------------
Vector4
[]
csVertices
=
new
Vector4
[
mesh
.
vertexCount
];
//clip space vertices
Vector4
[]
csVertices
=
new
Vector4
[
mesh
.
vertexCount
];
//clip space vertices
for
(
int
i
=
0
;
i
<
mesh
.
vertexCount
;
++
i
)
for
(
int
i
=
0
;
i
<
mesh
.
vertexCount
;
++
i
)
{
{
...
@@ -170,7 +170,9 @@ namespace URasterizer
...
@@ -170,7 +170,9 @@ namespace URasterizer
var
indices
=
mesh
.
triangles
;
var
indices
=
mesh
.
triangles
;
for
(
int
i
=
0
;
i
<
indices
.
Length
;
i
+=
3
)
for
(
int
i
=
0
;
i
<
indices
.
Length
;
i
+=
3
)
{
{
/// -------------- Primitive Assembly -----------------
//注意这儿对调了v0和v1的索引,因为原来的 0,1,2是顺时针的,对调后是 1,0,2是逆时针的
//注意这儿对调了v0和v1的索引,因为原来的 0,1,2是顺时针的,对调后是 1,0,2是逆时针的
//Unity Quard模型的两个三角形索引分别是 0,3,1,3,0,2 转换后为 3,0,1,0,3,2
//Unity Quard模型的两个三角形索引分别是 0,3,1,3,0,2 转换后为 3,0,1,0,3,2
int
idx0
=
indices
[
i
+
1
];
int
idx0
=
indices
[
i
+
1
];
...
@@ -185,14 +187,15 @@ namespace URasterizer
...
@@ -185,14 +187,15 @@ namespace URasterizer
};
};
//
do clipping
//
------ Clipping -------
if
(
Clipped
(
v
))
if
(
Clipped
(
v
))
{
{
continue
;
continue
;
}
}
//clip space to NDC (Perspective division)
// ------- Perspective division --------
for
(
int
k
=
0
;
k
<
3
;
k
++)
//clip space to NDC
for
(
int
k
=
0
;
k
<
3
;
k
++)
{
{
v
[
k
].
x
/=
v
[
k
].
w
;
v
[
k
].
x
/=
v
[
k
].
w
;
v
[
k
].
y
/=
v
[
k
].
w
;
v
[
k
].
y
/=
v
[
k
].
w
;
...
@@ -216,8 +219,8 @@ namespace URasterizer
...
@@ -216,8 +219,8 @@ namespace URasterizer
++
_trianglesRendered
;
++
_trianglesRendered
;
// ------- Viewport Transform ----------
//NDC to screen space
, viewport transform
//NDC to screen space
for
(
int
k
=
0
;
k
<
3
;
k
++)
for
(
int
k
=
0
;
k
<
3
;
k
++)
{
{
var
vec
=
v
[
k
];
var
vec
=
v
[
k
];
...
@@ -260,7 +263,7 @@ namespace URasterizer
...
@@ -260,7 +263,7 @@ namespace URasterizer
t
.
SetColor
(
2
,
Color
.
white
);
t
.
SetColor
(
2
,
Color
.
white
);
}
}
//
Rasterization
//
/ ---------- Rasterization -----------
if
(
_config
.
WireframeMode
)
if
(
_config
.
WireframeMode
)
{
{
RasterizeWireframe
(
t
);
RasterizeWireframe
(
t
);
...
@@ -299,6 +302,7 @@ namespace URasterizer
...
@@ -299,6 +302,7 @@ namespace URasterizer
}
}
#
region
Wireframe
mode
#
region
Wireframe
mode
//Breshham算法画线,颜色使用线性插值(非透视校正)
private
void
DrawLine
(
Vector3
begin
,
Vector3
end
,
Color
colorBegin
,
Color
colorEnd
)
private
void
DrawLine
(
Vector3
begin
,
Vector3
end
,
Color
colorBegin
,
Color
colorEnd
)
{
{
int
x1
=
Mathf
.
FloorToInt
(
begin
.
x
);
int
x1
=
Mathf
.
FloorToInt
(
begin
.
x
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录