Jump to content

OpenGl Terrain blend seams


koros

Recommended Posts

Terrain texture seams at blend edges with 2+ texture layers only in OpenGl.


Occurs when using any detail texture and seems independent of square size, resolutions, base texture size etc.


Only tested on AMD Radeon HD7700 + updated drivers.

Win 8.1

Tested with Torque v3.6.3 and 3.7 Release


Solution / workaround: In game\shaders\common\terrain\terrain.glsl

uv += 0.00195;

vec2 xy = floor( uv );



Anyone else see this issue?

Can anyone test this on Nvidia? :)


Did a search here and on Github, sorry if I missed an existing issue.

I did see something about new terrain blending perhaps soon, not sure how this might affect it.



Opened a Github issue here

https://github.com/GarageGames/Torque3D/issues/1318


http://i1260.photobucket.com/albums/ii567/aurobooth/seam3_zpsu1ggaooc.png


http://i1260.photobucket.com/albums/ii567/aurobooth/seam4_zpsimzg5c2l.png


http://i1260.photobucket.com/albums/ii567/aurobooth/seam2_zpsebmdl4pg.png

Link to comment
Share on other sites

Normal terrain material?

Do you mean D3D9? or just texture layers without a detail texture?

No seams show without at least one detail texture.

Seams don't show at all under D3D9.


The pics show the result when running under OpenGl and using at least one detail texture.


Just for clarity the pics are before adding the offset to uv in game\shaders\common\terrain\terrain.glsl

uv += 0.00195;


Hope this helps

:)

Link to comment
Share on other sites

Also just want to make sure that this is not perceived as a complaint!


Torque3D and the work everyone has done rocks!

PBR, OpenGl, Linux and all the bug fixes... thats why I am checking it out again.


Just trying to do my part.


Cheers

:)

Link to comment
Share on other sites

That's what was done.


Base+detail, Another texture+detail etc.


When using a detail texture with any of the layers the seams show under OpenGl.

Adding the offset I mentioned eliminates the seams, at least for my card.


Please try it, especially if you have an Nvidia card, and post pics of your results. :)


Cheers

Link to comment
Share on other sites

The point is just that this does not look like a terrain material with detail texture to me, it is just a base texture with nothing else.

I can remember another guy having problems with the terrain, but the issue was just that he used wrong settings in the terrain and materials.

Link to comment
Share on other sites

It is a terrain with a base texture + detail texture and a second texture + detail texture, all stock Torque3D textures.


It is zoomed in to show the seams and it looks blurry.


The seams go away with the offset added to uv in terrain.glsl


A few more pics might help clarify this. I should probably do a video.


OpenGl

http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamsFourmPost2_zpsfb7kg6qk.png


http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamForumPost3_zpsp3ymafgq.png


http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamsFourmPost4_zpstvkxlly1.png


http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamsForumPost5_zps50kuntlp.png


D3D9

http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamsFourmPost6_zpsednwtzwu.png


http://i1260.photobucket.com/albums/ii567/aurobooth/NewSeamsFourmPost7_zpsgzm4mqjy.png




Terrain.glsl

//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------


float calcBlend( float texId, vec2 layerCoord, float layerSize, vec4 layerSample )
{
  // This is here to disable the blend if none of 
  // the neighbors equal the current id.
  //
  // We depend on the input layer samples being 
  // rounded to the correct integer ids.
  //
  vec4 diff = clamp( abs( layerSample - texId ), 0.0, 1.0 );
  float noBlend = float(any( bvec4(1 - diff) ));

  // match the current texture id.
  vec4 factors = vec4(0);
  for(int i = 0; i < 4; i++)
     factors[i] = (layerSample[i] == texId) ? 1 : 0; // workaround for Intel

  // This is a custom bilinear filter.

  vec2 uv = layerCoord * layerSize;
  //uv += 0.00195;          //Adding this offset = 0.00195  eliminate seams 
  vec2 xy = floor( uv );
  vec2 ratio = uv - xy;
  vec2 opposite = 1 - ratio;

  float blend = ( factors.b * opposite.x + factors.g * ratio.x ) * opposite.y +
                ( factors.r * opposite.x + factors.a * ratio.x ) * ratio.y;

  return noBlend * blend;
}

 



If it was just settings that would be great!

Any way you could pull down the 3.7 release zip and confirm this? https://github.com/GarageGames/Torque3D/archive/release-3.7.zip

It would be helpful if you could verify this with an OpenGl project and post some pics!


Hope this helps clarify a bit.

Appreciate the help.


Cheers

:D

Link to comment
Share on other sites

I have a Linux version with openGL and it does not have the seams, but the terrain textures are all wrong there also but a different issue.

But I cannot help you there, I don't understand much of this.

 

No problem. :)


It's solved for me actually. :D

Guessing it's an issue, precision maybe, at least on my OpenGl implementation, with floor().

Took me longer than it should have to find it but it was a good intro course on Torque3D for me and a bit of a refresher on glsl.


Maybe while I'm here I'll fire up a vm and install some flavor of linux.

Crossplatform is part of what caught my eye when I was checking out Torque3D again and I want linux too :)

Link to comment
Share on other sites

There are bound to be little tweaks like this that come to light - OpenGL was dropped a while back and is just now making its way back in. And in that gap the terrain system changed - twice.


It's probably going to come down to little fiddling differences between drivers, but I hope not.

Link to comment
Share on other sites

There are bound to be little tweaks like this that come to light - OpenGL was dropped a while back and is just now making its way back in. And in that gap the terrain system changed - twice.


It's probably going to come down to little fiddling differences between drivers, but I hope not.

 

/agree


Unity has a 200+ page bug list, UE4 has issues and I don't mind getting my hands dirty for Torque3D.


Seams are solved for my project though. OpenGl works great for me on Win8.1. Can't wait to fire up a vm and test Linux.

The seams were the only thing that cropped up and I finally fixed that. :D

I am happy as long as I can craft a solution or workaround for an issue.


Whether the uv offset is a solution or just a workaround, that's for the real devs here to decide :D

Link to comment
Share on other sites

It's a good catch, anyway - T3D has been run on Mac and a few flavors of Ubuntu and this is the first I've heard of this issue since it was fixed in the DirectX version. I suppose my point was that it is important to compare detailed notes between cases so someone can eventually track down the cause and the final solution (even if the final solution is just the uv tweak).

Link to comment
Share on other sites

... I suppose my point was that it is important to compare detailed notes between cases so someone can eventually track down the cause and the final solution (even if the final solution is just the uv tweak).

 

Absolutely.


The crew here is obviously working hard and I plan to help where I can with my limited Torque skills.


Appreciate the feedback too!


:D

Link to comment
Share on other sites

  • 3 months later...

I'd love to be able to claim I derived it but then I had no idea how Torque textured the terrain.


Spent some time playing with shader gen locked down and just squeezing various values into ranges in the shaders,

coloring sections, using discard until I made some sense of it. Noticed that number along the way.


Looking for my notes, been a while.


Stop laughing! :D

Link to comment
Share on other sites

Mucked with asst. stuff in generated pixel shaders where the terrain detail blending was being done. Playing with tex coords etc.


Some of the files

14333febc477acdf_P.glsl

blendP.glsl

terrain.glsl




Doing stuff like this to visualize the lines


if( (detailBlend0 < 1.0) && (detailBlend1 < 1.0) )

{...}


or this


//auro uv values range: 64 to 128

//if( ( (uv.x <65.0) || (uv.y <65.0) ) || ( (uv.x >127.0) || (uv.y >127.0) ) ) // square perimeter

//{

//discard;

//}



I was just getting started with Torque and has been years since I touched a shader. :oops:

Link to comment
Share on other sites

Thing to remember about shaders, and particularly uvs, is 9999999.99999% of the math is gonna be in percentages, so that 0.00195 may be right when applied to the default tiling setup, but odds are it'll need adjusting for different scales. Make sense?

 

Yep! Thx :)


Just so I don't think I'm nuts here are you able to reproduce this?

Link to comment
Share on other sites

Trust me, at that point you're just going "crap, what *else* might crop up for potential customers for my games am I'm missing" :P.


So, fiddling with either of http://i.imgur.com/dRyPJIc.jpg have any impact on your end?

 

I honestly tried every combo of settings and formats for the textures I could think of including using alpha decals.


It could very well be that it's a single card/driver combo and in the proud tradition of broken clocks and blind squirrels I stumbled across the solution for my card.


If no one else can repro then it's not really an issue :D


I'll revisit this when I get an Nvidia card.


Sorry for the wild goose chase. :oops:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...