v2-2 HlmsUnlit AutomaticBatching Topic is solved

Problems building or running the engine, queries about how to use features etc.
Post Reply
dermont
Orc Shaman
Posts: 755
Joined: Thu Dec 09, 2004 2:51 am
x 4

v2-2 HlmsUnlit AutomaticBatching

Post by dermont » Thu Jun 14, 2018 4:53 am

Has something changed with the the HlmsUnlit implementation?

In the following example the 2nd datablock uses the texture from the first datablock when AutomaticBatching is enabled or the textures are the same size.

Code: Select all

    virtual void createScene(void) {
        SampleApplication::createScene();
        Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
        Ogre::HlmsUnlit* hlmsUnlit = static_cast<Ogre::HlmsUnlit*>(hlmsManager->getHlms(Ogre::HLMS_UNLIT));
        Ogre::TextureGpuManager* textureManager = Ogre::Root::getSingletonPtr()->getRenderSystem()->getTextureGpuManager();

        mCamera->setAutoAspectRatio(true);
        mCamera->setPosition(Vector3(0,0,100));
        mCamera->lookAt(Vector3(0,0,0));


        Ogre::v1::MeshPtr v1Mesh = Ogre::v1::MeshManager::getSingleton().createPlane( "MyPlane",
                                   Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                   Ogre::Plane( Ogre::Vector3::UNIT_Z, 1.0f ), 50.0f, 50.0f,
                                   1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Y,
                                   Ogre::v1::HardwareBuffer::HBU_DYNAMIC ,
                                   Ogre::v1::HardwareBuffer::HBU_DYNAMIC  , true, true);

        Ogre::MeshPtr v2Mesh = Ogre::MeshManager::getSingleton().createManual(
                                   "MyPlane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );

        bool halfPosition   = true;
        bool halfUVs        = true;
        bool useQtangents   = true;

        //Import the v1 mesh to v2
        v2Mesh->importV1( v1Mesh.get(), halfPosition, halfUVs, useQtangents );
        v1Mesh->unload();

        Ogre::Item* mRectangleItem[2];
        Ogre::HlmsUnlitDatablock* mDatablock[2];
        mDatablock[0] = static_cast<Ogre::HlmsUnlitDatablock*>( hlmsUnlit->createDatablock( 
                                                                Ogre::IdString("TestData1"), "TestData1",
                                                                Ogre::HlmsMacroblock(), 
                                                                Ogre::HlmsBlendblock(), 
                                                                Ogre::HlmsParamVec()));
        mDatablock[1] = static_cast<Ogre::HlmsUnlitDatablock*>( hlmsUnlit->createDatablock( 
                                                                Ogre::IdString("TestData2"), "TestData2",
                                                                Ogre::HlmsMacroblock(), 
                                                                Ogre::HlmsBlendblock(), 
                                                                Ogre::HlmsParamVec()));

        assert(mDatablock[0]!=mDatablock[1]);
        std::cout << mDatablock[1] << std::endl;
        // OK automatic batching not set
        TextureGpu *texture0 =
                        textureManager->createOrRetrieveTexture( "grass_1024.jpg", GpuPageOutStrategy::Discard,
                                                                 TextureFlags::AutomaticBatching |
                                                                 TextureFlags::PrefersLoadingFromFileAsSRGB,
                                                                 TextureTypes::Type2D,
                                                                 ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
        TextureGpu *texture1 =
                        textureManager->createOrRetrieveTexture( "Dr_Bunsen_Head.jpg", GpuPageOutStrategy::Discard,
                                                                 TextureFlags::AutomaticBatching |
                                                                 TextureFlags::PrefersLoadingFromFileAsSRGB,
                                                                 TextureTypes::Type2D,
                                                                 ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
         mDatablock[0]->setTexture( 0 , texture0, NULL, 0xFFFF );       
         mDatablock[0]->setTextureUvSource( 0, 0 );
         mDatablock[1]->setTexture( 0 , texture1, NULL, 0xFFFF);       
         mDatablock[1]->setTextureUvSource( 0, 0 );

/*       ---------------- OR -------------------------------------------------------------
         mDatablock[0]->setTexture( 0 , "clouds.jpg" );
         mDatablock[0]->setTextureUvSource( 0, 0 );

         //mDatablock[1]->setTexture( 0 , "grass_1024.jpg" ); // OK size > clouds.jpg
         //mDatablock[1]->setTexture( 0 , "checker.png" );    // OK size < clouds.jpg
         mDatablock[1]->setTexture( 0 , "10points.png" );     // Not OK TEXTURE size == clouds.jpg
         mDatablock[1]->setTextureUvSource( 0, 0 );
*/


        for (int j=0;j<2;j++) {
            mRectangleItem[j] = mSceneManager->createItem( "MyPlane",
                                     Ogre::ResourceGroupManager::
                                     AUTODETECT_RESOURCE_GROUP_NAME,
                                     Ogre::SCENE_DYNAMIC );
            Ogre::SceneNode* mSceneNode = mSceneManager->getRootSceneNode( Ogre::SCENE_DYNAMIC )->
                        createChildSceneNode( Ogre::SCENE_DYNAMIC );
            mSceneNode->attachObject(mRectangleItem[j]);
            mSceneNode->scale( 0.4f, 0.4f, 1.0f );
            mSceneNode->setPosition( Ogre::Vector3(float(j)*30.0f, 0.0f, 0.0f ));
        }
        //mShaderHlmsListener = new MyShaderHlmsListener(mRectangleItem[0]->mRenderables[0], mRectangleItem[1]->mRenderables[0]);
        //static_cast<HlmsUnlit*>(hlmsManager->getHlms(Ogre::HLMS_UNLIT))->setListener(mShaderHlmsListener);

        mRectangleItem[0]->setDatablock(mDatablock[0]);
        mRectangleItem[1]->setDatablock(mDatablock[1]);

    }

The fragment/vertex shaders:

Code: Select all

#if 0
	***	hlms_uv_count0	2
	***	hlms_uv_count	1
	***	PsoBlendblock	0
	***	diffuse_map0_idx	0
	***	glsl	635204550
	***	uv_diffuse0	0
	***	out_uv_count	1
	***	hlms_high_quality	0
	***	num_array_textures	1
	***	PsoMacroblock	0
	***	alpha_test	0
	***	glsles	1070293233
	***	out_uv0_out_uv	0
	***	sampler_unit_slot_start	2
	***	diffuse_map0	1
	***	out_uv0_texture_matrix	0
	***	GL_ARB_shading_language_420pack	1
	***	hlms_alphablend	0
	***	num_textures	0
	***	hlms_shadow_uses_depth_texture	0
	***	diffuse_map0_array	1
	***	hlms_tangent	0
	***	hlms_bones_per_vertex	0
	***	out_uv0_tex_unit	0
	***	materials_per_buffer	1024
	***	hlms_skeleton	0
	***	out_uv0_source_uv	0
	***	syntax	635204550
	***	metal	-1698855755
	***	GL_ARB_base_instance	1
	***	diffuse_map	1
	***	array_texture_bind0	2
	***	GL3+	450
	***	hlms_render_depth_only	0
	***	hlms_qtangent	0
	***	out_uv_half_count0	2
	***	diffuse	0
	***	out_uv_half_count	1
	***	hlms_normal	0
	***	num_samplers	1
	***	hlsl	-334286542
	***	GL_ARB_texture_buffer_range	1
	DONE DUMPING PROPERTIES
	***	out_uv0_swizzle	xy
	DONE DUMPING PIECES
#endif

#version 430 core


    #extension GL_ARB_shading_language_420pack: require
    #define layout_constbuffer(x) layout( std140, x )

    #define bufferFetch texelFetch

#define float2 vec2
#define float3 vec3
#define float4 vec4

#define int2 ivec2
#define int3 ivec3
#define int4 ivec4

#define uint2 uvec2
#define uint3 uvec3
#define uint4 uvec4

#define float3x3 mat3
#define float4x4 mat4

#define mul( x, y ) ((x) * (y))
#define saturate(x) clamp( (x), 0.0, 1.0 )
#define lerp mix
#define INLINE
#define NO_INTERPOLATION_PREFIX flat
#define NO_INTERPOLATION_SUFFIX

#define finalDrawId drawId

#define outVs_Position gl_Position
#define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv.xy, lod )
#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) textureLod( tex, vec3( uv, arrayIdx ), lod )
#define OGRE_BufferFetch1( buffer, intLocation ) texelFetch( buffer, intLocation ).x



out gl_PerVertex
{
	vec4 gl_Position;

};

layout(std140) uniform;


mat4 UNPACK_MAT4( samplerBuffer matrixBuf, uint pixelIdx )
{
	vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) );
	vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) );
	vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) );
	vec4 row3 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 3u) );
    return mat4( row0, row1, row2, row3 );
}


in vec4 vertex;



in vec2 uv0;


	in uint drawId;





out block
{

	
		flat uint drawId;
				
			vec2 uv0;			

} outVs;


// START UNIFORM DECLARATION

//Uniforms that change per pass
layout_constbuffer(binding = 0) uniform PassBuffer
{
	
	//Vertex shader
	float4x4 viewProj[2];
				//Pixel Shader
	float4 invWindowSize;
	

} passBuf;


//Uniforms that change per Item/Entity
layout_constbuffer(binding = 2) uniform InstanceBuffer
{
	//.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 passBuf.viewProj[]. Only used
	//if hlms_identity_viewproj_dynamic is set.
	uvec4 worldMaterialIdx[4096];
} instance;

/*layout(binding = 0) */uniform samplerBuffer worldMatBuf;



// END UNIFORM DECLARATION


	


void main()
{

    
	
	
		mat4 worldViewProj;
		worldViewProj = UNPACK_MAT4( worldMatBuf, finalDrawId );
	


	gl_Position = vertex * worldViewProj;










	
		outVs.uv0.xy = uv0.xy;
	

	outVs.drawId = finalDrawId;



	
	



	
}

Code: Select all

#if 0
	***	hlms_uv_count0	2
	***	hlms_uv_count	1
	***	PsoBlendblock	0
	***	diffuse_map0_idx	0
	***	hlms_disable_stage	0
	***	glsl	635204550
	***	uv_diffuse0	0
	***	out_uv_count	1
	***	hlms_high_quality	0
	***	num_array_textures	1
	***	PsoMacroblock	0
	***	alpha_test	0
	***	glsles	1070293233
	***	out_uv0_out_uv	0
	***	sampler_unit_slot_start	2
	***	diffuse_map0	1
	***	out_uv0_texture_matrix	0
	***	GL_ARB_shading_language_420pack	1
	***	hlms_alphablend	0
	***	num_textures	0
	***	hlms_shadow_uses_depth_texture	0
	***	diffuse_map0_array	1
	***	hlms_tangent	0
	***	hlms_bones_per_vertex	0
	***	out_uv0_tex_unit	0
	***	materials_per_buffer	1024
	***	hlms_skeleton	0
	***	out_uv0_source_uv	0
	***	syntax	635204550
	***	metal	-1698855755
	***	GL_ARB_base_instance	1
	***	diffuse_map	1
	***	array_texture_bind0	2
	***	GL3+	450
	***	hlms_render_depth_only	0
	***	hlms_qtangent	0
	***	out_uv_half_count0	2
	***	diffuse	0
	***	out_uv_half_count	1
	***	hlms_normal	0
	***	num_samplers	1
	***	hlsl	-334286542
	***	GL_ARB_texture_buffer_range	1
	DONE DUMPING PROPERTIES
	***	blend_mode_idx3	@insertpiece( NormalNonPremul)
	***	uv_diffuse_swizzle0	xy
	***	blend_mode_idx11	@insertpiece( NormalNonPremul)
	***	blend_mode_idx2	@insertpiece( NormalNonPremul)
	***	blend_mode_idx14	@insertpiece( NormalNonPremul)
	***	blend_mode_idx5	@insertpiece( NormalNonPremul)
	***	blend_mode_idx8	@insertpiece( NormalNonPremul)
	***	blend_mode_idx10	@insertpiece( NormalNonPremul)
	***	blend_mode_idx9	@insertpiece( NormalNonPremul)
	***	blend_mode_idx15	@insertpiece( NormalNonPremul)
	***	blend_mode_idx6	@insertpiece( NormalNonPremul)
	***	blend_mode_idx7	@insertpiece( NormalNonPremul)
	***	blend_mode_idx1	@insertpiece( NormalNonPremul)
	***	blend_mode_idx0	@insertpiece( NormalNonPremul)
	***	blend_mode_idx12	@insertpiece( NormalNonPremul)
	***	blend_mode_idx4	@insertpiece( NormalNonPremul)
	***	blend_mode_idx13	@insertpiece( NormalNonPremul)
	***	diffuse_map0_tex_swizzle	xyzw
	DONE DUMPING PIECES
#endif

#version 430 core


    #extension GL_ARB_shading_language_420pack: require
    #define layout_constbuffer(x) layout( std140, x )

    #define bufferFetch texelFetch

#define float2 vec2
#define float3 vec3
#define float4 vec4

#define int2 ivec2
#define int3 ivec3
#define int4 ivec4

#define uint2 uvec2
#define uint3 uvec3
#define uint4 uvec4

#define float3x3 mat3
#define float4x4 mat4

#define mul( x, y ) ((x) * (y))
#define saturate(x) clamp( (x), 0.0, 1.0 )
#define lerp mix
#define INLINE
#define NO_INTERPOLATION_PREFIX flat
#define NO_INTERPOLATION_SUFFIX

#define finalDrawId drawId

#define outVs_Position gl_Position
#define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv.xy, lod )
#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) textureLod( tex, vec3( uv, arrayIdx ), lod )
#define OGRE_BufferFetch1( buffer, intLocation ) texelFetch( buffer, intLocation ).x



layout(std140) uniform;
#define FRAG_COLOR		0




layout(location = FRAG_COLOR, index = 0) out vec4 outColour;


// START UNIFORM DECLARATION



struct Material
{
	vec4 alpha_test_threshold;
	vec4 diffuse;

	uvec4 indices0_3;
	uvec4 indices4_7;

	
};

layout_constbuffer(binding = 1) uniform MaterialBuf
{
	Material m[1024];
} materialArray;


//Uniforms that change per Item/Entity
layout_constbuffer(binding = 2) uniform InstanceBuffer
{
	//.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 passBuf.viewProj[]. Only used
	//if hlms_identity_viewproj_dynamic is set.
	uvec4 worldMaterialIdx[4096];
} instance;



// END UNIFORM DECLARATION

in block
{

	
		flat uint drawId;
				
			vec2 uv0;			

} inPs;



uniform sampler2DArray	textureMapsArray[1];




Material material;

void main()
{
	

	uint materialId	= instance.worldMaterialIdx[inPs.drawId].x;
	material = materialArray.m[materialId];

	




	//Load base image
	outColour = texture( textureMapsArray[0], vec3( inPs.uv0.xy, material.indices0_3.x & 0x0000FFFFu ) ).xyzw;





	
	


	



	
}


1 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3611
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 93
Contact:

Re: v2-2 HlmsUnlit AutomaticBatching

Post by dark_sylinc » Thu Jun 14, 2018 10:55 pm

Bug fixed. Thanks for the very good repro.
0 x

dermont
Orc Shaman
Posts: 755
Joined: Thu Dec 09, 2004 2:51 am
x 4

Re: v2-2 HlmsUnlit AutomaticBatching

Post by dermont » Fri Jun 15, 2018 6:37 am

Thanks.
0 x

Post Reply