Hlsl vertex shader question

hi meso-devs,

if you programm a vertex shader, you are at ‘algorithm level’, your code runs once for every vertex. inside the code you usualy modify the properties of this one vertex.

is there a possibility to write to the whole vertex (position) buffer ?
or any predefined array name, that points to all positions ?

my shader calculates an array, at the and i want to copy this array to the vertex y coordinates…

had the idea, to run a second vertexshader, but it seems that the effect passes dont share global variables … ?

i want to do fourier transformation on the GPU, see my try with the second shader in the .fx file attached.

DFT.fx (3.2 kB)

is there a possibility to write to the whole vertex (position) buffer ?
or any predefined array name, that points to all positions ?

the current HLSL versions dont allow for passing back data to the application. the usual reason given is that it would be slower than doing everything on the cpu in the first place. this seems to be a performance optimization thing by graphic card vendors - they seem to optimize for pushing things to the card.

the next HLSL version will give you texture lookups in the vertex shaders, which is a very helpful thing to have. one of our shader wizards can probably clarify if this would be possible just by having the right graphics card or if vvvv needs to be updated for that. i dont think you would be able to write anything back to the cpu in the vertex shader anyway.

doing everything in the pixel shader could be an option, as you can write pixels to a hidden buffer and use these in the next render pass as a texture. anyway there are many exciticing things going with shaders and we will try to do our best supporting the nonconventional applications for shaders…

tonfilm. i don’t quite get what you are up to.

accessing textures in vertex-shaders is only possible in vertexshader 3.0. at the moment only nvidias latest cards (>= 6800) deal with them. vvvv understands them in the next release.

ok, here more details:

first, i dont want to pass back data to application, i just want to display the results of the algorithm by copy the global (in the struct ‘arrays’ ) defined array amp to the y coordinates of vertex positions.

i stored the input data with Mesh(join) in 2D texture coordinates (iorec’s cool idea). the first coordinate texC0 is the index (0…119), the second texC1 is the input spread to transform.

pseudo code of DFT:

for every input slice (0…119)
{
__w = value of slice

__for every output spectral step (0…59)
__{
****calc the part of w in this frequency and sum up
__}
}

now, that the vertex shader runs over every vertex, i just have to do the second for loop:

init arrays if texC0 == 0

for every output spectral step (0…59)
{
__calc the part of texC1 in this frequency and sum up
}

store the output data in amp, if last slice

now my desired values are in the global defined amp array and i just want to use it in the second pass, where copy the values to the y coordinates.

but right now i have another idea, i create a special mesh with the vertexcount of input spread plus the ouput spread. in the first vertices i calc the dft, and in reminding i copy to y … hope its unerstandable …

do i get this right?!

you are doing some math for every vertex writing the result into amp. and only when you are finished with all vertices the final result is available from amp.

now you want to run through all the vertices again in a second pass and set their .y value to their corresponding value of amp?

if so, 2 things to consider:

  • if the global arrays are not persistent between passes…i am not sure how to go around that limitation. there is actually a third shader category: beside vertex and pixel-shaders there are texture-shaders. they allow you to generate procedural textures. i don’t know more about them and if they are already available in within vvvv. rather not. those textures would need to be created somewhere…but they could serve you as an alternative to global array between passes…mm. if you like you can try to find out something about those texture-shaders.

  • each pass you run through the vertexshader the mesh is actually drawn. you will have to pass another spread to the shader consisting of slices [0, 1](0, 1) and use that as alpha value for the vertices. so that the first grid is not visible. i think you cannot really prevent it from being drawn. this would be a minor problem though…

was this posting helpful?
1…10

do i get this right?!

you are doing some math for every vertex writing the result into amp. and only when you are finished with all vertices the final result is available from amp.

now you want to run through all the vertices again in a second pass and set their .y value to their corresponding value of amp?

you exactly got it ! … and you are right, the amp array doesnt persist with its values till the second pass.

there is another problem i’m confronted with, the DFT code has too many operations for vertexshder v1.1, i have to split the calculation somewhere …
the texture shader thing looks intersting, i will ask google about. textures should persist between passes (i hope).

thx, you post was very helpful !