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 on 27 de setembro de 2016 - 10:34 am

    Purchased it as being a present for the my mom and she loved it. nice excellent awesome rate as well as our mom loved things. And sent extremely quickly. So if you need a gifts fast while such as this versus this is actually the any it is important to buy!

  2. #2 by swords for sale on 27 de setembro de 2016 - 11:25 am

    Love Love Love cet amour des chaussures love love ce service

  3. #3 by katanas for sale on 27 de setembro de 2016 - 12:04 pm

    Great transaction et le vendeur – livraison rapide! Handshoe est belle! Je vous remercie !

  4. #4 by Ronny on 27 de setembro de 2016 - 12:04 pm

    An attention-grabbing discussion is value comment. I think that you need to write more on this matter, it might not be a taboo topic but typically people are not enough to talk on such topics. To the next. Cheers

  5. #5 by Chinese Sword for sale on 27 de setembro de 2016 - 1:14 pm

    Great experience. Fast ship and easy transaction. Thanks a bunch!

  6. #6 by Cartier Love Bracelet Replica on 27 de setembro de 2016 - 1:47 pm

    Our headset ended up being since breathtaking as in the visualize. It came immediately. I would advise using a towel through every single level while you press that off w / the best steam iron. It does not steam over and only a steamer. The actual iron ended up being necessary. It is very fine, so if you don’t trust yourself with all the towel additionally steam iron, well consume that it up to a certified. Perfect noise.

  7. #7 by make your own app on 27 de setembro de 2016 - 3:54 pm

    please take a look at the internet sites we comply with, including this one, because it represents our picks from the web

  8. #8 by Smart Balance Wheel on 27 de setembro de 2016 - 5:18 pm

    We have owned Smart Balance Wheel for provided that I can consider. I love them and that i enjoy this new model!!

  9. #9 by janpanese samurai sword on 27 de setembro de 2016 - 6:30 pm

    Excellent Seller !!!! Great Service, Item, and Shipping. A++++++

  10. #10 by on 27 de setembro de 2016 - 8:26 pm

    Purchased this one as a gifts of our mom and she liked it. sweet high quality awesome price to my personal mother enjoyed things. Also sent extremely fast. So if you require a gifts quickly while such as this then this is basically the one you ought to go for!

  11. #11 by on 27 de setembro de 2016 - 8:26 pm

    Yet not just as fancy inside real world if you think mothers wrist is not really 2small don’t choose that it reason they make tight .. the adorable however whatever yur 5year aged can make . No some sort of less its an okay gifts to award yet not the best wow gift…cant get wrong provided do not need much to blow for a gift and then get they

  12. #12 by homepage on 27 de setembro de 2016 - 8:59 pm

    confessions of a marriage counselor megashare

  13. #13 by hier sind die Ergebnisse on 27 de setembro de 2016 - 9:14 pm

    Solltest du noch nie einen unzensierten Hardcore Erotikcam mit schwarze Mösen gesehen haben, wird sich vor Geilheit bestimmt gleich dein Schwanz ein Stahlrohr transformieren und lautstark nach Masturbation schreien.

  14. #14 by Divorce Without Lawyers on 27 de setembro de 2016 - 10:12 pm

    the time to study or go to the subject material or websites we’ve linked to beneath the

  15. #15 by cold steel swords on 27 de setembro de 2016 - 11:14 pm

    very nice and quick delivery A+++++++++++

  16. #16 by custom katana swords on 27 de setembro de 2016 - 11:14 pm

    Fast shipping!!! Product is just as described. Thanks!!!

  17. #17 by Mehr Informationen bekommen on 27 de setembro de 2016 - 11:16 pm

    Ab 220 zieh ich nicht mehr mit, da wird es mir zu extrem….

  18. #18 by her latest blog on 28 de setembro de 2016 - 12:37 am

    marriage counselor edmonds wa weather

  19. #21 by zuccarello jersey on 28 de setembro de 2016 - 2:09 am

    Traditionally ColdFusion could sound heavy, additionally, there are possesses a smaller retract. It isn’t since cheap since some of her types, that include natural Windows or even UNIX organizing. Since preparing ColdFusion serp and service is fairly costly, its for you to putt out many individuals. Because ColdFusion web hosting service may well deliver database operation for active web computer software. And before deciding on ColdFusion server having, make sure that your card issuer has the ability to from this and even ought to have the capacity meant for other useful assistance. Just about the most important factors throughout buying a ColdFusion host will be sorts of assistance that features presents. There is absolutely no worse feeling compared to having concerns on the web page plus your ColdFusion sponsor simply lifting the cellular phone.

  20. #22 by look at this web-site on 28 de setembro de 2016 - 5:39 am

    just beneath, are a lot of completely not associated websites to ours, having said that, they are certainly worth going over

  21. #23 by continue reading this on 28 de setembro de 2016 - 9:59 am

    marriage counselor franklin tn newspaper

  22. #24 by adidas yeezy 350 boost on 28 de setembro de 2016 - 10:16 am

  23. #26 by vertical training program on 28 de setembro de 2016 - 12:46 pm

    It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or advice. Perhaps you could write next articles referring to this article. I want to read more things about it!

  24. #27 by real sword on 28 de setembro de 2016 - 2:07 pm

    grand article , exp茅dition rapide

  25. #28 by mspy pro on 28 de setembro de 2016 - 2:27 pm

    I’m juggling about 10 things now so I don’t have that much time for you to play around learning how to make a website. Exactly what are good assets to jump-start implementing javascript, php, mySQL, etc?.

  26. #29 by нап продажби на имоти on 28 de setembro de 2016 - 2:57 pm

    I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  27. #30 by great post to read on 28 de setembro de 2016 - 3:24 pm

    marriage counselor juneau alaska excursions

  28. #31 by Tanto knife on 28 de setembro de 2016 - 3:36 pm

    Article exactement comme d脙 漏 crit … Envoi rapide et soign茅 . R茅p茅tera entreprise

  29. #32 by Naginata weapon on 28 de setembro de 2016 - 3:36 pm

    Juste comme d茅crit . Exp茅dition super rapide et bien emball茅 . Merci

  30. #33 by samurai katana sword on 28 de setembro de 2016 - 3:57 pm

    perfect transaction grand vendeur va le mile supplémentaire

  31. #34 by samurai on 28 de setembro de 2016 - 3:58 pm

    La chaussure est belle et exactement comme décrit ! Je vous remercie !

  32. #35 by Mehr on 28 de setembro de 2016 - 4:26 pm

    Ich melde auch Orte wo er sein könnte, wenn wir uns doch mal sehen, missachten wir uns.

  33. #36 by chaussure led on 28 de setembro de 2016 - 4:29 pm

    He is enjoying this close to death. The palm of the hand clenched the steering wheel, suddenly, a touch of green shadow from his eyes flashed, he stopped the car doings of ghosts and gods. M big huge sign first caught his eye, less than two metres in front of a girl standing on the broken heels, limping ran to the arm of a man is ready to cross the road.

  34. #37 by casino on 28 de setembro de 2016 - 5:30 pm

    the time to study or take a look at the content or sites we have linked to below the

  35. #38 by Wakizashi Sword on 28 de setembro de 2016 - 5:31 pm

    recommend seller! Thanks for fast shipping & delivery!

  36. #39 by apply pr in singapore on 28 de setembro de 2016 - 6:45 pm

    Nice. Thank you for your post!

  37. #40 by Homer Fife on 28 de setembro de 2016 - 6:52 pm does it again! Quite a perceptive site and a well-written article. Nice work!

  38. #41 by the samurai on 28 de setembro de 2016 - 7:46 pm

    Wonderful seller ~ New As Described, Fast Shipping Thanks ! A++

  39. #42 by adidas yeezy boost 350 on 28 de setembro de 2016 - 8:51 pm

  40. #43 by world cup of hockey jerseys on 28 de setembro de 2016 - 10:43 pm

    A large number of boat chair manufacturers might also include leaning articles and reviews for their products. However these are occasionally fitted with the along with you can really use for sit on, are usually for the most part employed to keep cash on boats.

  41. #44 by redirected here on 28 de setembro de 2016 - 11:55 pm

    catholic marriage counselors in your area

  42. #45 by my sources on 28 de setembro de 2016 - 11:57 pm

    marriage counselor jackson wyoming

  43. #48 by adidas Yeezy 350 on 29 de setembro de 2016 - 1:07 am

  44. #49 by knife gate valve manufacturer on 29 de setembro de 2016 - 4:56 am

    we like to honor quite a few other world-wide-web web pages around the internet, even though they arent linked to us, by linking to them. Under are some webpages really worth checking out

1 159 160 161
(não será publicado)