javascript - Three.js Convert Customer ShaderMaterial to Lambert Material -
i using cell shading script shade lambert material on model using. have custom shader material use same script on proving easier said done. wondering if there way change custom material in lambert material. have done looking , can't seem find anything. appreciated. code far, three_lamberton script 1 using , applies object applying image to. scripts @ top using layer images , set custom shader material. ignore fact of images loaded in material more once, doing place holders currently. able apply three_lamberton script shader material named material_shh
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>web gl test 2</title> </head> <body style="overflow: hidden; background: black;"> <div id="container"> </div> <script src="three.min.js"></script> <script src="objloader.js"></script> <script src="three_lambertoon_c.js"></script> <script id="fragment_shh" type="x-shader/x-fragment"> #ifdef gl_es precision highp float; #endif uniform sampler2d tone; uniform sampler2d tsec; uniform sampler2d tthree; uniform sampler2d tfour; uniform sampler2d tfive; uniform sampler2d tsix; varying vec2 vuv; void main(void) { vec3 c; vec4 ca = texture2d(tone, vuv); vec4 cb = texture2d(tsec, vuv); vec4 cc = texture2d(tthree, vuv); vec4 cd = texture2d(tfour, vuv); vec4 ce = texture2d(tfive, vuv); vec4 cf = texture2d(tsix, vuv); c = ca.rgb * ca.a + cb.rgb * cb.a + cc.rgb * cc.a + cd.rgb * cd.a + ce.rgb * ce.a + cf.rgb * cf.a * (1.0 - ca.a - cb.a - cc.a - cd.a - ce.a); gl_fragcolor= vec4(c, 1.0); } </script> <script id="vertex_shh" type="x-shader/x-vertex"> varying vec2 vuv; void main() { vuv = uv; vec4 mvposition = modelviewmatrix * vec4( position, 1.0 ); gl_position = projectionmatrix * mvposition; } </script>
ok think see after, , think may little confused.
a material may have 1 vertex shader, , 1 fragment shader @ time. three.js provides default shaders, lambert render things in lambert shading. labertoon.js script appears hack three.js provided lambert shader , permanently alter it, means lambert material use hacked version instead. ugly way this.
see script yourself, it's not long: http://www.neocomputer.org/projects/donut/three_lambertoon_c.js
the fact combining shaders tricky. shader has single entry point main() , specific sequence of operations. order of operations incredibly important, order of operations in math problem. solution write new shader both things.
pull lines of shader code js file, , add them own custom shader. stop using lambertoon js file altogether.
in case, though, might able paste lines toon shader directly bottom of own fragment shader, , might work.
Comments
Post a Comment