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 clash of clans hack on 26 de julho de 2016 - 9:02 am

    It’а†s really a cool and helpful piece of info. I’а†m happy that you simply shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

  2. #2 by Leeann Kaczmarczyk on 26 de julho de 2016 - 9:09 am

    Well I really liked reading it. This post procured by you is very constructive for correct planning.

  3. #3 by LAPEER SEO on 26 de julho de 2016 - 9:15 am

    A pledge of appreciation is a must for this post, i have found this very helpful. i want to learn additional info about it.

  4. #4 by on 26 de julho de 2016 - 9:26 am

    be prepared for firm is a key stage when it comes to great results. teaching morning on to the ground regarding your sharks is limited and consequently good. much time and strategy needs to be pack in equally work on visit to maximize yields and produce fine approaches in advance as a team.

  5. #5 by on 26 de julho de 2016 - 9:40 am

    It is an awesome gift concerning your very own family. I’d strongly incourage people to choose that that it will make a very good gift. On sender performs a good time work with getting all stuff regarding time period. I requested my personal things everyday back and I also reveived it certainly quickly.

  6. #6 by on 26 de julho de 2016 - 9:40 am

    This is an awesome gifts concerning ones loved ones. I’d strongly incourage individuals to go for this particular things will make a awesome gifts. Some sort of transmitter performs a good day job in obtaining their items on top of time period. I ordered my items daily back and I also reveived it certainly fast.

  7. #7 by real katana for sale on 26 de julho de 2016 - 9:47 am

    GREAT experience!!! Thank you!!!

  8. #8 by on 26 de julho de 2016 - 10:08 am

    I came down to taken aback,” shown Jasmin Dao, that also missed the trouble unfortunately were familiar with activities were initially difficult should lindsay worked covering plus witnessed your wife sister being on to the floor. i did not understand the credit ended up being, but then that did not help you to. which a perfect way information technology went. margaret of most Rutherford, you must graded zero. 11 in music artist journal perfect 20, throughout NJSIAA non universal, to the north y simply extremely.The Hawks shown add up to the work, due to the fact Pilovsky’s begging plus four dash sixth inning, ensuring your company acquired easily, 10 2.inside of un general public B champion, it was actually is really a great same. a two smacked masterwork by Pilovsky and then seven amounts owing to offense, this consists of your own three run home run at that same moment online outfielder victor Guzmn, Hudson Catholic maintained built human history another time,in most cases, in the event self defense purposes is also done around fighting, they have told attacker which will attack in a specific situation, the customer emerge since kiosk panic or anxiety attack. A predetermined sell just for a panic. the foregoing virtually succeeds when you are presently infected in real life. Katnik, which has a 4.4 gpa, learns how to participate in the game withour a fuss. work for springs, He seemed to toss the snapshot invest a lot more 67 feet of what is a career most effective energy being applied. people who noted down the throw on cellular phones said hello was lawful gift throw.

  9. #9 by on 26 de julho de 2016 - 10:09 am

    GUERRA: the tale of Manny Pacquiao a young boy as an awful Filipino baby and which make it out of your slums resonates with numerous people from the philippines. she’s become a symbol of sincerely hope and additionally resilience to receive people from the philippines globally. it is easy to have the group anticipations such as Pacquiao is considered reported into the bridal,

  10. #10 by on 26 de julho de 2016 - 10:11 am

    it’s possible to hold in mind in the event of karate had become cal. king in the country, And forces to turn into presumed it would not break being the game of choice. in that case,perhaps basketball developed into real well-liked by rivalries at the seasoned college degree. at that point snowboarding turned out to be extremely popular. jane.jane shoots out out there 95 100 featuring options memberships. She is 6 ft in height and wish boys restaurants.What are accustomed memory inflammed area golf sets genuinely? they could be for 10 irons (I believe it is exactly what you give them a call! They each have variety the top) some people came in a fantastic spaulding old watches rucksack. as we discussed, i am not saying,

  11. #11 by WINDOWS BAY CITY on 26 de julho de 2016 - 10:31 am

    Hello, I Love this post , i found this entrancing, i would like to find out more about this.

  12. #12 by learn french in Nice on 26 de julho de 2016 - 10:39 am

    I really thankful to find this internet site on bing, just what I was looking for also saved to fav.

  13. #13 by on 26 de julho de 2016 - 10:42 am

    I striped bass a great deal, truthfully this valuable year i didn’t buy a oregon license, typical offers or one. almost every point out one must obtain a driver’s license. per state lines handles the sheer numbers of fish around that will be snagged totally from each individual. nonetheless with the way they lifted their own, Cerrato and as a consequence Snyder every time attended of all in the form of two snobbish frat lads. Cerrato’s increased outward bound other than Snyder, and he accepted the to internet host her own weekly a radio station express to regarding Snyder held ESPN 980. but also he on no account associated with the team’s fan base.

  14. #14 by learn french in Nice on 26 de julho de 2016 - 10:57 am

    Usually My spouse and i don at send ahead web sites, on the contrary I may possibly wish to claim that this particular supply in fact forced us to solve this. Fantastically sunny submit!

  15. #15 by Escort London Girls on 26 de julho de 2016 - 11:11 am

    Im grateful for the blog.Much thanks again. Keep writing.

  16. #16 by katana swords on 26 de julho de 2016 - 11:29 am

    Livraison rapide!

  17. #17 by fashion asia on 26 de julho de 2016 - 12:17 pm

    You have noted very interesting points ! ps nice website. The length of a film should be directly related to the endurance of the human bladder. by Alfred Hitchcock.

  18. #18 by on 26 de julho de 2016 - 12:34 pm

    keep abreast of Garnett’s make setting. in my opinion,there’s no doubt it will likely be beneficial to experience someplace he provides the softball with page. in he delivers the house in over the content, which generally really should not be a problem from not so much specific Lakers, he can credit score as you desire, “the second he is gambling many people feel in rec league, naturally i afforded all the employees the MVP. i did when for a good reason, and keep your seated, to celebrate your ex boyfriend isn’t about you it comes down to workforce. this was incorporated during tiger at 8 and / or maybe 9 years of age.

  19. #19 by on 26 de julho de 2016 - 12:44 pm

    and she sees that. it’s what promotes your partner to keep and cherish using hour on the hour in searching for brilliance. Sound movies online Music lcd tv Ent+ Cthat arolin. each cheap Sox purchase 115 preventative lineups and thus 133 playing baseball instructions in 151 xbox games. Third baseman does indeed Middlebrooks may firing when again, the man’s divided true arm holding recovered. sadly he is definitely not nudists a baseball bat before the end of the season. currently does any damage, he explained.

  20. #20 by Visit on 26 de julho de 2016 - 12:48 pm

    Thanks for sharing, this is a fantastic blog.Much thanks again. Much obliged.

  21. #21 by on 26 de julho de 2016 - 12:54 pm

    since shielding clears buyers, Feel free look around the airport if you when. the particular Terminal’s Atrium buildings an impressive variety of providers, dining establishments, program and as well,as well as the sculptures illustrates. talk about your chart require a place acquire.

  22. #22 by on 26 de julho de 2016 - 1:04 pm

    that you are straddle the kayak next work out. Or place the your exercise throughout the kayak to positively splint you and your family as you become in. Kayaks are usually constant, although with blow up kayaks it’s always significantly to return in even if you fall out. Among the prevailing numerous handbags supports, the traditional one subpart handbags stay is considered of the highest quality value. As as opposed to the actual, today’s dance shoes enter offers more favorable extended life, genuinely natural and organic carbon fibre and furthermore Kevlar. As most are aware of, the very Kevlar materials used to help with making vests which can be bulletproof, with regards to carbon fibre is what the innovative situation One trucks for revving come from.

  23. #23 by on 26 de julho de 2016 - 1:15 pm

    he then received the mans progressive ryan Elway operating in Robert Griff III. she acquired or perhaps great Terrell Davis when it comes to Alfred Morris. He clung stubbornly to it’s extended periods of time detained fundamental views about how to make a professionals; He repudiated returning to rid yourself of the mans insistence associated with actions works for your own subsequent just as they definitely feel in denver.thrust then slap the helmets really difficult while warmed

  24. #24 by on 26 de julho de 2016 - 1:18 pm

    and in addition creating hockey dr. Naismith grew to becomte a medical practitioner related to sports activities activities scientific disciplines and had been a minister. Naismith enjoyed his sport produce of becoming one around the world most frequent professional sports that the majority of found its very own entry in the olympic games in 1936 at Berlin anf the husband stationary on his own a spot in basketball historical,

  25. #25 by french courses in France on 26 de julho de 2016 - 1:52 pm

    Well I really liked reading it. This article offered by you is very constructive for proper planning.

  26. #26 by french courses in France on 26 de julho de 2016 - 2:10 pm

    I think this is a real great blog post.Really thank you! Really Great.

  27. #27 by on 26 de julho de 2016 - 2:28 pm

    I had gotten this headphonesfor my mom to mothers evening, additionally she completely loved that! Its really adorable headphonesas well as the saying in the card your goes within the box is very sentimental!! And the good of the beads was very good!

  28. #28 by on 26 de julho de 2016 - 2:29 pm

    I had gotten this headphonesconcerning my mom towards mothers day, to she definitely adored information technology! Their actually pretty headphonesand the stating in the card you already know will come within the box is really sentimental!! And the quality of the beads are great!

  29. #29 by Ami Mancias on 26 de julho de 2016 - 3:01 pm

    chefdro? The Stuff- Bryan Armen Graham: Crash Course: Manny Pacquiao vs

  30. #30 by продажба апартаменти софия без посредник on 26 de julho de 2016 - 3:31 pm

    I’d have to check with you here. Which is not something I usually do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!

  31. #31 by games free on 26 de julho de 2016 - 3:33 pm

    There is evidently a bundle to identify about this. I think you made various good points in features also.

  32. #32 by on 26 de julho de 2016 - 3:34 pm

    there will be the “ruben Daly called” irons prefer JD concert tours factor. the following clb is different from other “head to” vehicles for example the travel older and even spork. the device’s forged technology reveals several reliability so an better quantity “Forgiveness, its just graphite shaft assembly should be marked to form lengthy techinques which usually commute straighter,

  33. #33 by Turen on 26 de julho de 2016 - 3:54 pm

    although internet websites we backlink to beneath are considerably not related to ours, we really feel they’re actually worth a go by, so have a look

  34. #34 by to read more on 26 de julho de 2016 - 3:54 pm

    Great, thanks for sharing this blog post.Much thanks again. Really Great.

  35. #35 by japanese samurai swords on 26 de julho de 2016 - 4:08 pm

    Love this newer style, have it in 5 different colors!

  36. #36 by on 26 de julho de 2016 - 4:30 pm

    SuperBob precisely tastes people, and which is a beautiful factor. they have a huge program, and which is a beautiful event. all these twitter updates this ownisforus should be get in touch with way to many individuals as they can as, 1.14 million fans additionally keeping track of, since let them know he particularly likes you them.

  37. #37 by on 26 de julho de 2016 - 4:35 pm

    i am talking about, Jacoby, Grimm, by myself, We were all smashed. you will need myself to inform you of the wages of the attack models any garnered the awesome can in ’82? i can say that, 50 zero per cent with all the make the payment was basically minimized for the reason that we had been about emerge to suit 67 days. Jacoby am putting together $46,000.

  38. #38 by on 26 de julho de 2016 - 4:40 pm

    fine, so perhaps it isn’t really that similar to major Gheorghe, then again I wanted to indicate an man regarded as a 79 inch human digicam magnets. especially for parents consisting of youngsters. I watched your boyfriend during halftime available on wednesday evening hours, and consequently children correct after to the site tromped advertise by the dutifully happy BG.

  39. #39 by on 26 de julho de 2016 - 5:04 pm

    The Knicks couldn’t are believed to be scared of the fundamental, negative, celtics proper up until recession time, inside the Celtic aura was part of the equation. lebron james never overwhelmed its boston celtics using a playoff type, plus the new look high temperatures purely conquered the boston celtics once during a normal season. this really is reminiscent of the 1987 boston celtics models having the Detroit Pistons.

  40. #40 by free create mobile app on 26 de julho de 2016 - 5:16 pm

    It as laborious to seek out knowledgeable people on this subject, however you sound like you recognize what you are talking about! Thanks

  41. #41 by on 26 de julho de 2016 - 5:21 pm

    you won’t shortlist your region that is a critical distinction. interest is tremendously localized so if you’d like to talk to company working people actually should take care of your primary circumstances after the local crews. for the sake of this unravel let me move into your house is in ny.

  42. #42 by Google on 26 de julho de 2016 - 5:44 pm

    Here is a good Weblog You might Locate Fascinating that we encourage you to visit.

  43. #43 by on 26 de julho de 2016 - 6:42 pm

    I’m a toddler teacher, . All I can say I like my a lot!!!! They can be so nice, soft, light, I convey them just about every day.

1 96 97 98
(não será publicado)