Jump to content

Shader chain


Fen1kz
 Share

Recommended Posts

Don't know if it's better to ask at SO, whatever

 

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];}

Edit: Additional explanation below (with picture)

Link to comment
Share on other sites

I'm not a Phaser guy and I honestly find your explanation confusing (also wtf Phaser for calling Texture Sampler stages "channels") but I don't think your code reflects what I think you want to do.

As far as I know if you only set Texture Sampler stage 0 (iChannel0.value) that's the only texture your pixel/fragment shader sees. If you want to sample from 2 texture sources you need to set both (iChannel0.value and iChannel1.value)

Link to comment
Share on other sites

I'm not a Phaser guy and I honestly find your explanation confusing (also wtf Phaser for calling Texture Sampler stages "channels") but I don't think your code reflects what I think you want to do.

As far as I know if you only set Texture Sampler stage 0 (iChannel0.value) that's the only texture your pixel/fragment shader sees. If you want to sample from 2 texture sources you need to set both (iChannel0.value and iChannel1.value)

Nay, i apply shader to texture (it is called uSampler) PLUS iChannel0 as additional texture. First shader it is OK, second shader doesn't recieve processed texture.

 

 

Yeah, completely unrelated to question. No info for shaders.

Let me try to re-explain (with picture!)

 

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.

4VYqf.jpg

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...