float1 VES_TEXTURE_COORDINATES shader error Topic is solved

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


yubinyyy
Gnoblar
Posts: 2
Joined: Thu Oct 31, 2024 2:26 pm

float1 VES_TEXTURE_COORDINATES shader error

Post by yubinyyy »

Hello everyone!I use “Sample V2 mesh” demo to load a V1mesh(I have forgotten the source, but I have the impression that Ogre 1.18 is available).this V1mesh have two TEXTURE_COORDINATES,one of type is float1.this is shader.

Code: Select all

#version 430 core
#extension GL_ARB_shading_language_420pack: require

out gl_PerVertex
{
	vec4 gl_Position;
};

layout(std140) uniform;

struct ShadowReceiverData
{
	mat4 texViewProj;
	vec2 shadowDepthRange;
	float normalOffsetBias;
	float padding;
	vec4 invShadowMapSize;
};

struct Light
{
	vec4 position;	
	vec4 diffuse;		
	vec3 specular;
};

struct AreaLight
{
	vec4 position;	
	vec4 diffuse;		
	vec4 specular;	
	vec4 attenuation;	
	vec4 direction;
	vec4 tangent;
	vec4 doubleSided;						
};
struct AreaLtcLight
{
	vec4 position;	
	vec4 diffuse;			
	vec4 specular;		
	vec4 points[4];							
};

layout( std140, binding = 0 ) uniform PassBuffer
{
	mat4 viewProj;
	mat4 view;

mat3 invViewMatCubemap;

vec4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps;

vec4 aspectRatio_planarReflNumMips_unused2;

vec2 invWindowRes;
vec2 windowResolution;
Light lights[1];		

}
passBuf;

vec3 xAxis( vec4 qQuat )
{
	float fTy  = 2.0 * qQuat.y;
	float fTz  = 2.0 * qQuat.z;
	float fTwy = fTy * qQuat.w;
	float fTwz = fTz * qQuat.w;
	float fTxy = fTy * qQuat.x;
	float fTxz = fTz * qQuat.x;
	float fTyy = fTy * qQuat.y;
	float fTzz = fTz * qQuat.z;
	return vec3( 1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy );
	}		
vec3 getNormalOffsetBias( vec3 worldNormal, vec3 viewSpaceNormal,
											   vec3 lightDir, float shadowMapTexSize,
											   float depthRange, float normalOffsetBias
											   )
{
	float tmpNdotL = clamp( (dot( lightDir.xyz, vec3( viewSpaceNormal.xyz ) )), 0.0, 1.0 );		
	return ( ( 1.0f - tmpNdotL ) * normalOffsetBias * vec3( worldNormal.xyz ) * shadowMapTexSize );
}
		
vec3 getNormalOffsetBias( vec3 worldNormal, vec3 viewSpaceNormal,
											   vec3 lightDir, float shadowMapTexSize,
											   float depthRange, float normalOffsetBias
														   , vec2 minUV, vec2 maxUV )
{
	float tmpNdotL = clamp( (dot( lightDir.xyz, vec3( viewSpaceNormal.xyz ) )), 0.0, 1.0 );
	shadowMapTexSize /= maxUV.x - minUV.x;
	return ( ( 1.0f - tmpNdotL ) * normalOffsetBias * vec3( worldNormal.xyz ) * shadowMapTexSize );
}

in vec4 vertex;
in vec4 qtangent;
in vec2 uv0;
in vec1 uv1;
in uint drawId;
out block
{

flat uint drawId;

vec3 pos;
vec3 normal;
						
vec2 uv0;
float1 uv1;
} outVs;

layout(std430, binding = 0) readonly restrict buffer _worldMatBuf { vec4 worldMatBuf[]; };

void main()
{
		const vec4 qTangent = normalize( qtangent );
		vec3 inputNormal = xAxis( qTangent );

	mat3x4 worldMat = mat3x4( worldMatBuf[(drawId << 1u) << 2u], worldMatBuf[((drawId << 1u) << 2u)+1u], worldMatBuf[((drawId << 1u) << 2u)+2u] );
	
	mat4 worldView = mat4( worldMatBuf[((drawId << 1u) + 1u) << 2u], worldMatBuf[(((drawId << 1u) + 1u) << 2u)+1u], worldMatBuf[(((drawId << 1u) + 1u) << 2u)+2u], worldMatBuf[(((drawId << 1u) + 1u) << 2u)+3u] );
	vec4 worldPos = vec4( ((vertex) * (worldMat)).xyz, 1.0f );
	outVs.pos		= ((vertex) * (worldView)).xyz;
	mat3 worldMat3x3 = mat3( worldView );
	outVs.normal = ((inputNormal) * (worldMat3x3));
	gl_Position = ((worldPos) * (passBuf.viewProj));
	vec3 normalOffsetBias = vec3( 0, 0, 0 );
	outVs.uv0 = uv0;
	outVs.uv1 = uv1;
	outVs.drawId = drawId;
}

error log is
": GLSL compile log: 100000003VertexShader_vs
: error C0000: syntax error, unexpected identifier, expecting '{' at token "uv1" (in vec1 uv1;)
: error C7506: OpenGL does not define the global type float1 (float1 uv1;)
: error C1503: undefined variable "uv1" (outVs.uv1 = uv1;)
"
Dose Ogre-Next not support float1 TEXTURE_COORDINATES?
I tried to fix it.So I add some code in calculateHashForV2.if itElements is VES_TEXTURE_COORDINATES and mType is VET_FLOAT1 then skip.

Code: Select all

uint16 Hlms::calculateHashForV2( Renderable *renderable )
    {
        // TODO: Account LOD
        VertexArrayObject *vao = renderable->getVaos( VpNormal )[0];
        const VertexBufferPackedVec &vertexBuffers = vao->getVertexBuffers();

    uint numTexCoords = 0;
    uint16 semIndex[VES_COUNT];
    memset( semIndex, 0, sizeof( semIndex ) );
    VertexBufferPackedVec::const_iterator itor = vertexBuffers.begin();
    VertexBufferPackedVec::const_iterator endt = vertexBuffers.end();

    while( itor != endt )
    {
        const VertexElement2Vec &vertexElements = ( *itor )->getVertexElements();
        VertexElement2Vec::const_iterator itElements = vertexElements.begin();
        VertexElement2Vec::const_iterator enElements = vertexElements.end();

        while( itElements != enElements )
        {
            if( itElements->mSemantic == VES_TEXTURE_COORDINATES && itElements->mType == VET_FLOAT1 )
            {
                ++itElements;
                continue;
            }
            calculateHashForSemantic( itElements->mSemantic, itElements->mType,
                                      semIndex[itElements->mSemantic - 1]++, numTexCoords );
            ++itElements;
        }

        ++itor;
    }

    // We do not allow LODs with different operation types or vertex layouts
    setProperty( kNoTid, HlmsPsoProp::InputLayoutId, vao->getInputLayoutId() );

    return static_cast<uint16>( numTexCoords );
}

But it doesn't seem like a good idea, is there any other way?

jwwalker
Goblin
Posts: 285
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 21

Re: float1 VES_TEXTURE_COORDINATES shader error

Post by jwwalker »

Instead of vec1 and float1, just say float.

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

Re: float1 VES_TEXTURE_COORDINATES shader error

Post by dark_sylinc »

This is an OgreNext bug in shader generation. As a workaround you'll have to assign more than 1-component UVs. If memory consumption / bandwidth is an issue, you could make the first UV0 from float2 into float3; thus merging the two TEXTURE_COORDINATES into one.

Assigned a ticket.