簡體   English   中英

在 glsl opengl 中將嵌套結構數組作為統一傳遞

[英]Passing an array of nested structs as uniform in glsl opengl

我在這里看到了一個類似的問題,但它似乎並沒有解決我的問題。

我有一堆結構,它們是聚合的。

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];

我試圖將價值傳遞給制服。 我試圖將值傳遞給每個單獨的組件,但我遇到了以下類型的錯誤:


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

我應該使用不同的策略將值傳遞給這些結構嗎? 有任何想法嗎?

提前致謝

不是最優雅的解決方案,但我決定制作一個大的平面結構,然后在着色器中解析它。

基本上我改造了上述uniform Hittable hittables[20]; uniform NHittable hittables[20]; 其中NHittable定義為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM