opengl es - THREE.js custom shader with predefined lights -


i have following blendshader made based on three.blendshader , alteredqualia jupitershader. struggling adding directional light material shader. have read this tutorial still render lit object, without taking directional light consideration. wrong @ last row when defining gl_fragcolor can't figure out is. please help. thank you.

fragmentshader :

"#if num_dir_lights > 0", "uniform vec3 directionallightcolor[num_dir_lights];", "uniform vec3 directionallightdirection[num_dir_lights];", "#endif", "uniform float opacity;", "uniform float mixratio;", "uniform float staticratio;", "uniform sampler2d tdiffuse1;", "uniform sampler2d tdiffuse2;", "uniform sampler2d tdiffuse3;",  "varying vec2 vuv;", // = uv  // vnormal worldnormal calculated in vertex shader follows: // "vec3 worldnormal = mat3( modelmatrix[0].xyz, modelmatrix[1].xyz, modelmatrix[2].xyz ) * normal ;", // "vnormal = normalize( worldnormal );", "varying vec3 vnormal;",      "void main() {",      "vec4 texel1 = texture2d( tdiffuse1, vuv );", // frame     "vec4 texel2 = texture2d( tdiffuse2, vuv );", // frame + 1     "vec4 texel3 = texture2d( tdiffuse3, vuv );", //static texture     "texel1.xyz = pow( texel1.xyz, vec3( 1.7 ) );", // gamma correction     "texel2.xyz = pow( texel2.xyz, vec3( 1.7 ) );", // gamma correction     "float m = 1.0;",     "float m1 = smoothstep( 0.23, 0.3, vuv.y );", //      "float m2 = 1.0 - smoothstep( 0.75, 0.82, vuv.y );",      "m = m1 * m2;",     "vec4 dynamic = mix( texel1, texel2, mixratio );", // mixing 2 frames      //directional light      "vec4 sumdirlights = vec4(0.0, 0.0, 0.0, 1.0);",      "#if num_dir_lights > 0",     "for( int = 0; < num_dir_lights; i++ ) {",     "vec3 dir = directionallightdirection[i];",     "sumdirlights.rgb += clamp( dot( -dir, vnormal ), 0.0, 1.0 ) * directionallightcolor[i];",     "}",     "#endif",     "gl_fragcolor = vec4( 1.0, 1.0, 1.0, 1.0 ) * sumdirlights + ( opacity * mix( texel3, dynamic, staticratio * m ) ) ;",             "}" 


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -