Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLES 2 UV stretching / offset on iOS #39764

Closed
HEAVYPOLY opened this issue Jun 22, 2020 · 13 comments
Closed

GLES 2 UV stretching / offset on iOS #39764

HEAVYPOLY opened this issue Jun 22, 2020 · 13 comments

Comments

@HEAVYPOLY
Copy link
Contributor

HEAVYPOLY commented Jun 22, 2020

Godot version:
3.2.2 RC3
3.2.2 RC2

OS/device including version:
1st generation iPad Pro 9.7". iOS 13.5.1

Issue description:
on Mesh Instance with arraymesh, UVs are stretched and offset
I've tried with Batching turned off, as well as with the use half float precision option in project settings from #38318 and #39068 both don't change the outcome.

correct UVs, works on Windows, Android and Mac:
84718546-a7b0ea80-af2d-11ea-88a4-6ffa1f8af27d

Incorrect UVs, only happens on iOS
84718527-9e278280-af2d-11ea-9a71-106c8b6392c4

Steps to reproduce:
I've tried with a simpler project (just triangle meshinstance with arraymesh) and am not able to reproduce. But if I bring the same triangle meshinstance to my 'problematic project', the incorrect UVs happen
I've tried changing all project settings to match my working fresh project but haven't been able to find the settings that's breaking things.
Minimal reproduction project:
uv.shader
TestTriangle.gd

@HEAVYPOLY
Copy link
Contributor Author

Here are my project render settings:
[rendering]

quality/driver/driver_name="GLES2"
quality/intended_usage/framebuffer_allocation=0
quality/intended_usage/framebuffer_allocation.mobile=0
threads/thread_model=2
vram_compression/import_etc=true
quality/directional_shadow/size=1024
quality/directional_shadow/size.mobile=512
quality/shadow_atlas/size=512
quality/shadow_atlas/size.mobile=512
quality/reflections/texture_array_reflections=false
quality/reflections/high_quality_ggx=false
quality/shading/force_vertex_shading.mobile=false
quality/depth_prepass/enable=false
quality/filters/use_nearest_mipmap_filter=true
batching/options/use_batching=false
batching/options/use_batching_in_editor=false
gles2/compatibility/disable_half_float=true
limits/buffers/canvas_polygon_buffer_size_kb=2048
limits/buffers/canvas_polygon_index_buffer_size_kb=1024
quality/depth/hdr=false
quality/filters/anisotropic_filter_level=1
quality/2d/use_pixel_snap.mobile=false

@clayjohn
Copy link
Member

Can you check if this issue occurred in 3.1 or 3.2?

I have a feeling that it is just an issue with iOS that we haven't resolved similar to #38318 , but I would like to make sure it isn't a regression

@HEAVYPOLY
Copy link
Contributor Author

I'll check that. thanks.
Found another strange thing, when bringing the same test triangle from my working project to non working project, the triangle is squished about half in Y axis as well as UV's being squished

@HEAVYPOLY
Copy link
Contributor Author

GLES2 UV bug.zip

@HEAVYPOLY
Copy link
Contributor Author

Just tested with project saved from 3.2 stable, same result (UVs and triangle squished)

@HEAVYPOLY
Copy link
Contributor Author

HEAVYPOLY commented Jun 22, 2020

BTW this all works properly with GLES3 on iOS. Note the Black and white UV gradient on the triangle
Here is GLES3:
Screen Shot 2020-06-22 at 2 00 26 PM
GLES2:
Screen Shot 2020-06-22 at 1 59 20 PM

@clayjohn
Copy link
Member

Thanks for the additional info and the test project!

I don't have any apple devices to test on, so I can't be of much further help.

iOS is pretty difficult for us because of its closed nature (and high barrier to entry cost wise). Typically iOS issues take awhile to fix as very few contributors have iOS devices.

In the meantime, I suggest trying to export to iOS using GLES3 while using GLES2 for other platforms. Pretty much every apple device on the market supports GLES3 (from iPhone 4/iPad 2 and newer). In my experience, support for GLES3 has been much better on iOS devices than GLES2.

@HEAVYPOLY
Copy link
Contributor Author

Good to know, I'll do that for now. Thanks!

@lawnjelly
Copy link
Member

Also no idea what this is, but just on the off chance, try using the rendering/batching/uv_contract option with GLES2 batching. This has solved some UV precision bugs.

It isn't clear from your info and screenshots what you are doing btw, perhaps you are relying on some assumed knowledge of what your program does, so that makes it harder to guess what is going on. Also with your triangle example, I wasn't clear on what the correct and incorrect versions would look like.

@HEAVYPOLY
Copy link
Contributor Author

@lawnjelly I tried messing the uv_contract but didn't seem to have any effect. The triangle's uvs are (0,0) ,(0,1), (0,0) so there should be a 0 to 1 gradient across the face. (black to white). Same for the other strokes.

@naithar
Copy link
Contributor

naithar commented Jul 9, 2020

@HEAVYPOLY I wasn't been able to reproduce gradient issue with your sample project. Running it on iPhone XS I've got this:
IMAGE 2020-07-09 13:35:30
For iPhone 6 gradient was reverted, but still present.

When I switched sample code to use clockwise vertices like this:

verts.append(Vector2(-100,30))
verts.append(Vector2(0,-30))
verts.append(Vector2(100,30))
uvs.append(Vector2(0,0))
uvs.append(Vector2(0,1))
uvs.append(Vector2(1,0))

I've got this result on both devices, which was the same as editor's:
IMAGE 2020-07-09 13:37:26

I've also tried using indices, but without ordering vertices and uvs, I got the same incorrect result, which is kinda strange.

UPD:
It turns out that moving only verts.append(Vector2(0,-30)) up would fix this gradient for iPhone, but would break gradient on any other system

Using SurfaceTool to create a mesh also gave the same results on iOS - incorrect with default order of vertices and uvs and correct with vertices being ordered clockwise

@naithar
Copy link
Contributor

naithar commented Jul 9, 2020

This code:

var tmpMesh = Mesh.new()
var vertices = [Vector3(-100,30,0), Vector3(0,-30,0), Vector3(200,-30,0), Vector3(100,30,0)]
var UVs = [Vector2(1,1), Vector2(1,1), Vector2(1,1), Vector2(1,1)]
var indexes = [0, 1, 3, 3, 1, 2]
	
var mat = ShaderMaterial.new()
mat.shader = load('res://uv.shader')
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for i in indexes.size():
	st.add_index(indexes[i])
	
for v in vertices.size(): 
	st.add_uv(UVs[v])
	st.add_vertex(vertices[v])
	st.commit(tmpMesh)
meshinstance.mesh = tmpMesh
meshinstance.material = mat

With this shader:

shader_type canvas_item;

void fragment()
{
	COLOR.xy = UV;
}

On iOS resulted in a very strange results, while polygon was white in editor:
IMAGE 2020-07-09 15:50:44

UPD:
Well enabling compatibility/disable_half_float in Project Settings seems to be fixing this problem as well as previous problem that got fixed by reordering vertices.

@akien-mga
Copy link
Member

Well enabling compatibility/disable_half_float in Project Settings seems to be fixing this problem as well as previous problem that got fixed by reordering vertices.

Then this should also be fixed by #54229 (merged in 3.4 RC 2, though you can already use the disable_half_float setting in 3.3.x too).

@akien-mga akien-mga modified the milestones: 3.3, 3.4 Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants