2
\$\begingroup\$

I want to implement lighting via shadowmaps. I see process as:
1) render something to RenderTexture1(size as game)
2) create RenderTexture2 (custom size)
3) add it to Image2 (custom size)
4) apply "generate lightmap" shader to that image, with RenderTexture1 as additional channel
5) create RenderTexture3(size as game)
6) add it to Image3(size as game)
7) Apply "generate light from lightmap" shader, with rendered lightmap as additional channel

I have a problem on last step, seems texture passing as additional channel is not rendered with shader. however it's ok in image.

code:

create() {
    ...
    this.sourceRT = this.game.make.renderTexture(this.game.width, this.game.height);

    this.shadowMapRT = this.game.make.renderTexture(this.SHADER_SIZE, this.SHADER_SIZE);
    this.shadowMapImage = this.game.add.image(0, 0, this.shadowMapRT);
    this.shadowMapImage.filters = [this.shadowTexureShader];

    this.lightingRT = this.game.make.renderTexture(this.game.width, this.game.height);
    this.lightingImage = this.game.add.sprite(200, 0, this.lightingRT);
    this.lightingImage.filters = [this.shadowCastShader];

    this.shadowTexureShader.uniforms.iChannel0.value = this.sourceRT;
    this.shadowCastShader.uniforms.iChannel0.value = this.shadowMapRT;
}

update() {
    this.light.x = this.game.input.activePointer.x;
    this.light.y = this.game.input.activePointer.y;

    this.sourceRT.renderRawXY(this.renderGroup, 0, 0, true); // this.renderGroup is a group with shadow-casters

    this.shadowTexureShader.uniforms.uLightPosition.value = [this.light.x, this.light.y];
    this.shadowCastShader.uniforms.uLightPosition.value = [this.light.x, this.light.y];
}

Additional re-explanation with picture: enter image description here

I take texture0, apply shader to it (texture1 as an additional channel), to get shadowmap. Then i want to take texture1, apply shader2 to it, with texture2 (given by shader as additional channel) to get shadows from objects.

Problem at the question mark -- instead of getting texture2 (processed by shader1) i get texture0 (still unprocessed). I want to get rendered texture2 in my shader2.

\$\endgroup\$
  • \$\begingroup\$ Concision is good, but I suggest that if possible you post a screenshot in your question to clarify. \$\endgroup\$ – Engineer Oct 16 '15 at 20:41
  • \$\begingroup\$ @ArcaneEngineer screenshot of what? of black screen due to shader receiving black (vec4(0.0)) texture? \$\endgroup\$ – Fen1kz Oct 16 '15 at 21:54
  • 1
    \$\begingroup\$ @ArcaneEngineer added additional explanation + picture \$\endgroup\$ – Fen1kz Oct 18 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.