简体   繁体   English

GLSL 1.0.0 - 在顶点和片段着色器中使用“变化”时遇到麻烦

[英]GLSL 1.0.0 - Trouble using “Varying” in vertex and fragment shaders

I'm developing using OpenGL ES 2.0.0 and GLSL ES 1.0.0. 我正在使用OpenGL ES 2.0.0和GLSL ES 1.0.0进行开发。

Currently I'm rendering a square to screen to the screen, and now attempting to apply a texture. 目前我正在渲染一个正方形来筛选屏幕,现在尝试应用纹理。

I'm having trouble using " varying " in vertex and fragment shaders, receiving the error message: 我在顶点和片段着色器中使用“ 变化 ”时遇到问题,收到错误消息:

- Failed to compile vertex shader - 
0(3) : error C5060: out can't be used with non-varying tex_varying

in vec4 texture_coord ;
in vec4 position ;
out vec2 tex_varying ;
uniform mat4 translate ;
void main ( ) 
{
  gl_Position = translate * position ;
  tex_varying = texture_coord . xy ;
}

I've read through the documentation and can't figure out what I'm doing wrong. 我已经阅读了文档,无法弄清楚我做错了什么。

Here's the code. 这是代码。

Vertex: 顶点:

attribute vec4 position; 
attribute vec4 texture_coord; 
varying vec2 tex_varying; 
uniform mat4 translate; 

void main()
{ 
  gl_Position = translate * position; 
  tex_varying = texture_coord.xy;
}

Fragment: 分段:

varying vec2 tex_varying; 
uniform sampler2D texture; 

void main()
{
  gl_FragColor = texture2D(texture, tex_varying);
}

RESOLVED: This is a late reply, but I ended up solving this problem a long time ago - in case anyone else stumbles across the issue. 决议:这是一个迟到的回复,但我很久以前就解决了这个问题 - 万一其他人偶然发现了这个问题。 It turns out "tex_varying" is reserved by Nvidia! 事实证明,“tex_varying”是由Nvidia保留的! Simply renaming tex_varying solved the issue. 简单地重命名tex_varying解决了这个问题。

Cheers. 干杯。

The in and out keywords as you show them are for GLSL v3 and later. inout关键字,你告诉他们是GLSL v3和更高版本。 For v1 (which is what you're trying to use?) you need to replace in with attribute and out with varying in the vertex shader. 对于v1(你正在尝试使用它?),你需要用attribute替换in ,并在顶点着色器中varying out In the fragment shader, replace in with varying and you can't use out -- you need to output to gl_FragColor as you seem to be doing. 在片段着色器,替换invarying ,你不能用out -你需要输出到gl_FragColor你似乎做的事情。

So your 2nd/3rd shaders look like you've correctly translated the GLSL v3 code in the first shader to GLSL v1, and look like they should work with ES2/GLSL v1 所以你的第二个/第三个着色器看起来你已经正确地将第一个着色器中的GLSL v3代码翻译成GLSL v1,看起来它们应该与ES2 / GLSL v1一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM