gpt4 book ai didi

android - OpenGL ES 2.0 奇怪的着色器故障

转载 作者:行者123 更新时间:2023-11-30 04:00:02 26 4
gpt4 key购买 nike

我从 android SDK 附带的 API 演示中复制了三角形渲染器,并将着色器替换为我自己的 raymarcher。然而,我遇到了有史以来最令人 NumPy 的故障,它似乎只影响红色。

这是我的着色器:

private final String fs =
" precision mediump float;\n"+
"uniform float t;\n"+
"varying vec2 vtex;\n"+
"mat3 genRotMat(float a0,float x,float y,float z){\n"+
" float a=a0*3.1415926535897932384626433832795/180.0;\n"+
" return mat3(\n"+
" 1.0+(1.0-cos(a))*(x*x-1.0),\n"+
" -z*sin(a)+(1.0-cos(a))*x*y,\n"+
" y*sin(a)+(1.0-cos(a))*x*z,\n"+
" z*sin(a)+(1.0-cos(a))*x*y,\n"+
" 1.0+(1.0-cos(a))*(y*y-1.0),\n"+
" -x*sin(a)+(1.0-cos(a))*y*z,\n"+
" -y*sin(a)+(1.0-cos(a))*x*z,\n"+
" x*sin(a)+(1.0-cos(a))*y*z,\n"+
" 1.0+(1.0-cos(a))*(z*z-1.0)\n"+
" );\n"+
"}\n"+
"float cubeDist(vec3 p){\n"+
" float t0 = 0.5;\n"+
" float t1 = 0.6;\n"+
" float max = max(abs(p.x),max(abs(p.y),abs(p.z)));\n"+
" if(max > t1) return 0.0;\n"+
" else if(max > t0) return (t1-max)/(t1-t0);\n"+
" else return 1.0;\n"+
"};\n"+
"void main() {\n"+
" float spread = 1.0;\n"+
" float val=0.0;\n"+
" float delta="+delta+";\n"+
" float cameraz="+cameraz+";\n"+
" float nearz="+nearz+";\n"+
" float farz="+farz+";\n"+
" float r=0.0,g=0.0,b=0.0;"+
" vec3 ray=vec3(0.0,0.0,0.0);\n"+
" mat3 rot=genRotMat(sin(t/3.13)*360.0,1.0,0.0,0.0);\n"+
" rot=rot*genRotMat(sin(t/3.64)*360.0,0.0,1.0,0.0);\n"+
" rot=rot*genRotMat(sin(t/3.24)*360.0,0.0,0.0,1.0);\n"+
" ray.z=nearz;\n"+
" ray.xy+=vtex.xy*spread*(nearz-cameraz);\n"+
" for(int i=0;i<"+iterations+";i++){\n"+
" vec3 temp;\n"+
" ray.xy+=vtex.xy*spread*delta;\n"+
" temp=ray*rot;\n"+
" val+=cubeDist(temp);\n"+
" r+=abs(temp.x*delta*delta*val);\n"+
" g+=abs(temp.y*delta*delta*val);\n"+
" b+=abs(temp.z*delta*delta*val);\n"+
" ray.z+=delta;\n"+
" }\n"+
" gl_FragColor=vec4(r,g,b,1.0);\n"+
"}\n";

这是故障图片:http://imgur.com/2zcps.png

整个文件在这里:http://pastebin.com/JF7rnSdE

最佳答案

弄清楚了,这不是编码问题,而是 nvidia 硬件/驱动程序方面完全未知的奇怪故障。

变化:

  "    r+=abs(temp.x*delta*delta*val);\n"+
" g+=abs(temp.y*delta*delta*val);\n"+
" b+=abs(temp.z*delta*delta*val);\n"+

到:

  "    g+=abs(temp.y*delta*delta*val);\n"+
" r+=abs(temp.x*delta*delta*val);\n"+
" b+=abs(temp.z*delta*delta*val);\n"+

由于一些完全未知的原因解决了问题。此外,更改 for 循环迭代长度似乎也会影响此故障。这可能是由于 for 循环展开所致。

关于android - OpenGL ES 2.0 奇怪的着色器故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12655092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com