将数据传递到不同的着色器 [英] Passing data into different shaders
问题描述
可以说我的Shader程序包含一个Vertex-和Fragmentshader.
Lets say my Shaderprogram contains a Vertex- and a Fragmentshader.
我如何直接将信息传递给碎片破碎机?
How can i pass information straight to the fragmentshader?
当我使用gl_uniform ...并指定要在脆弱的着色器中处理的变量时,会向我抛出这样的错误:
When i Use gl_uniform... and specifiy the varaible I want to adress inside the fragmet shader it throws me an error like this:
Using ShaderProgram: The fragment shader uses varying myVarHere, but previous
shader doesnot write to it.
由于我先附加了顶点着色器,所以我发现我需要使用in和out将信息传递"通过顶点着色器.
Since I attach the vertexshader first, I found out that I need to "pass the information through" the vertex shader using in and out.
我不确定这是否可行,所以我的问题是:有没有办法告诉opengl在某个着色器中处理变量,还是我在做/理解一些可怕的错误?
Im not sure if this is the way to go, so my question: Is there a way to tell opengl to adress the variable in a certain shader or am I doing / understanding something horribly wrong?
VertexShader:
VertexShader:
#version 130
precision highp float;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
in vec3 vertexData;
in vec3 normalData;
out vec3 normal;
void main(void)
{
normal = (model * view * vec4(normalData, 0)).xyz;
gl_Position = projection * model * view * vec4(vertexData, 1);
}
片段:
#version 130
precision highp float;
in vec3 light0; // <- this is what i want to fill with data
const vec3 ambient = vec3(0.0, 0.0, 0.0);
const vec3 lightColor = vec3(0.6, 0.0, 0.0);
in vec3 normal;
out vec4 out_frag_color;
void main(void)
{
float diffuse = clamp(dot(normalize(light0), normalize(normal)), 0.5, 1.0);
out_frag_color = vec4(ambient + diffuse * lightColor, 1.0);
}
推荐答案
似乎就像您希望light0
成为制服一样.
It seems like you want light0
to be a uniform.
只需使其成为制服:
#version 130
precision highp float;
uniform vec3 light0;
...
这篇关于将数据传递到不同的着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!