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

Updated HLSL samplers to DirectX 10 syntax #166

Merged

Conversation

shadielhajj
Copy link
Collaborator

@shadielhajj shadielhajj commented Jul 15, 2024

Currently SAMPLER_TYPE is defined in HLSL as sampler2D, which is the obsolete DirectX 9 syntax from 2002.

This works fine with the old Unity Built-In render pipeline (BRP), which is itself deprecated.

However, it is not compatible with the newer URP and HDRP pipelines which are meant to supersede BRP. URP and HDRP use the Direct X 10 syntax (released in 2006).

Direct X 10 replaces the old sampler2D with Texture objects (eg. Texture2D) which also provide added benefits, like decoupling the texture object from the sampler state, querying size and max lod, etc...

Unreal also uses the DirectX 10 syntax exclusively.

This means texture-related functions in Lygia are currently unusable with Unity URP, Unity HDRP and Unreal.

I have updated the samplers to the DirectX 10 syntax in order to remedy this issue (which is also what has been done in the Lygia Unreal Examples repo).

I have defined a default sample state DEFAULT_SAMPLER_STATE defaultLinearClampSampler, which means SAMPLER_FNC(TEX, UV) still takes two arguments and no other change is required in Lygia.

The new syntax is perfectly compatible with Unity BRP, however the examples need to be slightly updated (sampler2D becomes Texture2D), I'll follow up with a PR of the Unity examples as soon as this one is merged.

@patriciogonzalezvivo
Copy link
Owner

What about backwards compatibility? It's possible to through macros to request the version number like https://github.com/patriciogonzalezvivo/lygia/blob/main/sampler.glsl#L9

@shadielhajj
Copy link
Collaborator Author

@patriciogonzalezvivo The new syntax is compatible with all Unity pipelines, so that shouldn't be an issue. I have amended using conditional macros anyway, just in case somebody prefers the old syntax for whichever reason.

@patriciogonzalezvivo patriciogonzalezvivo merged commit be4bd83 into patriciogonzalezvivo:main Jul 16, 2024
@patriciogonzalezvivo
Copy link
Owner

Thank you!!

@shadielhajj shadielhajj deleted the hlsl/sampler branch July 16, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants