Custom Material Renderer using Custom Vertices

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
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Custom Material Renderer using Custom Vertices

Post by Max Power »

I originally posted in the beginners' section, but I guess this is much more advanced than I was hoping it would be...

I want to have a material that uses 2 seperate alpha values for vertices. So I derived from S3DVertex and added a u8 "alpha2". One is for transparency, the other for creating a blend with second texture layer. But I realize it's probably not that simple. The CMeshBuffer<Alpha2Vertex> seem to work alright, but the CVertexBuffers (which I just found out about...) probably don't. Especially the stride can't be right. So, I would like to know what steps are necessary to properly implement a custom vertex-type, including corresponding mesh-buffer (and what not).

Question 2 would be: how do I use this data inside the custom material shader?
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Custom Material Renderer using Custom Vertices

Post by Granyte »

You need to create a custom vertex declaration that describe the memory layout of your custom vertex and set it as your custom vertex descriptor
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Custom Material Renderer using Custom Vertices

Post by Nadro »

You can check how to define custom vertex type in following example:
http://sourceforge.net/p/irrlicht/code/ ... g/main.cpp
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Custom Material Renderer using Custom Vertices

Post by Max Power »

Thanks for replies. I will look into it later. It's the first time I am working with shaders and I had no idea what to do yesterday. By now, I have figured out that I can easily use the standard S3DVertex2TCoords, pass the data through the vertex shader and simply interpret the extra texCoords as alpha-values inside the pixel shader. It's not the cleanest thing to do, but good enough for the time being.

It's working the way I wanted now :D
Texture 2 gets blended on top of texture 1, using texture 2's alpha-channel multiplied with interpolated vertex-alpha (texCoord2[0]). The result can be used as any base-material. So I can still use EMT_TRANSPARENT_VERTEX_ALPHA with the actual vertex-alpha values.
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Custom Material Renderer using Custom Vertices

Post by Max Power »

Nadro wrote:You can check how to define custom vertex type in following example:
http://sourceforge.net/p/irrlicht/code/ ... g/main.cpp
So, after a year I finally looked into that example, because I'm at a point now, where 2TexCoord-vertices won't do anymore. It's just that the example seems to be outdated. It uses an IVertexDescriptor-class which simply isn't there.

If anyone could help me out with this, I would really appreciate it. I just want to have additional variables in my vertices, nothing more. All I know is that creating a custom vertex and then a mesh-buffer with that vertex doesn't work. My guess is that I have to do something about the material renderer(?). Don't know how or what though...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom Material Renderer using Custom Vertices

Post by CuteAlien »

That example is from the shader-pipeline, not the official Irrlicht. Are you using that?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Custom Material Renderer using Custom Vertices

Post by Max Power »

I don't even know what it is :/

I think I might once again use a dirty workaround and use the vertex normal-components for other purposes, but in the long run, being able to define my own vertices might be handy.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom Material Renderer using Custom Vertices

Post by CuteAlien »

Shader-pipeline is an Irrlicht branch where developments for the version after the next are tried out. And like the name says it's about making materials all shader based. It also seems to have more flexibler vertex format, but admittably I haven't worked with it yet.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply