(OpenGL 3.1 - 4.2) Dynamic Uniform Arrays?

后端 未结 2 1789
鱼传尺愫
鱼传尺愫 2020-12-30 13:34

Lets say I have 2 species such as humans and ponies. They have different skeletal systems so the uniform bone array will have to be different for each species. Do I have to

2条回答
  •  伪装坚强ぢ
    2020-12-30 14:10

    You can use n-by-1-Textures as a replacement for arrays. Texture size can be specified at run-time. I use this approach for passing an arbitrary number of lights to my shaders. I'm surprised how fast it runs despite the many loops and branches. For an example see the polygon.f shader file in the jogl3.glsl.nontransp in the jReality sources.

    uniform sampler2D sys_globalLights;
    uniform int sys_numGlobalDirLights;
    uniform int sys_numGlobalPointLights;
    uniform int sys_numGlobalSpotLights;
    

    ...

    int lightTexSize = sys_numGlobalDirLights*3+sys_numGlobalPointLights*3+sys_numGlobalSpotLights*5;
    
        for(int i = 0; i < numDir; i++){
            vec4 dir = texture(sys_globalLights, vec2((3*i+1+0.5)/lightTexSize, 0));
    

    ...

提交回复
热议问题