SkillAgentSearch skills...

PystaMetalStudy

No description available

Install / Use

/learn @pome-ta/PystaMetalStudy
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

pystaMetalStudy

Pythonista 3 でMetal をチャレンジするリポリトリ

さまざまなサイトを参照しているので、参照URL などは、各ディレクトリ内に明記予定

以下列記は、実装日誌的なメモ

📝 2026/02/23

pystaRubiconObjcSandBox/playground/Metal/BeginningMetal at main · pome-ta/pystaRubiconObjcSandBox

rubicon でMetal を再度挑戦中。

📝 2023/10/19

過去の困りを確認しようとしても、困ってるお気持ちしか書いてないので、キャッチアップできない

困りのコードと、期待値と結果程度は残すようにしたい

src/everythingAboutTheMetalAPI/chapter04/sandbox/231019_0004.py

numpy で構造体を書いてみてる

サイズの取り方とか、どうかなぁ、、、

NumPy - Structured arrays

ヘッダーファイルの取り込み

目算がついていない

.metal に直書きにするとしても、cpu 側でのパスすることを確認しなければ、、、

[Metal]metalファイルをプリコンパイルしつつ実機でもコンパイルする #iOS - Qiita

[Metal]MTLLibraryをランタイムでコンパイルする #iOS - Qiita

User defined. What I typically do is 1) add some sensible defaults to the top of my shader code so that I can use a precompiled library if I choose: #ifndef THREADS_PER_THREADGROUP #define... - Matthew Kieber-Emmons - Medium

📝 2023/10/10

ui モジュール依存を剥がす

ちまちまと、やってく

📝 2022/10/07

simd 調査?

📝 2022/04/22

n0	simd::float3	(-0, -0.707106649, -0, -0)	
[0]	float	-0
[1]	float	-0.707106649
[2]	float	-0
[3]	float	-0
v0	simd::float3	(-0.25, 1.99000001, -0.25, 1)	
[0]	float	-0.25
[1]	float	1.99000001
[2]	float	-0.25
[3]	float	1
v1	simd::float3	(-0.25, 1.99000001, 0.25, 1)	
[0]	float	-0.25
[1]	float	1.99000001
[2]	float	0.25
[3]	float	1
v2	simd::float3	(0.25, 1.99000001, 0.25, 1)	
[0]	float	0.25
[1]	float	1.99000001
[2]	float	0.25
[3]	float	1
n1	simd::float3	(-0, -0.707106649, -0, -0)	
[0]	float	-0
[1]	float	-0.707106649
[2]	float	-0
[3]	float	-0
v3	simd::float3	(0.25, 1.99000001, -0.25, 1)	
[0]	float	0.25
[1]	float	1.99000001
[2]	float	-0.25
[3]	float	1
vertices	std::vector<float __attribute__((ext_vector_type(3))), std::allocator<float __attribute__((ext_vector_type(3)))> > &	size=6	0x00000001083dce80
[0]	float __attribute__((ext_vector_type(3)))	(-0.25, 1.99000001, -0.25, 1)	
[1]	float __attribute__((ext_vector_type(3)))	(-0.25, 1.99000001, 0.25, 1)	
[2]	float __attribute__((ext_vector_type(3)))	(0.25, 1.99000001, 0.25, 1)	
[3]	float __attribute__((ext_vector_type(3)))	(-0.25, 1.99000001, -0.25, 1)	
[4]	float __attribute__((ext_vector_type(3)))	(0.25, 1.99000001, 0.25, 1)	
[5]	float __attribute__((ext_vector_type(3)))	(0.25, 1.99000001, -0.25, 1)	
normals	std::vector<float __attribute__((ext_vector_type(3))), std::allocator<float __attribute__((ext_vector_type(3)))> > &	size=6	0x00000001045c6e98


[0]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	
[1]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	
[2]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	
[3]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	
[4]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	
[5]	float __attribute__((ext_vector_type(3)))	(-0, -0.707106649, -0, -0)	

colors	std::vector<float __attribute__((ext_vector_type(3))), std::allocator<float __attribute__((ext_vector_type(3)))> > &	size=6	0x00000001045c6eb0
[0]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
[1]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
[2]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
[3]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
[4]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
[5]	float __attribute__((ext_vector_type(3)))	(1, 1, 1, 0)	
color	simd::float3	(1, 1, 1, 0)	

📝 2021/12/11

delegate

__main__.py でのaddSubview_ は、class 定義したview を呼び出す

self.objc_instance.addSubview_({classのview})

simd の演算

objc

cubeVertices	simd::float3 [8]	
  [0]	simd::float3	(-0.25, 0.00999999046, -0.25, 1)	
  [1]	simd::float3	(0.25, 0.00999999046, -0.25, 1)	
  [2]	simd::float3	(-0.25, 1.99000001, -0.25, 1)	
  [3]	simd::float3	(0.25, 1.99000001, -0.25, 1)	
  [4]	simd::float3	(-0.25, 0.00999999046, 0.25, 1)	
  [5]	simd::float3	(0.25, 0.00999999046, 0.25, 1)	
  [6]	simd::float3	(-0.25, 1.99000001, 0.25, 1)	
  [7]	simd::float3	(0.5, 0.5, 0.5, 0)	

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [-0.5000, -0.5000, -0.5000, 1.0000]
matrixMULvertex: Vector4:
  [-0.2500, -0.9900, -0.2500, 0.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [0.5000, -0.5000, -0.5000, 1.0000]
matrixMULvertex: Vector4:
  [0.2500, -0.9900, -0.2500, 0.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [-0.5000, 0.5000, -0.5000, 1.0000]
matrixMULvertex: Vector4:
  [-0.2500, 0.9900, -0.2500, 1.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [0.5000, 0.5000, -0.5000, 1.0000]
matrixMULvertex: Vector4:
  [0.2500, 0.9900, -0.2500, 1.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [-0.5000, -0.5000, 0.5000, 1.0000]
matrixMULvertex: Vector4:
  [-0.2500, -0.9900, 0.2500, 0.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [0.5000, -0.5000, 0.5000, 1.0000]
matrixMULvertex: Vector4:
  [0.2500, -0.9900, 0.2500, 0.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [-0.5000, 0.5000, 0.5000, 1.0000]
matrixMULvertex: Vector4:
  [-0.2500, 0.9900, 0.2500, 1.5000]

transform: Matrix4:
  [0.5000, 0.0000, 0.0000, 0.0000]
  [0.0000, 1.9800, 0.0000, 0.0000]
  [0.0000, 0.0000, 0.5000, 0.0000]
  [0.0000, 1.0000, 0.0000, 1.0000]
transformedVertex: Vector4:
  [0.5000, 0.5000, 0.5000, 1.0000]
matrixMULvertex: Vector4:
  [0.2500, 0.9900, 0.2500, 1.5000]

📝 2021/12/06

前回のmatrix の素材をうまく生かしながら

実装をしていく予定!

ローテート関係が、ちょっと手こずりそう?

ray tracing チャレンジ

数値のlog 取り

testTransform

float4x4 testTransform = matrix4x4_translation(0.3275f, 0.3f, 0.3725f);
Printing description of testTransform:
(simd::float4x4) testTransform = {
  simd_float4x4 = {
    columns = {
      [0] = (1, 0, 0, 0)
      [1] = (0, 1, 0, 0)
      [2] = (0, 0, 1, 0)
      [3] = (0.327499986, 0.300000012, 0.372500002, 1)
    }
  }
}

testScale

float4x4 testScale = matrix4x4_scale(0.6f, 0.6f, 0.6f);
Printing description of testScale:
(simd::float4x4) testScale = {
  simd_float4x4 = {
    columns = {
      [0] = (0.600000024, 0, 0, 0)
      [1] = (0, 0.600000024, 0, 0)
      [2] = (0, 0, 0.600000024, 0)
      [3] = (0, 0, 0, 1)
    }
  }
}

testRotation

float4x4 testRotation = matrix4x4_rotation(-0.3f, vector3(0.0f, 1.0f, 0.0f));
Printing description of testRotation:
(simd::float4x4) testRotation = {
  simd_float4x4 = {
    columns = {
      [0] = (0.955336511, 0, 0.295520186, 0)
      [1] = (0, 1, 0, 0)
      [2] = (-0.295520186, 0, 0.955336511, 0)
      [3] = (0, 0, 0, 1)
    }
  }
}

transform

transform = matrix4x4_translation(0.3275f, 0.3f, 0.3725f) *
            matrix4x4_rotation(-0.3f, vector3(0.0f, 1.0f, 0.0f)) *
            matrix4x4_scale(0.6f, 0.6f, 0.6f);
Printing description of transform:
(simd::float4x4) transform = {
  simd_float4x4 = {
    columns = {
      [0] = (0.573201954, 0, 0.177312121, 0)
      [1] = (0, 0.600000024, 0, 0)
      [2] = (-0.177312121, 0, 0.573201954, 0)
      [3] = (0.327499986, 0.300000012, 0.372500002, 1)
    }
  }
}
    float4x4 transform = matrix4x4_translation(0.0f, 1.0f, 0.0f) *
                         matrix4x4_scale(0.5f, 1.98f, 0.5f);
Printing description of transform:
(simd::float4x4) transform = {
  simd_float4x4 = {
    columns = {
      [0] = (0.5, 0, 0, 0)
      [1] = (0, 1.98000002, 0, 0)
      [2] = (0, 0, 0.5, 0)
      [3] = (0, 1, 0, 1)
    }
  }
}
    transform = matrix4x4_translation(0.0f, 1.0f, 0.0f) * matrix4x4_scale(2.0f, 2.0f, 2.0f);
Printing description of transform:
(simd::float4x4) transform = {
  simd_float4x4 = {
    columns = {
      [0] = (2, 0, 0, 0)
      [1] = (0, 2, 0, 0)
      [2] = (0, 0, 2, 0)
      [3] = (0, 1, 0, 1)
    }
  }
}

📝 2021/12/01

構造体をShader に投げると、メモリ(?)がズレる問題

Shaderコードを直接イジる

  • float3
  • float
  • float3
  • float

の構造を、

struct Light {
  float3 color;
  float ambientIntensity;
  float diffuseIntensity;
  float3 direction;
};
  • float4
    • float3 + float
  • float4
    • float3 + float

と、まとめてShader.metal 上で、分解する

float3 light_color = float3(light.color.x, light.color.y, light.color.z);
float light_ambientIntensity = float(light.color.w);
float3 ambientColor = light_color * light_ambientIntensity;
  

📝 2021/11/29

Light の構造体が、Shader.metal で読めてない件

color は読めているが、ambientIntensity に参照できていない

cl
View on GitHub
GitHub Stars5
CategoryDevelopment
Updated28d ago
Forks0

Languages

Python

Security Score

85/100

Audited on Feb 24, 2026

No findings