View Single Post
Old 17th March 2014, 02:49   #7  |  Link
JanWillem32
Registered User
 
JanWillem32's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,083
I can perhaps help with some parts. To start off with one shader, for the DPX shader I see that you've tried to use the XYZ color space. The XYZ color space is the both the easiest and the hardest color space to manipulate. It demands linear light input, and also filters in linear light mode. That means that it's great for linear scaling, but will not work for any filter that expects non-linearity at all. It's also all-positive, and can encode all colors in the human-visable spectrum. The down-side to that is that it also encodes non-existing colors (which are actually not that hard to deal with).
Assuming R'G'B' input, the first conversion step is done by converting R'G'B' to RGB: "s1 = sign(s1)*pow(abs(s1), 2.4);// to linear RGB, negative input compatible". (The pow instructions will produce a NaN on all negative inputs. This method isn't the cleanest way to deal with exponentiation, but it does the job.) Note the standard 2.4 factor. This is correct for all consumer-grade digital video. For some reason the standards do specify all sorts of weird OECF formats, but those are usually not even close to the image reproduction reference.
After converting to RGB, you can convert to XYZ by matrix multiplication. There are four matrices in use for consumer-grade digital video (see code box at the bottom of this post). The line "c0 = mul(XYZ, c0);" as already in the shader will work fine, but breaking it up into multiply-add operations may be faster. (To try that: transpose() the matrix, use "s1 = s1.x*matrix[0]+s1.y*matrix[1]+s1.z*matrix[2];" and read the report from GPU ShaderAnalyzer or similar to determine if it's faster.)
Note that conversion to plain XYZ will yield a color space based on white point E. This means that the input white point will not be {1, 1, 1} on output when using these (unless the input white point was already E, but that's not the case for consumer-grade digital video). There are also white-point adapted matrices, that will fully or partially adapt the input white point. Different methods of these will yield different XYZ conversion matrices.
The line "float luma = dot(c0, float3(0.30, 0.59, 0.11)); //Use BT 709 instead?" is odd. XYZ doesn't describe luma at all. It does store luminance in the Y channel. If you denormalize the Y channel you actually get values expressed in cd/mē. Of course it's linear-light, and if you scale Y, you have to scale X and Z as well. XYZ is mostly good at encoding color, but not so much at describing it. Scaling in XYZ works fine, as long as you scale the three channels with the same factor. For describing actual color, by all means look beyond Y'CbCr, R'G'B', HSV, HSL, RGB and XYZ for a CAM (color appearance model). I achieved good results with CIECAM02 and at the moment I'm testing XLRCAM. These do specify lots of conversions and parameters to deal with, but these are totally worth it.

Some technical issues:
-"static float3x3 RGB" and "static float3x3 XYZ" are not marked const, even though their intention is so.
-"float4 DPXPass(float4 InputColor){" in this case it won't be a problem, but the compiler is horrible at inlining functions (even using a #define as a function will usually optimize better).
-As I already noted, check the usage of mul() intrinsics, as the compiler generally won't optimize by multiplying matrices with consecutive scalars and vectors.
-As I already noted, check the usage of pow() intrinsics where negative inputs can be expected, as NaN outputs will cause artifacts.

The notes that I made to construct the basis XYZ and LMS matrices:
Code:
BT.709 RGB to XYZ matrix
506752./1228815., 87881./245763., 12673./70218.,
87098./409605., 175762./245763., 12673./175545.,
7918./409605., 87881./737289., 1001167./1053270.
BT.709 RGB to LMS matrix
722868859153469683239595115393861./2255010826531620584211453297294600., 2585192674261804536498018473512337./4059019487756917051580615935130280., 431657167547167713128315634772483./10147548719392292628951539837825700.,
12180008436477856247752895389891./75167027551054019473715109909820., 307102197566215335489903665465341./405901948775691705158061593513028., 82569264131239864825730732355689./1014754871939229262895153983782570.,
53058419719444384066923671296./3075014763452209887561072678129., 111365697442061984458791034130./1025004921150736629187024226043., 2687859251406579550117775904443./3075014763452209887561072678129.
LMS to BT.709 RGB matrix
25377313278362757037750367./4668794666720483257968250., -214723657934986669707431539./46687946667204832579682500., 7638471818563931909610369./46687946667204832579682500.,
-605343464019237999732424841./518184319406495060865758750., 12063681187144308402184664197./5181843194064950608657587500., -828403352886977796202828287./5181843194064950608657587500.,
396581977151187822859327./10461567155328133121940425., -20775485687965286836237859./104615671553281331219404250., 121425337469734739827048839./104615671553281331219404250.

SMPTE 170M/SMPTE 240M/SMPTE C (NTSC) RGB to XYZ matrix
401584./932715., 2548549./7461720., 88721./497448.,
276089./1243620., 87881./124362., 88721./1243620.,
25099./1243620., 966691./7461720., 7008959./7461720.
SMPTE 170M/SMPTE 240M/SMPTE C (NTSC) RGB to LMS matrix
4582795022958559125948622834369921./13693077790023334631838222431764800., 465527727195754310063646435959647./746895152183090979918448496278080., 431705826356959866042061203601013./10269808342517500973878666823823600.,
77217992358463681223124506539751./456435926334111154394607414392160., 56048129428711216246386203396963./74689515218309097991844849627808., 82578571800427591248026245959679./1026980834251750097387866682382360.,
42047021865948932675414158432./2334047350572159312245151550869., 1103514589028385241176926280029./9336189402288637248980606203476., 2688162241932152092367341096573./3112063134096212416326868734492.
LMS to SMPTE 170M/SMPTE 240M/SMPTE C (NTSC) RGB matrix
763198626475360358257813253./147994540717374853866816250., -6373975142277374689886058001./1479945407173748538668162500., 221934284697519645976087971./1479945407173748538668162500.,
-605343464019237999732424841./518184319406495060865758750., 12063681187144308402184664197./5181843194064950608657587500., -828403352886977796202828287./5181843194064950608657587500.,
27361298410291889828212027./523137322083995952425108750., -1196635193693957989329923759./5231373220839959524251087500., 6154395430430998615298890989./5231373220839959524251087500.

BT.470-2 System M RGB to XYZ matrix
43349./71416., 12387./71416., 3581./17854.,
21351./71416., 293159./499912., 7162./62489.,
0., 4129./62489., 139659./124978.
BT.470-2 System M RGB to LMS matrix
4849241781348846485632006241./10503846560761984531342857600., 34978470582276588065997919961./73526925925333891719400003200., 35966897450120142609203434./574429108791671029057812525.,
1160596510009705046375091833./5251923280380992265671428800., 24013221393818167547899894193./36763462962666945859700001600., 72282281230950671674601009./574429108791671029057812525.,
-76116568237764117836011./65649041004762403320892860., 25082445529946839408599149./459543287033336823246250020., 108748414370263583165625737./114885821758334205811562505.
LMS to BT.470-2 System M RGB matrix
6356039832931337684547833./1907495674013736213630625., -9291369607363479369136241./3814991348027472427261250., 15771251581131057092073./152599653921098897090450.,
-13887055372386146338232481./12173183366310226933664375., 57992533744044875121627737./24346366732620453867328750., -234882250666085143113361./973854669304818154693150.,
737565350893551523311808./10557561064363507544066875., -1481563549980151961947408./10557561064363507544066875., 452062370538004319308099./422302442574540301762675.

BT.470-2 System B,G/EBU 3213 (PAL/SECAM) RGB to XYZ matrix
51177./130049., 4987652./13655145., 5234753./27310290.,
82858./390147., 1367582./1950735., 168863./1950735.,
2437./130049., 1528474./13655145., 5234753./5462058.
BT.470-2 System B,G/EBU 3213 (PAL/SECAM) RGB to LMS matrix
782910914364235953227073443841197./2505869460647788817876743483379180., 47437201892727083793508359035427793./75176083819433664536302304501375400., 4251554495779502145981742150711697./75176083819433664536302304501375400.,
124459316400474051550350235432343./751760838194336645363023045013754., 5551656166817314597571817932574949./7517608381943366453630230450137540., 240453017040437113518303387746387./2505869460647788817876743483379180.,
190503071007861562472684780870./11390315730217221899439743106269., 3484707111371743136520220253336./34170947190651665698319229318807., 30114730866256337874380954722861./34170947190651665698319229318807.
LMS to BT.470-2 System B,G/EBU 3213 (PAL/SECAM) RGB matrix
5889610677243193337436144851./1005872293755806060844662500., -50563246336667155788637763367./10058722937558060608446625000., 1725862501793283022722939857./10058722937558060608446625000.,
-156299752813513892312443129./118586087319713310233175625., 2972168594434151167364839293./1185860873197133102331756250., -223310193101879141908651753./1185860873197133102331756250.,
41217384068187972753550441./995689156108134584983951250., -1937830199233462093713839397./9956891561081345849839512500., 11482547919632928216017847487./9956891561081345849839512500.
__________________
development folder, containing MPC-HC experimental tester builds, pixel shaders and more: http://www.mediafire.com/?xwsoo403c53hv
JanWillem32 is offline   Reply With Quote