// TODO: the packing here is inefficient as we will fetch values far away from each other and they may not fit into the cache - Suggest we pack RGB continuously
// TODO: The calcul of texcoord could be perform with a single matrix multicplication calcualted on C++ side that will fold probeVolumeMin and probeVolumeSizeInv into it and handle the identity case, no reasons to do it in C++ (ask Ionut about it)
// It should also handle the camera relative path (if the render pipeline use it)
real3 SampleProbeVolumeSH4(TEXTURE3D_ARGS(SHVolumeTexture, SHVolumeSampler), real3 positionWS, real3 normalWS, real 4x4 WorldToTexture,
real transformToLocal, real texelSizeX, real3 probeVolumeMin, real 3 probeVolumeSizeInv)
float3 SampleProbeVolumeSH4(TEXTURE3D_ARGS(SHVolumeTexture, SHVolumeSampler), float3 positionWS, float3 normalWS, float 4x4 WorldToTexture,
float transformToLocal, float texelSizeX, float3 probeVolumeMin, float 3 probeVolumeSizeInv)
real3 position = (transformToLocal == 1.0) ? mul(WorldToTexture, real 4(positionWS, 1.0)).xyz : positionWS;
real 3 texCoord = (position - probeVolumeMin) * probeVolumeSizeInv.xyz;
float3 position = (transformToLocal == 1.0) ? mul(WorldToTexture, float 4(positionWS, 1.0)).xyz : positionWS;
float 3 texCoord = (position - probeVolumeMin) * probeVolumeSizeInv.xyz;
// Clamp to edge of the "internal" texture, as R is from real texel to size of R texture minus real texel.
// Clamp to edge of the "internal" texture, as R is from half texel to size of R texture minus half texel.
real 4 shAr = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
float 4 shAr = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
real 4 shAg = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
float 4 shAg = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
real 4 shAb = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
float 4 shAb = SAMPLE_TEXTURE3D(SHVolumeTexture, SHVolumeSampler, texCoord);
real4 SampleProbeOcclusion(TEXTURE3D_ARGS(SHVolumeTexture, SHVolumeSampler), real3 positionWS, real 4x4 WorldToTexture,
real transformToLocal, real texelSizeX, real3 probeVolumeMin, real 3 probeVolumeSizeInv)
float4 SampleProbeOcclusion(TEXTURE3D_ARGS(SHVolumeTexture, SHVolumeSampler), float3 positionWS, float 4x4 WorldToTexture,
float transformToLocal, float texelSizeX, float3 probeVolumeMin, float 3 probeVolumeSizeInv)
real3 position = (transformToLocal == 1.0) ? mul(WorldToTexture, real 4(positionWS, 1.0)).xyz : positionWS;
real 3 texCoord = (position - probeVolumeMin) * probeVolumeSizeInv.xyz;
float3 position = (transformToLocal == 1.0) ? mul(WorldToTexture, float 4(positionWS, 1.0)).xyz : positionWS;
float 3 texCoord = (position - probeVolumeMin) * probeVolumeSizeInv.xyz;
// Sample fourth texture in the atlas
// We need to compute proper U coordinate to sample.
return (decodeInstructions.x * pow(alpha, decodeInstructions.y)) * encodedIrradiance.rgb;
}
real3 SampleSingleLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), real2 uv, real 4 transform, bool encodedLightmap)
float3 SampleSingleLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), float2 uv, float 4 transform, bool encodedLightmap)
real3 illuminance = real 3(0.0, 0.0, 0.0);
float3 illuminance = float 3(0.0, 0.0, 0.0);
real 4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
float 4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance);
}
else
return illuminance;
}
real 3 SampleDirectionalLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), TEXTURE2D_ARGS(lightmapDirTex, lightmapDirSampler), real2 uv, real4 transform, real 3 normalWS, bool encodedLightmap)
float 3 SampleDirectionalLightmap(TEXTURE2D_ARGS(lightmapTex, lightmapSampler), TEXTURE2D_ARGS(lightmapDirTex, lightmapDirSampler), float2 uv, float4 transform, float 3 normalWS, bool encodedLightmap)
// in a way, that using it for real Lambert and then dividing by a "rebalancing coefficient"
// in a way, that using it for half Lambert and then dividing by a "rebalancing coefficient"
// gives a result close to plain diffuse response lightmaps, but normalmapped.
// Note that dir is not unit length on purpose. Its length is "directionality", like
uv = uv * transform.xy + transform.zw;
real 4 direction = SAMPLE_TEXTURE2D(lightmapDirTex, lightmapDirSampler, uv);
float 4 direction = SAMPLE_TEXTURE2D(lightmapDirTex, lightmapDirSampler, uv);
real3 illuminance = real 3(0.0, 0.0, 0.0);
float3 illuminance = float 3(0.0, 0.0, 0.0);
real 4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
float 4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeLightmap(encodedIlluminance);
}
else
real halfLambert = dot(normalWS, direction.xyz - 0.5) + 0.5;
float halfLambert = dot(normalWS, direction.xyz - 0.5) + 0.5;
return illuminance * halfLambert / max(1e-4, direction.w);
}