将自己的结构传递到 opengl es 2.0 着色器中

发布于 2024-10-01 01:21:25 字数 699 浏览 0 评论 0原文

我想尝试《OpenGL ES 2.0 编程指南》一书中的照明示例。在着色器中他们制作了两种结构。

struct directional_light   
{  

    vec3 direction; // normalized light direction in eye space  
    vec3 halfplane; // normalized half-plane vector  

    vec4 ambient_color;
    vec4 diffuse_color;
    vec4 specular_color;
};

struct material_properties 
{ 
    vec4 ambient_color; 
    vec4 diffuse_color; 
    vec4 specular_color; 
    float specular_exponent;
};

他们还根据这些结构制作了两套制服。

uniform  material_properties u_material_properties;   
uniform directional_light u_directional_light;

问题是,我不知道如何将自己的结构传递到实际的着色器中。

我想在我的主代码中创建相同的结构并将对象传递到着色器中。这怎么可能?

问候 尼克拉斯

I want to try a lighting example from the book OpenGL ES 2.0 Programming Guide. In the shader they have made two structures.

struct directional_light   
{  

    vec3 direction; // normalized light direction in eye space  
    vec3 halfplane; // normalized half-plane vector  

    vec4 ambient_color;
    vec4 diffuse_color;
    vec4 specular_color;
};

struct material_properties 
{ 
    vec4 ambient_color; 
    vec4 diffuse_color; 
    vec4 specular_color; 
    float specular_exponent;
};

They have also made two uniforms, based on these structures.

uniform  material_properties u_material_properties;   
uniform directional_light u_directional_light;

The problem is, I do not know how to pass own structures into the actual shader.

I want to create the same structures in my main code and pass the objects into the shader. How is this possible?

Regards
Niclas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾忌 2024-10-08 01:21:25

你不能,OpenGL ES 没有该功能,要上传,你必须获取每个嵌套变量的位置并对每个变量调用 glUniform*。

例如:

GLuint loc = glGetUniformLocation(program, "u_material_properties.ambient_color");
glUniform4f(loc, 1.0, 1.0, 1.0, 0.0);

You can't, OpenGL ES doesn't have that functionality, to upload you have to get the location of each of your nested variables and call glUniform* on each of them.

For example:

GLuint loc = glGetUniformLocation(program, "u_material_properties.ambient_color");
glUniform4f(loc, 1.0, 1.0, 1.0, 0.0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文