【发布时间】:2018-11-02 23:35:25
【问题描述】:
我最近刚刚编写了这段代码来模拟海洋中的水流:
// Global variables
int cols,rows;
int scl = 15;
int w = 3800;
int h = 1600;
float flying = 0;
float[][] terrain;
void setup() {
size(600, 600, P3D);
cols = w / scl;
rows = h / scl;
terrain = new float[cols][rows];
}
void draw() {
fill(255, 255, 255);
flying -= 0.01;
float yoff = flying;
for (int y = 0; y < rows; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
terrain[x][y] = map(noise(xoff,yoff), 0, 1, -50, 50);
xoff += 0.05;
}
yoff += 0.05;
}
background(0);
stroke(255);
translate(width/2, height/2+50);
rotateX(PI/3);
translate(-w/2,-h/2);
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
vertex(x*scl, y*scl, terrain[x][y]);
vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
// rect(x*scl, y*scl, scl, scl);
}
endShape();
}
}
但是,您可以看到它没有阴影,只是纯白色。我不知道如何遮蔽它,我到处都看过,但我不知道如何将它翻译成我的代码。
谁能帮助解释如何做或修改我的代码以添加着色器? (不一定要光面,漫射就好)
任何形式的帮助都将不胜感激!
【问题讨论】:
-
那么“着色”是指顶点着色器吗?您可以使用 LWJGL 之类的 Java 库来访问 OpenGL 着色器。 wiki.lwjgl.org/wiki/GLSL_Shaders_with_LWJGL.html
标签: java processing vertex-shader