原文
- ThreeJS材质对比
- MeshBasicMaterial 不受光照的影响。
- MeshLambertMaterial 只在顶点计算光照。
- MeshPhongMaterial 则在每个像素计算光照,还支持镜面高光。
- 定义diffuseColor和反射光reflectedLight
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec4 texelColor = texture2D( map, vUv )
texelColor = mapTexelToLinear( texelColor )
diffuseColor *= texelColor
diffuseColor.rgb *= vColor
IncidentLight directLight;
float dotNL;
vec3 directLightColor_Diffuse;
vIndirectFront += getAmbientLightIrradiance( ambientLightColor );
vIndirectFront += getLightProbeIrradiance( lightProbe, geometry );
#ifdef DOUBLE_SIDED
vIndirectBack += getAmbientLightIrradiance( ambientLightColor );
vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );
#endif
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack
reflectedLight.indirectDiffuse += vIndirectFront
vec4 lightMapTexel = texture2D( lightMap, vUv2 )
reflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity
reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb )
reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack
reflectedLight.directDiffuse = vLightFront
reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance
gl_FragColor = vec4( outgoingLight, diffuseColor.a )
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb )
gl_FragColor = linearToOutputTexel( gl_FragColor )
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth )
float fogFactor = smoothstep( fogNear, fogFar, fogDepth )
gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor )
gl_FragColor.rgb *= gl_FragColor.a
gl_FragColor.rgb = dithering( gl_FragColor.rgb )