none
Some problems about pixel shader in the .NET 3.5 sp1 RRS feed

Answers

  • tszzp said:

    Sorry, I still don't understand it because I'm freshman of pixel shader and direct3d. My problems as follow:
    1) create a height map texture, Is it the buffer data? is pointer the buffer1 and buffer2 data?how to create the height map texture? need i encode it in the .dds file? if yes, how to make it use for several
    project?can you explain it in detail, because I view a .fx file, there are .x, .dds and .fx file. I don't know their relative. can you tell me for it?

    The buffer needs to be large, potentially as big as your content.  The best way to encode that is in a texture, using WriteableBitmap is one way of doing this - this would be handled entirely in C#.

    2) The code for calculate the buffer2 data, swap the buffer1 and buffer2 are write it in C# code? not in the shader pixel code?if so, how to use the new buffer data for height map texture?

    Yes, C# code.  The "buffer data" is just a height at each coordinate, so in your texture you just write your height at each pixel in as the "color". 

    3) the pixel shader's function is take two inputs, the ImplicitInput(the origianl image) and height map texture(the buffer1 data), the pixel shader(.fx file) is like this:

    sampler2D implicitInputSampler : register(S0);
    texture waterHeightmap: register(S1); (use S1 or C0)?
    float4 main(float2 uv : TEXCOORD) : COLOR
    {
        float4 color = tex2D( implicitInputSampler, uv2 );
        //calcuate the new color value with the waterHeightmap, then return the new color value
        return color;
    }
    is it? Why you say use the writeableBitmap? the writeableBitmap should only can use in C# code,
    not use in the pixel shader? your meaning is implement the function in pixel shader like the WriteableBitmap, is it?

    You want to declare your waterHeightMap as a sampler2D as well.  See Greg's blog post linked above - it explains how to do multi-input effects.  You should just pass a second input (an ImageBrush pointing at your WriteableBitmap for example), and then you can sample from it in your shader as well.

    4) if the water ripple effect use the 2D water theory can implement only use pixel shader 2.0, because .Net 3.5 sp1 don't support the high version of pixel shade and don't support the vertex shader in wpf project. and I only know integrate it in wpf project use the UIElement's effect(main used in the image control's effect).I don't know how to make interactive between the C# code and pixel shader except the effect method. So I can't control it except the effect method. My meaning is if I can implement the same effect like I linked in the WPF project and pixel shader? if I can integrate it in the 3D wall?thanks.

    I think you should have enough instructions in ps_2_0 to accomplish this.  The tricky part is updating the "buffer", the height map.  You need to do this in C# yourself -> you cannot write to a texture from a pixel shader, so you can't implement the algorithm entirely in a pixel shader.  So your shader would run (probably a few times) with one version of the height map, and then once you've updated the height map yourself, the shader will use that updated input and render the next wave position. 

    I'd recommend trying to write some simple pixel shaders or looking at our examples in http://www.codeplex.com/wpffx to get started with writing shaders before you tackle something this complicated to get more familiar with the model.

    • Proposed as answer by Brendan Clark - MSFT Thursday, November 20, 2008 10:59 PM
    • Marked as answer by tszzp Friday, November 28, 2008 10:41 AM
    Thursday, November 20, 2008 3:11 AM

All replies

  • -> 1) where i can find the hlsl code for water ripple,smoke, fire, snow effect only use the pixel shader? because I need try it in WPF program. the water ripple effect like the effect as the url:
    http://blogs.msdn.com/nikola/archive/2008/07/04/building-the-reallistic-water-ripples-sample-in-silverlight.aspx

    You could try out the WPF effect library, which contains many cool shader effects:

    http://www.codeplex.com/wpffx

    -> 2) If the pixel shader 2.0 support the 3D use the hlsl? if can, where I can find the simple sample code?

    If you are talking about WPF/3D, then the current version of WPF doesn't support 3D shader effect, the current implementation could only manipulate the 2D texture generated by the 3D scene.

    Thanks


    • Edited by Marco Zhou Monday, November 17, 2008 7:29 AM bad typo
    • Proposed as answer by Brendan Clark - MSFT Wednesday, November 19, 2008 12:01 AM
    • Marked as answer by Marco Zhou Wednesday, November 19, 2008 10:03 AM
    • Unmarked as answer by tszzp Wednesday, November 19, 2008 10:48 AM
    Monday, November 17, 2008 7:28 AM
  • 1) If I can call multi pixel shaders in WPF project, and this pixel shaders is correlative. now I only know use the pixel shaders is set the UIElement(main is Image control)'s effect. So I don't know how to use the multi correlative pixel shader in the WPF Project. if can, pls tell me how to do it? if can give me a simple sample is better. thanks.
    2) If can allocate some buffer in pixel shader use HLSL? I think should not, if can't, how to transfer the buffer from WPF application to pixel shader. such as
    _buffer1 = new int[width, height]
    how to transfer the buffer1 from the wpf application to pixel shader? and buffer1 is the dynamic array.
    how to write it in hlsl code? thanks.
    Monday, November 17, 2008 11:31 AM
  • -> how to transfer the buffer1 from the wpf application to pixel shader? and buffer1 is the dynamic array.

    I think you are talking about shader effect which could accept multiple texture input, then please try the tutorial in this blog article:

    http://blogs.msdn.com/greg_schechter/archive/2008/09/16/introducing-multi-input-shader-effects.aspx


    Thanks
    Tuesday, November 18, 2008 6:37 AM
  • tszzp said:

    1) If I can call multi pixel shaders in WPF project, and this pixel shaders is correlative. now I only know use the pixel shaders is set the UIElement(main is Image control)'s effect. So I don't know how to use the multi correlative pixel shader in the WPF Project. if can, pls tell me how to do it? if can give me a simple sample is better. thanks.
    2) If can allocate some buffer in pixel shader use HLSL? I think should not, if can't, how to transfer the buffer from WPF application to pixel shader. such as
    _buffer1 = new int[width, height]
    how to transfer the buffer1 from the wpf application to pixel shader? and buffer1 is the dynamic array.
    how to write it in hlsl code? thanks.

    1) There is no support for running multiple pixel shaders or multiple-pass shaders on the same UIElement.  The best you can do for now is add more nodes to your Visual tree (wrap your UIElement in a Decorator or empty Canvas) and set Effects on those extra nodes.
    2) AFAIK, you cannot allocate dynamic buffers in ps_2_0 HLSL.  The shader won't compile.  Any constants you want to pass into your shader can be defined as DependencyProperties on your derived YourShaderEffect class, we will pass these contants into the shader dynamically for you.  There are examples of this on Greg's blog, linked above by Marco.
    • Proposed as answer by Brendan Clark - MSFT Wednesday, November 19, 2008 12:07 AM
    • Marked as answer by Marco Zhou Wednesday, November 19, 2008 10:03 AM
    • Unmarked as answer by tszzp Wednesday, November 19, 2008 10:48 AM
    Wednesday, November 19, 2008 12:06 AM
  •  I want to change the water ripple effect to pixel shader. the water ripple effect like the effect as the url:
    http://blogs.msdn.com/nikola/archive/2008/07/04/building-the-reallistic-water-ripples-sample-in-silverlight.aspx. the water ripple effect is cool than the corresponding effect in the WPF effect library.
    the theory of the water ripple effect you can view it in http://freespace.virgin.net/hugo.elias/graphics/x_water.htm.
    So how to change it to pixel shader, I want to write the swap buffer1 and buffer2 function to write a pixel shader, so I need transfer the buffer1 and buffer2 array to pixel shader,the buffer1 and buffer2 is a dynamic two dimension array. how to transfer it to pixel shader, and how to get the change value from pixel shader to C# code?
    the buffer1 as follow:
    _buffer1 = new int[width, height]
    Wednesday, November 19, 2008 10:56 AM
  • You're thinking about the problem in the wrong way.  Pixel shader programming is very different and far more constrained than regular (C# style) coding.  The only efficient way to store and access large amounts (per-pixel) of data in a shader is to encode the information in a texture, which is what you want to do here.  You want to create a height map texture (your buffer), and then modify your ShaderEffect to take two inputs, the ImplicitInput (the content you are going to make ripple) and your height map texture.  The shader itself would be simple - see the last part of the algorithm you linked - it would simply modify the content sampled by the height sampled.  The tricky part is going to be updating the height map texture - you'll need to update it often to make the waves smooth - look into using WriteableBitmap.

    Thursday, November 20, 2008 12:59 AM
  • Sorry, I still don't understand it because I'm freshman of pixel shader and direct3d. My problems as follow:
    1) create a height map texture, Is it the buffer data? is pointer the buffer1 and buffer2 data?how to create the height map texture? need i encode it in the .dds file? if yes, how to make it use for several
    project?can you explain it in detail, because I view a .fx file, there are .x, .dds and .fx file. I don't know their relative. can you tell me for it?

    2) The code for calculate the buffer2 data, swap the buffer1 and buffer2 are write it in C# code? not in the shader pixel code?if so, how to use the new buffer data for height map texture?

    3) the pixel shader's function is take two inputs, the ImplicitInput(the origianl image) and height map texture(the buffer1 data), the pixel shader(.fx file) is like this:

    sampler2D implicitInputSampler : register(S0);
    texture waterHeightmap: register(S1); (use S1 or C0)?
    float4 main(float2 uv : TEXCOORD) : COLOR
    {
        float4 color = tex2D( implicitInputSampler, uv2 );
        //calcuate the new color value with the waterHeightmap, then return the new color value
        return color;
    }
    is it? Why you say use the writeableBitmap? the writeableBitmap should only can use in C# code,
    not use in the pixel shader? your meaning is implement the function in pixel shader like the WriteableBitmap, is it?

    4) if the water ripple effect use the 2D water theory can implement only use pixel shader 2.0, because .Net 3.5 sp1 don't support the high version of pixel shade and don't support the vertex shader in wpf project. and I only know integrate it in wpf project use the UIElement's effect(main used in the image control's effect).I don't know how to make interactive between the C# code and pixel shader except the effect method. So I can't control it except the effect method. My meaning is if I can implement the same effect like I linked in the WPF project and pixel shader? if I can integrate it in the 3D wall?thanks.


    Thursday, November 20, 2008 2:32 AM
  • tszzp said:

    Sorry, I still don't understand it because I'm freshman of pixel shader and direct3d. My problems as follow:
    1) create a height map texture, Is it the buffer data? is pointer the buffer1 and buffer2 data?how to create the height map texture? need i encode it in the .dds file? if yes, how to make it use for several
    project?can you explain it in detail, because I view a .fx file, there are .x, .dds and .fx file. I don't know their relative. can you tell me for it?

    The buffer needs to be large, potentially as big as your content.  The best way to encode that is in a texture, using WriteableBitmap is one way of doing this - this would be handled entirely in C#.

    2) The code for calculate the buffer2 data, swap the buffer1 and buffer2 are write it in C# code? not in the shader pixel code?if so, how to use the new buffer data for height map texture?

    Yes, C# code.  The "buffer data" is just a height at each coordinate, so in your texture you just write your height at each pixel in as the "color". 

    3) the pixel shader's function is take two inputs, the ImplicitInput(the origianl image) and height map texture(the buffer1 data), the pixel shader(.fx file) is like this:

    sampler2D implicitInputSampler : register(S0);
    texture waterHeightmap: register(S1); (use S1 or C0)?
    float4 main(float2 uv : TEXCOORD) : COLOR
    {
        float4 color = tex2D( implicitInputSampler, uv2 );
        //calcuate the new color value with the waterHeightmap, then return the new color value
        return color;
    }
    is it? Why you say use the writeableBitmap? the writeableBitmap should only can use in C# code,
    not use in the pixel shader? your meaning is implement the function in pixel shader like the WriteableBitmap, is it?

    You want to declare your waterHeightMap as a sampler2D as well.  See Greg's blog post linked above - it explains how to do multi-input effects.  You should just pass a second input (an ImageBrush pointing at your WriteableBitmap for example), and then you can sample from it in your shader as well.

    4) if the water ripple effect use the 2D water theory can implement only use pixel shader 2.0, because .Net 3.5 sp1 don't support the high version of pixel shade and don't support the vertex shader in wpf project. and I only know integrate it in wpf project use the UIElement's effect(main used in the image control's effect).I don't know how to make interactive between the C# code and pixel shader except the effect method. So I can't control it except the effect method. My meaning is if I can implement the same effect like I linked in the WPF project and pixel shader? if I can integrate it in the 3D wall?thanks.

    I think you should have enough instructions in ps_2_0 to accomplish this.  The tricky part is updating the "buffer", the height map.  You need to do this in C# yourself -> you cannot write to a texture from a pixel shader, so you can't implement the algorithm entirely in a pixel shader.  So your shader would run (probably a few times) with one version of the height map, and then once you've updated the height map yourself, the shader will use that updated input and render the next wave position. 

    I'd recommend trying to write some simple pixel shaders or looking at our examples in http://www.codeplex.com/wpffx to get started with writing shaders before you tackle something this complicated to get more familiar with the model.

    • Proposed as answer by Brendan Clark - MSFT Thursday, November 20, 2008 10:59 PM
    • Marked as answer by tszzp Friday, November 28, 2008 10:41 AM
    Thursday, November 20, 2008 3:11 AM
  • oh, I understand it. your meaning is calculate the buffer1 and buffer2 data, swap buffer1 and buffer2 data in the C# code, then use the newest buffer1 data to make it to a image use WriteableBitmap, then use it as a sample and original image to pixel shader, deal the Creating Drops/Splashes also in C# code.
    is it? ok, I already try it, but the effect have some different with the linked effect. maybe my pixel shader have some problems, I'm checking it. thank you very much!

    another problem: how to debug the pixel shader in VS2008 when it is integrate in WPF project use the WPF effect library?
    Thursday, November 20, 2008 3:56 AM