Is it possible to use viewport as texture unit in material?
<material>
<technique name="Techniques/myTechinque" quality="0" loddistance="0" />
<texture unit="diffuse" name="viewport" />
</material>
Is it possible to use viewport as texture unit in material?
<material>
<technique name="Techniques/myTechinque" quality="0" loddistance="0" />
<texture unit="diffuse" name="viewport" />
</material>
I guess you could render viewport to a separate texture in the renderpath, and reference that texture in here.
Do you have an example ?
I believe we have found quite elegant solution for this if you really want to reference Render Target texture in Material w/o any material-related code.
SetSize
with TEXTURE_RENDERTARGET
to make it render target.This way you can have 100% dynamic resource natively accessible by components and other resources.
AddManualResource
will work too, but you will have to synchronize access in order not to access resource before its creation.
However, you must have explicit render target creation for this to work.
I know that I can create Texture2d class like this :
myTexture = Texture2D();
myTexture(int(size.x), int(size.y), GetRGBAFormat(), TEXTURE_RENDERTARGET);
myTexture.name = "myTexture";
cache.AddManualResource(myTexture);
This way I can use it like :
<texture unit="diffuse" name="myTexture" />
So your method seems to be similar. But I am confused.
Unfortunatelly, my solution cannot work neither for your main window viewport (but I think you don’t need it, right?), nor for internal renderpath textures (like gbuffer textures in deferred render path).
However, I assume that you have some custom render target and non-main viewport (like in sample 10_RenderToTexture
). In this scenario, all you need to do is to use texture from Resource Cache instead of new texture in this line
In this context, answers to your questions:
cache->GetResource
Ok, I confirm that this method is working,