I am currently working on a shader that will simulate issues with a connection on the back of a TV, more descriptively the Y, Pr, and Pb signals on the TV. This is my first unity shader. I have done some basic shaders for Renderman by pixar for CG work but this is my first unity shader so I am sure to have some questions.
Basically before I start writing it I worked out the math based on Equations on Wikipedia and I have some questions about accessing data for the shader in unity:
First the Math
What I would like to do is take an RBGA texture, convert it to YPrPb then back with eather the PrPb switched or one missing.
The equation for Y is : Y = 0.2126 R + 0.7152 G + 0.0722 B
Then I can solve for Pb and Pr Pr = Y-R Pb = Y-B
now converting back I solve for R and B first: R=Y+Pr B=Y+Pb
Then solving for G is a bit more tricky
G = Y-(.2126 R)-( 0.0722 B) / .7152
With the RGB Values I can manipulate the picture on the TV based on the inputs. Is this math correct?
My second question is can I access data from a game object in unity from within my shader and if so how?
Thanks for the math and the shader help! I will take a crack at it. I am trying to simulate what would happen to the picture on a HDTV if you remove or mix up one the composite cables. I will post the results once I get it written.
Hey Thank you for helping a new comer to writing shaders for unity. I am trying to find out how to access the red, green, and blue component of a texture I am bringing in. I cannot find it out in the reference. Could you point me to where I can find out how to access the RGB components of the image that I am reading in?
I was able to figure out how to access the different properties and replicated composite input issues. Thanks for your help!
I had no idea that writing shaders in unity would be this straight forward! If some reason somone wants to replicate manipulating an RGB signal for a YPbPr input here is the code, though I don’t think that is super common ; )