Some doubts/questions about DynamicTexture

Hi,

I’ve some doubts/questions about DynamicTexture that I would like to share with you:

  • I cannot find a way to draw the content of a DynamicTexture directly on the screen at a specific position. As I understood I cannot use directly the canvas context.
  • I would like to apply some glitchy effects on my texture. I don’t know if it is possible to apply a shader to a texture (maybe I have to code a shader for a material that have a texture? :roll_eyes: Sorry, never worked with shader :flushed:)
  • Is it possible to convert a DynamicTexture to a RawTexture? I was thinking to avoid shader and just offset the RGB buffer of some pixels randomly to obtain a glitch effect :wink:

Thank you.

About the 3rd point, this will be slow, I mean realllllly slow :slight_smile: so you should try to avoid it.

About the point 1. you could use your texture in a BABYLON.Layer and for the point 2. a post process would be the way to go.

@Evgeni_Popov do you see anything to add here ?

2 Likes

For 1 you can use a GUI image and put this image where you want in a fullscreen GUI (you will need to copy the texture content to the image context, though, which could be slow if you do this each frame).

You can also use a regular 3D plane always facing the camera. You will need to perform some computations if you want this plane to be positioned at some specific pixel coordinates but it can be done.

1 Like

Thank you for your quick replies!

I’ve already tried @sebavan suggestion for point 1, it works pretty well. Just one little question/confirmation more. If I got it right in order to draw/write whatever I want in my 2D screen I need to create a DynamicTexture with the same canvas size. So every time that canvas change size (browser is resized) I have to dispose the texture and create new one, right?

I will try to understand how to use post process to obtain my glitch effect.

P.S.:
About 3rd point: I was not thinking to copy all the RGB buffer at every frame, but just take an offseted pointer to them, but then I realized that we are not working with C/C++, so this kind of trick are not available here :wink:

1 Like

Oh, PostProcess is so funny with custom shader! :smiling_face_with_three_hearts:
I think I’m going to spend some time with it! At the moment I was able to just make this basic idea, but I am already happy :smiley::
https://playground.babylonjs.com/#DAC1WM#26

And a more interesting one (with color offsetting):
https://playground.babylonjs.com/#DAC1WM#28

3 Likes