[Solved] Indices and ManualObj/Datablock

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

[Solved] Indices and ManualObj/Datablock

Post by mmixLinus »

So I'm bringing my Galaxy Navigator (see the WiP thread) into the future :P and need some guidance with the "glue"..
Basically, the app is a giant POINT_LIST viewer :D Each point representing a star. My original material "StarTypes/StarBaseWhiteNoLightingShader" is BaseWhiteNoLighting with a little shader code added.

My 1.10 -> 2.1 code is roughly

Code: Select all

#if OGRE_VERSION_MAJOR == 1
	sMagnitudeObjName = "StarObj";
	m_pvStarsInMagnitude = OGRE_NEW Ogre::ManualObject(sMagnitudeObjName);
#else
	m_pvStarsInMagnitude = OGRE_NEW Ogre::ManualObject(Id::generateNewId<Ogre::ManualObject>(), &sm->_getEntityMemoryManager(Ogre::SCENE_STATIC), sm);
#endif

	// Material name used here, and for my Unlit Datablock...
	sMaterialName = "...";
	Ogre::MaterialPtr spOrigMaterial = Ogre::MaterialManager::getSingleton().getByName("StarTypes/StarBaseWhiteNoLightingShader");
	Ogre::MaterialPtr spDerivedMateral = spOrigMaterial->clone(sMaterialName);

#if OGRE_VERSION_MAJOR >= 2
	//		Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit(archiveUnlit, &library);
	Ogre::HlmsUnlit* hlmsUnlit = reinterpret_cast<HlmsUnlit*>(Ogre::Root::getSingleton().getHlmsManager()->getHlms(Ogre::HlmsTypes::HLMS_UNLIT));
	bool visibleToManager = true;
	HlmsUnlitDatablock *datablock = reinterpret_cast<HlmsUnlitDatablock*>(
			hlmsUnlit->createDatablock(sMaterialName, sMaterialName,
			HlmsMacroblock(), HlmsBlendblock(),
			HlmsParamVec(), visibleToManager ) );
#endif
	m_pvStarsInMagnitude->begin(sMaterialName, Ogre::v1::RenderOperation::OT_POINT_LIST);
	m_pvStarsInMagnitude->position(...) ; // x N where N is >1e5
	m_pvStarsInMagnitude->end();
Things I've noted:
1) I now MUST specify Indices "pvStarsInMagnitude->index(n);" which I didn't need before (I just wanted the vertices to be handled as they were ordered). This is completely unnecessary (for me)!
2) If I understand my code correctly I am overwriting my low-level material's datablock with a vanilla Unlit shader, correct? What would be a better way of doing this? I don't really need my low-level materials, and am aiming to just use Hlms. (Or HLSL?)
3) If I don't create this Unlit datablock, m_pvStarsInMagnitude->end() throws...

EDIT: I suppose I should say that this approach "works" in the sense that I do get a visible star field, but my impression is that it is showing "Unlit" rather than my low-level material. So the question is: Can I easily combine an Hlms datablock material (that includes my own shader code) with obj->begin(), obj->position(), obj->end(), and possibly without having to specify indices "->index(0)"? I assume I don't actually need low-level materials à la 1.x.

:) Thanks!
Last edited by mmixLinus on Sat Jan 21, 2017 5:22 pm, edited 1 time in total.
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Indices and ManualObj/Datablock

Post by dark_sylinc »

V2 ManualObject was a community addition to ease transition with those that like a familiar/friendly system that will let them build meshes using functions (i.e. position() normal() etc). Its use is discouraged as dealing with vertex buffers directly has become much easier than it was on 1.x

Any oddities (like requiring to use index() unnecessarily) are probably because it's not really the same class.
If I understand my code correctly I am overwriting my low-level material's datablock with a vanilla Unlit shader, correct? What would be a better way of doing this? I don't really need my low-level materials, and am aiming to just use Hlms. (Or HLSL?)
I don't know because in the fragment of code you posted you're actually never setting the Unlit datablock you created to the MovableObject, neither by name nor by pointer.
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

Ok, holidays are over, time for me to get back to work :D

Thanks, dark_sylinc, for your comments, I'm beginning to get the hang of things - I removed all v2/ManualObject code and moved on to VaoManager :)
I am using vanilla Unlit, and would like to add some shader code of my own, and am trying to get pieces working (if that's feasible for my usage).
I want to pass some floats per vertex to my HLSL code by including them in the vertex buffer

Code: Select all

	m_vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3, Ogre::VES_POSITION));
	m_vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT4, Ogre::VES_TEXTURE_COORDINATES));
	size_t vertexSize = vaoManager->calculateVertexSize(m_vertexElements);
and then, for each vertex, copy 7 floats.

My piece file begins with

Code: Select all

@piece( custom_vs_attributes )
	float4 starParams : TEXCOORD1;
@end
The HLSL parser now throws this

Code: Select all

        if( numShaderInputsFound < numShaderInputs )
        {
            OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR,
                         "Not all of the shader input semantics are set by the VertexArrayObject",
                         "D3D11VertexDeclaration::getILayoutByShader");
        }
Q: So how do I properly make use of the extra float4 as input? I'm unsure how to connect the remaining dots.. Do I need to subclass Unlit (and/or add a listener), as hinted upon in chapter 8.6.1 in the porting doc?

Thanks!
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Indices and ManualObj/Datablock

Post by dark_sylinc »

Your vertex declaration only defines one set of UVs, but "float4 starParams : TEXCOORD1;" refers to the second set of UVs.

i.e. likely you wanted to type "float4 starParams : TEXCOORD0;"; or you wanted to push an extra set of UVs to m_vertexElements.
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

Ahh yes - the resulting HLSL code is also expecting a

Code: Select all

	float2 uv0 : TEXCOORD0;
which I am not using (it's a non-textured POINT_LIST). When I change my input type to TEXCOORD0 I get a duplicated input semantics exception. Can I easily remove the uv0 texture reference from Unlit? Maybe hlmsunlit->setProperty("hlms_uv_count", 0) will work, if I subclass unlit?

EDIT: Or maybe I should just go ahead and define a dummy uv0 vertex, and pass my params as TEXCOORD1?
EDIT2: And, BTW, where does the need for float2 uv0 : TEXCOORD0 get into code?
EDIT3: Some code for clarity:

Code: Select all

#if OGRE_VERSION_MAJOR >= 2
		// See http://www.ogre3d.org/forums/viewtopic.php?f=25&t=83999

		Ogre::RenderSystem* renderSystem = Ogre::Root::getSingleton().getRenderSystem();
		Ogre::VaoManager* vaoManager = renderSystem->getVaoManager();
		Ogre::HlmsUnlitDatablock*	datablock;
		Ogre::String sDatablockName("StarDatablock");

		Ogre::HlmsUnlit* hlmsUnlit = reinterpret_cast<HlmsUnlit*>(Ogre::Root::getSingleton().getHlmsManager()->getHlms(Ogre::HlmsTypes::HLMS_UNLIT));
		bool visibleToManager = true;
		datablock = reinterpret_cast<HlmsUnlitDatablock*>(
			hlmsUnlit->createDatablock(sDatablockName, sDatablockName,
			HlmsMacroblock(), HlmsBlendblock(),
			HlmsParamVec(), visibleToManager));

		for (int i = 0; i < m_iNumMagRanges; ++i) {

			Ogre::VertexBufferPackedVec vertexBuffers;
			Ogre::VertexBufferPacked *pVertexBuffer = vaoManager->createVertexBuffer(m_vertexElements, m_piStarMagCount[i], Ogre::BT_IMMUTABLE, m_vertexData[i], false);
			vertexBuffers.push_back(pVertexBuffer);

			Ogre::VertexArrayObject *vao = vaoManager->createVertexArrayObject(
				vertexBuffers, NULL, Ogre::v1::RenderOperation::OT_POINT_LIST);

			Ogre::MeshPtr mesh = m_spvStarMeshes[i];
			Ogre::SubMesh* subMesh = mesh->getSubMesh(0);
			subMesh->setMaterialName(sDatablockName);

			subMesh->mVao[0].push_back(vao);
			//subMesh->mVao[1].push_back(vao);	// Used for shadow map caster passes
			Ogre::Aabb bounds;
			bounds.merge(m_AAMinBB[i]);
			bounds.merge(m_AAMaxBB[i]);
			mesh->_setBounds(bounds, false);
			mesh->_setBoundingSphereRadius(bounds.getRadius());
		}
#endif
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Indices and ManualObj/Datablock

Post by dark_sylinc »

That is weird: HlmsUnlit should generate "float4 uv0 : TEXCOORD0;" in the vertex shader so that you could use it directly.

If you have a texture, HlmsUnlit will pass the first uv0.xy to the pixel shader. Perhaps the "float2 uv0 : TEXCOORD0;" you are referring you mean the pixel shader? If so you only need to send the remaining .zw by defining custom_vs_posExecution and custom_VStoPS
If there are no textures (out_uv_count = 0), then you'll need to send the .xyzw, not just .zw

Alternatively you could try adding a dummy UV set. Or subclass HlmsUnlit like you said. Without knowing what you are trying to achieve, there could be a thousand ways to solve the problem.
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

:lol: yeah, I'm not quite sure yet what I want to achieve.

However, adding some VS_INPUT parameters is a good first achievement.
(Add some Uniform input textures is a good second achievement :) )
(And write to a custom uniform array/texture is a third achievement :) - for mouse picking!)

When GalaxyNavigator_piece_vs_piece_ps.hlsl(*) starts with

Code: Select all

@piece( custom_vs_attributes )
//	float4 starParams : TEXCOORD0;
@end
Output of 1610678272VertexShader_vs.hlsl is

Code: Select all



float4x4 UNPACK_MAT4( Buffer<float4> matrixBuf, uint pixelIdx )
{
	float4 row1 = matrixBuf.Load( int((pixelIdx) << 2u) );
	float4 row2 = matrixBuf.Load( int(((pixelIdx) << 2u) + 1u) );
	float4 row3 = matrixBuf.Load( int(((pixelIdx) << 2u) + 2u) );
	float4 row4 = matrixBuf.Load( int(((pixelIdx) << 2u) + 3u) );

	return float4x4( row1, row2, row3, row4 );
}


// START UNIFORM DECLARATION

//Uniforms that change per pass
cbuffer PassBuffer : register(b0)
{
	struct PassData
	{
	//Vertex shader
	float4x4 viewProj[2];
		
	} passBuf;
};


//Uniforms that change per Item/Entity
cbuffer instance : register(b2)
{
	//.x =
	//Contains the material's start index.
    //
    //.y =
    //shadowConstantBias. Send the bias directly to avoid an
    //unnecessary indirection during the shadow mapping pass.
    //Must be loaded with uintBitsToFloat
    //
    //.z =
    //Contains 0 or 1 to index into pass.viewProj[]. Only used
    //if hlms_identity_viewproj_dynamic is set.
	uint4 materialIdx[4096];
};

Buffer<float4> worldMatBuf : register(t0);


// END UNIFORM DECLARATION

struct VS_INPUT
{
	float4 vertex : POSITION;


	float2 uv0 : TEXCOORD0;
	uint drawId : DRAWID;
	
//	float4 starParams : TEXCOORD0;

};

struct PS_INPUT
{

	
		nointerpolation uint drawId	: TEXCOORD0;
				
			float2 uv0	: TEXCOORD1;			

	float4 gl_Position : SV_Position;
};


	


PS_INPUT main( VS_INPUT input )
{
	PS_INPUT outVs;
	

	
		float4x4 worldViewProj;
		worldViewProj = UNPACK_MAT4( worldMatBuf, input.drawId );
	


	outVs.gl_Position = mul( worldViewProj, input.vertex );










	
		outVs.uv0.xy = input.uv0.xy;
	

	outVs.drawId = input.drawId;



	

	return outVs;
}
My VertextShader_vs.hlsl is (Ogre standard Unlit)

Code: Select all

@insertpiece( SetCrossPlatformSettings )

@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 )

// START UNIFORM DECLARATION
@insertpiece( PassDecl )
@insertpiece( InstanceDecl )
Buffer<float4> worldMatBuf : register(t0);
@property( texture_matrix )Buffer<float4> animationMatrixBuf : register(t1);@end
@insertpiece( custom_vs_uniformDeclaration )
// END UNIFORM DECLARATION

struct VS_INPUT
{
	float4 vertex : POSITION;
@property( hlms_colour )	float4 colour : COLOR0;@end
@foreach( hlms_uv_count, n )
	float@value( hlms_uv_count@n ) uv@n : TEXCOORD@n;@end
	uint drawId : DRAWID;
	@insertpiece( custom_vs_attributes )
};

struct PS_INPUT
{
@insertpiece( VStoPS_block )
	float4 gl_Position : SV_Position;
};

@property( !hlms_identity_world )
	@piece( worldViewProj )worldViewProj@end
@end @property( hlms_identity_world )
	@property( !hlms_identity_viewproj_dynamic )
		@piece( worldViewProj )passBuf.viewProj[@value(hlms_identity_viewproj)]@end
	@end @property( hlms_identity_viewproj_dynamic )
		@piece( worldViewProj )passBuf.viewProj[materialIdx[input.drawId].z]@end
	@end
@end

PS_INPUT main( VS_INPUT input )
{
	PS_INPUT outVs;
	@insertpiece( custom_vs_preExecution )

	@property( !hlms_identity_world )
		float4x4 worldViewProj;
		worldViewProj = UNPACK_MAT4( worldMatBuf, input.drawId );
	@end

@property( !hlms_dual_paraboloid_mapping )
	outVs.gl_Position = mul( @insertpiece( worldViewProj ), input.vertex );
@end

@property( hlms_dual_paraboloid_mapping )
	//Dual Paraboloid Mapping
	outVs.gl_Position.w		= 1.0f;
	outVs.gl_Position.xyz	= mul( @insertpiece( worldViewProj ), input.vertex ).xyz;
	float L = length( outVs.gl_Position.xyz );
	outVs.gl_Position.z		+= 1.0f;
	outVs.gl_Position.xy	/= outVs.gl_Position.z;
	outVs.gl_Position.z	= (L - NearPlane) / (FarPlane - NearPlane);
@end

@property( !hlms_shadowcaster )
@property( hlms_colour )	outVs.colour = input.colour;@end

@property( texture_matrix )	float4x4 textureMatrix;@end

@foreach( out_uv_count, n )
	@property( out_uv@n_texture_matrix )
		textureMatrix = UNPACK_MAT4( animationMatrixBuf, (materialIdx[input.drawId].x << 4u) + @value( out_uv@n_tex_unit ) );
		outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = mul( textureMatrix, float4( input.uv@value( out_uv@n_source_uv ).xy, 0, 1 ) ).xy;
	@end @property( !out_uv@n_texture_matrix )
		outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = input.uv@value( out_uv@n_source_uv ).xy;
	@end @end

	outVs.drawId = input.drawId;

@end @property( hlms_shadowcaster )
	float shadowConstantBias = asfloat( materialIdx[input.drawId].y );
	//Linear depth
	outVs.depth	= (outVs.gl_Position.z - passBuf.depthRange.x + shadowConstantBias * passBuf.depthRange.y) * passBuf.depthRange.y;

	//We can't make the depth buffer linear without Z out in the fragment shader;
	//however we can use a cheap approximation ("pseudo linear depth")
	//see http://www.yosoygames.com.ar/wp/2014/01/linear-depth-buffer-my-ass/
	outVs.gl_Position.z = outVs.gl_Position.z * (outVs.gl_Position.w * passBuf.depthRange.y);
@end

	@insertpiece( custom_vs_posExecution )

	return outVs;
}
(*) My GalaxyNavigator_piece_vs_piece_ps.hlsl is a copy of Ogre standard Structs_piece_vs_piece_ps.hlsl with my piece inserted.

Not sure I cleared anything up ;)
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

My suggestion to why I'm getting this clash of semantics is that my project also uses some Samples materials. For example, packs/OgreCore.zip/OgreCore.material defines materials that are based on Unlit. So I can't just come along and add @pieces to Unlit. That would be equivalent to changing the "base class".

Q: Is the correct way forward to just make a renamed copy of the "Unlit" hlms folder, load a subclassed HlmsUnlit, and add @pieces to the copy instead?
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Indices and ManualObj/Datablock

Post by dark_sylinc »

mmixLinus wrote:Q: Is the correct way forward to just make a renamed copy of the "Unlit" hlms folder, load a subclassed HlmsUnlit, and add @pieces to the copy instead?
You can do a copy, but you don't necessarily have to do a copy of the template files. That's why "libraries" exist in Hlms.
Add the folder where your piece files are:

Code: Select all

Ogre::Archive *archiveLibrary = Ogre::ArchiveManager::getSingletonPtr()->load(
                dataFolder + "Hlms/Common/" + shaderSyntax,
                "FileSystem", true );
Ogre::Archive *archiveLibraryAny = Ogre::ArchiveManager::getSingletonPtr()->load(
                dataFolder + "Hlms/Common/Any",
                "FileSystem", true );

Ogre::Archive *archiveCustomPieces = Ogre::ArchiveManager::getSingletonPtr()->load(
                "PATH/TO/YOUR/CUSTOM/PIECES",
                "FileSystem", true );

Ogre::ArchiveVec library;
library.push_back( archiveLibrary );
library.push_back( archiveLibraryAny );
library.push_back( archiveCustomPieces );

Ogre::Archive *archiveUnlit = Ogre::ArchiveManager::getSingletonPtr()->load(
                dataFolder + "Hlms/Unlit/" + shaderSyntax,
                "FileSystem", true );

Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit( archiveUnlit, &library );
Ogre::Root::getSingleton().getHlmsManager()->registerHlms( hlmsUnlit );
By subclassing HlmsUnlit (and perhaps HlmsUnlitDatablock, depending on the granularity you need), you can set a property where you selectively define the pieces if a particular setting is present or not (so that regular Unlit datablocks aren't affected by your pieces):

Code: Select all

@property( enable_my_feature )
    @piece( custom_vs_attributes )my_code();@end
@end
Or you can copy-paste. That really is up to you (the advantage of not doing the copy paste is that most changes to the repo can be kept in sync automatically without further work from your end).
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

Ok, thanks ever so much for helping me out! I can tell from *many* of the posts relating to porting to 2.1, I'm about a year late :lol: and I suppose, because I'm new to shaders, I haven't fully understood everything :oops:

Anyway.. Using your suggestions, I now simply subclass HlmsUnlit, add a property, so I can optionally switch on my piece. Yay!

Though I'm not there yet: For some reason, of all the various HLSL files that are built (running my program outputs 6 *_vs.hlsl and 6 *_ps.hlsl) TWO of them contain my piece, though I only create my piece-enabled material in one place. Is this expected? Again, I get the "Not all of the shader input semantics are set by the VertexArrayObject" exception, so there is a discrepancy between the vertex data I am defining, and what (one of) these shaders is expecting.

Again, note that the program also uses the horribly slow, old Overlays (material based on Unlit) and at one other place I use an Unlit material (without my property switched on) to create some triangle strips...

Here's my code:
HlmsUnlitStars.h

Code: Select all

#ifndef __HLMSUNLITSTARS_H__
#define __HLMSUNLITSTARS_H__

namespace Gaia {

class HlmsUnlitStars : public Ogre::HlmsUnlit 
{
public:
	HlmsUnlitStars(Ogre::Archive* dataFolder, Ogre::ArchiveVec* libraryFolders);
	virtual ~HlmsUnlitStars();

protected:

	//Override to return a HlmsMyDatablock.
	virtual Ogre::HlmsDatablock* createDatablockImpl(Ogre::IdString datablockName,
		const Ogre::HlmsMacroblock *macroblock,
		const Ogre::HlmsBlendblock *blendblock,
		const Ogre::HlmsParamVec &paramVec);

	virtual void calculateHashForPreCreate(Ogre::Renderable *renderable, PiecesMap *inOutPieces);

	bool mIsStarParamsEnabled;

};

}

#endif
HlmsUnlitStars.cpp

Code: Select all

#include <stdafx.h>

#include <Ogre.h>
#include <OGRE/Hlms/Unlit/OgreHlmsUnlit.h>
#include "HlmsUnlitStars.h"

using namespace Gaia;

// ********************************************************************************************* HLMS
HlmsUnlitStars::HlmsUnlitStars(Ogre::Archive* dataFolder, Ogre::ArchiveVec* libraryFolders)
	: Ogre::HlmsUnlit(dataFolder, libraryFolders)
	, mIsStarParamsEnabled(false)  { }

HlmsUnlitStars::~HlmsUnlitStars() { }

Ogre::HlmsDatablock* HlmsUnlitStars::createDatablockImpl(
	Ogre::IdString datablockName,
	const Ogre::HlmsMacroblock *macroblock,
	const Ogre::HlmsBlendblock *blendblock,
	const Ogre::HlmsParamVec &paramVec)
{
	Ogre::String sParamValue;
	if (Ogre::Hlms::findParamInVec(paramVec, "enable_starparams", sParamValue))
		mIsStarParamsEnabled = true;	// <-- TODO ; )

	return HlmsUnlit::createDatablockImpl(datablockName, macroblock, blendblock, paramVec);
}

void HlmsUnlitStars::calculateHashForPreCreate(Ogre::Renderable *renderable, PiecesMap *inOutPieces)
{
	if (mIsStarParamsEnabled)
		setProperty("enable_starparams", mIsStarParamsEnabled);

	HlmsUnlit::calculateHashForPreCreate(renderable, inOutPieces);
}
My piece

Code: Select all

@property( enable_starparams )
	@piece( custom_vs_attributes )
		float4 starParams : TEXCOORD1; 
	@end
@end
And finally, the VS_INPUT and PS_INPUT from the two hlsl files, so you can see "the result"

File 1 - 1610842112VertexShader_vs.hlsl

Code: Select all

// END UNIFORM DECLARATION

struct VS_INPUT
{
	float4 vertex : POSITION;
	float4 colour : COLOR0;

	float2 uv0 : TEXCOORD0;
	uint drawId : DRAWID;
	
		float4 starParams : TEXCOORD1; 
	
};

struct PS_INPUT
{

	
		nointerpolation uint drawId	: TEXCOORD0;
		float4 colour	: TEXCOORD1;
		
			float2 uv0	: TEXCOORD2;
	
	
	

	float4 gl_Position : SV_Position;
};
File 2 1610809344VertexShader_vs.hlsl

Code: Select all

// END UNIFORM DECLARATION

struct VS_INPUT
{
	float4 vertex : POSITION;


	float4 uv0 : TEXCOORD0;
	uint drawId : DRAWID;
	
		float4 starParams : TEXCOORD1; 
	
};

struct PS_INPUT
{

	
		nointerpolation uint drawId	: TEXCOORD0;
		
		
	
	
	

	float4 gl_Position : SV_Position;
};
My declarations etc

Code: Select all

	m_vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT3, Ogre::VES_POSITION));
	m_vertexElements.push_back(Ogre::VertexElement2(Ogre::VET_FLOAT4, Ogre::VES_TEXTURE_COORDINATES));

...
		Ogre::HlmsUnlitDatablock*	datablock;

		Ogre::String sDatablockName("StarDatablock");

		Gaia::HlmsUnlitStars* hlmsUnlit = reinterpret_cast<HlmsUnlitStars*>(Ogre::Root::getSingleton().getHlmsManager()->getHlms(Ogre::HlmsTypes::HLMS_UNLIT));
		bool visibleToManager = true;

		HlmsParamVec paramVec;
		paramVec.push_back(std::pair<Ogre::IdString, Ogre::String>(Ogre::IdString("enable_starparams"), "1"));
		
		datablock = reinterpret_cast<Ogre::HlmsUnlitDatablock*>(
			hlmsUnlit->createDatablock(sDatablockName, sDatablockName,
			HlmsMacroblock(), HlmsBlendblock(),
			paramVec, visibleToManager));

Any ideas? File 1 has an extra "float4 colour : COLOR0;".. wonder where that comes from 8) .. and uv0 is float2 which then becomes float4
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: Indices and ManualObj/Datablock

Post by mmixLinus »

There must be a word or expression for this in software engineering.. When you are altering some functionality by making changes in too many places at once, making it close to impossible to find the reason it doesn't work. All you can do is persevere, and you will get there in the end.

Turns out, I wasn't resetting my property variable properly (mIsStarParamsEnabled). My (very simple) Unlit class:

HlmsUnlitStars.h

Code: Select all

#ifndef __HLMSUNLITSTARS_H__
#define __HLMSUNLITSTARS_H__

namespace Gaia {

class HlmsUnlitStars : public Ogre::HlmsUnlit 
{
public:
	HlmsUnlitStars(Ogre::Archive* dataFolder, Ogre::ArchiveVec* libraryFolders);
	virtual ~HlmsUnlitStars();

protected:

	//Override to return a HlmsMyDatablock.
	virtual Ogre::HlmsDatablock* createDatablockImpl(Ogre::IdString datablockName,
		const Ogre::HlmsMacroblock *macroblock,
		const Ogre::HlmsBlendblock *blendblock,
		const Ogre::HlmsParamVec &paramVec);

	virtual void calculateHashForPreCreate(Ogre::Renderable *renderable, PiecesMap *inOutPieces);

	bool mIsStarParamsEnabled;

};

}

#endif
HlmsUnlitStars.cpp

Code: Select all

#include <stdafx.h>

#include <Ogre.h>
#include <OGRE/Hlms/Unlit/OgreHlmsUnlit.h>
#include "HlmsUnlitStars.h"

using namespace Gaia;

// ********************************************************************************************* HLMS
HlmsUnlitStars::HlmsUnlitStars(Ogre::Archive* dataFolder, Ogre::ArchiveVec* libraryFolders)
	: Ogre::HlmsUnlit(dataFolder, libraryFolders)
	, mIsStarParamsEnabled(false)  { }

HlmsUnlitStars::~HlmsUnlitStars() { }

Ogre::HlmsDatablock* HlmsUnlitStars::createDatablockImpl(
	Ogre::IdString datablockName,
	const Ogre::HlmsMacroblock *macroblock,
	const Ogre::HlmsBlendblock *blendblock,
	const Ogre::HlmsParamVec &paramVec)
{
	Ogre::String sParamValue;
	if (Ogre::Hlms::findParamInVec(paramVec, "enable_starparams", sParamValue))
		mIsStarParamsEnabled = atoi(sParamValue.c_str()) != 0;
	else
		mIsStarParamsEnabled = false;      // <---  must reset it too!

	return HlmsUnlit::createDatablockImpl(datablockName, macroblock, blendblock, paramVec);
}

void HlmsUnlitStars::calculateHashForPreCreate(Ogre::Renderable *renderable, PiecesMap *inOutPieces)
{
	setProperty("enable_starparams", mIsStarParamsEnabled);

	HlmsUnlit::calculateHashForPreCreate(renderable, inOutPieces);
}
Thanks for all help sorting everything out!
/mmixLinus
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
Post Reply