shader-pipeline: Accessing custom vertex attribute in shader

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
afuzzyllama
Posts: 13
Joined: Thu Oct 10, 2013 2:20 am
Location: Tampa, FL

shader-pipeline: Accessing custom vertex attribute in shader

Post by afuzzyllama »

I have the follow custom vertex:

Code: Select all

 
...
driver->addVertexDescriptor("custom");
driver->getVertexDescriptor("custom")->addAttribute("inPosition",  3, irr::video::EVAS_POSITION,  irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inNormal",    3, irr::video::EVAS_NORMAL,    irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inColor",     4, irr::video::EVAS_COLOR,     irr::video::EVAT_UBYTE);
driver->getVertexDescriptor("custom")->addAttribute("inTexCoord0", 2, irr::video::EVAS_TEXCOORD0, irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inCustom",    3, irr::video::EVAS_CUSTOM,    irr::video::EVAT_FLOAT);
...
 
If I want to access "inCustom" in a shader:

Code: Select all

 
...
varying vec3 inCustom;
...
 
How can I do this in the shader pipeline branch?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: shader-pipeline: Accessing custom vertex attribute in sh

Post by Nadro »

If you know how vertex structure looks you should use direct access eg.
YourVerticesStruct* vrt = Meshbuffer->getVertexBuffer()->getVertices();
vrt[0].InCustom = vector3df(1.f, 1.f, 1.f);
Of course you can use just vertex descriptor and offsets, but it's more complicate and slower solution. You should use offsets only in situation when you don't know how your format looks eg. you write universal method for some different vertex types.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
afuzzyllama
Posts: 13
Joined: Thu Oct 10, 2013 2:20 am
Location: Tampa, FL

Re: shader-pipeline: Accessing custom vertex attribute in sh

Post by afuzzyllama »

Right, that is how you access the vertex information in C++, but how do you access the custom attribute in a shader language like GLSL?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: shader-pipeline: Accessing custom vertex attribute in sh

Post by Nadro »

You should use 'attribute' for it. eg.
attribute vec3 inCustom;
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Post Reply