jjzjj

ios - 片段着色器未读取顶点着色器 'colorVarying' 的输出

coder 2024-01-21 原文

如下图,报错很奇怪。我在我的 iPad 程序中使用了 OpenGLES 2.0 和着色器,但似乎代码或项目配置出了问题。模型完全没有颜色(黑色)绘制。

2012-12-01 14:21:56.707 medicare[6414:14303] Program link log:
WARNING: Could not find vertex shader attribute 'color' to match BindAttributeLocation request.
WARNING: Output of vertex shader 'colorVarying' not read by fragment shader
[Switching to process 6414 thread 0x1ad0f]

我使用 glBindAttibLocation 来传递位置和正常数据,如下所示:

// This needs to be done prior to linking.
glBindAttribLocation(_program, INDEX_POSITION, "position");
glBindAttribLocation(_program, INDEX_NORMAL, "normal");

glBindAttribLocation(_program, INDEX_COLOR, "color"); //pass color to shader

我的项目中有两个着色器。那么这个奇怪的错误有什么好的解决方案吗?非常感谢!

我的顶点着色器:

uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;

attribute vec4 position;
attribute vec3 normal;
attribute vec4 color;

varying lowp vec4 DestinationColor;
void main()
{
    //vec4 a_Color = vec4(0.9, 0.4, 0.4, 1.0);
    vec4 a_Color = color;
    vec3 u_LightPos = vec3(1.0, 1.0, 2.0);

    float distance = 2.4;
    vec3 eyeNormal=normalize(normalMatrix * normal);

    float diffuse = max(dot(eyeNormal, u_LightPos), 0.0); // remove approx ambient light
    diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance)));
    DestinationColor = a_Color * diffuse; // average between ambient and diffuse   a_Color * (diffuse + 0.3)/2.0;

    gl_Position = modelViewProjectionMatrix * position;
}

我的片段着色器是:

varying lowp vec4 DestinationColor;

void main()
{
  gl_FragColor = DestinationColor;
}

很简单。非常感谢!

最佳答案

我认为这里有一些问题。首先,您对属性的使用可能不正确。一个属性就像一个元素,随着每个顶点的变化而变化。你的数据结构中是否有颜色作为元素?否则,着色器将无法正常工作。

And I use glBindAttibLocation to pass position and normal data like this:

不,你不知道。 glBindAttribLocation “将通用顶点属性索引与命名属性变量相关联”。它不传递数据。它将索引(闪烁)与变量相关联。您稍后可以通过以下方式传递内容:glVertexAttribPointer。

我什至不使用绑定(bind)..我这样做 - 设置属性:

glAttributes[PROGNAME][A_vec3_vertexPosition] = glGetAttribLocation(glPrograms[PROGNAME],   "a_vertexPosition");
glEnableVertexAttribArray(glAttributes[PROGNAME][A_vec3_vertexPosition]);

然后在调用 glDrawElemetns 之前将您的指针传递给它,以便它可以获取数据:

glVertexAttribPointer(glAttributes[PROGNAME][A_vec3_vertexPosition], 3, GL_FLOAT, GL_FALSE, stride, (void *) 0);

我正在使用一个名为 glAttributes 的二维整数数组来保存我所有的属性索引。但是您可以像现在这样使用闪烁。

错误消息告诉您出了什么问题。在你的顶点着色器中你说:

attribute vec4 color;

但是下面还有一个 a_Color:

DestinationColor = a_Color * diffuse;

与您的变量名称保持一致。我现在把 a_ v_ 和 u_ 放在我所有变量的前面,试图弄清楚它是什么类型的变量。你所说的 a_ 确实有所不同。

我还怀疑错误消息不是来自您发布的相同版本的着色器和代码,因为错误:

WARNING: Output of vertex shader 'colorVarying' not read by fragment shader

关于 colorVarying 的错误令人困惑,因为它甚至不在您的顶点着色器的这个版本中。重新发布着色器的当前版本和您从中获得的错误消息,这将更容易为您提供帮助。

关于ios - 片段着色器未读取顶点着色器 'colorVarying' 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13657076/

有关ios - 片段着色器未读取顶点着色器 'colorVarying' 的输出的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  5. ruby - 在 jRuby 中使用 'fork' 生成进程的替代方案? - 2

    在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',

  6. ruby - 通过 erb 模板输出 ruby​​ 数组 - 2

    我正在使用puppet为ruby​​程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby​​不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这

  7. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  8. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  9. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

  10. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

随机推荐