I managed to make the screen to texture conversion as you can see here:
Thank you both @sebavan and @Evgeni_Popov for your help, this is exactly what I wanted!
During my progress I noticed something weird, if you have the uniform “world” in the shader uniform array, the shader is not working anymore as expected. On the contrary, you have to indicate “worldViewProjection” in the array. I don’t know if it is a bug or something willing.
The ShaderMaterial documentation do precise that:
worldViewProjection
must be declared in the Vertex Shader as type mat4
and must be in the uniforms
array
but nothing concerning the “world” uniform.
Hope that helps 
You must declare in the uniform array the uniforms you are using in your shader:
worldPos = world * vec4(position, 1.0);
gl_Position = worldViewProjection * vec4(position, 1.0);
You use world
and worldViewProjection
, so they should be in the list of the uniforms.
However, worldPos
is not used, so world
is not really needed: you should remove the line which computes it and from the uniform mat4 world, viewProjection, view, worldViewProjection;
declaration. You can also remove view
and viewProjection
as they are not used.
2 Likes
Hello, I come back because I still have some issues with uniforms, unfortunately.
As you can see in this playground, I am using the uniform world
in my shader code. But if I put it in the shader uniform array (see line 153), the shader mouse computation is broken.
Testing the code I realized that my shader also works using viewProjection
instead of world
. But again if I put viewProjection
in the shader uniform array, it stops working.
I think I need more explanations on how to use uniforms. I read the documentation again and found nothing to explain what I experience but I will continue to dig in. 
Actually, putting world
in the uniform array is what you should do, else a wrong value for world
is passed to the shader.
Using Spector:
You must have a bug somewhere in the shader if passing the identity matrix makes it break.
2 Likes
Okayyyyy, this is actually way simpler than I thought:
Thanks, I now understand way better how uniforms must be managed!
2 Likes
I am in front of a new issue: I can’t manage to deal with screen resizing and keeping the correct mouse position.
https://playground.babylonjs.com/#4C900K#57 (Line 161)
I use the rtt.resize
function and update the resolution uniform in all glsl code but if I resize the canvas window, I get an offset with the mouse.
Should I also do something with the effect renderer maybe?
I also tried to check the scene SpectorJS but no clue.
Cheers 
Don’t do eWrapper.effect.setVector2("resolution", new BABYLON.Vector3(width, height))
in engine.onResizeObservable
, eWrapper.effect
is invalid in this function (it can only be used in the eWrapper.onApplyObservable
observable):
2 Likes