{"id":854,"date":"2011-07-21T20:20:02","date_gmt":"2011-07-22T00:20:02","guid":{"rendered":"http:\/\/www.oztalay.com\/matt\/?page_id=854"},"modified":"2012-01-19T11:50:00","modified_gmt":"2012-01-19T16:50:00","slug":"flaming-rainbow-material-advanced-udk","status":"publish","type":"page","link":"https:\/\/www.oztalay.com\/matt\/tutorials\/flaming-rainbow-material-advanced-udk\/","title":{"rendered":"Flaming Rainbow Material (Advanced) &#8211; UDK"},"content":{"rendered":"<p>This is an improvement to yesterday&#8217;s <a href=\"http:\/\/www.oztalay.com\/matt\/tutorials\/flaming-rainbow-material-udk\/\">Flaming Rainbow Material &#8211; UDK tutorial<\/a>, it replaces the rainbow texture with a custom texture node that blends between colors based on a gradient.<\/p>\n<p>I was tinkering with the techniques describe on this <a href=\"http:\/\/www.polycount.com\/forum\/showthread.php?p=1369859\">Polycount Thread<\/a>, and I realized &#8220;Hey, what is a rainbow if nothing more than a gradient. Hey, I bet I could save a 512 texture if I did something like this!&#8221; The tradeoff is that instead of a 26 instruction shader using the texture map this is now 49 instructions.<\/p>\n<p>So, if you have an inkling to get your hands dirty with some HLSL (this is a tutorial after all, you&#8217;ll have to work through it the way I did), dive right in. This is written for someone with little to know experience working with custom nodes in UDK&#8217;s material editor.<\/p>\n<p>At the base level I took this:<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/01_texture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-855\" title=\"01_texture\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/01_texture-300x191.jpg\" alt=\"\" width=\"300\" height=\"191\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/01_texture-300x191.jpg 300w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/01_texture.jpg 578w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>And turned it into this:<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/02_gradient.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-856\" title=\"02_gradient\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/02_gradient-797x1024.jpg\" alt=\"\" width=\"640\" height=\"822\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/02_gradient-797x1024.jpg 797w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/02_gradient-233x300.jpg 233w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/02_gradient.jpg 822w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Ahh! Scary! What is that!? You might say. You might also notice that each of those colors is actually a <a href=\"http:\/\/udn.epicgames.com\/Three\/MaterialsCompendium.html#Constant4Vector\">Constant4Vector<\/a><\/p>\n<p>Further, you might notice that no node named &#8220;Gradient Mapper&#8221; exists in the Unreal Material Editor&#8217;s list of nodes. It is, in fact, a <a href=\"http:\/\/udn.epicgames.com\/Three\/MaterialsCompendium.html#Custom\">Custom<\/a> node. I adapted some of <a href=\"http:\/\/www.polycount.com\/forum\/showthread.php?p=1369859#21\">Vailias&#8217; HLSL<\/a> to suit my needs and dropped it into that node. You have to add and name the inputs manually, and Unreal expects something for each input unless you tell it otherwise.<\/p>\n<p>The code he wrote checks if a given pixel input into ControlTexChannel. If its value is equal to the value of one of the input colors, it sets that output pixel to equal the input color. The code then outputs all pixels between two alpha values to lerp between those two input colors. For example, if I had a 0 &#8211; 1 gradient, and two input values of 1,0,0,1 (Red at Alpha=1) and 0,0,1,0 (Blue at Alpha = 0), all the pixels with a value of 1 would output as 1,0,0, and all pixels at 0 would output as 0,0,1. Between Red and Blue would be a mix of those two colors.<\/p>\n<p>ColorTexChannel expects an input that is a \u00a0float1 value (a single vector value), not a float2 (UVs have 2 float channels), so I masked out the R (for UVs the horizontal) channel because I don&#8217;t do anything to it in the shader, I only need the vertical positions.<\/p>\n<p>I expanded the list of Gradient to include 8 color positions (think of them like points on a graph).<\/p>\n<p>I have yet to find a way to increase the number of inputs without having to go into the code, I can tell you that the input colors can be parameterized so an artist can adjust the values and position without having to rebuild the shader every time.<\/p>\n<p>If you do choose to parameterize the color inputs, make sure you append the alpha channel to the RGB so the Custom node can handle the input.<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/03_append.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-857\" title=\"03_append\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/03_append-797x1024.jpg\" alt=\"\" width=\"640\" height=\"822\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/03_append-797x1024.jpg 797w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/03_append-233x300.jpg 233w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/03_append.jpg 822w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>So we go from this:<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/04_textureProcess.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-858\" title=\"04_textureProcess\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/04_textureProcess.jpg\" alt=\"\" width=\"309\" height=\"705\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/04_textureProcess.jpg 309w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/04_textureProcess-131x300.jpg 131w\" sizes=\"auto, (max-width: 309px) 100vw, 309px\" \/><\/a><\/p>\n<p>To this:<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/05_gradientProcess.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-859\" title=\"05_gradientProcess\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/05_gradientProcess.jpg\" alt=\"\" width=\"309\" height=\"415\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/05_gradientProcess.jpg 309w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/05_gradientProcess-223x300.jpg 223w\" sizes=\"auto, (max-width: 309px) 100vw, 309px\" \/><\/a><\/p>\n<p>So now I can do this without ever opening Photoshop!<\/p>\n<p><a href=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/06_instance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-860\" title=\"06_instance\" src=\"http:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/06_instance-982x1024.jpg\" alt=\"\" width=\"640\" height=\"667\" srcset=\"https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/06_instance-982x1024.jpg 982w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/06_instance-287x300.jpg 287w, https:\/\/www.oztalay.com\/matt\/wp-content\/uploads\/06_instance.jpg 983w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Going to continue tinkering with this. I have a few ideas&#8230;<\/p>\n<p>Questions? Post them to the <a href=\"http:\/\/forums.epicgames.com\/showthread.php?t=806691\">UDK forum thread<\/a>, if you had a question I&#8217;m sure someone else did.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an improvement to yesterday&#8217;s Flaming Rainbow Material &#8211; UDK tutorial, it replaces the rainbow texture with a custom texture node that blends between colors based on a gradient. I was tinkering with the techniques describe on this Polycount Thread, and I realized &#8220;Hey, what is a rainbow if nothing more than a gradient. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":407,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-854","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/comments?post=854"}],"version-history":[{"count":3,"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/854\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/854\/revisions\/948"}],"up":[{"embeddable":true,"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/pages\/407"}],"wp:attachment":[{"href":"https:\/\/www.oztalay.com\/matt\/wp-json\/wp\/v2\/media?parent=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}