从浮充转换为INT(怪异的行为) [英] conversion from float to int (weird behavior)
问题描述
我有这样的着色器来实现角色动画
I have this shader to implement character animation
uniform mat4 u_mVxP;
uniform mat4 u_mBlendMatrices[54];
uniform vec4 u_vDLDiffuseColor;
uniform vec4 u_vDLAmbientColor;
uniform vec3 u_vLightDir;
attribute vec4 a_Position;
attribute vec3 a_BWeights;
attribute vec3 a_BIndices;
attribute vec3 a_Normal;
attribute vec2 a_TextureCoordinates;
varying vec2 v_TextureCoordinates;
varying vec4 v_Color;
void main()
{
vec4 vPos;
vec3 vNormal;
int i=int(a_BIndices.x);
int j=int(a_BIndices.y);
int k=int(a_BIndices.z);
vPos=a_BWeights.x * a_Position * u_mBlendMatrices[i];
vPos+=a_BWeights.y * a_Position * u_mBlendMatrices[j];
vPos+=a_BWeights.z * a_Position * u_mBlendMatrices[k];
vNormal=a_BWeights.x * vec3(vec4(a_Normal,0.0) * u_mBlendMatrices[i]);
vNormal+=a_BWeights.y * vec3(vec4(a_Normal,0.0) * u_mBlendMatrices[j]);
vNormal+=a_BWeights.z * vec3(vec4(a_Normal,0.0) * u_mBlendMatrices[k]);
vNormal = normalize(vNormal);
v_Color = u_vDLDiffuseColor * max(dot(-u_vLightDir,vNormal),0.0) + u_vDLAmbientColor;
gl_Position = vPos * u_mVxP;
v_TextureCoordinates = a_TextureCoordinates;
}
code运行完美的银河S3和S4和我的角色有正确的动画thier。
但在索尼Xperia Z和银河注3它们只呈现在POS绑定,没有动画!
大量的测试后,我发现,当浮在转换XPERIA z和银河注3只返回INT 0
code runs perfect on galaxy s3 and s4 and my characters have thier animation correctly. but in sony xperia Z and galaxy note3 they are rendered only in bind pos with no animation! after a lot of test i found out that when float converts to int in xperia z and galaxy note3 it only return 0
int i=int(a_BIndices.x); // i is always 0
int j=int(a_BIndices.y); // j is always 0
int k=int(a_BIndices.z); // k is always 0
我甚至用这个code
i even used this code
int i=1;
但我仍然是0。任何人都可以帮我这是怎么回事
but i is still 0. could anyone help me what is going on
推荐答案
我终于找到了我应该用vec4阵列代替矩阵阵列的!
其奇怪,但解决了我的情况。
I finally found out that i should use vec4 array instead of matrix array! its weird but solved my case
这篇关于从浮充转换为INT(怪异的行为)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!