XNA Creators Club Online
foros de la comunidad
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Pixel/Vertex Shader

Last post 10/11/2009 11:44 by GoGo Robot. 1 replies.
  • 06/11/2009 13:19

    Pixel/Vertex Shader

    Hi,

    I'm writing a bit of software for an image capturing system, which basically projects a series of patterns (usually hoz/vert stripes) on to a physical object, captures images of that object, and emalgamates those images to create a 3D model that is viewable in a CAD system.  Typically the sequence involves projecting 50 patterns on to the object, with an image being captured for each projection.  The time to make the projection and capture the image needs to be of the order of ~10ms.

    This is all working well, however I now need to vary the intensity of the light according to results that are returned from the previous image, so if the image contains a light spot in one corner then I need to project less light to that area on the next projection.  I was thinking that it would be best to leave the patterns (stripes) as they are, and apply a texture that basically contained solid white but had variable opacity, i.e. I decrease the alpha in the bright spots.  In order to achieve this in the required time periods I want to pass off as much as I can to the GPU, and I was wondering whether you thought like this should be best achieved through a vertex shader, a pixel shader, or none of the above.  The system is based on XP Embedded, so it's D3D9 or earlier for me.

    As you can see the system is not exactly stretched as it is only displaying a single quad that is updated 50 times a second, but this system will have to scale up in future and I would like to keep it as fast as possible.

    Opinions?

    Thanks

  • 10/11/2009 11:44 In reply to

    Re: Pixel/Vertex Shader

    If I understand you correctly, you have the previous image as a texture, right? If so, then it should be pretty easy to vary the intensity of the light using a pixel shader. You just need to get the intensity of the image:

    float4 PreviousImage = tex2d(previousImage, In.UV);

    Then you can calculate the intensity, using something like this:

    float Luminosity = (0.2126* PreviousImage.r) + (0.7152* PreviousImage.g) + (0.0722* PreviousImage.b);


    Then just use that to modulate your texture:

    float4 OutColour = tex2d(overlayImage, In.UV) * float4(1, 1, 1, Luminosity);

    (Note: My HLSL is very rusty and untested, so this might not be exactly right, but it should be about right :) )
Page 1 of 1 (2 items) Previous Next