Fen1kz Posted October 14, 2015 Share Posted October 14, 2015 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 channel5) 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 More sharing options...
Fen1kz Posted October 16, 2015 Author Share Posted October 16, 2015 Does this explanation too short or no one really knows? =( Link to comment Share on other sites More sharing options...
chg Posted October 16, 2015 Share Posted October 16, 2015 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 More sharing options...
DonFrag Posted October 16, 2015 Share Posted October 16, 2015 http://gamemechanicexplorer.comDid you check this? Link to comment Share on other sites More sharing options...
Fen1kz Posted October 18, 2015 Author Share Posted October 18, 2015 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. http://gamemechanicexplorer.comDid you check this?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. Link to comment Share on other sites More sharing options...
chg Posted October 18, 2015 Share Posted October 18, 2015 EDIT: Nevermind Link to comment Share on other sites More sharing options...
DonFrag Posted October 19, 2015 Share Posted October 19, 2015 No info for shaders? http://gamemechanicexplorer.com/#lightning-3 Link to comment Share on other sites More sharing options...
Fen1kz Posted October 19, 2015 Author Share Posted October 19, 2015 No info for shaders?http://gamemechanicexplorer.com/#lightning-3 Yeah, it reads: "Fragment shaders are beyond the scope of this tutorial."Anyway, it's about applying basic Glow filter to 1 sprite, while i need to apply filter to texture to use it in another shader, so, provided article is not helpful. Link to comment Share on other sites More sharing options...
Recommended Posts