1

我有一个简单的 OpenGL 代码,glumpy在 python 中使用,来绘制一个插值的二维数组:

在此处输入图像描述

我想以下列方式绘制一个 3D 插值数组:将其切成 10 个(比方说)垂直于观察者的平面并添加透明度以给人以深度的印象。

首先,我想在上面绘制我的 2D 数组,但作为一个 3D 立方体的切片,就像我在下面绘制的那样。

在此处输入图像描述

我怎么会开始这样做?


MWE:

import numpy as np
from PIL import Image
from glumpy import app, gl, gloo, data, library
from glumpy.geometry import primitives
from glumpy.transforms import Trackball

vertex = """
#include "misc/spatial-filters.frag"
uniform sampler2D data;
uniform vec2 data_shape;
attribute vec3 position;
attribute vec2 texcoord;
varying float zz;
void main()
{
    float z = Bicubic(data, data_shape, texcoord).x;
    zz = z;
    gl_Position = <transform>;
}
"""

fragment = """
#include "misc/spatial-filters.frag"
#include "colormaps/colormaps.glsl"
varying float zz;

void main()
{
    vec4 col = vec4(colormap_icefire(zz),1);
    gl_FragColor = col;

} """

def func3(x,y,t):
    return np.exp(-10*(x-0.5*np.cos(t))**2-10*(y-0.5*np.sin(t))**2)

x = np.linspace(-2.0, 2.0, 64).astype(np.float32)
y = np.linspace(-2.0, 2.0, 64).astype(np.float32)
X,Y = np.meshgrid(x, y)
Z = func3(X,Y,0)

window = app.Window(width=1200, height=800, color = (1,1,1,1))

@window.event
def on_draw(dt):

    window.clear()

    surface['data'] = Z 

    surface.draw(gl.GL_TRIANGLES, s_indices)

n = 100
surface = gloo.Program(vertex, fragment)
vertices, s_indices = primitives.plane(2.0, n=n)
surface.bind(vertices)

surface['data_shape'] = Z.shape[1], Z.shape[0]

surface['u_kernel'] = data.get("spatial-filters.npy")
surface['u_kernel'].interpolation = gl.GL_LINEAR

transform = Trackball("vec4(position.xy, 0, 1.0)")
surface['transform'] = transform
window.attach(transform)

app.run()
4

0 回答 0