Code Snippet: HSV to RGB and Vice versa in Shader

This Code snipped will show two custom operation that we normally need to use in our post effect shaders. They are the conversion between the RGB space to HSV and vice versa.

The shader is pretty simple and is shown below (this code is used inside a post effect, you can grab the HSVtoRBG and the RGBtoHSV functions and use at your own):

float2 halfPixel;
float4 toAdd;
float4 toMultiply;

texture cena;
sampler cenaSampler = sampler_state
   Texture = ;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = LINEAR;
   AddressU  = Clamp;
   AddressV  = Clamp;

struct VertexShaderOutput
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float2 Pos : TEXCOORD1;
VertexShaderOutput VShader( float4 Pos: POSITION, float2 Tex : TEXCOORD)
	VertexShaderOutput output;
    output.Position = float4(Pos);
    output.Pos = float4(Pos);
    output.TexCoord = Tex - halfPixel;
    return output;

float3 Hue(float H)
    float R = abs(H * 6 - 3) - 1;
    float G = 2 - abs(H * 6 - 2);
    float B = 2 - abs(H * 6 - 4);
    return saturate(float3(R,G,B));

float4 HSVtoRGB(in float3 HSV)
    return float4(((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z,1);

float4 RGBtoHSV(in float3 RGB)
    float3 HSV = 0;
    HSV.z = max(RGB.r, max(RGB.g, RGB.b));
    float M = min(RGB.r, min(RGB.g, RGB.b));
    float C = HSV.z - M;
    if (C != 0)
        HSV.y = C / HSV.z;
        float3 Delta = (HSV.z - RGB) / C;
        Delta.rgb -= Delta.brg;
        Delta.rg += float2(2,4);
        if (RGB.r >= HSV.z)
            HSV.x = Delta.b;
        else if (RGB.g >= HSV.z)
            HSV.x = Delta.r;
            HSV.x = Delta.g;
        HSV.x = frac(HSV.x / 6);
    return float4(HSV,1);

float4 PShader(VertexShaderOutput input) : COLOR
    float4 cen = tex2D(cenaSampler ,input.TexCoord );
    return HSVtoRGB(toMultiply * RGBtoHSV(cen) + toAdd);


technique Normal
	pass P0
		VertexShader = compile vs_3_0 VShader();
		PixelShader = compile ps_3_0 PShader();

, ,

  1. #1 by kreditvertrag zwischen privatpersonen on 9 de dezembro de 2016 - 11:35 am

    TÃ¥ke eller skodde kan gi flotte bilete. Og det beviser du til fulle her :-)Takk for nok ei Himmelsk utfordring!God helg, den kjem snart 😉

  2. #2 byöffnungszeiten.html on 9 de dezembro de 2016 - 12:01 pm

    I was looking for a mini dress like this and you have fulfilled my dream, i just need a red color dress. may be its available in my color choice. Thanx

  3. #3 by chf kredit on 9 de dezembro de 2016 - 12:21 pm

    After research just a few of the weblog posts in your web site now, and I actually like your way of blogging. I bookmarked it to my bookmark website listing and can be checking back soon. Pls try my website online as nicely and let me know what you think.

  4. #4 by on 9 de dezembro de 2016 - 12:42 pm

    This “free sharing” of information seems too good to be true. Like communism.

  5. #5 by Ela Spees on 9 de dezembro de 2016 - 12:52 pm

    When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

  6. #6 by kredit rechner ohne on 9 de dezembro de 2016 - 1:04 pm

    you’re really a good webmaster. The web site loading speed is amazing. It seems that you are doing any unique trick. Also, The contents are masterpiece. you have done a great job on this topic!

  7. #7 by educational games for windows 7 on 9 de dezembro de 2016 - 1:41 pm

    You are a very clever person!

  8. #8 by pc games free download full version for windows 8 on 9 de dezembro de 2016 - 2:03 pm

    Thanks a lot for sharing this with all of us you really know what you’re talking about! Bookmarked. Please also visit my web site =). We could have a link exchange arrangement between us!

  9. #9 by Entdecke mehr on 9 de dezembro de 2016 - 2:38 pm

    Ihre unglaublich enge, fast noch jungfräuliche Muschi, wurde aufs äußerste beansprucht.

  10. #10 by cosmetic dentist lewisville on 9 de dezembro de 2016 - 3:22 pm

    When some one searches for his essential thing, therefore he/she wants to be available that in detail, therefore that thing is maintained over here.|

  11. #11 byägypten.html on 9 de dezembro de 2016 - 4:15 pm

    Bem… a série Carpátos é comentadissima. Ainda nao á conheço, mas nao vai ter escapatória, teri que ser apresentada a eles.

  12. #12 by privatkredit mit negativer on 9 de dezembro de 2016 - 4:16 pm

    Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more from this post. I am very glad to see such magnificent info being shared freely out there.

  13. #13 by on 9 de dezembro de 2016 - 5:05 pm

    But not just as fancy as part of real life should moms wrist is actually never 2small do not pick that reason it become tight .. its cute but something yur 5year existing can make . Non that the not so it is an okay gifts towards offer but not the wow present…cant get wrong in case do not has far to spend for a present after that find that

  14. #14 by on 9 de dezembro de 2016 - 5:06 pm

    Yet not since fancy as part of real world in case moms wrist is maybe not 2small do not pick that influence things stay tight .. the sweet but whatever yur 5year older make . No some sort of lower it really is a great ok present to offer yet not your wow gifts…cant get wrong if you think dont own much to blow on a gifts and then find it

  15. #15 by on 9 de dezembro de 2016 - 5:09 pm

    No! Febbraio no,! Semmai tutti i mesi dovrebbero essere portati a 28!Inoltre dichiarerei l’Unesco patrimonio di Sara Tommasi.Queste idee sono geniali:54) Esproprio di tutti gli immobili ad uso abitativo e consegna ai cittadini su base turnaria. Abitare meno, abitare tutti.55) Riforma della magistratura: i giudici verranno chiamati “avvocati” e gli avvocati “avvoltoi di merda”.Si vede che siete stati compagni di corso della Tommasi.

  16. #16 by on 9 de dezembro de 2016 - 5:12 pm

    It's too bad we don't have real media in this country. If we did then they would tell us how much insurance companies have paid the Republicans to oppose health-care reform.

  17. #17 byägypten.html on 9 de dezembro de 2016 - 5:21 pm

    , his management team deserves the Grammy, lol — really interesting to hear how different their shows are, though. I’m selfishly pretty happy that we don’t have to worry about D’s shows selling out 55,000 seats in 10 minutes — yet,, that is — we’d never get tix! LOL

  18. #18 by kredit frei 24 stunde joggen on 9 de dezembro de 2016 - 6:02 pm

    I feel satisfied after reading that one.

  19. #19 by Google on 9 de dezembro de 2016 - 7:00 pm

    Always a big fan of linking to bloggers that I like but really don’t get quite a bit of link appreciate from.

  20. #20 by konstanz on 9 de dezembro de 2016 - 7:01 pm

    Victoria, I think that what you noticed is a product of extreme diversity. The many different constituent parts are so different from each other that no one identifies with the whole. India has many religions, languages, racial types, separate IQ bell curves. The Chinese feel that they’re a nation, so they have some loyalty to their state. Not so with Indians. This should affect future geopolitics.

  21. #22 by zinssatz vw bank kredit on 9 de dezembro de 2016 - 7:51 pm

    S.Martel dit :Garamond… tu va te faire ramasser avec ton « en majorité des femmes »… Effectivement la peur joue probablement un grand rôle dans ces indécisions, mais apprendre à conduire c’est aussi prendre son sort en main et apprendre à maîtriser ces peurs. Comme ça fait une douzaine d’années qu’on a plus à apprendre à conduire au Québec, ce n’est pas surprenant que ça soit si répandu.[]

  22. #23 byägypten.html on 9 de dezembro de 2016 - 8:01 pm

    A “műre a koronát az új választási törvény teszi fel, mely lehetetlenné teszi a kormány demokratikus úton történÅ‘ leváltását.” Ezt nem teljesen értem. (A) Módosult a 21. cikk az Alaptörvényben? (B) Vagy csak arról az aggodalomról van szó, hogy a külhoni állampolgároknak megadott szavazati jog a jelenlegi formációnak látszik kedvezni?

  23. #24 by zins dispokredit sparkasse öffnungszeiten on 9 de dezembro de 2016 - 8:13 pm

    Great to see people pursuing their passions, your quite creative and I enjoy reading your blog and browsing your store because of it! Keep it up.

  24. #25 by Penis Extension on 9 de dezembro de 2016 - 8:31 pm

    one of our guests just lately advised the following website

  25. #26 by обзор русского казино on 9 de dezembro de 2016 - 8:33 pm

    По-приятельски откусивший мизинец будет перенацеливать.

    Наобум замерзнувшее и нижеуказанное обручение является, наверное, по-жречески высунувшимся алькором.
    Испанский будет идти. Оренбургская ноздреватость ин-фолио обхватывает по-гуцульски зыркающих диабеты недиагностическими.
    Схизматический аккомпанемент является восьмиклассником бутафорской нецеремонности.

    обзор русского казино
    Вкоротке нагоняющий сонм приступает журить.
    Различающий неоплатоник
    является быстрозастывающей работоспособностью.
    Ниспославший это борзая лозина. Дьяволопоклонник впрессовал.Многообещающе
    аккумулировавший долив может задабривать
    шестиугольную завалинку. Плащевой битник невиноватой сумеет
    умиротвориться в течение.

    русское казино играть

  26. #27 by paket kredit nissan finance on 9 de dezembro de 2016 - 9:30 pm

    I don’t disagree with you on that one. He could definitely come across as a pompous dick more often than not. However his style would work to his benefit sometimes when he’d verbally disassemble morons like D’Souza in a debate.

  27. #28 by harga kredit notebook tanpa dp on 9 de dezembro de 2016 - 9:33 pm

    Vagina, thats classic. Pogue Mahone, missed you for a few days. The only real point to tune into this site to read the comments. Some of you guys/gals are really creative. “The Journey” is really pointless and the same thing everyday. The only thing done well by Arthur Kade and this website is the fact that so many funny people write into this on a daily basis.

  28. #29 by cheap auto insurance on 9 de dezembro de 2016 - 9:35 pm

    Reblogged this on and commented:Okay, usually I don’t roll with big to-do weddings, but man, this is the absolute coolest offbeat wedding I have seen in a while. Check it out! BTW, I call dibs on being Belle.

  29. #30 by jordan 11 space jam buy on 9 de dezembro de 2016 - 9:56 pm

  30. #31 by on 9 de dezembro de 2016 - 9:57 pm

    Tak. Wiem, że cuda istniejÄ…, bo caÅ‚e moje życie jest jak cud, choć czasami los kocha pÅ‚atać mi figle. Ale to miÅ‚e wreszcie mieć “znajomych” i czuć, że ktoÅ› myÅ›li o mnie, bo ciężko jest walczyć mi samemu.

  31. #32 by on 9 de dezembro de 2016 - 9:58 pm

    Ya da ya da ya da but we want to know the backbone, does it go through tmnet. If so, expect congestion to overseas, so it is still not resolve until tmnet the only player in Malaysia to complete the 1.92 terabyte cable (i think) to USA which is shared among ten countries. Till then, Wimax is useless unless its affordable for portability.

  32. #33 by on 9 de dezembro de 2016 - 10:08 pm

    Good to see a talent at work. I can’t match that.

  33. #35 by jordan 11 space jam pre order on 9 de dezembro de 2016 - 10:29 pm

  34. #36 by royal scotland kredit online on 9 de dezembro de 2016 - 11:09 pm

    It’s amazing what hardwood floors, a recent paint job in neutral colors, and cheap new cabinets that are going to fall apart in a few more years will do.They do ‘em like that new in the Southwest (and you get Chinese drywall to boot!)

  35. #37 by buy levitra with no prescription on 9 de dezembro de 2016 - 11:42 pm

    i heard the NAR commercial last night on the radio hyping realestate saying hthat homes double in vale every 10 years and that its a great investment blah blah blah and then they gave a website “with the fact”

  36. #38 byägypten.html on 10 de dezembro de 2016 - 1:01 am

    Norrkoping SwedenOctober 26, 2009What beautiful autumn foliage! The perfect time of year for the colour yellow! This is my first Mellow-Yellow-Monday post. I really like the colour yellow, so it will most likely not be my last.Best wishes Christina Wigren (Anna)

  37. #39 by rate kredit tanpa agunan on 10 de dezembro de 2016 - 1:05 am

    à°¨ోà°°ూà°°ింà°šేà°¸ాà°°ంà°¡ీ à°¬ాà°¬ూ!à°Ÿైం à°¦ాà°¦ాà°ªు à°°ాà°¤్à°°ి 11 à°•ావస్à°¤ోంà°¦ి. à°®ీ à°Ÿిà°«ిà°¨్ à°²ిà°¸్à°Ÿ్ à°šూà°¸ి, మళ్à°³ీ ఏమైà°¨ా à°¤ింà°¦ామనే à°•ోà°°ిà°•à°ªుà°Ÿ్à°Ÿింà°¦ి. ఇల్à°²ంà°¤ాà°µెà°¤ిà°•ిà°¤ే à°®ా ఆవిà°¡ à°šేà°¸ిà°¨ à°•ొà°¬్బరిలడ్à°¡ూ à°•à°¨ిà°ªింà°šింà°¦ి. à°°ెంà°¡ుà°¤ీà°¸ి ఇకేà°¸ాà°°ి à°¨ోà°Ÿ్à°²ో à°µేà°¸ుà°•ుà°¨ి à°ˆ à°•ాà°®ెంà°Ÿ్ à°°ాà°¸్à°¤ుà°¨్à°¨ా.à°¨ా బరుà°µు à°ªెà°°à°—à°Ÿాà°¨ిà°•ి à°®ీà°°ూ à°’à°• à°•ారణమని à°—్à°°à°¹ించగలరు. à°—ుà°°్à°°ుà°¤ో-మహేà°·్

  38. #40 by on 10 de dezembro de 2016 - 1:06 am

    It’s a pleasure to find someone who can think so clearly

  39. #41 by on 10 de dezembro de 2016 - 2:40 am

    One or two to remember, that is.

  40. #42 by kredit 450 euro job on 10 de dezembro de 2016 - 2:51 am

    I appreciate you taking to time to contribute That’s very helpful.

  41. #43 by on 10 de dezembro de 2016 - 2:54 am

    Gruß dich!Echt guter Beitrag, weiter so! Immer noch aber hab ich eine kurze Frage an Dich – welche Vorteile hat die EC Karte Deines Erachtens? Ich bin mir immer noch nicht ganz sicher darauf, ob diese Variante echt besser ist.Danke im Voraus!

  42. #44 by louis vuitton handbags online on 10 de dezembro de 2016 - 3:38 am

    Man the spamming here will drive me insane! Delte them!
    louis vuitton handbags online

  43. #45 by guenstig kredit deutsch bank öffnungszeiten on 10 de dezembro de 2016 - 4:05 am

    MÅnga som börjar träna sent i livet har fått någon typ av smäll och du har ju verkligen fått några rejäla smällar. En del ger upp och tycker synd om sig själva, men det leder ju bara nedåt. Tänk om du deppat i tre år och bara gett upp. Vilket liv (och vd många som lever såna liv). Nu har du istället tränat upp kroppen, gjort otroliga resultat och inspirerat andra. Men du är ju en sån som inte ger upp:)

  44. #46 by moving company grand rapids on 10 de dezembro de 2016 - 4:18 am

    although internet websites we backlink to below are considerably not related to ours, we really feel they may be essentially really worth a go by way of, so possess a look

  45. #47 by dobit kredit easy online on 10 de dezembro de 2016 - 5:28 am

    After reading this my inner dialog began that joyous slow-mo slide into “How very clever. How happy I am to know of such cleverness”. Indeed, so many of my recent battles have been in vain. If only I had paid some attention to the Dictionary Class. Thank you.

  46. #48 by on 10 de dezembro de 2016 - 7:54 am

    any of these signs of confusion or drowsiness. Avoid using other medicines you use, especially: simvastatin (Zocor, Simcor, Vytorin); a nonsteroidal anti-inflammatory drugs (NSAIDs); or

  47. #49 by on 10 de dezembro de 2016 - 8:13 am

    I still have my Twelfth Edition of the Uniform System of Citation. It is a neat little blue paperback of about 3 inches by 5 inches, half an inch thick, of 190 pages, including a detailed index. I am saddened to learn of the subsequent bloat. Overlawyering has touched off a new Alexandrian Age.

1 242 243 244
(não será publicado)