urho icon indicating copy to clipboard operation
urho copied to clipboard

Xamarin.Forms - Custom shader not working on iOS only

Open TimLariviere opened this issue 5 years ago • 1 comments

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 avatar Sep 03 '18 17:09 TimLariviere

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

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

TimLariviere avatar Sep 04 '18 09:09 TimLariviere