mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-01 00:02:45 +03:00
feat: Add texture matrix transform support to Metal shaders for animated textures
This commit is contained in:
parent
7cf7127810
commit
8935c520c0
@ -236,6 +236,18 @@ namespace {
|
||||
" float pointSize;\n"
|
||||
" float pad[3];\n"
|
||||
"};\n"
|
||||
"// Transform UV using texture matrix from vertex constants\n"
|
||||
"// Texture matrix 0: vc[6] and vc[7] (2 rows for tex unit 0)\n"
|
||||
"// Texture matrix 1: vc[8] and vc[9] (2 rows for tex unit 1)\n"
|
||||
"float2 transformTexCoord(float2 uv, constant float4* vc, uint unit) {\n"
|
||||
" uint base = 6 + unit * 2;\n"
|
||||
" float4 row0 = vc[base];\n"
|
||||
" float4 row1 = vc[base + 1];\n"
|
||||
" // Check if matrix is uninitialized (identity placeholder)\n"
|
||||
" if (row0.x > 1e30) return uv;\n"
|
||||
" float4 uvw = float4(uv, 0.0, 1.0);\n"
|
||||
" return float2(dot(uvw, row0), dot(uvw, row1));\n"
|
||||
"}\n"
|
||||
"vertex VertexOut vs_color(VertexColorIn in [[stage_in]], constant VSConstants& c [[buffer(1)]]) {\n"
|
||||
" VertexOut out;\n"
|
||||
" float4 pos4 = c.mvp * float4(in.position, 1.0);\n"
|
||||
@ -247,46 +259,46 @@ namespace {
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
"}\n"
|
||||
"vertex VertexOut vs_tex(VertexTexIn in [[stage_in]], constant VSConstants& c [[buffer(1)]]) {\n"
|
||||
"vertex VertexOut vs_tex(VertexTexIn in [[stage_in]], constant VSConstants& c [[buffer(1)]], constant float4* vc [[buffer(2)]]) {\n"
|
||||
" VertexOut out;\n"
|
||||
" float4 pos4 = c.mvp * float4(in.position, 1.0);\n"
|
||||
" out.position = pos4;\n"
|
||||
" out.color = float4(1.0, 1.0, 1.0, 1.0);\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
"}\n"
|
||||
"vertex VertexOut vs_tex2(VertexTex2In in [[stage_in]], constant VSConstants& c [[buffer(1)]]) {\n"
|
||||
"vertex VertexOut vs_tex2(VertexTex2In in [[stage_in]], constant VSConstants& c [[buffer(1)]], constant float4* vc [[buffer(2)]]) {\n"
|
||||
" VertexOut out;\n"
|
||||
" float4 pos4 = c.mvp * float4(in.position, 1.0);\n"
|
||||
" out.position = pos4;\n"
|
||||
" out.color = float4(1.0, 1.0, 1.0, 1.0);\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord1;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord1, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
"}\n"
|
||||
"vertex VertexOut vs_color_tex(VertexColorTexIn in [[stage_in]], constant VSConstants& c [[buffer(1)]]) {\n"
|
||||
"vertex VertexOut vs_color_tex(VertexColorTexIn in [[stage_in]], constant VSConstants& c [[buffer(1)]], constant float4* vc [[buffer(2)]]) {\n"
|
||||
" VertexOut out;\n"
|
||||
" float4 pos4 = c.mvp * float4(in.position, 1.0);\n"
|
||||
" out.position = pos4;\n"
|
||||
" out.color = in.color;\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
"}\n"
|
||||
"vertex VertexOut vs_color_tex2(VertexColorTex2In in [[stage_in]], constant VSConstants& c [[buffer(1)]]) {\n"
|
||||
"vertex VertexOut vs_color_tex2(VertexColorTex2In in [[stage_in]], constant VSConstants& c [[buffer(1)]], constant float4* vc [[buffer(2)]]) {\n"
|
||||
" VertexOut out;\n"
|
||||
" float4 pos4 = c.mvp * float4(in.position, 1.0);\n"
|
||||
" out.position = pos4;\n"
|
||||
" out.color = in.color;\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord1;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord1, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
@ -356,8 +368,8 @@ namespace {
|
||||
" float4 emissive = vc[29];\n"
|
||||
" float4 color = diffuse + emissive;\n"
|
||||
" out.color = (diffuse.x > 1e30) ? float4(1.0, 1.0, 1.0, 1.0) : color;\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
@ -386,8 +398,8 @@ namespace {
|
||||
" float4 emissive = vc[29];\n"
|
||||
" float4 color = diffuse + emissive;\n"
|
||||
" out.color = (diffuse.x > 1e30) ? float4(1.0, 1.0, 1.0, 1.0) : color;\n"
|
||||
" out.texcoord = in.texcoord;\n"
|
||||
" out.texcoord1 = in.texcoord1;\n"
|
||||
" out.texcoord = transformTexCoord(in.texcoord, vc, 0);\n"
|
||||
" out.texcoord1 = transformTexCoord(in.texcoord1, vc, 1);\n"
|
||||
" out.viewZ = pos4.w;\n"
|
||||
" out.pointSize = c.pointSize;\n"
|
||||
" return out;\n"
|
||||
@ -1242,7 +1254,9 @@ void CGxDeviceMTL::Draw(CGxBatch* batch, int32_t indexed) {
|
||||
|
||||
[encoder setVertexBuffer:mtlVertexBuf offset:vertexBuf->m_index atIndex:0];
|
||||
[encoder setVertexBytes:&vsConsts length:sizeof(vsConsts) atIndex:1];
|
||||
if (useSkin) {
|
||||
// Pass vertex constants for texture matrix transforms (needed for animated textures)
|
||||
// and skinning. All texture shaders now use buffer(2) for texture matrix lookup.
|
||||
if (useSkin || useTex) {
|
||||
[encoder setVertexBytes:CGxDevice::s_shadowConstants[1].constants
|
||||
length:sizeof(CGxDevice::s_shadowConstants[1].constants)
|
||||
atIndex:2];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user