<?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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Last Ray of Hope &#187; Cg</title>
	<atom:link href="http://www.lastrayofhope.com/tag/cg/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lastrayofhope.com</link>
	<description>Home of Kaluriel Hargrove</description>
	<lastBuildDate>Thu, 02 Feb 2012 00:21:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Cg/HLSL Saturate</title>
		<link>http://www.lastrayofhope.com/2009/04/13/cghlsl-saturate/</link>
		<comments>http://www.lastrayofhope.com/2009/04/13/cghlsl-saturate/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 01:19:43 +0000</pubDate>
		<dc:creator>Kaluriel</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Cg]]></category>
		<category><![CDATA[glsl]]></category>
		<category><![CDATA[shader]]></category>

		<guid isPermaLink="false">http://www.lastrayofhope.com/?p=1175</guid>
		<description><![CDATA[I've been converting my Cg shaders I wrote for my AGT work in university into GLSL, however I came by an annoying problem, Cg uses a function that doesn't exist in GLSL, but does exist in HLSL. I eventually found documentation on what it does and so looked up the GLSL equivilant. The Cg version [...]]]></description>
			<content:encoded><![CDATA[<p>I've been converting my Cg shaders I wrote for my AGT work in university into GLSL, however I came by an annoying problem, Cg uses a function that doesn't exist in GLSL, but does exist in HLSL. I eventually found documentation on what it does and so looked up the GLSL equivilant. The Cg version shown below...</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="c" style="font-family:monospace;">float3 outValue <span class="sy0">=</span> saturate<span class="br0">&#40;</span> inValue <span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>Becomes the following when converted to GLSL...</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="glsl" style="font-family:monospace;"><span class="kw3">vec3</span> outValue <span class="sy0">=</span> <span class="kw5">clamp</span><span class="br0">&#40;</span> inValue<span class="sy0">,</span> 0<span class="sy0">.</span>0<span class="sy0">,</span> 1<span class="sy0">.</span>0 <span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>&nbsp;</p>
<p>Thought this might be useful for others who might be having the same problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lastrayofhope.com/2009/04/13/cghlsl-saturate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Texture Splat Shader</title>
		<link>http://www.lastrayofhope.com/2008/02/26/texture-splat-shader/</link>
		<comments>http://www.lastrayofhope.com/2008/02/26/texture-splat-shader/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 17:56:54 +0000</pubDate>
		<dc:creator>Kaluriel</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Cg]]></category>

		<guid isPermaLink="false">http://www.lastrayofhope.com/?p=660</guid>
		<description><![CDATA[A shader for using an RGBA Map to texture map a primitive with four textures. The first texture is the base texture splat map. The image on this blog entry is a texture splat map that I've used, anywhere there is a green component is grass, anywhere there is blue is sand/dirt, and anywhere there [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lastrayofhope.com/wp-content/uploads/2008/02/ground.png"><img class="alignleft size-medium wp-image-2611" title="Texture Splat Base" src="http://www.lastrayofhope.com/wp-content/uploads/2008/02/ground-300x300.png" alt="Texture Splat Base" width="180" height="180" /></a>A shader for using an RGBA Map to texture map a primitive with four textures.</p>
<p>The first texture is the base texture splat map. The image on this blog entry is a texture splat map that I've used, anywhere there is a green component is grass, anywhere there is blue is sand/dirt, and anywhere there is red is rock/road. The colour component acts as a blend value.</p>
<p>The other three textures represent the area I just mentioned, there is room for texture to be applied to the same texture splat if the alpha channel is used, but I prefer to save that for use as a height map in the vertex stage.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="glsl" style="font-family:monospace;"><span class="co1">// --- [ structs ] --------------------------------------------</span>
<span class="co1">//</span>
<span class="kw3">struct</span> VS_OUTPUT
<span class="br0">&#123;</span>
	float4 position <span class="sy0">:</span> POSITION<span class="sy0">;</span>
	float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">struct</span> VS_INPUT
<span class="br0">&#123;</span>
	float4 position <span class="sy0">:</span> POSITION<span class="sy0">;</span>
	float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// --- [ vertex program ] -------------------------------------</span>
<span class="co1">//</span>
VS_OUTPUT main_vp<span class="br0">&#40;</span> VS_INPUT In<span class="sy0">,</span> <span class="kw2">uniform</span> float4x4 worldViewProj <span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	VS_OUTPUT Out<span class="sy0">;</span>
&nbsp;
	Out<span class="sy0">.</span><span class="me1">position</span> <span class="sy0">=</span> mul<span class="br0">&#40;</span>worldViewProj<span class="sy0">,</span> In<span class="sy0">.</span><span class="me1">position</span> <span class="br0">&#41;</span><span class="sy0">;</span>
	Out<span class="sy0">.</span><span class="me1">uv</span> <span class="sy0">=</span> In<span class="sy0">.</span><span class="me1">uv</span><span class="sy0">;</span>
&nbsp;
	<span class="kw1">return</span> Out<span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">// --- [ fragment program ] -----------------------------------</span>
<span class="co1">//</span>
float4 main_fp<span class="br0">&#40;</span> float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">sampler2D</span> texBase<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">sampler2D</span> tex0<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">sampler2D</span> tex1<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">sampler2D</span> tex2 <span class="br0">&#41;</span> <span class="sy0">:</span> COLOR
<span class="br0">&#123;</span>
	float3 colour <span class="sy0">=</span> tex2D<span class="br0">&#40;</span>texBase<span class="sy0">,</span> uv<span class="br0">&#41;</span><span class="sy0">.</span><span class="me1">rgb</span><span class="sy0">;</span>
	<span class="kw1">return</span> tex2D<span class="br0">&#40;</span>tex0<span class="sy0">,</span> uv<span class="br0">&#41;</span> <span class="sy0">*</span> colour<span class="sy0">.</span><span class="me1">r</span> <span class="sy0">+</span> tex2D<span class="br0">&#40;</span>tex1<span class="sy0">,</span> uv<span class="br0">&#41;</span> <span class="sy0">*</span> colour<span class="sy0">.</span><span class="me1">g</span> <span class="sy0">+</span> tex2D<span class="br0">&#40;</span>tex2<span class="sy0">,</span> uv<span class="br0">&#41;</span> <span class="sy0">*</span> colour<span class="sy0">.</span><span class="me1">b</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lastrayofhope.com/2008/02/26/texture-splat-shader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Water Shader</title>
		<link>http://www.lastrayofhope.com/2008/02/13/basic-water-shader/</link>
		<comments>http://www.lastrayofhope.com/2008/02/13/basic-water-shader/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 17:50:32 +0000</pubDate>
		<dc:creator>Kaluriel</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Cg]]></category>

		<guid isPermaLink="false">http://www.lastrayofhope.com/?p=655</guid>
		<description><![CDATA[A very simple vertex shader for creating basic wave motion. I designed this shader for use with the Tales of Phantasia Remake for the river in Totus Village. And despite its simplicity it turned out quite well. &#160;]]></description>
			<content:encoded><![CDATA[<p>A very simple vertex shader for creating basic wave motion. I designed this shader for use with the Tales of Phantasia Remake for the river in Totus Village. And despite its simplicity it turned out quite well.</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="glsl" style="font-family:monospace;"><span class="co1">// --- [ structs ] --------------------------------------------</span>
<span class="co1">//</span>
<span class="kw3">struct</span> VS_OUTPUT
<span class="br0">&#123;</span>
	float4 position <span class="sy0">:</span> POSITION<span class="sy0">;</span>
	float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="kw3">struct</span> VS_INPUT
<span class="br0">&#123;</span>
	float4 position <span class="sy0">:</span> POSITION<span class="sy0">;</span>
	float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// --- [ vertex program ] -------------------------------------</span>
<span class="co1">//</span>
VS_OUTPUT main_vp<span class="br0">&#40;</span> VS_INPUT In<span class="sy0">,</span> <span class="kw2">uniform</span> float4x4 worldViewProj<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">float</span> time <span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	VS_OUTPUT Out<span class="sy0">;</span>
&nbsp;
	Out<span class="sy0">.</span><span class="me1">position</span> <span class="sy0">=</span> In<span class="sy0">.</span><span class="me1">position</span><span class="sy0">;</span>
	Out<span class="sy0">.</span><span class="me1">position</span><span class="sy0">.</span><span class="me1">y</span> <span class="sy0">=</span> In<span class="sy0">.</span><span class="me1">position</span><span class="sy0">.</span><span class="me1">y</span> <span class="sy0">+</span> 0<span class="sy0">.</span>10 <span class="sy0">*</span> <span class="br0">&#40;</span> <span class="kw5">sin</span><span class="br0">&#40;</span> <span class="br0">&#40;</span> In<span class="sy0">.</span><span class="me1">position</span><span class="sy0">.</span><span class="me1">z</span> <span class="sy0">+</span> <span class="br0">&#40;</span> time <span class="sy0">*</span> 30 <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="sy0">+</span> <span class="br0">&#40;</span> In<span class="sy0">.</span><span class="me1">position</span><span class="sy0">.</span><span class="me1">x</span> <span class="sy0">+</span> <span class="br0">&#40;</span> time <span class="sy0">*</span> 30 <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="sy0">-</span> <span class="nu0">0.10</span><span class="sy0">;</span>
	Out<span class="sy0">.</span><span class="me1">position</span> <span class="sy0">=</span> mul<span class="br0">&#40;</span>worldViewProj<span class="sy0">,</span> Out<span class="sy0">.</span><span class="me1">position</span><span class="br0">&#41;</span><span class="sy0">;</span>
	Out<span class="sy0">.</span><span class="me1">uv</span><span class="sy0">.</span><span class="me1">x</span> <span class="sy0">=</span> <span class="br0">&#40;</span> In<span class="sy0">.</span><span class="me1">uv</span><span class="sy0">.</span><span class="me1">x</span> <span class="sy0">-</span> time <span class="sy0">*</span> 5 <span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">0.5</span><span class="sy0">;</span>
	Out<span class="sy0">.</span><span class="me1">uv</span><span class="sy0">.</span><span class="me1">y</span> <span class="sy0">=</span> <span class="br0">&#40;</span> In<span class="sy0">.</span><span class="me1">uv</span><span class="sy0">.</span><span class="me1">y</span> <span class="sy0">+</span> time <span class="sy0">*</span> 10 <span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">0.5</span><span class="sy0">;</span>
&nbsp;
	<span class="kw1">return</span> Out<span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">// --- [ fragment program ] -----------------------------------</span>
<span class="co1">//</span>
float4 main_fp<span class="br0">&#40;</span> float2 uv <span class="sy0">:</span> TEXCOORD0<span class="sy0">,</span> <span class="kw2">uniform</span> <span class="kw3">sampler2D</span> tex0 <span class="br0">&#41;</span> <span class="sy0">:</span> COLOR
<span class="br0">&#123;</span>
	<span class="kw1">return</span> tex2D<span class="br0">&#40;</span>tex0<span class="sy0">,</span> uv<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lastrayofhope.com/2008/02/13/basic-water-shader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

