2018-01-26 23:17:11 +00:00
|
|
|
var Class = require('../../../utils/Class');
|
|
|
|
var WebGLPipeline = require('../WebGLPipeline');
|
|
|
|
var Utils = require('../Utils');
|
|
|
|
var TextureTintPipeline = require('./TextureTintPipeline');
|
|
|
|
var ShaderSourceFS = require('../shaders/ForwardDiffuse.frag');
|
|
|
|
|
|
|
|
var ForwardDiffuseLightPipeline = new Class({
|
|
|
|
|
|
|
|
Extends: TextureTintPipeline,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function ForwardDiffuseLightPipeline(game, gl, renderer)
|
|
|
|
{
|
2018-01-29 21:46:48 +00:00
|
|
|
TextureTintPipeline.call(this, game, gl, renderer, ShaderSourceFS);
|
|
|
|
this.name = 'ForwardDiffuseLightPipeline';
|
2018-01-26 23:17:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onBind: function ()
|
|
|
|
{
|
|
|
|
TextureTintPipeline.prototype.onBind.call(this);
|
|
|
|
|
|
|
|
var renderer = this.renderer;
|
|
|
|
var program = this.currentProgram;
|
|
|
|
|
|
|
|
this.mvpUpdate();
|
|
|
|
|
2018-01-29 21:46:48 +00:00
|
|
|
//renderer.setInt1(program, 'uNormSampler', 1);
|
2018-01-26 23:17:11 +00:00
|
|
|
renderer.setFloat2(program, 'uResolution', this.width, this.height);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-29 21:46:48 +00:00
|
|
|
onRender: function (scene, camera)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-26 23:17:11 +00:00
|
|
|
updateLightShaderData: function (scene)
|
|
|
|
{
|
|
|
|
var program = this.currentProgram;
|
|
|
|
var lights = lightLayer.lights;
|
|
|
|
|
|
|
|
renderer.setFloat4(program, 'uCamera', camera.x, camera.y, camera.rotation, camera.zoom);
|
|
|
|
renderer.setFloat4(program, 'uAmbientLightColor', lightLayer.ambientLightColorR, lightLayer.ambientLightColorG, lightLayer.ambientLightColorB);
|
|
|
|
|
|
|
|
for (var index = 0; index < lights.length; ++index)
|
|
|
|
{
|
|
|
|
var light = lights[index];
|
|
|
|
var lightName = 'uLights[' + index + '].';
|
|
|
|
renderer.setFloat3(program, lightName + 'position', light.x, light.y, light.z);
|
|
|
|
renderer.setFloat3(program, lightName + 'color', light.r, light.g, light.b);
|
|
|
|
renderer.setFloat1(program, lightName + 'attenuation', light.attenuation);
|
|
|
|
renderer.setFloat1(program, lightName + 'radius', light.radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = ForwardDiffuseLightPipeline;
|