|
| 1 | +var Class = require('../../../utils/Class'); |
| 2 | +var WebGLPipeline = require('../WebGLPipeline'); |
| 3 | +var Utils = require('../Utils'); |
| 4 | +var TextureTintPipeline = require('./TextureTintPipeline'); |
| 5 | +var ShaderSourceFS = require('../shaders/ForwardDiffuse.frag'); |
| 6 | + |
| 7 | +var ForwardDiffuseLightPipeline = new Class({ |
| 8 | + |
| 9 | + Extends: TextureTintPipeline, |
| 10 | + |
| 11 | + initialize: |
| 12 | + |
| 13 | + function ForwardDiffuseLightPipeline(game, gl, renderer) |
| 14 | + { |
| 15 | + TextureTintPipeline.call(game, gl, ShaderSourceFS); |
| 16 | + }, |
| 17 | + |
| 18 | + onBind: function () |
| 19 | + { |
| 20 | + TextureTintPipeline.prototype.onBind.call(this); |
| 21 | + |
| 22 | + var renderer = this.renderer; |
| 23 | + var program = this.currentProgram; |
| 24 | + |
| 25 | + this.mvpUpdate(); |
| 26 | + |
| 27 | + renderer.setInt1(program, 'uNormSampler', 1); |
| 28 | + renderer.setFloat2(program, 'uResolution', this.width, this.height); |
| 29 | + |
| 30 | + return this; |
| 31 | + }, |
| 32 | + |
| 33 | + updateLightShaderData: function (scene) |
| 34 | + { |
| 35 | + var program = this.currentProgram; |
| 36 | + var lights = lightLayer.lights; |
| 37 | + |
| 38 | + renderer.setFloat4(program, 'uCamera', camera.x, camera.y, camera.rotation, camera.zoom); |
| 39 | + renderer.setFloat4(program, 'uAmbientLightColor', lightLayer.ambientLightColorR, lightLayer.ambientLightColorG, lightLayer.ambientLightColorB); |
| 40 | + |
| 41 | + for (var index = 0; index < lights.length; ++index) |
| 42 | + { |
| 43 | + var light = lights[index]; |
| 44 | + var lightName = 'uLights[' + index + '].'; |
| 45 | + renderer.setFloat3(program, lightName + 'position', light.x, light.y, light.z); |
| 46 | + renderer.setFloat3(program, lightName + 'color', light.r, light.g, light.b); |
| 47 | + renderer.setFloat1(program, lightName + 'attenuation', light.attenuation); |
| 48 | + renderer.setFloat1(program, lightName + 'radius', light.radius); |
| 49 | + } |
| 50 | + |
| 51 | + return this; |
| 52 | + } |
| 53 | + |
| 54 | +}); |
| 55 | + |
| 56 | +module.exports = ForwardDiffuseLightPipeline; |
0 commit comments