// pointlight的定义
struct PointLight {
vec3 position
vec3 color
float distance
float decay
}
uniform PointLight pointLights[ 1 ]
void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {
vec3 lVector = pointLight.position - geometry.position
directLight.direction = normalize( lVector )
float lightDistance = length( lVector )
directLight.color = pointLight.color
directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay )
directLight.visible = ( directLight.color ! = vec3( 0.0 ) )
}
// pointlight影响光照的计算
PointLight pointLight
PointLightShadow pointLightShadow
pointLight = pointLights[ 0 ]
getPointDirectLightIrradiance( pointLight, geometry, directLight )
pointLightShadow = pointLightShadows[ 0 ]
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ 0 ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ 0 ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0
RE_Direct( directLight, geometry, material, reflectedLight )
//输出转化为颜色
float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0
reflectedLight.indirectDiffuse *= ambientOcclusion
float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) )
reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness )
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 )