xamarin / urho

Code to integrate with the Urho3D engine
Other
462 stars 122 forks source link

Xamarin.Forms - Custom shader not working on iOS only #347

Open TimLariviere opened 6 years ago

TimLariviere commented 6 years ago

Hi, Not sure if this the correct place to ask.

In a Xamarin.Forms app, I made a custom shader to draw the Earth that combines multiple textures (diffuse, specular, normals, clouds and night).

This is a direct port from HLSL to GLSL (didn't know any of them before, so port might not be great) of the sample https://github.com/xamarin/urho-samples/tree/master/HoloLens/02_HelloWorldAdvanced

This shader works great on MacOS (Urho Editor) and Android, but on iOS normals are wrong.

Expected: (rendering from Android)

expected

Actual: (rendering from iOS)

actual

Here's the shader: https://github.com/TimLariviere/ElmishPlanets/blob/8b1fefaa248100a46c087675f80599bcc79c611a/ElmishPlanets.iOS/Resources/Data/Shaders/GLSL/CustomLitSolid.glsl

(For reference, the HLSL version: https://github.com/xamarin/urho-samples/blob/master/HoloLens/02_HelloWorldAdvanced/Data/Shaders/HLSL/CustomLitSolid.hlsl)

I think this is because this line returns 0 and so turns the "day" texture to black all the time.

finalColor *= clamp(dot(normal, cLightDirPS), 0.0, 1.0);

From what I've tried, the function GetWorldTangent seems to return a bad tangent on iOS only. Any idea what could be wrong and how to fix it?

Thanks

TimLariviere commented 6 years ago

I found that if I invert the X axis of the normal, it works.

normal = vec3(-normal.x, normal.y, normal.z);