123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- ( function () {
- /**
- * Currently contains:
- *
- * toon1
- * toon2
- * hatching
- * dotted
- */
- const ToonShader1 = {
- uniforms: {
- 'uDirLightPos': {
- value: new THREE.Vector3()
- },
- 'uDirLightColor': {
- value: new THREE.Color( 0xeeeeee )
- },
- 'uAmbientLightColor': {
- value: new THREE.Color( 0x050505 )
- },
- 'uBaseColor': {
- value: new THREE.Color( 0xffffff )
- }
- },
- vertexShader:
- /* glsl */
- `
- varying vec3 vNormal;
- varying vec3 vRefract;
- void main() {
- vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
- vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
- vec3 worldNormal = normalize ( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );
- vNormal = normalize( normalMatrix * normal );
- vec3 I = worldPosition.xyz - cameraPosition;
- vRefract = refract( normalize( I ), worldNormal, 1.02 );
- gl_Position = projectionMatrix * mvPosition;
- }`,
- fragmentShader:
- /* glsl */
- `
- uniform vec3 uBaseColor;
- uniform vec3 uDirLightPos;
- uniform vec3 uDirLightColor;
- uniform vec3 uAmbientLightColor;
- varying vec3 vNormal;
- varying vec3 vRefract;
- void main() {
- float directionalLightWeighting = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);
- vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;
- float intensity = smoothstep( - 0.5, 1.0, pow( length(lightWeighting), 20.0 ) );
- intensity += length(lightWeighting) * 0.2;
- float cameraWeighting = dot( normalize( vNormal ), vRefract );
- intensity += pow( 1.0 - length( cameraWeighting ), 6.0 );
- intensity = intensity * 0.2 + 0.3;
- if ( intensity < 0.50 ) {
- gl_FragColor = vec4( 2.0 * intensity * uBaseColor, 1.0 );
- } else {
- gl_FragColor = vec4( 1.0 - 2.0 * ( 1.0 - intensity ) * ( 1.0 - uBaseColor ), 1.0 );
- }
- }`
- };
- const ToonShader2 = {
- uniforms: {
- 'uDirLightPos': {
- value: new THREE.Vector3()
- },
- 'uDirLightColor': {
- value: new THREE.Color( 0xeeeeee )
- },
- 'uAmbientLightColor': {
- value: new THREE.Color( 0x050505 )
- },
- 'uBaseColor': {
- value: new THREE.Color( 0xeeeeee )
- },
- 'uLineColor1': {
- value: new THREE.Color( 0x808080 )
- },
- 'uLineColor2': {
- value: new THREE.Color( 0x000000 )
- },
- 'uLineColor3': {
- value: new THREE.Color( 0x000000 )
- },
- 'uLineColor4': {
- value: new THREE.Color( 0x000000 )
- }
- },
- vertexShader:
- /* glsl */
- `
- varying vec3 vNormal;
- void main() {
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
- vNormal = normalize( normalMatrix * normal );
- }`,
- fragmentShader:
- /* glsl */
- `
- uniform vec3 uBaseColor;
- uniform vec3 uLineColor1;
- uniform vec3 uLineColor2;
- uniform vec3 uLineColor3;
- uniform vec3 uLineColor4;
- uniform vec3 uDirLightPos;
- uniform vec3 uDirLightColor;
- uniform vec3 uAmbientLightColor;
- varying vec3 vNormal;
- void main() {
- float camera = max( dot( normalize( vNormal ), vec3( 0.0, 0.0, 1.0 ) ), 0.4);
- float light = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);
- gl_FragColor = vec4( uBaseColor, 1.0 );
- if ( length(uAmbientLightColor + uDirLightColor * light) < 1.00 ) {
- gl_FragColor *= vec4( uLineColor1, 1.0 );
- }
- if ( length(uAmbientLightColor + uDirLightColor * camera) < 0.50 ) {
- gl_FragColor *= vec4( uLineColor2, 1.0 );
- }
- }`
- };
- const ToonShaderHatching = {
- uniforms: {
- 'uDirLightPos': {
- value: new THREE.Vector3()
- },
- 'uDirLightColor': {
- value: new THREE.Color( 0xeeeeee )
- },
- 'uAmbientLightColor': {
- value: new THREE.Color( 0x050505 )
- },
- 'uBaseColor': {
- value: new THREE.Color( 0xffffff )
- },
- 'uLineColor1': {
- value: new THREE.Color( 0x000000 )
- },
- 'uLineColor2': {
- value: new THREE.Color( 0x000000 )
- },
- 'uLineColor3': {
- value: new THREE.Color( 0x000000 )
- },
- 'uLineColor4': {
- value: new THREE.Color( 0x000000 )
- }
- },
- vertexShader:
- /* glsl */
- `
- varying vec3 vNormal;
- void main() {
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
- vNormal = normalize( normalMatrix * normal );
- }`,
- fragmentShader:
- /* glsl */
- `
- uniform vec3 uBaseColor;
- uniform vec3 uLineColor1;
- uniform vec3 uLineColor2;
- uniform vec3 uLineColor3;
- uniform vec3 uLineColor4;
- uniform vec3 uDirLightPos;
- uniform vec3 uDirLightColor;
- uniform vec3 uAmbientLightColor;
- varying vec3 vNormal;
- void main() {
- float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);
- vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;
- gl_FragColor = vec4( uBaseColor, 1.0 );
- if ( length(lightWeighting) < 1.00 ) {
- if ( mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {
- gl_FragColor = vec4( uLineColor1, 1.0 );
- }
- }
- if ( length(lightWeighting) < 0.75 ) {
- if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {
- gl_FragColor = vec4( uLineColor2, 1.0 );
- }
- }
- if ( length(lightWeighting) < 0.50 ) {
- if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {
- gl_FragColor = vec4( uLineColor3, 1.0 );
- }
- }
- if ( length(lightWeighting) < 0.3465 ) {
- if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {
- gl_FragColor = vec4( uLineColor4, 1.0 );
- }
- }
- }`
- };
- const ToonShaderDotted = {
- uniforms: {
- 'uDirLightPos': {
- value: new THREE.Vector3()
- },
- 'uDirLightColor': {
- value: new THREE.Color( 0xeeeeee )
- },
- 'uAmbientLightColor': {
- value: new THREE.Color( 0x050505 )
- },
- 'uBaseColor': {
- value: new THREE.Color( 0xffffff )
- },
- 'uLineColor1': {
- value: new THREE.Color( 0x000000 )
- }
- },
- vertexShader:
- /* glsl */
- `
- varying vec3 vNormal;
- void main() {
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
- vNormal = normalize( normalMatrix * normal );
- }`,
- fragmentShader:
- /* glsl */
- `
- uniform vec3 uBaseColor;
- uniform vec3 uLineColor1;
- uniform vec3 uLineColor2;
- uniform vec3 uLineColor3;
- uniform vec3 uLineColor4;
- uniform vec3 uDirLightPos;
- uniform vec3 uDirLightColor;
- uniform vec3 uAmbientLightColor;
- varying vec3 vNormal;
- void main() {
- float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);
- vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;
- gl_FragColor = vec4( uBaseColor, 1.0 );
- if ( length(lightWeighting) < 1.00 ) {
- if ( ( mod(gl_FragCoord.x, 4.001) + mod(gl_FragCoord.y, 4.0) ) > 6.00 ) {
- gl_FragColor = vec4( uLineColor1, 1.0 );
- }
- }
- if ( length(lightWeighting) < 0.50 ) {
- if ( ( mod(gl_FragCoord.x + 2.0, 4.001) + mod(gl_FragCoord.y + 2.0, 4.0) ) > 6.00 ) {
- gl_FragColor = vec4( uLineColor1, 1.0 );
- }
- }
- }`
- };
- THREE.ToonShader1 = ToonShader1;
- THREE.ToonShader2 = ToonShader2;
- THREE.ToonShaderDotted = ToonShaderDotted;
- THREE.ToonShaderHatching = ToonShaderHatching;
- } )();
|