Skip to content

feat: add material perspective quad#73

Open
yuchanns wants to merge 2 commits intocloudwu:masterfrom
yuchanns:feat/material-projection
Open

feat: add material perspective quad#73
yuchanns wants to merge 2 commits intocloudwu:masterfrom
yuchanns:feat/material-projection

Conversation

@yuchanns
Copy link
Contributor

@yuchanns yuchanns commented Feb 9, 2026

see #69
参考讨论内容, 试着实现了四边形透视材质.

  1. 添加 soluna.material.perspective_quad 模块以及一个 matpq.sprite api.
  2. 添加 test/perspective_quad.lua 测试, 预览地址: https://yuchanns.github.io/soluna/examples/perspective_quad/
  3. 参考仓库现有的 lua 代码风格定义了 .editorconfig (主要是方便像我这样使用 emmylua 自动格式化的开发者), 顺便格式化了下 test/ 之前被我破坏的两个测试文件的代码格式.

@yuchanns yuchanns force-pushed the feat/material-projection branch from 6b28077 to bcfb134 Compare February 9, 2026 06:21
}
if (get_bool_field(L, 2, "flip_y", 0)) {
info |= PQUAD_INFO_FLIP_Y;
}
Copy link
Owner

@cloudwu cloudwu Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码我还没有太仔细看。不过这里我有点疑问:通常都是用负的 scale_x 实现 flip_x ,用负的 scale_y 实现 flip_y 。因为用矩阵做变换时,就是将 scale_x 设为 -1 实现镜像的。

这里需要额外的 flip_x/flip_y 参数吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你说的有道理, 我改一下。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale 为负数时,是不是下面计算 struct corner_primitive prim[PQUAD_CORNER_N] 的时候,就自然镜像了呀?(但好像需要把对称轴线调整一下)

比如把 scale_x 设为 -1 ,那么在计算 tx 的时候就是负的。左右两个点就换过来了。在光栅化的时候就镜像了。
如果在这里就把 prim 都算好的吧,看起来 submit 那里就不需要额外做判断去处理。

不过,如果这样做,感觉需要确保 cull_mode 为 SG_CULLMODE_NONE ( sokol 的确以这个为默认值, soluna 没有额外设置)

@yuchanns yuchanns force-pushed the feat/material-projection branch 2 times, most recently from 4791f3a to d9442be Compare February 9, 2026 08:25
@yuchanns yuchanns force-pushed the feat/material-projection branch from d9442be to eecdb0f Compare February 9, 2026 08:38
@yuchanns yuchanns requested a review from cloudwu February 9, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants