OpenGL ES漫反射着色器不起作用 [英] Opengl ES diffuse shader not working

查看:170
本文介绍了OpenGL ES漫反射着色器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为片段着色器中的球实现简单的光线跟踪,并且我目前正在研究为扩散阴影球计算颜色的函数.这是该函数的代码:

I'm implementing simple ray tracing for spheres in a fragment shader and I'm currently working on the function that computes color for a diffusely shaded sphere. Here is the code for the function:

vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material) {
      vec3 color = vec3(1.,2.,3.);
      vec3 N = (point - sphere.xyz) / sphere.w;
      vec3 diffuse = max(dot(Ldir, N), 0.0);
      vec3 ambient = material/5;
      color = ambient   + Lrgb * diffuse *  max(0.0, N * Ldir);
      return color;
   }

我在使用max函数的两行出现错误.我从使用功能max(dot(ec_light_dir, ec_normal), 0.0);的webgl备忘单中获得了分配max(dot(Ldir,N),0.0)的行的代码 由于某种原因,由于出现错误,我的实现无法正常工作:

I'm getting errors on the two lines where I'm using the max function. I got the code for the line where I'm assigning max(dot(Ldir,N),0.0) from the webgl cheat sheet which uses the function max(dot(ec_light_dir, ec_normal), 0.0); For some reason, my implementation is not working as I'm getting the error:

ERROR: 0:38: 'max' : no matching overloaded function found

我正在使用的这些max函数中的任何一个可能是什么问题?

What could be the problem with either of the these max functions I'm using?

推荐答案

着色器中有2个max语句.是第二个问题了

There's 2 max statements in your shader. It's the 2nd one that's the problem

max(0.0, N * LDir)没有任何意义. N是vec3.没有使用max(float, vec3)max版本.有 max的版本,是max(vec3, float),因此将其替换为

max(0.0, N * LDir) makes no sense. N is a vec3. There's no version of max that takes max(float, vec3). There is a version of max that's max(vec3, float) so swap that to be

`max(N * LDir, 0.0)`

,它可能会起作用.基本上,您的着色器是的ES 2.0着色器.可能是在不符合规范的驱动程序上使用了该驱动程序(即,该驱动程序存在错误). WebGL尝试遵循100%的规范

and it might work. Basically your shader is NOT an ES 2.0 shader. Maybe it's being used on a driver that is not spec compliant (ie, the driver has a bug). WebGL tries to follow the spec 100%

这篇关于OpenGL ES漫反射着色器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆