<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" >

<channel><title><![CDATA[Xor Shaders - Tutorials]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials]]></link><description><![CDATA[Tutorials]]></description><pubDate>Sat, 15 Oct 2022 19:50:08 -0700</pubDate><generator>Weebly</generator><item><title><![CDATA[New Tutorial WEBSite!]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/new-tutorial-website]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/new-tutorial-website#comments]]></comments><pubDate>Tue, 05 Oct 2021 14:12:22 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/new-tutorial-website</guid><description><![CDATA[My new website is finally live at GMshaders.com!&#8203; Please check there for future shader tutorials as I retire this website.&#8203;Thanks! [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">My new website is finally live at <a href="https://gmshaders.com" target="_blank">GMshaders.com</a>!&#8203; Please check there for future shader tutorials as I retire this website.<br /><br />&#8203;Thanks!<br /></div>]]></content:encoded></item><item><title><![CDATA[Tutorial Newsletter!]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/tutorial-newsletter]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/tutorial-newsletter#comments]]></comments><pubDate>Mon, 18 Nov 2019 17:14:47 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/tutorial-newsletter</guid><description><![CDATA[Hey!It's been a while since I've updated this blog, but here's a short update. I recently created a newsletter that you should subscribe to! I'll be sending out updates on my future tutorials via the newsletter!Thanks for patience! I think it will be worth while!You can find sneak peeks on my social media:   	 		 			 				 					 						    Twitter     					 								 					 						    Facebook     					 							 		 	  [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">Hey!<br />It's been a while since I've updated this blog, but here's a short update. I recently created a <a href="https://mailchi.mp/ea4f785cd72e/xor" target="_blank">newsletter</a> that you should subscribe to! I'll be sending out updates on my future tutorials via the newsletter!<br /><br />Thanks for patience! I think it will be worth while!<br />You can find sneak peeks on my social media:<br /></div>  <div><div class="wsite-multicol"><div class="wsite-multicol-table-wrap" style="margin:0 -15px;"> 	<table class="wsite-multicol-table"> 		<tbody class="wsite-multicol-tbody"> 			<tr class="wsite-multicol-tr"> 				<td class="wsite-multicol-col" style="width:22.838709677419%; padding:0 15px;"> 					 						  <div style="text-align:left;"><div style="height: 10px; overflow: hidden;"></div> <a class="wsite-button wsite-button-large wsite-button-highlight" href="https://twitter.com/XorDev" target="_blank"> <span class="wsite-button-inner">Twitter</span> </a> <div style="height: 10px; overflow: hidden;"></div></div>   					 				</td>				<td class="wsite-multicol-col" style="width:77.161290322581%; padding:0 15px;"> 					 						  <div style="text-align:left;"><div style="height: 10px; overflow: hidden;"></div> <a class="wsite-button wsite-button-large wsite-button-highlight" href="https://www.facebook.com/xorshaders/" target="_blank"> <span class="wsite-button-inner">Facebook</span> </a> <div style="height: 10px; overflow: hidden;"></div></div>   					 				</td>			</tr> 		</tbody> 	</table> </div></div></div>]]></content:encoded></item><item><title><![CDATA[Future Tutorials]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/future-tutorials]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/future-tutorials#comments]]></comments><pubDate>Thu, 03 Jan 2019 20:38:37 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/future-tutorials</guid><description><![CDATA[Hello everyone!It's been too since I posted here and I think it's time for an update. I've been busy working on many Game Maker projects (I sometimes post about them on Twitter) which is why I stopped posting new tutorials. In 2019, I would like to change that and reboot my tutorial series. I've learned a lot in these past 5 years which will help me bring better content to you all.  plans and ideas  These are my tentative feature plans for the new series:New website domain and hosting.&#8203;Fun [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">Hello everyone!<br />It's been too since I posted here and I think it's time for an update. I've been busy working on many Game Maker projects (I sometimes post about them on <a href="https://twitter.com/XorDev" target="_blank">Twitter</a>) which is why I stopped posting new tutorials. In 2019, I would like to change that and reboot my tutorial series. I've learned a lot in these past 5 years which will help me bring better content to you all.<br /></div>  <h2 class="wsite-content-title">plans and ideas</h2>  <div class="paragraph">These are my tentative feature plans for the new series:<ul><li>New website domain and hosting.&#8203;</li><li>Fundamental tutorials for covering shader syntax.</li><li>Example tutorials showing how to apply the fundamentals.</li><li>Shader gallery with source code.</li><li>Shader glossary with explanations of functions and variables.</li><li>And perhaps HLSL tutorials. Let me know if you're interested!</li></ul><br />I don't know for certain that I'll get to all of this, but if I'm able, then I intend to.</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title">Your input</h2>  <div class="paragraph">I would love to hear your thoughts and input on this project. If you have any ideas for tutorials or features, you can send them below and I'll see what I can do.&nbsp;</div>  <h2 class="wsite-content-title">How you can help</h2>  <div class="paragraph">I've been writing these tutorials and examples in my spare time and I've made these tutorials for free without using ads. I will continue to create ad-free resources however I need help now to bring the new series. Please donate using the link below. Any little bit will help.<br /><a href="https://paypal.me/XDev" target="_blank">https://paypal.me/XDev</a><br />The new website will be shared on all my social media and on this website when it's ready.<br />In the meantime, feel free to join my <a href="https://discord.gg/RAC79Ud" target="_blank">Discord server</a>. Let's talk about shaders and GM.<br /><span style="color:rgb(161, 161, 161); font-weight:400">Thanks for reading! </span></div>]]></content:encoded></item><item><title><![CDATA[#8 wind shader]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/8-wind-shader]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/8-wind-shader#comments]]></comments><pubDate>Mon, 30 May 2016 19:15:22 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/8-wind-shader</guid><description><![CDATA[Hey, I'm back! I haven't been very active on here for months because I was trying to make a new shader tutorial site. I still might on occasion, post a tutorial here (just simple ones for now), but I'm planning on making a more organized format on the new site. Anyway, by request I decided to make a tutorial about a 2D wind effect.  Ripple effect  To make our wind, we need a simple ripple effect. We will create a vec2 and call it "Coord". This will be used for the wind distortion. We will set it [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">Hey, I'm back! I haven't been very active on here for months because I was trying to make a new shader tutorial site. I still might on occasion, post a tutorial here (just simple ones for now), but I'm planning on making a more organized format on the new site. Anyway, by request I decided to make a tutorial about a 2D wind effect.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Ripple effect</font></h2>  <div class="paragraph" style="text-align:left;">To make our wind, we need a simple ripple effect. We will create a vec2 and call it "Coord". This will be used for the wind distortion. We will set it to "v_vTexcoord". Now you need to change the texture2D coordinates to our Coord vector. It should look like this:<br />&nbsp;<font size="2"><br />&#8203;&nbsp;&nbsp;&nbsp; </font><em><font size="3">vec2 Coord = v_vTexcoord;<br />&nbsp;&nbsp;&nbsp; gl_FragColor = v_vColour * texture2D( gm_BaseTexture, Coord);</font></em><br /><br />This&#8203; is a pass-through shader. If you run the shader applied to a sprite, it shouldn't change anything. To make a ripple we&nbsp;will use a <a href="https://en.wikipedia.org/wiki/Trigonometric_functions#cosine">cosine</a>&nbsp;wave. We could do it like this:<br />&#8203;<br /><em><font size="3">&nbsp;&nbsp;&nbsp; vec2 Coord = v_vTexcoord + vec2(cos(v_vTexcoord.y*30.0)/30.0,0);</font></em><br /><br />If you run this you will see this (before and after):</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/184175895.png" alt="Picture" style="width:100%;max-width:513px" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">&nbsp;This is closer to what we want, but we need it to be animated. This works by shifting the X coordinates in a cosine wave shape. This makes a nice ripple. You can adjust the frequency by changing the first 30.0 and adjust the amplitude by changing the second 30.0. We'll come back to this at the end of the tutorial<br /><br /></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Animating</font></h2>  <div class="paragraph" style="text-align:left;">&#8203;We need to add a uniform float and we'll call it "Time" and we'll add it in the cosine like this:<br /><br />&#8203;&nbsp;&nbsp;&nbsp; <em><font size="3">vec2 Coord = v_vTexcoord + vec2(cos(v_vTexcoord.y*30.0+Time*6.2831)/30.0,0);</font></em><br />&#8203;<br />It is multiplied by 6.2831 (pi times two) because cosine uses angles in <a href="https://en.wikipedia.org/wiki/Radian">radians</a>&nbsp;so that it does a full cycle every second.<br />We'll set the time uniform in GameMaker&nbsp;like this in the draw event:<br /><br /><em><font size="3">&nbsp;&nbsp;&nbsp; var uTime = shader_get_uniform(shdr_wind,"Time");<br /><br />&nbsp;&nbsp;&nbsp; shader_set(shdr_wind)<br />&nbsp;&nbsp;&nbsp; shader_set_uniform_f(uTime,current_time/1000)<br />&nbsp;&nbsp;&nbsp; draw_self()</font></em><br /><em><font size="3">&nbsp;&nbsp; &nbsp;</font><font size="3">shader_reset()</font></em><br /><br />This will set "Time" to the number of seconds since the game started.<br />If you run this it will be animated. You may notice a problem where the&nbsp;base of the grass moves&#8203;<br />just as much as the top.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Fixing and perfecting</font></h2>  <div class="paragraph" style="text-align:left;">So to fix the problem I just mentioned we will multiply cosine by the" (1.0-v_vTexcoord.y)". This will make the distortion decrease as it approaches the bottom of the sprite. Here is what I did:<br /><br />&#8203;&nbsp;&nbsp;&nbsp; <em><font size="3">vec2 Coord = v_vTexcoord + vec2(cos(v_vTexcoord.y*30.0 + Time*6.2831)/30.0,0)*(1.0-v_vTexcoord.y);</font></em><br /><br />It looks much better now.&nbsp;This shader is currently&nbsp;proportion to&nbsp;the sprite size. If it's long it will stretch the waves, but if it's short it will shrink the waves. That is because the waves are&nbsp;based off of the v_vTexcoord which is between 0 and 1. To fix this we can use the position attribute from the vertex shader because it uses the vertex coordinates rather than the texture coordinates.<br />&nbsp;We need to add a varying vec2 called "v_vPosition" in the vertex and fragment shaders by the other varying vectors. Set it in the vertex shader like this:<br /><br />&nbsp;&nbsp;&nbsp; <em><font size="3">v_vPosition = in_Position.xy;</font></em><br /><br />And back to the fragment shader use this&nbsp;for&nbsp;the coordinates:<br /><br />&nbsp;&nbsp;&nbsp; <em><font size="3">vec2 Size = vec2(256,128);<br />&nbsp;&nbsp;&nbsp; vec2 Wave = vec2(48,5);<br /><br />&nbsp;&nbsp;&nbsp; vec2 Coord = v_vTexcoord + </font></em><font size="3">vec2(cos((v_vPosition.y/Wave.x+Time)*6.2831)*Wave.y,0)/Size*(1.0-v_vTexcoord.y)&#8203;;</font><br /><font size="3"><br /><em>&#8203;</em></font>"Size" should&nbsp;be the size of the texture. Use a uniform if necessary. "Wave" is for adjusting the wave shape. The first number is the height of the wave and the second number is the amplitude.<br />This works by making a cosine wave of the chosen size with time added&nbsp;(multiplied by 6.2831 because of radians) and then multiplied by the amplitude;&nbsp;then divided by "Size" to get it between 0 and 1 and finally multiplied by the code I mentioned above to fix the bottom.<br /><br />Thanks for reading.<br /><a href="https://www.dropbox.com/s/67z7xfp98cvf4ck/Tutorial_8_Wind.gmz?dl=0">DOWNLOAD EXAMPLE</a><br />&#8203;<br />Basic tutorials used:<br /><a href="http://xorshaders.weebly.com/tutorials/vertex-shader-4">#4 Vertex Shader</a><br /><a href="http://xorshaders.weebly.com/tutorials/black-and-white-shader">#2 Black and White Shader</a><br /><a href="http://xorshaders.weebly.com/tutorials/shader-basics1">#1 Shader Basics</a>&#8203;<a href="https://www.dropbox.com/s/67z7xfp98cvf4ck/Tutorial_8_Wind.gmz?dl=0">&#8203;&#8203;&#8203;</a></div>]]></content:encoded></item><item><title><![CDATA[#7 Introduction to 3D part 3]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/7-introduction-to-3d-part-3]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/7-introduction-to-3d-part-3#comments]]></comments><pubDate>Sat, 08 Aug 2015 08:05:21 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/7-introduction-to-3d-part-3</guid><description><![CDATA[In the last tutorial I explained how to create 3D lights using vertex attributes. Today, I'll explain 3D distortion. The main difference is that 3D distortion is done in the vertex shader&nbsp;unlike our last 2 shaders. That means you can move each vertex with the vertex shader.  Flattening shapes  We will first try making a shader that flattens the 3d shapes. To do this we will simply set the z position to 0 for all vertices while leaving x and y positions unchanged. Make sure to comment out th [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">In the last <a title="" href="http://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-2">tutorial</a> I explained how to create 3D lights using vertex attributes. Today, I'll explain 3D distortion. The main difference is that 3D distortion is done in the vertex shader&nbsp;unlike our last 2 shaders. That means you can move each vertex with the vertex shader.<br /></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Flattening shapes</font></h2>  <div class="paragraph" style="text-align:left;">We will first try making a shader that flattens the 3d shapes. To do this we will simply set the z position to 0 for all vertices while leaving x and y positions unchanged. Make sure to comment out the normal attribute and use the default pass through fragment shader.<br />An&nbsp;important variable&nbsp; is "object_space_pos". It is the variable we can use for setting the position.<br />We will use the x and y components but will use 0 instead of z.<br />Here is the result:</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:0;padding-bottom:0;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/618694698.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">As you can see the shapes are properly flattened. Because&nbsp;you now know how to change the vertex position we'll try making water.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Creating a plane</font></h2>  <div class="paragraph" style="text-align:left;">Before we begin with the water shader, we will need something to apply the shader to. We will make a plane instead of our basic shapes. In GameMaker, this may be a little tricky, because we need to generate one with enough vertices. Here is the code I used:<br /><br /><font size="3"><em><strong>water = d3d_model_create();<br />cells = 64;//Number of cells<br />cell = 8;//Cell width<br />height = 32;//Water max height<br />for(var X = -cells/2;X&lt;cells/2;X++)<br />{<br />&nbsp;&nbsp;&nbsp; d3d_model_primitive_begin(water,pr_trianglestrip)<br />&nbsp;&nbsp;&nbsp; for(var Y = -cells/2;Y&lt;cells/2-1;Y++)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d3d_model_vertex(water,X*cell,Y*cell,height)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d3d_model_vertex(water,(X+1)*cell,Y*cell,height)<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; d3d_model_primitive_end(water)<br />}</strong></em></font><br /><span class="rangySelectionBoundary" id="selectionBoundary_1438908355857_6852289677801063" style="line-height: 0; display: none;">&#65279;</span><br /><br />This generates a plane model with many vertices to create higher quality water.<br />Apply your shader to this model instead of the basic shapes&nbsp;using "d3d_model_draw()".</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Water shader</font></h2>  <div class="paragraph" style="text-align:left;">We will use our knowledge to make detailed 3d water using perlin noise and height displacement. You should see the <a title="" href="http://xorshaders.weebly.com/tutorials/vertex-shader-4">Vertex shader tutorial</a>. We will be using&nbsp;the&nbsp;rand&nbsp;and noise&nbsp;functions to determine the height of the water for each vertex so put them in the vertex shader. Now we'll create a variable called height. This will be used to set the height of the water per vertex. Use this code:<br /><br /><em><strong><font size="3">float height = noise(in_Position.xy/64.0)*0.4+noise(in_Position.xy/32.0)*0.3+noise(in_Position.xy/16.0)*0.2+noise(in_Position.xy/8.0)*0.1;</font></strong></em><br /><br />That code generates a perlin noise pattern to make waves in the water.<br />Instead of setting the z position to 0 we'll set it to "height * in_Position.z". This makes it so we can determine the wave height by setting z position. And now finally we'll make a varying float called "v_vHeight" and pass our height variable through it.&nbsp;Now set the color in the fragment shader:<br /><br /><font size="3"><em><strong>gl_FragColor = vec4(mix(vec3(0.1,0.2,0.4),vec3(0.1,0.1,0.3),v_vHeight),1.0);</strong></em></font><br /><br />This is the result:</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/237878808.png" alt="Picture" style="width:100%;max-width:512px" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">This is a start to your water shader! We'll add more in the next tutorial.<br /><br /><a href="https://www.dropbox.com/s/9ka2vt0b39gh4cy/Tutorial_7_3_Water.gmz?dl=0">DOWNLOAD EXAMPLE</a></div>]]></content:encoded></item><item><title><![CDATA[#7 Introduction to 3D part 2]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-2]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-2#comments]]></comments><pubDate>Sat, 13 Jun 2015 05:54:34 GMT</pubDate><category><![CDATA[3D]]></category><category><![CDATA[Intermediate]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-2</guid><description><![CDATA[In the last tutorial&nbsp;we made a basic flood shader. Today we'll make a basic 3D lighting shader.Lighting shader usually use normals. As you may remember from the last tutorial, normals are the vectors which are perpendicular to each triangle. I will explain them in better detail.  Normals  Normal vector information can be received using the "in_Normal" attribute. This is only processed for each vertex (because it's in the vertex shader). So we'll create a varying vector called "v_vNormal" an [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">In the last <a href="http://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-1" title="">tutorial</a>&nbsp;we made a basic flood shader. Today we'll make a basic 3D lighting shader.<br />Lighting shader usually use normals. As you may remember from the last tutorial, normals are the vectors which are perpendicular to each triangle. I will explain them in better detail.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Normals</font></h2>  <div class="paragraph" style="text-align:left;">Normal vector information can be received using the "in_Normal" attribute. This is only processed for each vertex (because it's in the vertex shader). So we'll create a varying vector called "v_vNormal" and we'll add it to both shaders (fragment and vertex). This way the normal can processed per pixel rather than per vertex. To test this shader we'll set the color to the normals so we can see what the normals look like. This is the code I used:<br /><br /><em><strong><font size="3">gl_FragColor = vec4(v_vNormal*0.5+0.5,1.0);<br /></font></strong></em><br />Because normals are in the range of -1 and 1 we'll multiply it be 0.5 and add 0.5 to put it in the range of 0 to 1 (since we can't see negative colors).&nbsp;<br /><br />Here is what it looks like (downloads at the bottom):</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <div><div class="wsite-image wsite-image-border-border-width:0 " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/1434069323.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">That is a simple scene with a sphere, cube and cone. You can see the normals with our shader. When you make your own models, you'll want to make sure the normals are correct.<br />Now we'll move on to a simple lighting shader.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Simple lighting</font></h2>  <div class="paragraph" style="text-align:left;">Now that we get normals we'll make some simple directional lighting. To do this we will need to create a few vectors. We'll create a vec3 called "dir" and set it to something like "vec3( 0.6, 0.1, -1.0)".<br />This will be the direction of our light. Next create another vec3 called "col". This will be for the light color. We'll set this to a nice blue color (I used "vec3( 0.5, 0.8, 1.0)<span style="line-height: 1.5; background-color: initial;">"</span><span style="line-height: 1.5; background-color: initial;">).</span><br /><span style="line-height: 1.5; background-color: initial;">Now create a float called "lighting". Since this will be for the brightness of the pixel we'll need to calculate how much light it is receiving. We'll use the <a href="http://en.wikipedia.org/wiki/Dot_product" title="">dot product</a> function. This function finds the difference between two vectors in the range of -1 to 1 (if used properly). The vectors should be normalized. When you normalize a vector it sets the length of the vector to 1 while keeping it in proportion. If you do not do this to the vectors of a dot product, then it will return something in a range larger (or smaller) than -1 to 1 and in this case, ruin the lighting.</span><br /><span style="line-height: 1.5; background-color: initial;"><br /></span><br /><span style="line-height: 1.5; background-color: initial;">So now we'll set lighting to the dot product of "v_vNormal" and "dir" (make sure their both normalized). This will find the difference of the normal and the light (between -1 and 1).</span><br /><span style="background-color: initial;"><span style="line-height: 1.5;">To convert this to a&nbsp;</span>visible<span style="line-height: 1.5;">&nbsp;value we&nbsp;</span>multiply<span style="line-height: 1.5;">&nbsp;it by 0.5 and add 0.5. Now mulitply the "lighting" float &nbsp;and "col" vector to the texture color (making sure it is a vec4). Your code should look like this:</span></span><br /><br />&nbsp; &nbsp; <font size="3"><em><strong>vec3 dir = vec3( 0.6, 0.1, -1.0);//Light direction<br />&nbsp; &nbsp; vec3 col = vec3( 0.5, 0.8, 1.0);//Light color<br />&nbsp; &nbsp; float lighting = (dot( normalize(v_vNormal), normalize(dir)) * 0.5 + 0.5);//Calculate<br />&nbsp; &nbsp; gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord) * vec4( lighting * col, 1.0);</strong></em></font><br /><br /><span style="background-color: initial;"><span style="line-height: 1.5;">This gets the desired light direction and color, then calculates it with "lighting" and finally applies it to the texture. This is the result (downloads below):</span></span><br /></div>  <div><div class="wsite-image wsite-image-border-border-width:0 " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/1434069638.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">As you can see, our nice scene now has lighting. Lets take this farther by creating a point light.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Point lights</font></h2>  <div class="paragraph" style="text-align:left;">Now that you have a basic understanding of 3D lighting we can create point lights.<br />We want the point lights to have a radius. So we can add a float called "rad".<br />Since these lights cast shine in all directions, we'll need to change the "dir" vector.<br />This is actually simple to set, but we'll need the position of each pixel, so we'll add another varying vec3 and call it "v_vPosition". In the vertex shader, set it to "in_Position".<br /><br />With the position we can calculate the direction from the light to each pixel. We simple put in the desired position for the point light (I used "vec3( 0.0, 32.0, -96.0)<span style="line-height: 1.5; background-color: initial;">") and then subtract the pixel position ("v_vPoisiton"). That gets the direction for the light.</span><br /><br /><span style="line-height: 1.5; background-color: initial;">Now the last thing we'll add is a radius. This will make the light fade the farther the it is from the surface of each object. This is called <a href="https://en.wikipedia.org/wiki/Attenuation" title="">Attenuation</a>&nbsp;so we'll make a variable called "attenuation".&nbsp;</span><span style="line-height: 1.5; background-color: initial;">Set this variable to the length of "dir" (so we get the distance from the light) and divide it by "rad" (so the &nbsp;brightness equals one when it is at the radius distance and 0 when at the light). This is opposite of what we want so we'll have it 1 minus are current code. To keep this from going negative we'll put the max function around our code with the second argument to 0 (which keeps it from going below 0).</span><br /><span style="line-height: 1.5; background-color: initial;"><br /></span><br /><span style="line-height: 1.5; background-color: initial;">The fragment code should look like this:</span><br /><br />&nbsp; &nbsp; <font size="3"><em><strong>vec3 dir = vec3( 0.0, 32.0, -96.0) - v_vPosition;//Light direction<br />&nbsp; &nbsp; float rad = 128.0;//Light radius<br />&nbsp; &nbsp; vec3 col = vec3( 0.5, 0.8, 1.0);//Light color<br />&nbsp; &nbsp; float attenuation = max( 1.0 - length(dir)/rad, 0.0);//Calculate brightness<br />&nbsp; &nbsp; float lighting = (dot( normalize(v_vNormal), normalize(dir)) * 0.5 + 0.5) * attenuation;//Calculate lighting<br />&nbsp; &nbsp; gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord) * vec4( lighting * col, 1.0);<br /></strong></em></font><br /><span style="line-height: 1.5; background-color: initial;"><br /></span><br />When running the code, the result should look like this (downloads at the bottom):</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/341635122.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">There's a simple light in the center of the screen which properly fades. You can easily add a uniform for changing light position, radius, direction, or color if you want, but that is up to the developer.<br /><br /><a href="https://www.dropbox.com/s/b24fonf9486b8xb/Tutorial_7_2_Normals.gmz?dl=0" title="">DOWNLOAD NORMALS EXAMPLE</a><br /><a href="https://www.dropbox.com/s/c4f046vo1p0phy4/Tutorial_7_2_Directional_Light.gmz?dl=0" title="">DOWNLOAD DIRECTIONAL LIGHT EXAMPLE</a><br /><a href="https://www.dropbox.com/s/qrma4lk20j50nxy/Tutorial_7_2_Point_Light.gmz?dl=0" title="">DOWNLOAD POINT LIGHT EXAMPLE</a></div>]]></content:encoded></item><item><title><![CDATA[#7 Introduction to 3D Part 1]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-1]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-1#comments]]></comments><pubDate>Tue, 09 Jun 2015 05:55:06 GMT</pubDate><category><![CDATA[3D]]></category><category><![CDATA[Intermediate]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/introduction-to-3d-7-part-1</guid><description><![CDATA[It's been I while. I've finally made time to continue the tutorial series, and I would like to make an introduction to explain how shaders handle 3D in GameMaker. This is not a 3D tutorial for the GameMaker Language, but only for the shader aspect of it. To do this it is important that you read the Vertex Shader Tutorial.  getting 3D information  In order to make a shader for 3D you will most likely need to no 3d information such as position and normals. In the Vertex Shader Tutorial I explained [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">It's been I while. I've finally made time to continue the tutorial series, and I would like to make an introduction to explain how shaders handle 3D in GameMaker. This is not a 3D tutorial for the GameMaker Language, but only for the shader aspect of it. To do this it is important that you read the <a href="http://xorshaders.weebly.com/tutorials/vertex-shader-4" title="">Vertex Shader Tutorial</a>.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">getting 3D information</font></h2>  <div class="paragraph" style="text-align:left;">In order to make a shader for 3D you will most likely need to no 3d information such as position and normals. In the Vertex Shader Tutorial I explained in briefly how to get the position with the "in_Position" vector (only in the vertex shader). In order to add this to the fragment shader you'll need a varying vec3 for position. Create one and call it "v_vPosition". Make sure it's in the fragment shader also.<br /><br />To get the position in 3D we will simply use the Z component along with the X and Y components. You can also get the <a href="http://en.wikipedia.org/wiki/Normal_(geometry)" title="">normals</a>&nbsp;(which is essentially a vector perpendicular to the currently processed triangle) of the triangles as they are set (d3d_draw functions have the normals already). When you apply the shader to a 3D object then you can retrieve the normal which is useful for lighting.</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5"><span style="line-height: 30px;">Flood shader</span></font></h2>  <div class="paragraph" style="text-align:left;">For our first example we'll make a simple shader which makes all 3D objects below a certain height turn black. This is rather simple to do. In the fragment shader we can check if "v_vPosition.z" is less than your desired height, then set it to black if it is. Because the vertex shader is only run for every vertex it's not precise enough for this shader. That is why we passed it to the fragment shader so that we can check each pixel rather than each vertex. For my example I used:<br /><br /><em><strong><font size="3">if (v_vPosition.z&gt;0.0)<br />{<br />&nbsp;gl_FragColor = vec4(0.0,0.0,0.0,1.0);<br />}<br /></font></strong></em><br />Here is a screenshot of a simple 3D demo scene:</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://xorshaders.weebly.com/uploads/4/1/6/0/41606175/814747485.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;">As you can see the parts below 0 Z are black.<br /><a href="https://www.dropbox.com/s/jalj5ipfi3vubck/Tutorial_7_1_Flood.gmz?dl=0">DOWNLOAD EXAMPLE</a></div>]]></content:encoded></item><item><title><![CDATA[Converting GlSLsandbox Shaders]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/converting-glslsandbox-shaders]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/converting-glslsandbox-shaders#comments]]></comments><pubDate>Mon, 09 Mar 2015 17:05:00 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/converting-glslsandbox-shaders</guid><description><![CDATA[In the last tutorial&nbsp;we talked about converting ShaderToy shaders to GameMaker: Studio. Today we'll be converting GLSL Sandbox shaders. Today we'll convert this shader (the code can also be found below). The main differences are caused by undeclared variables. I will list the fixes to the most common ones.  Shaders on glslsandbox.com  Shaders on&nbsp;GLSL Sandbox&nbsp;have a few differences from shaders in GameMaker. Like on ShaderToy there are no textures most of the time. However GLSL San [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">In the last <a href="http://xorshaders.weebly.com/tutorials/converting-sandbox-shaders" title="">tutorial</a>&nbsp;we talked about converting <a href="https://www.shadertoy.com/" title="">ShaderToy</a> shaders to <a href="http://yoyogames.com/studio" title="">GameMaker: Studio</a>. Today we'll be converting <a href="http://glslsandbox.com/" title="">GLSL Sandbox</a> shaders. Today we'll convert <a href="http://glslsandbox.com/e#23569.0">this</a> shader (the code can also be found below). The main differences are caused by undeclared variables. I will list the fixes to the most common ones.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Shaders on glslsandbox.com</font></h2>  <div class="paragraph" style="text-align:left;">Shaders on&nbsp;<a href="http://glslsandbox.com/" title="">GLSL Sandbox</a>&nbsp;have a few differences from shaders in GameMaker. Like on <a href="https://www.shadertoy.com/" title="">ShaderToy</a> there are no textures most of the time. However GLSL Sandbox only supports&nbsp;<a href="http://en.wikipedia.org/wiki/Framebuffer" title="">frame buffers</a>. If a shader uses theses, there will be a uniform sampler2D with the other uniforms. It can be named anything, but it is most often called "backbuffer" or "bb". Frame buffers must be made in GameMaker outside of the shader. These can be done with surfaces in GameMaker, but because these are very rarely used I will not get in too much detail.&nbsp;</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Varying vectors</font></h2>  <div class="paragraph" style="text-align:left;">Check out&nbsp;<a href="http://xorshaders.weebly.com/tutorials/vertex-shader-4" title="" style="">tutorial&nbsp;4</a>&nbsp;if you haven't already for information about varying vectors. You will need to create a varying vec2 called "fragCoord". Then set it in the vertex shader to "in_Position.xy". You can also remove v_vColour and v_vTexcoord because they won' be used in this shader.<br />Some shaders also have a varying vec2 called "surfacePosition" (although it is not in this shader). This is used to make shaders where you can scroll and zoom. To make this in GameMaker you should another varying vector in vertex shader called "surfacePosition". Then you should be set like this:&nbsp;<br /><br /><em><strong><font size="3"><font color="#d5d5d5">surfacePosition = in_Position.xy*Scroll.zw+Scroll.xy;</font></font></strong></em><br /><br />"Scroll" will be a vec4 uniform that we'll add next. That code will zoom with z and w components and offset with the x and y.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Uniforms</font></h2>  <div class="paragraph" style="text-align:left;">Make sure you see&nbsp;<a href="http://xorshaders.weebly.com/tutorials/blur-shaders-5-part-2" title="" style="">tutorial 5 part 2</a>&nbsp;for details about uniforms.<br />GLSL Sandbox shaders already have the uniforms setup. As long as you set them to the right values it should work fine. If the shader has "surfacePosition" then only thing you need to add is a vec4 uniform called "Scroll".&nbsp;<span style="line-height: 1.5; background-color: initial;">This can be used in GameMaker to scroll and zoom.</span></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Summary</font></h2>  <div class="paragraph" style="text-align:left;">Here's a final summary of what we have learned:<br /><ul><li>Change "gl_FragCoord" to "fragCoord"</li><li>Add "fragCoord" and &nbsp;"surfacePosition" (if needed) to vertex shader</li><li>Add "Scroll" vec4 uniform if needed</li><li>Set all uniforms (may include time, resolution or mouse)</li></ul>Here is the GLSL Sandbox code:<br /><br /><em><strong><font size="3"><font color="#d5d5d5">#ifdef GL_ES<br />precision mediump float;<br />#endif<br /><br />uniform float time;<br />uniform vec2 resolution;<br /><br />void main( void ) {<br /><br />vec2 uv = ( gl_FragCoord.xy / resolution.y );<br /><br />vec3 color = vec3(fract(sin(dot(floor(uv.xy*32.0+time*2.0),vec2(5.364,6.357)))*357.536));<br />gl_FragColor = vec4( color, 1.0 );</font></font></strong></em><br /><font size="3"><span style="line-height: 24px;"><br /></span></font><span style="line-height: 24px;"><strong><font size="4">Converted GameMaker fragment code:</font></strong></span><br /><em><font size="3"><br /><strong><font color="#d5d5d5">#ifdef GL_ES<br />precision mediump float;<br />#endif<br />varying vec2 FragCoord;<br />uniform float time;<br />uniform vec2 resolution;<br /><br />void main( void )<br />{<br />&nbsp; &nbsp; vec2 uv = ( FragCoord.xy / resolution.y );<br />&nbsp; &nbsp; vec3 color = vec3(fract(sin(dot(floor(uv.xy*32.0+time*2.0),vec2(5.364,6.357)))*357.536));<br />&nbsp; &nbsp; gl_FragColor = vec4( color, 1.0 );<br />}</font></strong></font></em><br /><br />Converted vertex code:<br /><br /><em><strong><font size="3"><font color="#d5d5d5">attribute vec3 in_Position; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (x,y,z)<br />//attribute vec3 in_Normal; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (x,y,z) &nbsp; &nbsp; unused in this shader.<br />//attribute vec4 in_Colour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (r,g,b,a) unused in this shader.<br />//attribute vec2 in_TextureCoord; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (u,v) &nbsp; &nbsp; unused in this shader.<br /><br />varying vec2 FragCoord;<br /><br />void main()<br />{<br />&nbsp; &nbsp; vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);<br />&nbsp; &nbsp; gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; FragCoord = in_Position.xy;<br />}</font></font></strong></em><br /><br />Here is the example file:<br /><a href="https://www.dropbox.com/s/kydw5ls3q3sys0v/Tutorial_GLSL_Sandbox.gmz?dl=0">DOWNLOAD EXAMPLE</a></div>]]></content:encoded></item><item><title><![CDATA[Converting Shadertoy Shaders]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/converting-sandbox-shaders]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/converting-sandbox-shaders#comments]]></comments><pubDate>Sun, 08 Mar 2015 21:55:25 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/converting-sandbox-shaders</guid><description><![CDATA[Shaders on websites like Shadertoy.com or GLSLsandbox.com&nbsp;work a little different than shaders in GameMaker: Studio. Today I'll be talking about&nbsp;Shadertoy.com. For this example, we will port my "Pixel Noise" shader&nbsp;to GameMaker (code also below), so use that for the code.&nbsp;Note that because the shaders are designed for&nbsp;Shadertoy.com, they won't always be fully optimized for GameMaker. It can often be best to just design a shader yourself. This tutorial may not cover all t [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">Shaders on websites like <a href="https://www.shadertoy.com/" title="">Shadertoy.com</a> or <a href="http://glslsandbox.com/" title="">GLSLsandbox.com</a>&nbsp;work a little different than shaders in <a href="http://www.yoyogames.com/studio" title="">GameMaker: Studio</a>. Today I'll be talking about&nbsp;<a href="https://www.shadertoy.com/" title="">Shadertoy.com</a>. For this example, we will port my <a href="https://www.shadertoy.com/view/Mls3zs" title="">"Pixel Noise" shader</a><a href="https://www.shadertoy.com/view/lls3zs" title="">&nbsp;</a>to GameMaker (code also below), so use that for the code.&nbsp;<br />Note that because the shaders are designed for&nbsp;<a href="https://www.shadertoy.com/" title="" style="line-height: 1.5; background-color: initial;">Shadertoy.com</a>, they won't always be fully optimized for GameMaker. It can often be best to just design a shader yourself. This tutorial may not cover all the differences, but it should help you convert most shaders from&nbsp;<a href="https://www.shadertoy.com/" title="" style="line-height: 1.5; background-color: initial;">Shadertoy.com</a>.</div>  <div class="paragraph" style="text-align:left;">The shaders on <a href="https://www.shadertoy.com/" title="">Shadertoy.com</a>&nbsp;don't need textures and most of them don't even use textures (my shader does not use any textures either). If a shader does use textures it will show the textures at the bottom right (at the iChannel0-iChannel3).&nbsp;In GameMaker: Studio, shaders must &nbsp;be applied to something, so most of the shaders designed for GameMaker, are applied to sprites, backgrounds, or in 3D they can be applied to planes.&nbsp;That means shaders in GameMaker must have at least one texture (although that texture can be a blank rectangle). Another difference is&nbsp;Shadertoy shaders recently started using fragColor for gl_FragColor. To remove errors simply change those back to gl_FragColor. Also "void mainImage( out vec4 fragColor, in vec2 fragCoord )" should be replaced with this "void main( void)".</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Shaders on shadertoy.com</font></h2>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Varying Vectors</font></h2>  <div class="paragraph" style="text-align:left;">Check out&nbsp;<a href="http://xorshaders.weebly.com/tutorials/vertex-shader-4" title="">tutorial&nbsp;4</a> if you haven't already for information about varying vectors. You will need to create a varying vec2 called fragCoord. Then set it in the vertex shader to "in_Position.xy". You can also remove v_vColour and v_vTexcoord because they won' be used in this shader.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Uniforms</font></h2>  <div class="paragraph" style="text-align:left;">To see all the uniforms you may need, click the "Shader inputs" menu above the shader code. This will show all the uniforms ShaderToy uses. You should copy all the uniforms the specific shader uses in to the shader in GameMaker. Make sure you see <a href="http://xorshaders.weebly.com/tutorials/blur-shaders-5-part-2" title="">tutorial 5 part 2</a> for details about uniforms.<br /></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5"><span style="line-height: 30px;">Texture Differences</span></font></h2>  <div class="paragraph" style="text-align:left;">&nbsp;If a shader does not use textures, then you just apply the shader to a rectangle or blank texture. In order to get textures, you must use uniform samplers (unless it's just one texture). With one texture you could just use the base texture (which is whatever you applied it to). For now we won't worry about textures since we're not using them.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Summary</font></h2>  <div class="paragraph" style="text-align:left;">So to make things easier I'll make a list for you. So when converting shaders you'll most likely need to change all these things:<br /><ul><li>Change "fragColor" to "gl_FragColor"</li></ul><ul><li>Change "void mainImage( out vec4 fragColor, in vec2 fragCoord )" to "void main( void)"</li><li>Create the varying vec2 called "fragCoord"</li><li>Remove unneeded attribute vectors</li><li>Add the needed uniforms including the samplers</li></ul>That's it! Here is the Shadertoy code:<br /><br /><em><strong><font size="3"><span class="rangySelectionBoundary" id="selectionBoundary_1425859095640_7238222868181765" style="line-height: 0; display: none;">&#65279;</span>float rand(vec3 n)<br />{<br />&nbsp;	return fract(abs(sin(dot(n,vec3(4.3357,-5.8464,6.7645))*52.47))*256.75+0.325); &nbsp;&nbsp;<br />}<br />void mainImage( out vec4 fragColor, in vec2 fragCoord )<br />{<br />	vec3 p = vec3(fragCoord.xy+vec2(iGlobalTime)*64.0,0.0);<br />&nbsp; &nbsp; float b = (rand(floor(p/64.0))*0.5+rand(floor(p/32.0))*0.3+rand(floor(p/16.0))*0.2);<br />	fragColor = vec4(vec3(b*0.6),1.0);<br />}<span class="rangySelectionBoundary" id="selectionBoundary_1425859095640_2988183388952166" style="line-height: 0; display: none;">&#65279;</span></font></strong></em><br /><br />Here's the converted fragment code:<br /><br /><em><strong><font size="3">uniform float iGlobalTime;</font></strong></em><br /><em><strong><font size="3">varying vec2 fragCoord;<br />float rand(vec3 n)<br />{<br />&nbsp;return fract(abs(sin(dot(n,vec3(4.3357,-5.8464,6.7645))*52.47))*256.75+0.325); &nbsp;&nbsp;<br />}<br />void main(void)<br />{<br />&nbsp; &nbsp; vec3 p = vec3(fragCoord.xy+vec2(iGlobalTime)*64.0,0.0);<br />&nbsp; &nbsp; float b = (rand(floor(p/64.0))*0.5+rand(floor(p/32.0))*0.3+rand(floor(p/16.0))*0.2);<br />&nbsp; &nbsp; gl_FragColor = vec4(vec3(b*0.6),1.0);<br />}</font></strong></em><br /><br />Now here is the vertex code:<br /><br /><em><strong><font size="3">attribute vec3 in_Position; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (x,y,z)<br />//attribute vec3 in_Normal; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (x,y,z) &nbsp; &nbsp; unused in this shader.<br />//attribute vec4 in_Colour; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (r,g,b,a) unused in this shader.<br />//attribute vec2 in_TextureCoord; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// (u,v) &nbsp; &nbsp; unused in this shader.<br /><br />varying vec2 fragCoord;<br /><br />void main()<br />{<br />&nbsp; &nbsp; vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);<br />&nbsp; &nbsp; gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; fragCoord = in_Position.xy;<br />}</font></strong></em><br /><br />Here's the example file:<br /><a title="" href="https://www.dropbox.com/s/onzufortvlc6isu/Tutorial_ShaderToy.gmz?dl=0">DOWNLOAD EXAMPLE</a><br />For a challenge you can convert&nbsp;my <a title="" href="https://www.shadertoy.com/view/MlXGWf">"Cool Lake"shader</a>.</div>]]></content:encoded></item><item><title><![CDATA[When to use shaders]]></title><link><![CDATA[https://xorshaders.weebly.com/tutorials/when-to-use-shaders]]></link><comments><![CDATA[https://xorshaders.weebly.com/tutorials/when-to-use-shaders#comments]]></comments><pubDate>Tue, 03 Feb 2015 15:30:03 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://xorshaders.weebly.com/tutorials/when-to-use-shaders</guid><description><![CDATA[I have gotten many shader requests for effects that shaders wouldn't be good at making. Today I would like to explain the uses of shaders so that you know when to use them and when to look in to other resources like particles.  SHader uses  Shaders are for changing the color of pixels. It isn't used for anything more. Shaders can use textures or math to mix colors or blend them, but shaders can't easily be used for clickable or interactive objects in a scene. In general shaders are for recolorin [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">I have gotten many shader requests for effects that shaders wouldn't be good at making. Today I would like to explain the uses of shaders so that you know when to use them and when to look in to other resources like particles.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">SHader uses</font></h2>  <div class="paragraph" style="text-align:left;">Shaders are for changing the color of pixels. It isn't used for anything more. Shaders can use textures or math to mix colors or blend them, but shaders can't easily be used for clickable or interactive objects in a scene. In general shaders are for recoloring or distorting. If you need textured shapes that can have gravity or motion (like rain for example), then you should use particles.</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Particle uses</font></h2>  <div class="paragraph" style="text-align:left;">Particles are for moving and animated, textures or shapes that don't interact with objects or the scene. These are useful for effects like fire, rain, smoke, snow, etc. Blend modes can be applied to them also, so you can have additive blend (brightens the scene). However because particles aren't very interactive, then you may need objects.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Object uses</font></h2>  <div class="paragraph" style="text-align:left;">Objects should be used for anything interactive. That means that it should be used for things that can collide with other objects and bounce for instance. These however should be used lightly, because the are often the slowest. You probably don't want to use this for rain that can collide unless you don't have much rain.</div>  <h2 class="wsite-content-title" style="text-align:left;"><font size="5">Conclusion</font></h2>  <div class="paragraph" style="text-align:left;">Shaders are designed for effects like <a href="http://en.wikipedia.org/wiki/Scan_line">scan lines</a>, <a href="http://en.wikipedia.org/wiki/Vignetting">vignette</a> or <a href="http://en.wikipedia.org/wiki/Photographic_print_toning">sepia tone</a>. Particles are designed for rain, fire, smoke, etc. Objects are for anything interactive like a bouncing ball. Now this doesn't mean that you can't use shaders for interactive things, but the process is harder and may be slower.</div>]]></content:encoded></item></channel></rss>