阴影贴图的光通过不适用于曲面细分?

时间:2014-02-02 17:12:42

标签: java opengl shader shadow-mapping tesselation

我目前正在实施Shadow Mapping,我在程序中遇到了一些奇怪的逻辑,我使用以下程序:

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的{​​{1}},已经确保在此之前调用drawLightPass,这在代码中可能看起来不太明显。

正如您所看到的那样,我在lightProgram.use()中使用drawArrays作为参数调用drawLightPass,现在这确实应该出错了,因此在我的整个程序中我得到了每个部分被认为是阴影,所以我有这些问题:

1)我当前的设置是否存在问题? (我个人认为是。)

2)当附加的着色器没有启用Tesselation时,如果我传入GL_PATCHES,OpenGL如何不会出错?

3)如何修复它以便它也适用于Tesselation?

如果需要更多代码,那么我会发布它,我只是不想用不必要的代码过多地混淆帖子。

0 个答案:

没有答案