Análisis de funciones para lograr GlobalIllumination

代码在:
E: \ OGL \ scripts-render-tubería-08--iluminación global \ Activos \ Mi Pipeline \ ShaderLibrary


float3 GlobalIllumination (VertexOutput input, LitSurface surface) 
{
	#if defined(LIGHTMAP_ON)
		float3 gi = SampleLightmap(input.lightmapUV);
		#if defined(DYNAMICLIGHTMAP_ON)
			gi += SampleDynamicLightmap(input.dynamicLightmapUV);
		#endif
		return gi;
	#elif defined(DYNAMICLIGHTMAP_ON)
		return SampleDynamicLightmap(input.dynamicLightmapUV);
	#else
		return SampleLightProbes(surface);
	#endif
}

Tres casos:
1: Si abre una iluminación estática, la iluminación estática de muestreo. Si la iluminación abierto y dinámico, iluminación dinámica y luego continuar el muestreo.
2: iluminación dinámica sólo está abierta, la iluminación dinámica.
3: El movimiento no se abre, la luz de la sonda de muestreo por defecto.

Muestreo de iluminación estática:

float3 SampleLightmap (float2 uv) 
{
	return SampleSingleLightmap(
		TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), uv,
		float4(1, 1, 0, 0),
		#if defined(UNITY_LIGHTMAP_FULL_HDR)
			false,
		#else
			true,
		#endif
		float4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0, 0.0)
	);
}

Aquí la función función SampleSingleLightmap llamando, lo que a:
D: \ Archivos de programa \ Unity2018.3.0f2 \ Unidad \ Editor \ la Pena de datos \ Resources \ PackageManager \ Editor \ paquete de \ ShaderLibrary \ EntityLighting.hlsl

real3 SampleSingleLightmap(
TEXTURE2D_ARGS(lightmapTex, lightmapSampler), 
float2 uv, float4 transform, bool encodedLightmap, real4 decodeInstructions)
{
    // transform is scale and bias
    uv = uv * transform.xy + transform.zw;
    real3 illuminance = real3(0.0, 0.0, 0.0);
    // Remark: baked lightmap is RGBM for now, dynamic lightmap is RGB9E5
    if (encodedLightmap)
    {
        real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
        illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions);
    }
    else
    {
        illuminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgb;
    }
    return illuminance;
}

TEXTURE2D_PARAM y TEXTURE2D_ARGS definiciones de macro:

#define TEXTURE2D_PARAM(textureName, samplerName)                textureName, samplerName
#define TEXTURE2D_ARGS(textureName, samplerName)                 TEXTURE2D(textureName),         SAMPLER(samplerName)

Aquí el cuarto parámetro: float4 transformar UV es escalado y compensado.

// transform is scale and bias
uv = uv * transform.xy + transform.zw;

A medida que tratan de hacer pasar los rayos UV que ha sido escalado y compensado (en el procesamiento de sombreado de vértices), se pasa a la transformada es (1,1,0,0), los dos primeros están reduciendo UV, después de Offset UV es dos.

#if defined(LIGHTMAP_ON)
	output.lightmapUV = input.lightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
#endif

Los primeros cinco parámetros: encodedLightmap
si es verdadera:

if (encodedLightmap)
{
    real4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
    illuminance = DecodeLightmap(encodedIlluminance, decodeInstructions);
}

SAMPLE_TEXTURE2D define como sigue:

#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2)                               textureName.Sample(samplerName, coord2)

formularios de muestreo #define half4 real4 (plataforma móvil) o REAL4 float4 #define
función DecodeLightmap de la siguiente manera:
// Observación, la: al horno lightmap IS RGBM por ahora, IS Dinámico RGB9E5 lightmap

real3 DecodeLightmap(real4 encodedIlluminance, real4 decodeInstructions)
{
	#if defined(UNITY_LIGHTMAP_RGBM_ENCODING)
	    return UnpackLightmapRGBM(encodedIlluminance, decodeInstructions);
	#elif defined(UNITY_LIGHTMAP_DLDR_ENCODING) //双倍低动态double low dynamic range(色值乘二...)
	    return UnpackLightmapDoubleLDR(encodedIlluminance, decodeInstructions);
	#else // (UNITY_LIGHTMAP_FULL_HDR)
	    return encodedIlluminance.rgb;
	#endif
}

Primero: UnpackLightmapRGBM

real3 UnpackLightmapRGBM(real4 rgbmInput, real4 decodeInstructions)
{
	#ifdef UNITY_COLORSPACE_GAMMA
	    return rgbmInput.rgb * (rgbmInput.a * decodeInstructions.x);
	#else
	    return rgbmInput.rgb * (PositivePow(rgbmInput.a, decodeInstructions.y) * decodeInstructions.x);
	#endif
}

Segundo: UnpackLightmapDoubleLDR

real3 UnpackLightmapDoubleLDR(real4 encodedColor, real4 decodeInstructions)
{
    return encodedColor.rgb * decodeInstructions.x;
}

Ver dos macros: LIGHTMAP_HDR_MULTIPLIER y LIGHTMAP_HDR_EXPONENT

#define LIGHTMAP_RGBM_MAX_GAMMA     real(5.0)       // NB: Must match value in RGBMRanges.h
#define LIGHTMAP_RGBM_MAX_LINEAR    real(34.493242) // LIGHTMAP_RGBM_MAX_GAMMA ^ 2.2

#ifdef UNITY_LIGHTMAP_RGBM_ENCODING
    #ifdef UNITY_COLORSPACE_GAMMA
        #define LIGHTMAP_HDR_MULTIPLIER LIGHTMAP_RGBM_MAX_GAMMA
        #define LIGHTMAP_HDR_EXPONENT   real(1.0)   // Not used in gamma color space
    #else
        #define LIGHTMAP_HDR_MULTIPLIER LIGHTMAP_RGBM_MAX_LINEAR
        #define LIGHTMAP_HDR_EXPONENT   real(2.2)
    #endif
#elif defined(UNITY_LIGHTMAP_DLDR_ENCODING)
    #ifdef UNITY_COLORSPACE_GAMMA
        #define LIGHTMAP_HDR_MULTIPLIER real(2.0)
    #else
        #define LIGHTMAP_HDR_MULTIPLIER real(4.59) // 2.0 ^ 2.2
    #endif
    #define LIGHTMAP_HDR_EXPONENT real(0.0)
#else // (UNITY_LIGHTMAP_FULL_HDR)
    #define LIGHTMAP_HDR_MULTIPLIER real(1.0)
    #define LIGHTMAP_HDR_EXPONENT real(1.0)
#endif

SampleDynamicLightmap

float3 SampleDynamicLightmap (float2 uv) 
{
	return SampleSingleLightmap(
		TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), uv,
		float4(1, 1, 0, 0), false,
		float4(LIGHTMAP_HDR_MULTIPLIER, LIGHTMAP_HDR_EXPONENT, 0.0, 0.0)
	);
}

SampleLightProbes

float3 SampleLightProbes (LitSurface s) 
{
	if (unity_ProbeVolumeParams.x) 
	{
		return SampleProbeVolumeSH4(
			TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),
			s.position, s.normal, unity_ProbeVolumeWorldToObject,
			unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
			unity_ProbeVolumeMin, unity_ProbeVolumeSizeInv
		);
	}
	else {
		float4 coefficients[7];
		coefficients[0] = unity_SHAr;
		coefficients[1] = unity_SHAg;
		coefficients[2] = unity_SHAb;
		coefficients[3] = unity_SHBr;
		coefficients[4] = unity_SHBg;
		coefficients[5] = unity_SHBb;
		coefficients[6] = unity_SHC;
		return max(0.0, SampleSH9(coefficients, s.normal));
	}

Aquí rechazado rastreado, adiós! ! !

Publicados 646 artículos originales · ganado elogios 107 · vistas 360 000 +

Supongo que te gusta

Origin blog.csdn.net/wodownload2/article/details/105114964
Recomendado
Clasificación