## understanding shader mat4 * vec4 calculation​ 转

a
aspirs

understanding shader mat4 * vec4 calculation

can someone confirm following calculation, please? :)

in normal android opengl shader the computation:

``````mat4 a;
vec3 p;

vec3 pos = (a * vec4(p,1.0)).xyz;``````

would be calculated like this:

``````pos.x = a0 * p.x + a1 * p.y + a2 * p.z + a3 * 1.0;
pos.y = a4 * p.x + a5 * p.y + a6 * p.z + a7 * 1.0;
pos.z = a8 * p.x + a9 * p.y + a10 * p.z + a11 * 1.0;``````

is this correct? or did I miss something? every help is highly appreciated.

answer1:

Ok actually I've found a reliable source: http://www.khronos.org/files/opengles_shading_language.pdf

``````vec3 v, u;
mat3 m;``````

And

``u = m * v;``

is equivalent to

``````u.x = m.x * v.x  +  m.x * v.y  +  m.x * v.z;
u.y = m.y * v.x  +  m.y * v.y  +  m.y * v.z;
u.z = m.z * v.x  +  m.z * v.y  +  m.z * v.z;``````

Therefore

``````vec3 v, u;
mat4 m;``````

And

``u = (mat * vec4(v,1.0)).xyz``

should be equivalent to

``````u.x = m.x * v.x  +  m.x * v.y  +  m.x * v.z + m.x * 1;
u.y = m.y * v.x  +  m.y * v.y  +  m.y * v.z + m.y * 1;
u.z = m.z * v.x  +  m.z * v.y  +  m.z * v.z + m.z * 1;``````

Please correct me if I'm wrong though.

a

### aspirs

FreeBlues
2016/07/17
17
0
xcode 7.2.1 新建cocos2d项目 运行报错

Warning: Error creating LLDB target at path '/Users/sweetieTAM/Library/Developer/Xcode/DerivedData/GP_CrazyForest_v2.0-ffxxxkrfizurpfgqrvqonkczmogo/Build/Products/Debug-iphonesi......

2016/02/21
1K
1
[Qt和GLSL的笔记4] GLSL基本语法和数据类型

Mahabharata_
2017/04/21
0
0
vsh(顶点着色器),.fsh(片段着色器)

AGLKPointParticleShader.vsh //顶点着色器。 // VERTEX ATTRIBUTES attribute vec3 a_emissionPosition; //位置 attribute vec3 a_emissionVelocity; //速度 attribute vec3 a_emissionFor......

iOS技术者
2017/09/17
0
0

FreeBlues
2016/07/26
24
0

Linux就该这么学
29分钟前
2
0

https://blog.csdn.net/Blockchain_lemon/article/details/80589123

Moks角木

3
0

4
0

wanxiangming

1
0
CentOS7安装xrdp环境可实现远程桌面访问

CentOS7安装xrdp环境可实现远程桌面访问 2018-07-14 06:39:28 分类：运维 阅读(2051) 评论(0) 在"Ubuntu系统安装xrdp桌面客户端及实现远程连接桌面"文章中有分享过在Ubuntu系统中安装XRDP环境...

linjin200

5
0 