Context: I invented a solution to get ugly GI for low finish platform (goal being Mali 400 mp GPU) by texture suggestions and texture PVS.
Downside: To be able to bypass the precision restrict of 8bits textures, once I accumulate mild in a number of cross, I attempted to encode the consequence as YCoCg with 16bits float packing of the Y parts within the RG channel. Nevertheless the consequence do not work as supposed, within the take a look at case I’ve no colours, however the decoding again to RGB present purple and inexperienced outcomes as a substitute of shades of grey.
(at this level of time picture embedding is failing and imgur’s web site is not responding on my laptop, will replace when an answer is discovered).
Right here is the code that encode to chromalum in fragment:
//chromaLum encoding
float3 chromalum = RgbToYCoCg(irradiance);
//divide lum by num ray
chromalum.x /= numRays;
//flip the Y (lum) into 16bits
float4 lum = Float32ToIntrgba(chromalum.x);
//encode break up lum and chroma
float4 consequence = float4(lum.x,lum.y, chromalum.y,chromalum.z);
//return 16bit encoding to accumulation //show materials should reconstruct RGB from chroma lum
return consequence;
And right here is the half that decode it again
fixed4 shade = tex2D(_MainTex, enter.uv);
fixed4 GI = tex2D(_GI, enter.uv); //return GI;
//decode GI (16bit -> chromalum -> RGB)
float luminance = IntrgbaToFloat32(float4(GI.xy,0,0)); //return luminance*16;
float3 lighting = YCoCgToRgb(float3(luminance,GI.z,GI.w));
// return float4(lighting,1);
GI = float4(lighting,1);
shade += GI; //ought to masks albedo with mild, not including mild, at the moment shade is black, so add is a hack
return shade;
Perform particulars are right here:
float3 RgbToYCoCg(float3 c){
float Y = 0.25 * c.r + 0.5 * c.g + 0.25 * c.b;
float Cb = 0.5 * c.r - 0.0 * c.g - 0.50 * c.b;
float Cr = -0.25 * c.r + 0.5 * c.g - 0.25 * c.b;
return float3(Y, Cb, Cr);
}
float3 YCoCgToRgb(float3 c){
float R = c.x + c.y - c.z;
float G = c.x + c.z;
float B = c.x - c.y - c.z;
return float3(R, G, B);
}
float4 Float32ToIntrgba(float floatValue){
const float toFixed = 255.0/256;
float4 output;
output.r = frac(floatValue*toFixed*1);
output.g = frac(floatValue*toFixed*255);
output.b = frac(floatValue*toFixed*255*255);
output.a = frac(floatValue*toFixed*255*255*255);
return output;
}
float IntrgbaToFloat32(float4 Worth){
const float fromFixed = 256.0/255;
float enter;
enter =
Worth.r*fromFixed/(1)
+Worth.g*fromFixed/(255)
+Worth.b*fromFixed/(255*255)
+Worth.a*fromFixed/(255*255*255);
return enter;
}