AwesomesauceLabs / piglet-viewer

Demo viewer app for Piglet glTF Importer
MIT License
6 stars 4 forks source link

Support texture rotation in KHR_texture_transform #6

Open edwardbosz opened 1 year ago

edwardbosz commented 1 year ago

Do you have plans to support KHR_texture_transform's uv rotation in Piglet Viewer?

Thanks

benvvalk commented 1 year ago

Hi @edwardbosz :-)

(I received your private message too btw, but I prefer to discuss things in public when possible.)

I would like to support UV rotation, but to be honest it isn't a high priority. (You are the first person to ask for it since Piglet was released about 3 years ago!)

I'm a one-man operation and there are some other frequently requested features that I would probably try to address first (e.g. glTF export, avatar support). Also, I'm in the middle of another challenging Piglet-related project that I'm keeping a secret for now (for competitive reasons).

That said, I don't think implementing UV rotation would be too difficult. It would require a non-trivial amount of work/experiementation, because Unity lacks a built-in UV rotation function that is analogous to Material.SetTextureScale and Material.SetTextureOffset. (Piglet implements the scale/offset aspects of KHR_texture_transform by calling Material.SetTextureScale/Material.SetTextureOffset in the LoadMaterial method, found in Assets/Piglet/Scripts/Importer/GltfImporter.cs.)

I looked a bit online, and the general consensus is that texture rotation is best implemented on the shader side (as opposed to the C# code). This Unity Forum thread has some good starting points for an implementation: https://forum.unity.com/threads/rotate-texture.19018/. (The Piglet shader files are located under Assets/Piglet/Resources/Shaders/{Standard,URP} for the built-in render pipeline and Universal Render Pipeline, respectively.)

If you want to try implementing UV rotation yourself, I would happy to provide guidance and answer questions about the code.

benvvalk commented 1 year ago

Oops, I was just looking through the forum thread I linked above (https://forum.unity.com/threads/rotate-texture.19018/), and I noticed they're using a material.SetMatrix method that I wasn't aware of.

It looks like Material.SetMatrix could be used to replace my current calls to Material.SetTextureScale/Material.SetTextureOffset and properly support scale/offset/rotation all at the same time. So I was wrong -- it should be possible to implement UV rotation on the C# side, without needing to write/modify the shader code.

I will put this on my TODO list and give you a heads up if I start working on it. (But like I said, currently I'm focused on other things.)

edwardbosz commented 1 year ago

Thanks Ben.


De: Ben Vandervalk @.> Enviado: quarta-feira, 19 de outubro de 2022 16:28 Para: AwesomesauceLabs/piglet-viewer @.> Cc: Edward Boszczowski @.>; Mention @.> Assunto: Re: [AwesomesauceLabs/piglet-viewer] Support texture rotation in KHR_texture_transform (Issue #6)

Oops, I was just looking through the forum thread I linked above (https://forum.unity.com/threads/rotate-texture.19018/), and I noticed they're using a material.SetMatrixhttps://docs.unity3d.com/ScriptReference/Material.SetMatrix.html method that I wasn't aware of.

It looks like Material.SetMatrix could be used to replace my current calls to Material.SetTextureScale/Material.SetTextureOffset and properly support scale/offset/rotation all at the same time. So I was wrong -- it should be possible to implement UV rotation on the C# side, without needing to write/modify the shader code.

I will put this on my TODO list and give you a heads up if I start working on it. (But like I said, currently I'm focused on other things.)

— Reply to this email directly, view it on GitHubhttps://github.com/AwesomesauceLabs/piglet-viewer/issues/6#issuecomment-1284474924, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A3WP5XHQR2UGRHTVWPPATGDWEBDVDANCNFSM6AAAAAARJKD3XA. You are receiving this because you were mentioned.Message ID: @.***>