<?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"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: first shader, first troubles</title>
		<atom:link href="http://cycling74.com/forums/topic/first-shader-first-troubles/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/first-shader-first-troubles/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 08:58:47 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-37797</guid>
					<title><![CDATA[first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-37797</link>
					<pubDate>Thu, 15 May 2008 11:39:41 +0000</pubDate>
					<dc:creator>bryanteoh</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;m trying to write a shader that will basically extract the alpha channel from a video, invert it, then spit it out just the alpha layer so I can glue it onto other videos later on in the processing chain.  This is my first shader, so if this code looks hopelessly stupid you can tell me to go back to the manuals, but I&#8217;m hoping it&#8217;s something simple.  </p>
<p><jittershader name="alphainverse"><br />
	<description><br />
	samples the alpha channel, inverts it, and spits out single plane(??)<br />
	</description></jittershader></p>
<param name="tex0" type="int" default="0" />
	language name=&#8221;glsl&#8221; version=&#8221;1.0&#8243;><br />
		<bind param="tex0" program="fp"></bind>
<program name="vp" type="vertex" source="op.unary.vp.glsl"></program>
<program name="fp" type="fragment">
< ![CDATA[</p>
<p>uniform sampler2DRect tex0;<br />
varying vec2 texcoord0;</p>
<p>void main()<br />
{<br />
	vec4 at = texture2DRect(tex0, texcoord0);<br />
	float pl = at.a &#8211; 1.0;<br />
	gl_FragColor = abs(pl);<br />
}<br />
]]>
		</p></program>
	<br />

						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130772</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130772</link>
					<pubDate>Thu, 15 May 2008 12:51:27 +0000</pubDate>
					<dc:creator>nesa</dc:creator>

					<description>
						<![CDATA[
						<p>Hi,</p>
<p>your code looks ok shader-vise, that&#8217;s good:)</p>
<p>but the math:</p>
<p>> 	float pl = at.a &#8211; 1.0;</p>
<p>should probably be: 1.0 &#8211; at.a (if incoming values are < = 1.0)</p>
</p><p>hth,<br />
nesa</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130773</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130773</link>
					<pubDate>Thu, 15 May 2008 13:01:26 +0000</pubDate>
					<dc:creator>bryanteoh</dc:creator>

					<description>
						<![CDATA[
						<p>thanks nesa.  The values are in fact less than or equal to 1.0, but I&#8217;m trying to invert the values of the black and white matrix.  To do this I&#8217;m trying to subtract 1 to get a value between -1.0 and 0.0, and then take the absolute value before spitting it out to make it positive again.  Is this illegal in glsl?  If so, how else could I go about this?</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130774</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130774</link>
					<pubDate>Thu, 15 May 2008 13:27:50 +0000</pubDate>
					<dc:creator>bryanteoh</dc:creator>

					<description>
						<![CDATA[
						<p>ok, actually it turns out the negative number wasn&#8217;t an issue.  I had forgotten to enclose the &#8220;language name&#8221; tag in an opening &#8216;< '.  DOH!  </p>
</p><p>However, now there is another problem.  When I try to run the shader, I get the following error:</p>
<p>&#8211; START GLSL INFO LOG: fp &#8211;<br />
ERROR: 0:8: &#8216;assign&#8217; :  cannot convert from &#8216;float&#8217; to &#8216;FragColor 4-component vector of float&#8217;<br />
&#8211; END GLSL INFO LOG: fp &#8211;<br />
jit.gl.shader: GLSL program failed to compile.</p>
<p>This seems to imply that I can&#8217;t set the gl_FragColor to a float.  I only want/need to spit out the alpha channel.  The shader does work if I express it if I write it as:</p>
<p>void main()<br />
{<br />
vec4 at = texture2DRect(tex0, texcoord0);<br />
vec4 pl = vec4(at.a &#8211; 1.0);<br />
gl_FragColor = abs(pl);<br />
}</p>
<p>but then to use the alpha channel for another video later on in the slab chain, I&#8217;d have to make a shader that would just extract the layer again anyway which seems redundant to me.  Clearly I need to work through the orange book a bit more, but if someone could tip me off on how to output just the single channel it would help me a lot with this current patch I&#8217;m working on.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130775</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130775</link>
					<pubDate>Thu, 15 May 2008 14:08:19 +0000</pubDate>
					<dc:creator>yair reshef</dc:creator>

					<description>
						<![CDATA[
						<p>you cannot have output a single &#8220;planes&#8221; from shaders.  gl_FragColor is a<br />
vec4 type.</p>
<p>On Thu, May 15, 2008 at 4:27 PM, bryanteoh <bryanteoh @gmail.com> wrote:</bryanteoh></p>
<p>><br />
> ok, actually it turns out the negative number wasn&#8217;t an issue.  I had<br />
> forgotten to enclose the &#8220;language name&#8221; tag in an opening &#8216;< '.  DOH!<br />
><br />
> However, now there is another problem.  When I try to run the shader, I get<br />
> the following error:<br />
><br />
> &#8212; START GLSL INFO LOG: fp &#8211;<br />
> ERROR: 0:8: &#8216;assign&#8217; :  cannot convert from &#8216;float&#8217; to &#8216;FragColor<br />
> 4-component vector of float&#8217;<br />
> &#8212; END GLSL INFO LOG: fp &#8211;<br />
> jit.gl.shader: GLSL program failed to compile.<br />
><br />
> This seems to imply that I can&#8217;t set the gl_FragColor to a float.  I only<br />
> want/need to spit out the alpha channel.  The shader does work if I express<br />
> it if I write it as:<br />
><br />
> void main()<br />
> {<br />
> vec4 at = texture2DRect(tex0, texcoord0);<br />
> vec4 pl = vec4(at.a &#8211; 1.0);<br />
> gl_FragColor = abs(pl);<br />
> }<br />
><br />
> but then to use the alpha channel for another video later on in the slab<br />
> chain, I&#8217;d have to make a shader that would just extract the layer again<br />
> anyway which seems redundant to me.  Clearly I need to work through the<br />
> orange book a bit more, but if someone could tip me off on how to output<br />
> just the single channel it would help me a lot with this current patch I&#8217;m<br />
> working on.<br />
></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130776</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130776</link>
					<pubDate>Thu, 15 May 2008 14:39:51 +0000</pubDate>
					<dc:creator>bryanteoh</dc:creator>

					<description>
						<![CDATA[
						<p>thanks yair!  A single float is no longer necessary anyway.  It recently dawned on me that it was kind of a dumb idea to pass out a single value only to use it in another shader later.  I&#8217;m currently working on one shader that will do all the necessary processing so a final vec4 output will be fine.  </p>
<p>I&#8217;d like to thank both of you for such speedy responses.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130777</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130777</link>
					<pubDate>Thu, 15 May 2008 15:11:29 +0000</pubDate>
					<dc:creator>nesa</dc:creator>

					<description>
						<![CDATA[
						<p>><br />
> ok, actually it turns out the negative number wasn&#8217;t an issue.  I  <br />
> had forgotten to enclose the &#8220;language name&#8221; tag in an opening &#8216;< '.   <br />
> DOH!<br />
></p>
<p>btw, did the jit.gl.shader complian when you tried to read that file?</p>
<p>> vec4 pl = vec4(at.a &#8211; 1.0);</p>
<p>ah, yes, sorry for that oversight.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130778</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130778</link>
					<pubDate>Thu, 15 May 2008 15:47:24 +0000</pubDate>
					<dc:creator>Andrew Benson</dc:creator>

					<description>
						<![CDATA[
						<p>GLSL doesn&#8217;t do well with implicit type casting.  You have to always be explicit about moving from one data-type to another.  In this case, gl_FragColor is expecting a vec4.  If you want to pass the alpha channel and set all other channels to 0., you could do the following:<br />
gl_FragColor = vec4(pl,0.,0.,0.);</p>
<p>But it sounds like you are looking to add this alpha channel to another texture, which would be better accomplished using a shader similar to cc.alphaglue.jxs.  You should be able to alter that shader to your needs fairly easily.</p>
<p>AB</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130779</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130779</link>
					<pubDate>Fri, 16 May 2008 03:31:43 +0000</pubDate>
					<dc:creator>bryanteoh</dc:creator>

					<description>
						<![CDATA[
						<p>Thanks Andrew.  I was able to successfully alter the alphaglue shader.  In an attempt to rip you off more completely, I attempted to add a lumagate to the shader as well so I could specify values to use.  The material I&#8217;ll be using for the alpha channel in this patch is comprised of several shades of white.  As far as I can tell the code is ok but I got the following error:</p>
<p>jit_xml_document: error reading file at byte offset 2392 / mismatched tag<br />
line (80): jittershader><br />
jit.gl.shader: error reading shader xml file&#8230;</p>
<p>I first assumed that I didn&#8217;t close one of my tags correctly, so I picked through it several times to make sure that wasn&#8217;t the issue.  I apologize for posting so much on this topic but if anyone has any ideas of what I did wrong, please let me know.</p>
<p><jittershader name="abripoff"><br />
	<description><br />
	alphaglue, lumagate, and their forbidden love<br />
	</description></jittershader></p>
<param name="lum" type="vec2" default="0. 1."/>
		<description>luminance low hi thresholds</description>
<param name="plane" type="int" default="0"/>
		<description>select plane to use as alpha</description>
	
<param name="lum2alpha" type="float" default="0."/>
		<description>use luminence of second texture</description>
	
<param name="thresh" type="float" default="0."/>
		<description>brightness threshold</description>
	
<param name="fade" type="float" default="1.0"/>
		<description>fade amount for threshold</description>
	
<param name="lumcoeff" type="vec4" default="0.299 .587 0.114 0."/>
		<description>Luminance coefficients (RGBA)</description>
	
<p>
<param name="tex0" type="int" default="0" /></p>
<param name="tex1" type="int" default="1" />
	<language name="glsl" version="1.0"><br />
		<bind param="lum" program="fp"></bind><br />
		<bind param="plane" program="fp"></bind><br />
		<bind param="lum2alpha" program="fp"></bind><br />
		<bind param="thresh" program="fp"></bind><br />
		<bind param="fade" program="fp"></bind><br />
		<bind param="lumcoeff" program="fp"></bind><br />
		<bind param="tex0" program="fp"></bind><br />
		<bind param="tex1" program="fp"></bind>	
<program name="vp" type="vertex" source="sh.passthrudim.vp.glsl"></program>
<program name="fp" type="fragment">
< ![CDATA[</p>
<p>// Andrew Benson &#8211; <a href="mailto:andrewb@cycling74.com">andrewb@cycling74.com</a><br />
//Copyright 2006 &#8211; Cycling &#8217;74</p>
<p>//fragment shader for applying alpha channel from second texture</p>
<p>//setup for 2 texture<br />
varying vec2 texcoord0;<br />
varying vec2 texcoord1;<br />
uniform sampler2DRect tex0;<br />
uniform sampler2DRect tex1;</p>
<p>//wipe state<br />
uniform vec2 lum;<br />
uniform int plane;<br />
uniform float fade;<br />
uniform float lum2alpha;<br />
uniform float thresh;<br />
uniform vec4 lumcoeff;</p>
<p>void main()<br />
{   <br />
	vec4 at = texture2DRect(tex0, texcoord0);//texture for blend<br />
	vec4 bt = texture2DRect(tex1, texcoord1);//texture for alpha</p>
<p>	//lumagate the intended alpha channel<br />
	float luminance = dot(bt,lumcoeff);<br />
	float clo = smoothstep(lum.x,lum.x+fade.x,luminance);<br />
	float chi = 1.-smoothstep(lum.y-fade.y,lum.y,luminance);<br />
	float amask = float (clo * chi);</p>
<p>	// decide which plane to use<br />
	float lumi = dot(bt,lumcoeff);//calc the luminance<br />
	amask = mix(amask,lumi,lum2alpha);//pick plane or luma<br />
	amask = smoothstep(thresh,thresh+fade,amask);//apply threshold</p>
<p>	at = vec4(at*amask);//map video onto mask</p>
<p>	// output texture along with alpha channel<br />
	gl_FragColor = vec4 (at.rgb,amask);<br />
}<br />
]]>
		</p></program>
	</language><br />

						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130780</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130780</link>
					<pubDate>Fri, 16 May 2008 07:28:15 +0000</pubDate>
					<dc:creator>rikimazza</dc:creator>

					<description>
						<![CDATA[
						<p>Hello from italy,</p>
<p>I&#8217;m installing a video server system that will run on a number of  <br />
macmini in network using jitter of course.</p>
<p>I&#8217;m trying to establish the best video compression setting in order to  <br />
load off the most from the cpu and macmini videocard that is quite  <br />
cheap.</p>
<p>It will be only one video for each machine that will playback direct  <br />
to the videoprojector in fullscreen (I&#8217;ll try to go 1024 or 800).</p>
<p>Any experience and suggestions will be very valuable.</p>
<p>Thanks in advance.</p>
<p>ciao ciao<br />
riccardo mazza</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130781</guid>
					<title><![CDATA[Re: first shader, first troubles]]></title>
					<link>http://cycling74.com/forums/topic/first-shader-first-troubles/#post-130781</link>
					<pubDate>Fri, 16 May 2008 14:49:10 +0000</pubDate>
					<dc:creator>Andrew Benson</dc:creator>

					<description>
						<![CDATA[
						<p>The &#8220;plane&#8221; param wasn&#8217;t closed.   Also, you aren&#8217;t using a vec2 for &#8220;fade&#8221;, so you can&#8217;t write &#8220;fade.x&#8221;/&#8221;fade.y&#8221;.  Fixing these things will allow your shader to compile.  I also notice that you are calculating luminance twice (luminance, lumi), and that you aren&#8217;t using the &#8220;plane&#8221; variable at all.  </p>
<p>I don&#8217;t understand the purpose of this line:</p>
<p>at = vec4(at*amask);//map video onto mask</p>
<p>Since you are trying to create an alpha channel, why are you multiplying the RGBA values by the &#8220;amask&#8221;?  The vec4 constructor in the final line is adding the alpha mask to the color vector already.  The multiplication is just going to add weird dark halos around your mask and make your image darker.  Of course, maybe that&#8217;s what you&#8217;re looking for&#8230;</p>
<p>ab</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

