What is simplest way to flip uv coordinates?

Problems building or running the engine, queries about how to use features etc.
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

What is simplest way to flip uv coordinates?

Post by slapin »

Hi, all!
How can I flip UVs by Y when Vulkan is used and not flip
when OpenGL is used? Need to support both.

Ogre Version: master branch
Operating System: Ubuntu 22.04
Render System: GL ES 2.0, Vulkan

rpgplayerrobin
Orc Shaman
Posts: 752
Joined: Wed Mar 18, 2009 3:03 am
x 421

Re: What is simplest way to flip uv coordinates?

Post by rpgplayerrobin »

For my water I use reflection, and then I do need to flip the projection coords between OpenGL and Direct3D, maybe this will also help in your scenario?

I use this in the shader material:

Code: Select all

default_params
{
	param_named_auto renderTargetFlipping render_target_flipping
}

Then in the hlsl code I use this:

Code: Select all

float renderTargetFlipping;

float4 main_ps( float4 projectionCoord : TEXCOORD0 ) : COLOR0
{
	float2 projectionUV = projectionCoord.xy / projectionCoord.w;
	projectionUV.y = (1.0 - saturate(renderTargetFlipping)) + renderTargetFlipping * projectionUV.y;

Otherwise, you could simply add your own parameter and then just set it in code:

Code: Select all

param_named flipUVY float 1.0

You could also use a shared parameter for it, in the shader material:

Code: Select all

shared_params_ref FlipParams

In C++:

Code: Select all

GpuSharedParametersPtr tmpGpuSharedParameters = GpuProgramManager::getSingleton().createSharedParameters("FlipParams");
tmpGpuSharedParameters->addConstantDefinition("flipUVY", GCT_FLOAT);
if(IsUsingVulkan)
	tmpGpuSharedParameters->setNamedConstant("flipUVY", 1.0f);
else
	tmpGpuSharedParameters->setNamedConstant("flipUVY", -1.0f);

And then simply just add it normally in the shader itself:

Code: Select all

float flipUVY;
slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: What is simplest way to flip uv coordinates?

Post by slapin »

Thanks a lot!

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: What is simplest way to flip uv coordinates?

Post by slapin »

looks like renderTargetFlipping works in reverse for me :)

paroj
OGRE Team Member
OGRE Team Member
Posts: 2204
Joined: Sun Mar 30, 2014 2:51 pm
x 1188

Re: What is simplest way to flip uv coordinates?

Post by paroj »

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 146
Joined: Fri May 23, 2025 5:04 pm
x 5

Re: What is simplest way to flip uv coordinates?

Post by slapin »

ifdef is good too, thanks!