Problems with Vertex Texture Lookup

Problems building or running the engine, queries about how to use features etc.
Post Reply
Pellaeon
Goblin
Posts: 230
Joined: Thu Apr 28, 2011 12:23 pm
x 28

Problems with Vertex Texture Lookup

Post by Pellaeon »

Ogre Version: 1.11.1
Operating System: Windows 10
Render System: DirextX9

Hi,

at first I want to describe what I want achieve: I have a plane and corresponding force values. Depending of the force values I want to displace the z value and also depending on the z value I want to choose a proper color. See an attached image with front view ( I only used ellipses but the shape may vary).

To achieve this I have done the following.

1. create a simple material file with reference to HLSL shaders
1. create a manual texture with R16 format
2. create a quad as manual object with intermediate points (e.g. a resolution for the quad of 6x4 vertices ore more) with the dimenons [0;1] in x and z, y is 0 (can me translated and scaled later on with scene node methods)
3. set the material from the material file and attach the manual created texture
4. update the texture every frame with the new values
5. set a proper color in the pixel shader depending of the value.

I attached my material file and my shader. It compiles but I didn't get the expected result and I have no idea why.

I read the value from the texture in the vertex shader (because here I want to use it later to displace the z coordinate.
I transfer the value from teh vertex shader to the pixel shader and in the PS I choose a color depending on the value. The value range is between 1000 and 6500. But my plane is always blue. So he always picks the first color.
Why aren't my values transfered proper to the shaders?

Best regards

Pellaeon


Update of the texture:

Code: Select all

void WarpPlane::update(const std::vector<float>& values)
{	Ogre::HardwarePixelBufferSharedPtr pixelBuffer = m_valueTexture->getBuffer();
	auto ptr = pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
	memcpy(ptr, values.data(), pixelBuffer->getSizeInBytes());

	pixelBuffer->unlock();
}
edit: this is how I create the texture:

Code: Select all

m_valueTexture = Ogre::TextureManager::getSingleton().createManual("WarpPlaneVertexTex", ArGraphic::getARViewerResourceGroup(),
																	   Ogre::TEX_TYPE_2D, 6, 4, 0, Ogre::PF_FLOAT32_R, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
And this is how I set the texture to the material

Code: Select all

m_warpPlane->setMaterialName(0, "WarpPlaneMaterial", ArGraphic::getARViewerResourceGroup());

	auto mat = Ogre::MaterialManager::getSingleton().getByName("WarpPlaneMaterial", ArGraphic::getARViewerResourceGroup());
	mat->getTechnique(0)->getPass(0)->createTextureUnitState(m_valueTexture->getName())->setBindingType(Ogre::TextureUnitState::BT_VERTEX);



Image
Attachments
WarpPlaneMaterial.material
(789 Bytes) Downloaded 49 times
WarpPlane.hlsl
(1.48 KiB) Downloaded 41 times
Post Reply