将数据传递到不同的着色器(Passing data into different shaders)

2019-10-17 13:28发布

比方说我Shaderprogram包含Vertex-和Fragmentshader。

如何传递信息,直接到fragmentshader?

当我使用gl_uniform ......和specifiy我想在里面fragmet的ADRESS着色器varaible它抛出我的错误是这样的:

Using ShaderProgram: The fragment shader uses varying myVarHere, but previous 
shader doesnot write to it.

因为我第一次装上vertexshader,我发现我需要“通过信息”顶点着色器使用和缩小。

林不知道这是否是要走的路,所以我的问题:有没有办法来告诉OpenGL ADRESS变量在一定的着色器或我在做/理解可怕的错误?

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);
}

Answer 1:

好像你想light0为均匀。

只是让一个统一的:

#version 130

precision highp float;

uniform vec3 light0;  

...


文章来源: Passing data into different shaders
标签: opengl shader