我目前正在实现阴影映射,并且在我的程序中遇到了一些奇怪的逻辑,我使用以下程序:
light.vs.glsl
#version 440 core
layout(location = 4) uniform mat4 light_mvp;
layout(location = 0) in vec4 position;
void main(void) {
gl_Position = light_mvp * position;
}
light.fs.glsl
#version 440 core
layout(location = 0) out vec4 color;
void main(void) {
color = vec4(gl_FragCoord.z);
}
但是我得出的结论是我实际上是在做 Tesselation,所以我真的不知道现在发生了什么,在Terrain.java
:
public class Terrain implements Drawable {
//<editor-fold defaultstate="collapsed" desc="keep-imports">
static {
int KEEP_LWJGL_IMPORTS = GL_2_BYTES | GL_ALIASED_LINE_WIDTH_RANGE | GL_ACTIVE_TEXTURE | GL_BLEND_COLOR | GL_ARRAY_BUFFER | GL_ACTIVE_ATTRIBUTE_MAX_LENGTH | GL_COMPRESSED_SLUMINANCE | GL_ALPHA_INTEGER | GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH | GL_ALREADY_SIGNALED | GL_ANY_SAMPLES_PASSED | GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH | GL_ACTIVE_PROGRAM | GL_ACTIVE_ATOMIC_COUNTER_BUFFERS | GL_ACTIVE_RESOURCES | GL_BUFFER_IMMUTABLE_STORAGE;
int KEEP_OWN_IMPORTS = UNIFORM_PROJECTION_MATRIX.getLocation() | VS_POSITION.getLocation();
}
//</editor-fold>
private static final float EPSILON = 0.0001f;
private FloatBuffer data;
private Program program;
private final int width;
private final int depth;
private final Random random = new Random();
private final float maxHeight = 8f;
private final int maxDecayFactor = 5;
private final float factor = 4f;
public Terrain(final int width, final int depth) {
this.width = width;
this.depth = depth;
data = generateRandomTerrain();
data.clear();
}
@Override
public void compileProgram() {
program = new Program(
new VertexShader("data/shaders/terrain.vs.glsl").compile(),
new TessellationControlShader("data/shaders/terrain.tcs.glsl").compile(),
new TessellationEvaluationShader("data/shaders/terrain.tes.glsl").compile(),
new FragmentShader("data/shaders/terrain.fs.glsl").compile()
).compile().setUniforms(
UNIFORM_MODEL_MATRIX,
UNIFORM_VIEW_MATRIX,
UNIFORM_PROJECTION_MATRIX,
UNIFORM_SHADOW_MATRIX
);
}
@Override
public Program getProgram() {
return program;
}
@Override
public int getDataSize() {
return width * depth * 16;
}
@Override
public FloatBuffer putData(final FloatBuffer dataBuffer) {
return dataBuffer.put(data);
}
@Override
public int getDataMode() {
return GL_PATCHES;
}
@Override
public void drawLightPass(final int offset, final Program lightProgram) {
lightProgram.drawArrays(getDataMode(), offset, getDataSize());
}
@Override
public void draw(final int offset) {
program.use();
program.drawArrays(getDataMode(), offset, getDataSize());
}
@Override
public void delete() {
program.delete();
}
public void refresh() {
data.clear();
data = generateRandomTerrain();
}
//...
}
同样对于lightProgram
传递给 的drawLightPass
,已确保lightProgram.use()
在此之前已调用过 ,这从代码中可能看起来并不明显。
正如你所看到的,我用 as argument调用drawArrays
,现在这真的应该出错了,因为在我的整个程序中,我发现每个部分都被认为是在阴影中,所以我有这些问题:drawLightPass
GL_PATCHES
1) 我当前的设置有问题吗?(我个人认为是。)
GL_PATCHES
2) 如果我在附加的着色器没有启用 Tesselation 时传入,OpenGL 如何不给出错误?
3)如何修复它,使其也适用于 Tesselation?
如果需要更多代码,那么我会发布它,我只是不想用不必要的代码使帖子过于混乱。