Untitled
unknown
csharp
3 years ago
2.6 kB
8
Indexable
//-----------------------------------------------
// reproject to previous frame and pull history
//-----------------------------------------------
//I basically hardcoded 1280x720 aspect ratio X(
//Y_Scale = 1;
//X_Scale = 0.315;
//X_Offset = 0.345;
//Y_Offset = 0;
float resT;
float3 col = Indirect_Lighting;
float Aspect_Ratio = (float) Resolution[1] / (float) Resolution[0];
float nearfield = 10;
float farfield = 3000;
float3 pos = normalize(World_Pos - Pos_camera_previous) * (nearfield + (farfield - nearfield)) + Pos_camera_previous;
float2 uv2 = 0;
float3 toCam = mul(World_Matrix_Previous_Frame, float4(pos, 1));
float camPosZ = toCam.z;
float height = 2 * camPosZ / World_Matrix_Projection_Previous_Frame._m11;
float width = Aspect_Ratio * height;
uv2.x = X_Scale * (1 - (toCam.x + width / 2) / width) + X_Offset;
uv2.y = 1 - (Y_Scale * ((toCam.y + height / 2) / height) + Y_Offset);
float2 reprojecton_uv = uv2.xy;
float2 new_uv = 0.5 * uv_view.xy + 0.5;
float4 wpos = float4(World_Pos, 1.0);
// convert to camera space
float4 rp_cs_pos = mul(World_Matrix_Previous_Frame, wpos);
// convert to NDC space (project)
float2 rp_ss_ndc = rp_cs_pos.xy / rp_cs_pos.w;
float2 Change = float2(reprojecton_uv.x - new_uv.x, reprojecton_uv.y - new_uv.y);
int3 Texture_Pos = int3(uv2.x * Resolution.x, uv2.y * Resolution.y, 0);
float Drifting_Threshold = 0.002;
Drifting_Threshold = 0.00001;
if (Change.x < Drifting_Threshold && Change.y < Drifting_Threshold * 1.3)
{
// should stop drifting
Texture_Pos = int3(new_uv.x * Resolution.x, new_uv.y * Resolution.y, 0);
if (Graphics_Settings[26].status == 1)
col = float3(0, 1, 0);
}
float4 ocolt = _RT_Previous_Frame.Load(Texture_Pos);
// if we consider the data contains the history for this point
float Change_Threshold = 0.08;
if ((Change.y > 0.08 || Change.x > Change_Threshold * 1.3) || Texture_Pos[0] > Resolution[0] || Texture_Pos[0] < 0 || Texture_Pos[1] > Resolution[1] || Texture_Pos[1] < 0)
{
if (Graphics_Settings[26].status == 1)
col = float3(1, 0, 0);
}
else
{ // blend with history (it's a IIR low pas filter really)
col = lerp(ocolt.xyz, col, 0.08 * Graphics_Settings[14].status);
}
Output_Texture_Photons[id.xy] = float4(col, 1);
if (_Debug == 6)
{
// Output_Texture_Photons[id.xy] = float4(ocolt.rgb, 1);
Output_Texture_Photons[id.xy] = float4(Change.x, Change.y, 0, 1);
}Editor is loading...