Opengl es 在LibGDX中使用简单的颜色着色器

Opengl es 在LibGDX中使用简单的颜色着色器,opengl-es,libgdx,glsl,lwjgl,Opengl Es,Libgdx,Glsl,Lwjgl,我已经为基于体素的世界开发了一个渲染引擎,它使用了非常有效的渲染方案。我已经能够通过加载新材质为渲染使用特定的颜色。我遇到的问题是加载一个着色器,它只会使颜色看起来很漂亮。我以前在LWJGL中做过,但在LibGdx中似乎无法实现。我已经阅读了blog.xoppa的所有内容,很明显,着色器是我目前最难以解决的问题。也许我需要某种SSAO着色器或延迟DAO着色器 着色器.frag varying vec3 position; varying vec3 normal; varying vec4 col

我已经为基于体素的世界开发了一个渲染引擎,它使用了非常有效的渲染方案。我已经能够通过加载新材质为渲染使用特定的颜色。我遇到的问题是加载一个着色器,它只会使颜色看起来很漂亮。我以前在LWJGL中做过,但在LibGdx中似乎无法实现。我已经阅读了blog.xoppa的所有内容,很明显,着色器是我目前最难以解决的问题。也许我需要某种SSAO着色器或延迟DAO着色器

着色器.frag

varying vec3 position;
varying vec3 normal;
varying vec4 color;

void main(){
vec4 ambient = vec4( vec3(abs(normal.x)*.8 + abs(normal.z)*.9  + abs(normal.y)*1), 1);

gl_FragColor = vec4(color) * ambient;
}

着色器.vert

varying vec3 position;
varying vec3 normal;
varying vec4 color;

void main(){
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_FrontColor = gl_Color;
    position = vec3(gl_Vertex);
    normal = vec3(gl_Normal);
    color = vec4(gl_Color);
}

我的TestShader扩展了Shader,我也在里面实现了所有其他方法。这些都是相关的。

...
@Override
public void init() {
    program = new ShaderProgram(vert, frag);
    if (!program.isCompiled())
        throw new GdxRuntimeException(program.getLog());

} ...

@Override
public void begin(Camera camera, RenderContext context) {
    this.camera = camera;
    this.context = context;
    program.begin();
    context.setDepthTest(GL_LEQUAL);
    context.setCullFace(GL_BACK);
} ...

@Override
public void render(Renderable renderable) {
    renderable.meshPart.render(program);
} ... 
我想要它的样子:(从以前开始)
使用默认Libgdx着色器时的外观,很明显,我还没有为每个块提供多种类型的体素,但即将出现:

好吧,我实际上需要使用一个SSAO着色器,使其看起来既漂亮又简单:

片段着色器:

uniform sampler2D texture0;
uniform sampler2D texture1;

uniform vec2 camerarange;
uniform vec2 screensize;

float readDepth( in vec2 coord ) {
    return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture0, coord ).x * (camerarange.y - camerarange.x));  
}


void main(void)
{   
    vec2 texCoord = gl_TexCoord[0].st;
    //vec2 texCoord = texture2D(texture0, gl_TexCoord[0].st).xy;
    //vec3 texColor = texture2D(texture1, gl_TexCoord[0].st).rgb;

    float depth = readDepth( texCoord );
    float d;

    float pw = 1.0 / screensize.x;
    float ph = 1.0 / screensize.y;

    float aoCap = 0.45;

    float ao = 0.0;

    float aoMultiplier=1000.0;

    float depthTolerance = 0.00001;

    d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    pw*=2.0;
    ph*=2.0;
    aoMultiplier/=2.0;

    d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    pw*=2.0;
    ph*=2.0;
    aoMultiplier/=2.0;

    d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    pw*=2.0;
    ph*=2.0;
    aoMultiplier/=2.0;

    d=readDepth( vec2(texCoord.x+pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y+ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x+pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    d=readDepth( vec2(texCoord.x-pw,texCoord.y-ph));
    ao+=min(aoCap,max(0.0,depth-d-depthTolerance) * aoMultiplier);

    ao/=16.0;

    gl_FragColor = vec4(1.05 - ao) * texture2D(texture1, texCoord);
}
顶点着色器

#version 110

void main(){
    gl_Position = ftransform();
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

这是OpenGL ES还是桌面OpenGL?@Nicolas使用libgdx作为桌面,因此它的OpenGL ES