将自己的结构传递到 opengl es 2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能,OpenGL ES 没有该功能,要上传,你必须获取每个嵌套变量的位置并对每个变量调用 glUniform*。
例如:
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: