Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (34 sloc) 1.62 KB
/*Input Values...
float3 CameraPosition, float3 UVW, Tex2D Tex, float2 SubImages, int Steps, float StepsMultiplier float3 UVWScale, float3 WindVector
*/
/*Prequisites*/
Steps = trunc(Steps);
const float StepsDistance = StepsMultiplier / Steps;
const float3 windOffset = (WindVector*ResolvedView.RealTime);
UVW = (-UVW / UVWScale) + windOffset;
CameraPosition = (CameraPosition / UVWScale) + windOffset;
const float3 camDir = Parameters.CameraVector; //Replace?
//const float3 d = normalize(CameraPosition - UVW);
struct VolumeFunctions
{
inline float4 Texture2DVolumeFlipbookSample(float3 UVW, Texture2D Tex, float2 SubImages)
/*Texture sample for a flipbook volume texture, linearly lerp between flipbook layers*/
{
float2 fsi = {(SubImages.x * SubImages.y), SubImages.y};
float2 f0_uv = (floor((fsi)*(frac(UVW).z + ((1/(SubImages.x * SubImages.y))*0)).xx)/SubImages)+(frac(UVW.xy)/SubImages);
float2 f1_uv = (floor((fsi)*(frac(UVW).z + ((1/(SubImages.x * SubImages.y))*1)).xx)/SubImages)+(frac(UVW.xy)/SubImages);
return lerp(
Texture2DSample(Tex, View.MaterialTextureBilinearWrapedSampler, f0_uv),
Texture2DSample(Tex, View.MaterialTextureBilinearWrapedSampler, f1_uv),
frac(frac(UVW.z)*(SubImages.x * SubImages.y)));
}
};
static const VolumeFunctions f;
float4 currentDensity = 0;
float3 CurrentPosition = UVW;
for(int i = 0; i < Steps; i++)
{
currentDensity += f.Texture2DVolumeFlipbookSample(CurrentPosition, Tex, SubImages);
CurrentPosition += -camDir*StepsDistance;
}
return 1-(saturate(currentDensity/Steps));