Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualtonemgub

Posted 13 April 2014 - 04:42 PM


Can I add multiple textures of "the hole" to the multitexture? Or is it possible to combine all of the "holes" that point made into one texture, and use it in the multi-texture?

 

You can do both.

 

The first method: you can send your 2D points vector into the fragment shader, as a 1D-texture object, and then iteratively sample the "hole" texture for each point from the 1D texture, then blend all of the "hole" samples together (multiply them, or just add them and clamp the final result), then use the final value instead of the texval2. You get the points from the 1D texture with texelFetch(), and the iteration (for loop) should run from 0 to the size of the points vectorm which you also send into a separate uniform variable to the fragment shader (or you could put it in the first float from the 1D texture...).
You'll have to re-create the 1D texture every time one of your 2D points changes, so it might be slow if it changes a lot, and/or you have a lot of points. There is also a limit on the size of a 1D texture (I don't know what it is, though).

Also, instead of a single offset&size for the "hole", you now have to send an array of offsets&sizes, for all of the holes, and use them like before.

 

The second method (combining all of the "hole" textures into one) can be done by using render-to-texture and then drawing the "hole" at different spots. First, clear everything to white (glClearColor, glClear), apply an ortho projection (glOrtho) then iterate over your 2D points vector, and for each point, draw a polygon with the "hole" texture applied to it at the position of the point. You may have to translate the points to OpenGL's screen coordinates first [-1, 1], if they're not already transformed. The texture you rendered to (let's call it "holes") can then be used for multi-texturing as before.

For this method, you have to re-draw the "holes" texture every time your 2D points changes, and it will be at least eight times slower than the first method (because instead of just sending the 2D points to the programmable pipeline, you are now sending four vertices of a polygon for each point), and you are also doing more work on the CPU (like the iteration of the 2D points).


#1tonemgub

Posted 13 April 2014 - 04:38 PM


Can I add multiple textures of "the hole" to the multitexture? Or is it possible to combine all of the "holes" that point made into one texture, and use it in the multi-texture?

 

You can do both.

 

The first method: you can send your 2D points vector into the fragment shader, as a 1D-texture object, and then iteratively sample the "hole" texture for each point from the 1D texture, then blend all of the "hole" samples together (multiply them, or just add them and clamp the final result), then use the final value instead of the texval2. You get the points from the 1D texture with texelFetch(), and the iteration (for loop) should run from 0 to the size of the points vectorm which you also send into a separate uniform variable to the fragment shader (or you could put it in the first float from the 1D texture...).
You'll have to re-create the 1D texture every time one of your 2D points changes, so it might be slow if it changes a lot, and/or you have a lot of points. There is also a limit on the size of a 1D texture (I don't know what it is, though).

 

The second method (combining all of the "hole" textures into one) can be done by using render-to-texture and then drawing the "hole" at different spots. First, clear everything to white (glClearColor, glClear), apply an ortho projection (glOrtho) then iterate over your 2D points vector, and for each point, draw a polygon with the "hole" texture applied to it at the position of the point. You may have to translate the points to OpenGL's screen coordinates first [-1, 1], if they're not already transformed. The texture you rendered to (let's call it "holes") can then be used for multi-texturing as before.

For this method, you have to re-draw the "holes" texture every time your 2D points changes, and it will be at least eight times slower than the first method (because instead of just sending the 2D points to the programmable pipeline, you are now sending four vertices of a polygon for each point), and you are also doing more work on the CPU (like the iteration of the 2D points).


PARTNERS