首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在glsl opengl中以一致的方式传递嵌套结构的数组

在glsl opengl中以一致的方式传递嵌套结构的数组
EN

Stack Overflow用户
提问于 2020-05-24 02:20:27
回答 1查看 271关注 0票数 0

我在here中看到了类似的问题,但它似乎并没有解决我的问题。

我有一堆结构,它们是聚合的。

代码语言:javascript
运行
复制
struct Lambert {
  vec3 albedo;
};
struct Metal {
  vec3 albedo;
  float roughness;
};
struct Dielectric {
  float ref_idx;
};
struct Material {
  int type; // 0: lambert, 1: metal, 2: dielectric;
  Lambert lam;
  Metal met;
  Dielectric die;
};
struct Sphere {
  vec3 center;
  float radius;
  Material mat_ptr;
};
struct Material {
  int type; // 0: lambert, 1: metal, 2: dielectric;
  Lambert lam;
  Metal met;
  Dielectric die;
};
struct Sphere {
  vec3 center;
  float radius;
  Material mat_ptr;
};
struct Hittable {
  int type; // 0 sphere, 1, other
  Sphere sp;
};

uniform Hittable hittables[20];

我正试图将价值传递给制服。我试图将值传递给每个单独的组件,但我遇到了以下类型的错误:

代码语言:javascript
运行
复制
1282: state is not legal for given parameters | weekend.cpp (96)
Shader program can not find the uniform location for hittables[2].type
1282: state is not legal for given parameters | weekend.cpp (164)
Shader program can not find the uniform location for hittables[2].sp.center
1282: state is not legal for given parameters | weekend.cpp (143)
Shader program can not find the uniform location for hittables[2].sp.radius
1282: state is not legal for given parameters | weekend.cpp (146)
Shader program can not find the uniform location for hittables[2].sp.mat_ptr.type
1282: state is not legal for given parameters | weekend.cpp (124)
Shader program can not find the uniform location for hittables[2].sp.mat_ptr.lam.albedo

我是否应该使用不同的策略来将值传递给这些结构?有什么想法吗?

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2020-05-24 09:55:48

这不是最优雅的解决方案,但我决定做一个很大的平面结构,然后在着色器中解析它。

基本上,我将上面的uniform Hittable hittables[20];转换为uniform NHittable hittables[20];,其中NHittable定义为

代码语言:javascript
运行
复制
struct NHittable {
  int hittable_type;
  vec3 sphere_center;
  float sphere_radius;
  int material_type; // 0: lambert, 1: metal, 2: dielectric;
  vec3 lambert_albedo;
  vec3 metal_albedo;
  float metal_roughness;
  float dielectric_ref_idx;
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61976655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档