Welcome, Guest.
Username: Password: Remember me

TOPIC: S-Log3 shader

S-Log3 shader 1 year 3 weeks ago #1

  • moriz1
  • moriz1's Avatar
  • Offline
  • Posts: 47
  • Thank you received: 26
so, i was reading up on some camera reviews, and i came across this feature (for the Sony a7s II): link

specifically, it is a feature that allows the camera to capture more dynamic range in videos, without having to record in uncompressed form. i was thinking that something like this would make it easier to grade frames in post. so, i found Sony's implementation (LINK: second last page), and tried to implement it in shader form.

here's what i got:
/**
 * S-Log3 Simulation
 * by moriz1
 */

#include "ReShade.fxh"

float3 SLog3(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target {
	float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
	float3 cutoff = float3(0.01125, 0.01125, 0.01125);
	
	if (color.r >= cutoff.r || color.g >= cutoff.g || color.b >= cutoff.b) {
        color.rgb = (420.0 + log10((color.rgb + 0.01) / (0.18 + 0.01)) * 261.5) / 1023.0;
    }
    else {
        color.rgb = (color.rgb * (171.2102946929 - 95.0) / 0.01125 + 95.0) / 1023.0;
    }
	
	return saturate(color);
}

technique SLogThree {
	pass ToSLogThree {
		VertexShader = PostProcessVS;
		PixelShader = SLog3;
	}
}

well, it "works", but the result looks nothing like that video. the effect is dramatically more pronounced: i.imgur.com/8ZECCWJ.jpg

so my question is: am i doing it right? i know most camera sensors can manage around 14bit per color channel, but reshade shaders are typically 32bit per channel. i don't know if i have to do any kind of adjustments in the code to account for it.
Last Edit: 1 year 3 weeks ago by moriz1.
The administrator has disabled public write access.

S-Log3 shader 1 year 3 weeks ago #2

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 942
  • Thank you received: 945
Color channel that ReShade grabs from the game is always 8 bit per channel (LDR range, common 000000-FFFFFF color space). No matter what algorithms you apply on it afterwards, the colors still have only 256 different shades per channel. What you do is just like upscaling 800x600 on a 4k screen and think it's true 4k. Same here. It's not XX bit data, it's 8 bit data blown up on higher bit storage.
What the shader you originally got there does is allowing cameras to capture a higher dynamic range (range, not data amount. 0-100 in 100 steps are 100x steps of 1. 1-1000 in 100 steps are 100 steps of 10. Different range, same amount of data).
It's basically tonemapping while capturing video, instead of capturing in uncompressed and tone mapping in offline tools. Hope that clears it up a bit :)
The administrator has disabled public write access.

S-Log3 shader 1 year 3 weeks ago #3

  • moriz1
  • moriz1's Avatar
  • Offline
  • Posts: 47
  • Thank you received: 26
Marty McFly wrote:
Color channel that ReShade grabs from the game is always 8 bit per channel (LDR range, common 000000-FFFFFF color space). No matter what algorithms you apply on it afterwards, the colors still have only 256 different shades per channel. What you do is just like upscaling 800x600 on a 4k screen and think it's true 4k. Same here. It's not XX bit data, it's 8 bit data blown up on higher bit storage.
What the shader you originally got there does is allowing cameras to capture a higher dynamic range (range, not data amount. 0-100 in 100 steps are 100x steps of 1. 1-1000 in 100 steps are 100 steps of 10. Different range, same amount of data).

i'm well aware. i'm not looking for some magical formula to somehow get me more data.

what i AM hoping for, is a shader that allows me to store more dynamic range in the color space that we do have, by giving more of that space for shadow and highlights, and less for midtones. the formula for S-Log3 appears to do just that: more dynamic range being recorded to a LDR format, and then you bring back the correct color balance in post, while preserving the dynamic range.
Marty McFly wrote:
It's basically tonemapping while capturing video, instead of capturing in uncompressed and tone mapping in offline tools. Hope that clears it up a bit :)

my understanding of the purpose of S-Log3, is specifically so that you can record in compressed form without losing dynamic range data, and then fixing the color balance in post. my goal with the shader is similar: attempt to capture more dynamic range using S-Log3, store that data in a HDR texture, restore color data using a different shader, and then use deband to hide any banding. basically, LDR->HDR with S-Log3->graded LDR.
Last Edit: 1 year 3 weeks ago by moriz1.
The administrator has disabled public write access.

S-Log3 shader 1 year 3 weeks ago #4

  • v00d00m4n
  • v00d00m4n's Avatar
  • Offline
  • Posts: 77
  • Thank you received: 21
it does not work like that.

S-log is for cameras, cameras capture footage in that "flat" grey format, then camera specific LUTs or curves applied in post processing to convert S-log captured videos to properly colored image (and unfortunately most of dumb fuck movie editors does not do that right and we have washed out grey movies and tv series in result. like Mr. Robot for example) with high contrast.

It useless for games, until some dumb fuck devs (trust me, there are lot of them in AAA industry) who don't know what they doing (for example Fable Anniversary has a color grading very similar to S-log captured footage), made some post process shader for game that outputs in s-log format. Only for such games it would be useful to have S-log to RGB conversion shader.

Also you probably don't realise, that while most of modern game outputs on pc as HDR 0-255 they have post processing calibrations that outputs in LDR range of around 16-235 ( or actually around 233 222 211 for White point, check gta v and witche 3 for example in hudless mode under histogram - total lack of white, too much of red, a little less of green and way too less of blue, seems like PS4 or o X1 specific calibrations that lazy or stupid PC devs from Rockstar and CDPR didn't change for PC..

You don't have HDR input to begin with. If you want to correct such LDR consolish games to HDR you have to use Levels shader that basically shifts white and black points and color range between them. The only problem with it - it does it with banding and clipping.. Would be nice to combine it with some visual curve editor shader so that that we can keep colors that was in 0-16 and 335-255 range at same positions and only expand everything between 16-235 to 0-255, with some configurable grain and debanding attached.
Last Edit: 1 year 1 week ago by v00d00m4n.
The administrator has disabled public write access.
The following user(s) said Thank You: Marty McFly, Anal_destroyer