<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - Adding custom GLSL shader to all meshes on scene]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=431</link>
		<description><![CDATA[The most recent posts in Adding custom GLSL shader to all meshes on scene.]]></description>
		<lastBuildDate>Wed, 29 Aug 2012 13:35:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2453#p2453</link>
			<description><![CDATA[<p>Ok, thanks</p><div class="quotebox"><cite>anael wrote:</cite><blockquote><p>Depth of Field is more complex yes, you need the depth information to blur the image.<br />I must say it can be very slow on iOS, depend if you target only the last iPhone.</p><p>You need to render the scene to a texture with a depth texture like the example :<br /></p><div class="codebox"><pre><code>render-&gt;bindFrameBuffer(m_renderBufferId);
render-&gt;attachFrameBufferTexture(M_ATTACH_COLOR0, m_colorTextureId);
render-&gt;attachFrameBufferTexture(M_ATTACH_DEPTH, m_depthTextureId);</code></pre></div><p>Then you render the texture with a shader like the example, but you also need to pass the depth texture (witch the example doesn&#039;t do). The depth texture will be used to specify the blur influence or the blur size.</p></blockquote></div><p>In realization of DoF that I use blur size stored in alpha component of each fragment<br />vsh:<br /></p><div class="codebox"><pre><code>precision mediump float;

attribute vec2 a_texcoord;
varying vec2 v_texcoord;

varying float z;

void main(void)
{
    vec4 pos = ModelViewProjectionMatrix * gl_Vertex;

    z               = pos.z;
    v_texcoord = a_texcoord;
    gl_Position     = pos;
}</code></pre></div><p>fsh:<br /></p><div class="codebox"><pre><code>precision mediump float;

uniform sampler2D tex;
uniform float focalDistance, focalRange;

varying float z;
varying vec2 v_texcoord;

void main (void)
{
    float    blur = clamp ( abs ( focalDistance  + z ) / focalRange, 0.0, 1.0 );
    gl_FragColor = vec4 ( texture2D ( tex, v_texcoord ).rgb, blur );
}</code></pre></div><p>This is the first shader, which applied while drawing meshes.</p><p>The in last three shaders information in alpha component of pixel is used to make blur.</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:35:59 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2453#p2453</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2452#p2452</link>
			<description><![CDATA[<p>Last thing, <br />if you want your shader to work with desktop and iOS (or Android), add this on top of the shaders :</p><div class="codebox"><pre><code>#ifdef GL_ES
precision highp float;
#endif</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:25:24 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2452#p2452</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2451#p2451</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>Ok, thanks<br />This must be done once, after loading scene?</p></blockquote></div><p>Yes, but if you can, it&#039;s better to just export your meshs from blender with the correct shader, so you will see it in the editor.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:22:31 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2451#p2451</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2450#p2450</link>
			<description><![CDATA[<p>Depth of Field is more complex yes, you need the depth information to blur the image.<br />I must say it can be very slow on iOS, depend if you target only the last iPhone.</p><p>You need to render the scene to a texture with a depth texture like the example :<br /></p><div class="codebox"><pre><code>render-&gt;bindFrameBuffer(m_renderBufferId);
render-&gt;attachFrameBufferTexture(M_ATTACH_COLOR0, m_colorTextureId);
render-&gt;attachFrameBufferTexture(M_ATTACH_DEPTH, m_depthTextureId);</code></pre></div><p>Then you render the texture with a shader like the example, but you also need to pass the depth texture (witch the example doesn&#039;t do). The depth texture will be used to specify the blur influence or the blur size.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:21:27 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2450#p2450</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2449#p2449</link>
			<description><![CDATA[<p>Ok, thanks<br />This must be done once, after loading scene?</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:19:41 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2449#p2449</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2448#p2448</link>
			<description><![CDATA[<p>I just understood we was in the SDK forum,<br />you can force a shader to all meshs in a scene from code.</p><p>- create an fx : vert = level-&gt;loadShader(&quot;vertexShader&quot;, M_SHADER_VERTEX), frag = level-&gt;loadShader(&quot;fragShader&quot;, M_SHADER_PIXEL), fxRef = level-&gt;createFX(vert, frag)<br />- scan all entities in the scene : scene-&gt;getEntitiesNumber(), for loop using scene-&gt;getEntityByIndex(id)<br />- get the entity mesh and scan all mesh materials : entity-&gt;getMesh(), mesh-&gt;getMaterial(id)<br />- set an fx to the material : material-&gt;setFXRef(fxRef)</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:15:40 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2448#p2448</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2447#p2447</link>
			<description><![CDATA[<p>Thanks!<br />I want to add post processing Depth of Field effect in my app. <br />My current realization of that effect consist of 4 shaders.<br />First shader must be applied when drawing meshes.<br />Last three shaders must be applied to entire screen image consequentially.<br />As I realized, I must apply first shader&nbsp; as you described in post above,<br />and last three must be applied as you show in Post Process example in <a href="http://www.maratis3d.com/code/post-process/.">http://www.maratis3d.com/code/post-process/.</a><br />Is that way right? <br />Or may be exist more simple and correct way to add this effect to app?</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 29 Aug 2012 13:09:31 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2447#p2447</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2444#p2444</link>
			<description><![CDATA[<p>You can export your mesh from Blender, there is a doc here : <a href="http://www.maratis3d.org/?p=277">http://www.maratis3d.org/?p=277</a></p><p>For custom shader it happen with this in Blender : <br /><span class="postimg"><img src="http://www.maratis3d.com/wp-content/uploads/2011/01/05.jpg" alt="http://www.maratis3d.com/wp-content/uploads/2011/01/05.jpg" /></span></p><p>Look at this page for more doc :<br /><a href="http://www.maratis3d.org/?page_id=53">http://www.maratis3d.org/?page_id=53</a></p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 29 Aug 2012 12:52:25 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2444#p2444</guid>
		</item>
		<item>
			<title><![CDATA[Adding custom GLSL shader to all meshes on scene]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=2442#p2442</link>
			<description><![CDATA[<p>Hello!<br />I&#039;m developing iOS app that uses maratis3d.<br />I want to add custom GLSL shader (vertex and fragment) to all my meshes.<br />How to do this best?<br />I have my models in 3ds format.<br />Thank you.</p>]]></description>
			<author><![CDATA[dummy@example.com (Petr)]]></author>
			<pubDate>Wed, 29 Aug 2012 12:43:12 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=2442#p2442</guid>
		</item>
	</channel>
</rss>
