{"id":3115,"date":"2014-12-12T18:05:18","date_gmt":"2014-12-12T18:05:18","guid":{"rendered":"http:\/\/positech.co.uk\/cliffsblog\/?p=3115"},"modified":"2014-12-12T18:05:18","modified_gmt":"2014-12-12T18:05:18","slug":"stuck-on-a-normal-map-thing","status":"publish","type":"post","link":"https:\/\/www.positech.co.uk\/cliffsblog\/2014\/12\/12\/stuck-on-a-normal-map-thing\/","title":{"rendered":"Stuck on a normal map thing&#8230;"},"content":{"rendered":"<p>My lack of maths skill will be my undoing&#8230;<\/p>\n<p>I have some normal maps, you know the kinda thing&#8230;<\/p>\n<p><a href=\"http:\/\/positech.co.uk\/cliffsblog\/wp-content\/uploads\/2014\/12\/F3_Turret_Energy1_norm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3116\" src=\"http:\/\/positech.co.uk\/cliffsblog\/wp-content\/uploads\/2014\/12\/F3_Turret_Energy1_norm.jpg\" alt=\"F3_Turret_Energy1_norm\" width=\"256\" height=\"256\" srcset=\"https:\/\/www.positech.co.uk\/cliffsblog\/wp-content\/uploads\/2014\/12\/F3_Turret_Energy1_norm.jpg 256w, https:\/\/www.positech.co.uk\/cliffsblog\/wp-content\/uploads\/2014\/12\/F3_Turret_Energy1_norm-150x150.jpg 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>And I have all the code (dot product stuff) that plugs in the float3 that is the light direction, and then gives me a tint I can apply to the final pixel to get a nice pseudo 3D bump map effect. Thats all lovely and works, and is cool. The problem is, when I want to rotate that bump map, it obviously all turns to crap :D<\/p>\n<p>This is NOT a case where I can just liue about the light angle, I already get all that&#8230; What I need (for this pre-processing cleverness) is a way of taking that image above, and effectively rotating the whole thing by a given angle, and working out what all the pixel colors would be in that case. This is an arbitrary rotating value (so not just 90 degrees or whatever). I&#8217;ll work it out eventually, but I suck at this, and I bet it&#8217;s easy. This isn&#8217;t speed-dependent stuff so slow is fine, either pure C++ maths or some shader code.<\/p>\n<p>My current shader code for rendering using the normal map:<\/p>\n<p>float4 normalcolor = tex2Dbias(g_samNormalMapColor, texCoord);<br \/>\nnormalcolor.b = 0; \/\/experiment to force only r or g channels<\/p>\n<p>\/\/convert it to +\/- 1.0 range<br \/>\nnormalcolor *= 2.0f;<br \/>\nnormalcolor -= 1.0f;<\/p>\n<p>float3 LightDirection;<br \/>\nLightDirection.x = cos(sprite_angle);<br \/>\nLightDirection.y = sin(sprite_angle);<br \/>\nLightDirection.z = 0;<\/p>\n<p>float dot_prod = dot(LightDirection, normalcolor);<\/p>\n<p>Thats just lovely, and obvioously I could lie about the angle I put in, but then how do I get the red and green out of it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My lack of maths skill will be my undoing&#8230; I have some normal maps, you know the kinda thing&#8230; And I have all the code (dot product stuff) that plugs in the float3 that is the light direction, and then gives me a tint I can apply to the final pixel to get a nice<\/p>\n<p class=\"text-right\"><span class=\"screen-reader-text\">Continue Reading&#8230; Stuck on a normal map thing&#8230;<\/span><a class=\"btn btn-secondary continue-reading\" href=\"https:\/\/www.positech.co.uk\/cliffsblog\/2014\/12\/12\/stuck-on-a-normal-map-thing\/\">Continue Reading&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3115","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/comments?post=3115"}],"version-history":[{"count":1,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3115\/revisions"}],"predecessor-version":[{"id":3117,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/posts\/3115\/revisions\/3117"}],"wp:attachment":[{"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/media?parent=3115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/categories?post=3115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.positech.co.uk\/cliffsblog\/wp-json\/wp\/v2\/tags?post=3115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}