cutomParam for InstancedEntity ( layout location)

Problems building or running the engine, queries about how to use features etc.
User avatar
paul424
Gnome
Posts: 385
Joined: Thu May 24, 2012 7:16 pm
x 20

cutomParam for InstancedEntity ( layout location)

Post by paul424 »

Ogre Version: : 1 13 5 6:
Operating System: :Linux Tumbleweed:
Render System: :OpenGL3+

Hello, I try to add simple setCustomParam for my Instancing Entities.
I did reserve a "slot" for custom parameter :

Code: Select all

    mInstanceManagerDirt = mSceneManager->createInstanceManager(
        "InstanceManagerMeshDirt",
        "FogOfWarDirt.mesh",
        "Graphics",
        Ogre::InstanceManager::HWInstancingBasic,
        128,
        Ogre::IM_USEALL,
        0);
    
mInstanceManagerCloud = mSceneManager->createInstanceManager( "InstanceManagerMeshCloud2", "FogOfWarCloud2.mesh", "Graphics", Ogre::InstanceManager::HWInstancingBasic, 64, Ogre::IM_USEALL, 0); mInstanceManagerDirt->setNumCustomParams(1); // Number of vec4 custom params mInstanceManagerDirt->defragmentBatches(true); mInstanceManagerCloud->defragmentBatches(true);

and then I setup it : like that :
mFogOfWarDirtMesh->setCustomParam(0, Ogre::Vector4(1.0f, 0.0f, 0.0f, 0.0f)); // Example: RGBA color

Example header for vertex shader program look like that :

Code: Select all

#version 330 core
#extension GL_ARB_explicit_uniform_location : enable
#extension GL_ARB_shading_language_include : enable

#include <OgreUnifiedShader.h>
#include "PerlinNoise.glsl" 
#include "FFPLib_Transform.glsl"

uniform    mat4 projectionMatrix;
uniform    mat4 viewMatrix;
uniform    mat4 worldMatrix;
uniform    mat4 lightMatrix;

layout (location = 0) in vec4 position;
layout (location = 2)  in vec3 normal;



/* layout (location = 3)  in mat3x4 uv1; */
layout (location = 8) in vec2 uv_0;
layout (location = 8) in vec2 uv_1;
layout (location = 12) in vec4 color;
layout (location = 14) in vec3 tangent;
IN(mat3x4	uv1, TEXCOORD1)
out vec2 out_UV0;
out vec2 out_UV1;

out vec3 FragPos;
out vec4 VertexPos; 
out vec4 outputColor; 
 
out mat3 TBN;

In the manual I read :

Custom parameters

Some instancing techniques allow passing custom parameters to vertex shaders. For example a custom colour in an RTS game to identify player units; a single value for randomly colouring vegetation, light parameters for rendering deferred shading's light volumes (diffuse colour, specular colour, etc)

At the time of writing only HW Basic supports passing the custom parameters. All other techniques will ignore it.[8]

To use custom parameters, call InstanceManager::setNumCustomParams to tell the number of custom parameters the user will need. This number cannot be changed after creating the first batch (call createInstancedEntity)

Afterwards, it's just a matter of calling InstancedEntity::setCustomParam with the param you wish to send.

For HW Basic techniques, the vertex shader will receive the custom param in an extra TEXCOORD.

So is the choice layout (location = 12) in vec4 color; ( as chatgpt suggested ) right ?
Or what layout location I should choose for passing the color of a Tile from the c++ code side ?
So far I get LSD-checkboard pattern when it comes to color , so the choice for sure is wrong ..........

rpgplayerrobin
Orc Shaman
Posts: 788
Joined: Wed Mar 18, 2009 3:03 am
x 447

Re: cutomParam for InstancedEntity ( layout location)

Post by rpgplayerrobin »

I am not that familiar with GLSL, but your code looks incorrect to me.
You are inputting uv_0 and uv_1 to the same layout location.

But I am unsure in GLSL how to know where that parameter is actually placed.
As the documentation says, it is in the next TEXCOORD, but it seem you are not using that.

For example, in HLSL it would most likely just be like this:

Code: Select all

VS_OUTPUT main_vs( float4 position : POSITION,
				   float3 normal : NORMAL,
				   float3 tangent : TANGENT,
				   float2 uv : TEXCOORD0,
				   float4 customParameter : TEXCOORD1 )
{
User avatar
paul424
Gnome
Posts: 385
Joined: Thu May 24, 2012 7:16 pm
x 20

Re: cutomParam for InstancedEntity ( layout location)

Post by paul424 »

The macro IN(mat3x4 uv1, TEXCOORD1) seems to be the culprit.
After folding this into :

Code: Select all

layout(location = 9) in vec4 uv1_0;
layout(location = 10) in vec4 uv1_1;
layout(location = 11) in vec4 uv1_2;
mat3x4 uv1 = mat3x4(uv1_0, uv1_1, uv1_2);

The moral from this story is : it's bad to mix layout location with IN invocation macros !