[2.1] Blending Textures Using Unlit

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
crancran
Greenskin
Posts: 138
Joined: Wed May 05, 2010 3:36 pm
x 6

[2.1] Blending Textures Using Unlit

Post by crancran »

Lets assume I have 2 diffuse textures:

grass.png Image rock.png Image

Along with 2 single-channel mask textures:

grass_mask.png Image rock_mask.png Image

By using one mask and one diffuse texture, I can successfully blend them using this material

Code: Select all

{
  "unlit" :
  {
    "BlendTest" :
    {
      "diffuse_map0" :
      {
        "texture" : "grass_mask.png"
      },
      "diffuse_map1" :
      {
        "texture" : "grass.png",
        "blendmode" : "Multiply"
      }
    }
  }
}
But what I ultimately need is to combine the multiplication of the mask and diffuse textures for both pairs making the final rendered texture contain grass along the outside edges (based on grass_mask.png) and rocks that run down the center (based on rock_mask.png).

I thought I could accomplish this using blend modes for each associated diffuse_map entry, but I could not get the desired outcome. Is this possible using the Unlit material system? If so, could someone show/explain what I am missing?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Blending Textures Using Unlit

Post by dark_sylinc »

if I understand correctly, you want (grass * grass_mask) + (rock * rock_mask)?

I don't think it's possible with Unlit's out of the box, since the operations are stacked together eg. (grass * grass_mask + rock) * rock_mask. It was written to do the same GIMP & Photoshop layer blending modes do.
hyyou
Gremlin
Posts: 173
Joined: Wed Feb 03, 2016 2:24 am
x 17
Contact:

Re: [2.1] Blending Textures Using Unlit

Post by hyyou »

It is easy if you use custom HLMS.
This is a great starting point : viewtopic.php?f=25&t=83763 (Kinslore's tutorial)
crancran
Greenskin
Posts: 138
Joined: Wed May 05, 2010 3:36 pm
x 6

Re: [2.1] Blending Textures Using Unlit

Post by crancran »

I went ahead and implemented by own HLMS as suggested and it works quite well except that I am noticing a Vertex and Pixel shader is being generated for each renderable despite their input parameters being the same. I assume this is likely some cache miss or hash calculation failure on my part, but I am not sure exactly where to look as I mimic'd the same code from Unlit; however when I use Unlit rather than my own I don't experience these duplicated pixel/vertex shader files. Any suggestions on on what I might have overlooked or done incorrectly?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: [2.1] Blending Textures Using Unlit

Post by dark_sylinc »

That would only happen if a property is different for every Item/shader.

Try looking at the generated shaders (Hlms::setDebugOutputPath is set to true which is the default) and compare their dumped properties at the beginning of the file (outputProperties from setDebugOutputPath must be set to true which is also the default).

If all dumped properties are exactly the same, then the most reasonable explanation is that your Hlms implementation is overloading a routine and bypassing our shader cache lookup (or somehow causing it to malfunction).
For example Hlms::calculateHashFor calls:

Code: Select all

uint32 renderableHash = this->addRenderableCache( mSetProperties, pieces );
...
uint32 renderableCasterHash = this->addRenderableCache( mSetProperties, piecesCaster );
...
outHash         = renderableHash;
outCasterHash   = renderableCasterHash;
Is somehow this gets broken and outHash (or outCasterHash) is left uninitialized or ends up always with a different value, then it would explain what you're seeing.
crancran
Greenskin
Posts: 138
Joined: Wed May 05, 2010 3:36 pm
x 6

Re: [2.1] Blending Textures Using Unlit

Post by crancran »

I didn't think to check the output of the properties & pieces but that lead me to the culprit. It seemed I had forgotten to initialize a data block variable and that lead to some pieces being randomly generated erroneously leading to the multiple vertex/pixel shaders. Great catch dark_sylinc!
Post Reply