![unity – customized 8Bits RGBA textures YCoCg encoding decoding with 16 bits Y packing not working appropriately unity – customized 8Bits RGBA textures YCoCg encoding decoding with 16 bits Y packing not working appropriately](https://thefuntrove.com/wp-content/uploads/https://cdn.sstatic.net/Sites/gamedev/Img/apple-touch-icon@2.png?v=9bca23db2259)
[ad_1]
Context: I invented a technique to get ugly GI for low finish platform (goal being Mali 400 mp GPU) via texture suggestions and texture PVS.
Problem: In order to bypass the precision restrict of 8bits textures, once I accumulate gentle in a number of go, I attempted to encode the end result as YCoCg with 16bits float packing of the Y parts within the RG channel. However the end result 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).
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 end result = float4(lum.x,lum.y, chromalum.y,chromalum.z);
//return 16bit encoding to accumulation //show materials should reconstruct RGB from chroma lum
return end result;
And right here is the half that decode it again
fixed4 coloration = 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);
coloration += GI; //ought to masks albedo with gentle, not including gentle, presently coloration is black, so add is a hack
return coloration;
Function 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 Value){
const float fromFixed = 256.0/255;
float enter;
enter =
Value.r*fromFixed/(1)
+Value.g*fromFixed/(255)
+Value.b*fromFixed/(255*255)
+Value.a*fromFixed/(255*255*255);
return enter;
}
[ad_2]