[转]Passing an RTT to a shader

http://www.ogre3d.org/tikiwiki/Intermediate+Tutorial+7

As RTTs are often used with shaders, you have to know how to pass the RenderTexture to one. Fortunately, this is really simple.

The most simple case is one where you never change the texture for the shader during runtime. If it remains constant, you just have to tell your material script the name of the texture you create during runtime, in our case "RttTex". So your texture_unit in the material should look like this:

texture_unit
{
     texture RttTex
}

If you need to change the texture the shader should use during runtime, just add the two following lines:

Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("Sepia");
material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("OtherRttTex");

With the first line we get a pointer to the material (in this case here a sepia shader material) where we change the texture name in the second line to the desired one.

Now, as you have set the correct texture name in your material script with one of these two methods, you can access the texture in your cg shader with the following line:

uniform sampler2D SceneSampler : register(s0)
原文地址:https://www.cnblogs.com/pulas/p/2361202.html