2015-01-30 2 views
0

저는 Libgdx로 턴 기반 게임을 만들고 있습니다.LibGDX 게임에서 쉐이더 라이트를 슈퍼 임 포즈하십시오.

나는 맵에 마스크를 추가하고 전투 지역의 각 셀에 maplight를 추가하여 전투에 대한 전쟁의 안개를 만들려고합니다.

이렇게하려면 조명을 슈퍼 임 포즈해야하지만 그렇게 할 수는 없습니다. 게임에서

결과 :

//draw the light to the FBO 
fbo.begin(); 
batch.setProjectionMatrix(cam.combined); 
batch.setShader(defaultShader); 
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

batch.begin(); 
float lightSize = lightOscillate? (4.75f + 0.25f * (float)Math.sin(zAngle) + .2f*MathUtils.random()):5.0f; 
//Draw light 1 
batch.draw(light, 0, 0, lightSize, lightSize); 

//Draw light 2 
batch.draw(light, 2, 2, lightSize, lightSize); 

batch.end(); 
fbo.end(); 

//draw the actual scene 
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
batch.setProjectionMatrix(cam.combined); 
batch.setShader(finalShader); 
batch.begin(); 
fbo.getColorBufferTexture().bind(1); //this is important! bind the FBO to the 2nd texture unit 
light.bind(0); //we force the binding of a texture on first texture unit to avoid artefacts 
      //this is because our default and ambiant shader dont use multi texturing... 
      //youc can basically bind anything, it doesnt matter 
tilemap.render(batch, dt); 
batch.end(); 

조각 쉐이더 코드 :

varying LOWP vec4 vColor; 
varying vec2 vTexCoord; 

//texture samplers 
uniform sampler2D u_texture; //diffuse map 
uniform sampler2D u_lightmap; //light map 

//additional parameters for the shader 
uniform vec2 resolution; //resolution of screen 
uniform LOWP vec4 ambientColor; //ambient RGB, alpha channel is intensity 

void main() { 
    vec4 diffuseColor = texture2D(u_texture, vTexCoord); 
    vec2 lighCoord = gl_FragCoord.xy/resolution.xy; 
    vec4 light = texture2D(u_lightmap, lighCoord); 

    vec3 ambient = ambientColor.rgb * ambientColor.a; 
    vec3 intensity = ambient + light.rgb; 
    vec3 finalColor = diffuseColor.rgb * intensity; 

    gl_FragColor = vColor * light; //vec4(finalColor, diffuseColor.a); 
} 
+0

것 같습니다 : 여기

올바른

코드 렌더링. – user3256930

+0

'Gdx.gl20.glEnable (GL20.GL_BLEND);을 추가하려고했습니다. \t \t Gdx.gl20.glBlendFunc (GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);'는 batch.begin()과 create() 메소드 뒤에 있지만 아무 작업도 수행하지 않습니다. – OmiCroh

답변

0

나는 해결책을 발견

enter image description here

자바 코드 렌더링. 알파 블렌딩을 활성화해야했습니다. 당신이 알파 블렌딩을 활성화해야처럼

public void render() { 
    final float dt = Gdx.graphics.getRawDeltaTime(); 

    Gdx.gl.glClearColor(0f,0f,0f,1f); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); 

    //draw the light to the FBO 
    fbo.begin(); 
    Gdx.gl.glClearColor(0f,0f,0f,0f); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     batch.setProjectionMatrix(cam.combined); 
     batch.setShader(defaultShader); 

     batch.begin(); 
     float lightSize = lightOscillate? (4.75f + 0.25f * (float)Math.sin(zAngle) + .2f*MathUtils.random()):5.0f; 
     //Draw light 1 
     batch.draw(light, 0, 0, lightSize, lightSize); 

     //Draw light 2 
     batch.draw(light, 2, 2, lightSize, lightSize); 

     batch.end(); 
    fbo.end(); 

    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); 

    //draw the actual scene 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    batch.setProjectionMatrix(cam.combined); 
    batch.setShader(finalShader); 
    batch.begin(); 
    fbo.getColorBufferTexture().bind(1); //this is important! bind the FBO to the 2nd texture unit 
    light.bind(0); //we force the binding of a texture on first texture unit to avoid artefacts 
        //this is because our default and ambiant shader dont use multi texturing... 
        //youc can basically bind anything, it doesnt matter 
    tilemap.render(batch, dt); 
    batch.end(); 
}