<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.xna.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Direct3D</title><link>http://forums.xna.com/forums/27.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196567.aspx</link><pubDate>Sun, 05 Jul 2009 15:01:19 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196567</guid><dc:creator>NightCreature</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196567.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196567</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://forums.xna.com//Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;phort99:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;I found a very different solution than the one I was looking for.&lt;br /&gt;
&lt;br /&gt;
I wound up pulling this off by using a rendertarget with a surface format that allowed alpha transparency. I used spritebatch to draw my color texture twice (for the top and bottom half) on top of the alpha texture, moving down the render target using gameTime, and used GraphicsDevice blend mode settings so that the minimum alpha value would be used. I saved the render target result in a texture and applied that on the model, and voilà, a moving texture with a static alpha channel! Now I just need to sort out some problems with depth buffering because the transparent parts of the object now obscure the rest of the object when they pass in front of it.&lt;br /&gt;
&lt;br /&gt;
Here was my inspiration for the alpha blending stuff:&lt;br /&gt;
http://www.gamedev.net/community/forums/topic.asp?topic_id=532775&lt;br /&gt;
&lt;br /&gt;
And I didn&amp;#39;t even have to change from using the BasicEffect!&lt;br /&gt;
&lt;br /&gt;
Legalize, I found another link to Chapter 11 of your book in another thread when I was trying to solve this! It wasn&amp;#39;t much help to me in this case since it isn&amp;#39;t XNA-specific and I was still looking for the specific XNA code for accessing the texture coordinates so i could transform them. Sorry!&lt;br /&gt;
&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;br /&gt;
You don&amp;#39;t want to access your texture coordinates on the CPU side, you want to do this on the GPU side it&amp;#39;s much faster (orders of magnitude faster). For that you either have to write your own shader like this&lt;br /&gt;
&lt;br /&gt;
Vertex Shader:&lt;br /&gt;
&lt;div style="border:1px solid #7f9db9;overflow:auto;background-color:white;font-family:courier new;font-size:11px;"&gt;
&lt;table cellspacing="0" cellpadding="0" style="border-width:0px;border-bottom:0px solid #eeeeee;margin:2px 0px;width:99%;border-collapse:collapse;background-color:#ffffff;"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="font-size:11px;"&gt;float4x4&amp;nbsp;matViewProjection;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&lt;span style="color:blue;"&gt;float&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;time;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;VS_INPUT&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float4&amp;nbsp;Position&amp;nbsp;:&amp;nbsp;POSITION0;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float2&amp;nbsp;Texcoord&amp;nbsp;:&amp;nbsp;TEXCOORD0;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;};&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;VS_OUTPUT&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float4&amp;nbsp;Position&amp;nbsp;&amp;nbsp;:&amp;nbsp;POSITION0;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float2&amp;nbsp;Texcoord&amp;nbsp;&amp;nbsp;:&amp;nbsp;TEXCOORD0;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float2&amp;nbsp;Texcoord2&amp;nbsp;:&amp;nbsp;TEXCOORD1;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;};&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;VS_OUTPUT&amp;nbsp;vs_main(&amp;nbsp;VS_INPUT&amp;nbsp;Input&amp;nbsp;)&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;VS_OUTPUT&amp;nbsp;Output;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Output.Position&amp;nbsp;=&amp;nbsp;mul(&amp;nbsp;Input.Position,&amp;nbsp;matViewProjection&amp;nbsp;);&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Output.Texcoord&amp;nbsp;=&amp;nbsp;Input.Texcoord;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Output.Texcoord2&amp;nbsp;=&amp;nbsp;Input.Texcoord;&lt;br /&gt;
            &amp;nbsp;&amp;nbsp;&amp;nbsp;Output.Texcoord2.x += time;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:11px;"&gt;(&amp;nbsp;Output&amp;nbsp;);&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
Pixel Shader:&lt;br /&gt;
&lt;div style="border:1px solid #7f9db9;overflow:auto;background-color:white;font-family:courier new;font-size:11px;"&gt;
&lt;table cellspacing="0" cellpadding="0" style="border-width:0px;border-bottom:0px solid #eeeeee;margin:2px 0px;width:99%;border-collapse:collapse;background-color:#ffffff;"&gt;
    
    
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="font-size:11px;"&gt;sampler2D&amp;nbsp;baseMap;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;sampler2D&amp;nbsp;staticAlpha;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&lt;span style="color:blue;"&gt;struct&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;PS_INPUT&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float2&amp;nbsp;Texcoord&amp;nbsp;&amp;nbsp;:&amp;nbsp;TEXCOORD0;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;float2&amp;nbsp;Texcoord2&amp;nbsp;:&amp;nbsp;TEXCOORD1;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;};&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;float4&amp;nbsp;ps_main(&amp;nbsp;PS_INPUT&amp;nbsp;Input&amp;nbsp;)&amp;nbsp;:&amp;nbsp;COLOR0&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;{&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:11px;"&gt;&amp;nbsp;tex2D(&amp;nbsp;baseMap,&amp;nbsp;Input.Texcoord2&amp;nbsp;)&amp;nbsp;*&amp;nbsp;tex2D(&amp;nbsp;staticAlpha,&amp;nbsp;Input.Texcoord&amp;nbsp;).a;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="background-color:#f7f7f7;"&gt;}&amp;nbsp;&lt;/td&gt;
        &lt;/tr&gt;
    
&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
The fixed function way of doing it would have been:&lt;br /&gt;
&lt;br /&gt;
D3DXMATRIX16A textureTransform;&lt;br /&gt;
//Seeing we are in an update loop with a gameTime variable&lt;br /&gt;
D3DXCreateMatrixTranslation(&amp;amp;textureTransform, gameTime, 0.0f, 0.0f);&lt;br /&gt;
m_device-&amp;gt;SetTransform(D3DST_TEXTURE0, &amp;amp;textureTransform);&lt;br /&gt;
&lt;br /&gt;
//yourColorTexture defined elsewhere&lt;br /&gt;
m_device-&amp;gt;SetTexture(0, &amp;amp;yourColorTexture );&lt;br /&gt;
//yourAlphaTexture defined elsewhere&lt;br /&gt;
m_device-&amp;gt;SetTexture(1, &amp;amp;yourAlphaTexture );&lt;br /&gt;
&lt;br /&gt;
//Set up blending stuff&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
//Draw polygon&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
results are:&lt;br /&gt;
&lt;a href="http://lh3.ggpht.com/_UNm8vsUbvk4/SlC9n9RbA9I/AAAAAAAAAZY/0X1I1a0n4y4/s144/staticAlpha1.png"&gt;&lt;/a&gt;&lt;a href="http://picasaweb.google.com/PaulKruitz/Random#5354988451103704018"&gt;Screen shot 1&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://picasaweb.google.com/PaulKruitz/Random#5354988452761861506"&gt;Screen shot 2&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Seeing that the basic effect doesn&amp;#39;t support setting texture matrices you will need to write your own shader most of the time.&lt;br /&gt;</description></item><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196492.aspx</link><pubDate>Sun, 05 Jul 2009 05:04:17 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196492</guid><dc:creator>legalize</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196492.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196492</wfw:commentRss><description>&lt;p&gt;Yes, my book doesn&amp;#39;t use the XNA API for the code examples and details, but all the explanations of concepts still apply.&lt;/p&gt;
&lt;p&gt;Glad you got it to work.&lt;/p&gt;</description></item><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196455.aspx</link><pubDate>Sun, 05 Jul 2009 02:04:08 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196455</guid><dc:creator>phort99</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196455.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196455</wfw:commentRss><description>I found a very different solution than the one I was looking for.&lt;br /&gt;
&lt;br /&gt;
I wound up pulling this off by using a rendertarget with a surface format that allowed alpha transparency. I used spritebatch to draw my color texture twice (for the top and bottom half) on top of the alpha texture, moving down the render target using gameTime, and used GraphicsDevice blend mode settings so that the minimum alpha value would be used. I saved the render target result in a texture and applied that on the model, and voilà, a moving texture with a static alpha channel! Now I just need to sort out some problems with depth buffering because the transparent parts of the object now obscure the rest of the object when they pass in front of it.&lt;br /&gt;
&lt;br /&gt;
Here was my inspiration for the alpha blending stuff:&lt;br /&gt;
http://www.gamedev.net/community/forums/topic.asp?topic_id=532775&lt;br /&gt;
&lt;br /&gt;
And I didn&amp;#39;t even have to change from using the BasicEffect!&lt;br /&gt;
&lt;br /&gt;
Legalize, I found another link to Chapter 11 of your book in another thread when I was trying to solve this! It wasn&amp;#39;t much help to me in this case since it isn&amp;#39;t XNA-specific and I was still looking for the specific XNA code for accessing the texture coordinates so i could transform them. Sorry!&lt;br /&gt;</description></item><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196452.aspx</link><pubDate>Sun, 05 Jul 2009 01:45:52 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196452</guid><dc:creator>legalize</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196452.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196452</wfw:commentRss><description>&lt;p&gt;Because XNA doesn&amp;#39;t exposed the fixed-function pipeline, you&amp;#39;ll have to write a shader to handle this the way you want.&lt;/p&gt;
&lt;p&gt;It may be helpful to review &lt;a href="http://www.xmission.com/~legalize/book/download/05-Modeling.pdf"&gt;Chapter 5. Modeling&lt;/a&gt; and &lt;a href="http://www.xmission.com/~legalize/book/download/11-Basic%20Texturing.pdf"&gt;Chapter 11. Basic Texturing&lt;/a&gt; from my book &lt;a href="http://www.xmission.com/~legalize/book/download/"&gt;The Direct3D Graphics Pipeline&lt;/a&gt; to make sure you understand how vertex data is supplied to the pipeline and how the fixed-function pipeline processes texture coordinates. I know XNA doesn&amp;#39;t use the fixed-function pipeline, but its easier to write a shader when you understand how the FFP does things.&lt;/p&gt;</description></item><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196400.aspx</link><pubDate>Sat, 04 Jul 2009 19:54:11 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196400</guid><dc:creator>phort99</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196400.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196400</wfw:commentRss><description>That still doesn&amp;#39;t help me much as I still can&amp;#39;t figure out how in code to access the texture coordinates for the mesh so that I can transform them, how to duplicate them for the second texture, or how to render the mesh with two textures without creating a new effect.&lt;br /&gt;
&lt;br /&gt;
All the tutorials I&amp;#39;ve found through hours of searching all use hard coded triangles and texture coordinates and I need to know how to access the texture coordinates for a loaded model.&lt;br /&gt;</description></item><item><title>Re: Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196282.aspx</link><pubDate>Sat, 04 Jul 2009 11:01:34 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196282</guid><dc:creator>NightCreature</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196282.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196282</wfw:commentRss><description>You would need to use two texture coordinates they can have the same values, one is used for the alpha texture and stay statics. The second set is used to display your color map and is animated with a texture coordinate transform matrix, this is just like a world matrix except it&amp;#39;s only applied to the texture coordinates and not to the vertices or normals.&lt;br /&gt;
&lt;br /&gt;
If you are going to write a custom shader for this you can get away with one texture coordinate set in the vertex declaration, in the vertex shader you would output two sets of texcoord sets. The first one is the unchanged one and is just a pass through the second set is multiplied with the texture coordinate transform matrix. In the pixel shader you index the alpha texture with the first set and the color texture with the second set, then multiply the results and output that.</description></item><item><title>Moving texture with non-moving alpha channel</title><link>http://forums.xna.com/forums/thread/196245.aspx</link><pubDate>Sat, 04 Jul 2009 05:11:45 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:196245</guid><dc:creator>phort99</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/196245.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=27&amp;PostID=196245</wfw:commentRss><description>I&amp;#39;ve just started learning 3D in XNA after about 6 months of using it for 2D development.&lt;br /&gt;
I&amp;#39;ve created a model that I am trying to make it so that my mesh is transparent at the top edge using one texture but has a color map moving vertically along it constantly. I already have alpha blending working and most of the textures, it&amp;#39;s just a matter of figuring out how to either move the texture or move the vertex texture positions, and figuring out how to use multiple textures for alpha and color, since the alpha texture will not be moving.&lt;br /&gt;
&lt;br /&gt;
I haven&amp;#39;t gotten into the HLSL stuff yet so is there a way to do this with the BasicEffect? If not, what would be the easiest way to do this with a custom effect?&lt;br /&gt;
&lt;br /&gt;
Thanks.&lt;br /&gt;</description></item></channel></rss>