<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - Need help with a texture scroll shader]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=1027</link>
		<description><![CDATA[The most recent posts in Need help with a texture scroll shader.]]></description>
		<lastBuildDate>Fri, 18 Jul 2014 16:48:24 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Need help with a texture scroll shader]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7007#p7007</link>
			<description><![CDATA[<p>I&#039;m happy to announce that shader code worked fine. Thanks anael for help. This is the final working code:</p><p>VERT shader:</p><div class="codebox"><pre><code>//VERT

attribute vec3 Vertex;
attribute vec2 TexCoord0;

varying vec2 TexCoord;  

uniform mat4 TextureMatrix[8];
uniform mat4 ProjModelViewMatrix;

void main(void) 
{  
    TexCoord = vec2(TextureMatrix[0] * vec4(TexCoord0, 1.0,1.0));  
    gl_Position = ProjModelViewMatrix * vec4(Vertex,1.0);  
} </code></pre></div><p>FRAG shader:</p><div class="codebox"><pre><code>//FRAG shader

uniform float Time;
uniform sampler2D Texture[8];

  
varying vec2 TexCoord;  

void main(void) 
{  
    gl_FragColor = texture(Texture[0], vec2(TexCoord.x+Time,TexCoord.y));
}   </code></pre></div><p>For the ones that will be implementing the code, they will need a code that updates the &quot;Time&quot; variable. C++ or hopefully lua in the future.</p>]]></description>
			<author><![CDATA[dummy@example.com (Skywriter)]]></author>
			<pubDate>Fri, 18 Jul 2014 16:48:24 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7007#p7007</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help with a texture scroll shader]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7006#p7006</link>
			<description><![CDATA[<p>I just meant to check if the function was called, because &quot;if (material)&quot; and &quot;if (FXRef)&quot; needs to be true.<br />You can just use a printf to be sure you enter the code :</p><div class="codebox"><pre><code>render-&gt;sendUniformFloat(fxId, &quot;Time&quot;, &amp;time);
printf(&quot;send uniform now\n&quot;); // DEBUG</code></pre></div><p>if &quot;send uniform now&quot; doesn&#039;t appear in the console, it means you don&#039;t enter the code.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Fri, 18 Jul 2014 16:40:34 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7006#p7006</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help with a texture scroll shader]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7005#p7005</link>
			<description><![CDATA[<p>Hi anael. How can i check it? In documentation it says its void(returns no value). Sorry for being stupid...</p><p>I done this calll:</p><p>gl_FragColor=vec4(Time,1.0,1.0,1.0);</p><p>It had no effect. Seems Time is not being passed. What else i can do?</p>]]></description>
			<author><![CDATA[dummy@example.com (Skywriter)]]></author>
			<pubDate>Fri, 18 Jul 2014 16:26:30 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7005#p7005</guid>
		</item>
		<item>
			<title><![CDATA[Re: Need help with a texture scroll shader]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7004#p7004</link>
			<description><![CDATA[<p>It looks ok,<br />did you check if &quot;render-&gt;sendUniformFloat&quot; is called ?<br />also, are you sure the shader is linked to material 0 of Entity0 ?</p><p>the line &quot;if(! game-&gt;isRunning()) return;&quot; means the code will only run when you play the game (pacman button).</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Fri, 18 Jul 2014 14:34:21 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7004#p7004</guid>
		</item>
		<item>
			<title><![CDATA[Need help with a texture scroll shader]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=7003#p7003</link>
			<description><![CDATA[<p>Hi, i have this shader and i want texture to scroll x direction, but something is wrong and texture wont move. I&#039;m new to shaders, please help</p><br /><p>VERT:<br />attribute vec3 Vertex;<br />attribute vec2 TexCoord0;</p><p>varying vec2 TexCoord;&nbsp; </p><p>uniform mat4 TextureMatrix[8];<br />uniform mat4 ModelViewMatrix;<br />uniform mat4 ProjModelViewMatrix;</p><p>void main(void) <br />{&nbsp; <br />&nbsp; &nbsp; TexCoord = vec2(TextureMatrix[0] * vec4(TexCoord0, 1.0,1.0));&nbsp; <br />&nbsp; &nbsp;<br />&nbsp; &nbsp; gl_Position = ProjModelViewMatrix * vec4(Vertex,1.0);&nbsp; <br />}&nbsp; </p><br /><p>FRAG:</p><p>uniform sampler2D Texture[8];</p><p>uniform float Time;&nbsp; <br />varying vec2 TexCoord;&nbsp; </p><p>void main(void) {&nbsp; <br />&nbsp; &nbsp; vec4 texel = texture2D(Texture[0], vec2(TexCoord.x + 100.0, TexCoord.y));&nbsp; <br />&nbsp; &nbsp; //vec4 texel = texture(Texture[0], vec2(TexCoord.x + Time,0.0));&nbsp; </p><p>&nbsp; &nbsp; gl_FragColor = texel; <br />&nbsp; &nbsp; //gl_FragColor=vec4(1.0,1.0,1.0,1.0); <br />}&nbsp; &nbsp;</p><p>I have time implemented in behaviour dll and its set to &lt;time+=0.1&gt;. But for some reason it doesnt scroll the texture. Setting 0.5f instead of time scrolls the texture. This is my dll code:</p><p>.......<br />void MyBehavior::update(void)<br />{<br />&nbsp; &nbsp; MEngine * engine = MEngine::getInstance();</p><p>&nbsp; &nbsp; MRenderingContext *render = engine-&gt;getRenderingContext();</p><p>&nbsp; &nbsp; MGame * game = engine-&gt;getGame();</p><p>&nbsp; &nbsp; MLevel * level = engine-&gt;getLevel();</p><p>&nbsp; &nbsp; MScene * scene = level-&gt;getCurrentScene();</p><p>&nbsp; &nbsp; MOEntity* entity = scene-&gt;getEntityByName(&quot;Entity0&quot;);</p><p>&nbsp; &nbsp; MMesh * mesh = entity-&gt;getMesh();</p><p>&nbsp; &nbsp; // check if the game is running, removing thif test will enable In-Editor update (like for the lookAt behavior)<br />&nbsp; &nbsp; if(! game-&gt;isRunning())<br />&nbsp; &nbsp; &nbsp; &nbsp; return;</p><p>&nbsp; &nbsp; // get the associated parent object (who is using this behavior)<br />&nbsp; &nbsp; MObject3d * parent = getParentObject();</p><p>&nbsp; &nbsp; // lets rotate the parent object around the z axis, using our custom &quot;rotationSpeed&quot; variable<br />&nbsp; &nbsp; //parent-&gt;addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);<br />&nbsp; &nbsp; if (time &gt; 1.0)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; time = 0.0;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; time += 0.1;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; MMaterial * material = mesh-&gt;getMaterial(0);<br />&nbsp; &nbsp; if (material)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; MFXRef * FXRef = material-&gt;getFXRef();<br />&nbsp; &nbsp; &nbsp; &nbsp; if (FXRef)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned int fxId = FXRef-&gt;getFXId();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; render-&gt;bindFX(fxId);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // send uniform variable<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; render-&gt;sendUniformFloat(fxId, &quot;Time&quot;, &amp;time);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; render-&gt;bindFX(0);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}<br />........</p>]]></description>
			<author><![CDATA[dummy@example.com (Skywriter)]]></author>
			<pubDate>Fri, 18 Jul 2014 12:03:41 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=7003#p7003</guid>
		</item>
	</channel>
</rss>
