openfl
openfl copied to clipboard
Shader system improvements and fixes.
Provides the following changes:
- Store the original values for the fragment/vertex header such that they can be accessed by child classes.
- Store the original values for the fragment/vertex body such that they can be accessed by child classes.
- Store the original values for the fragment/vertex source such that they can be accessed by child classes.
- Added a configurable
glVersion
annotation (and corresponding variables) which can be used to modify the GLSL version directive. The default value has been set to120
, which should resolve an issue on some platforms where theuniform
type is unavailable. - Added checks to
__processGLData
to ensure a variable exists before it is assigned via Reflection.- This resolves an issue caused by custom implementation of variables in child classes.
- Added caching to the field check to reduce calls to
Reflect.fields
, improving performance.
These changes were performed to support fixes for FlxRuntimeShader, as part of the pull request HaxeFlixel/flixel-addons#368. Making changes here prevents code duplication in FlxRuntimeShader, improving maintainability.
These changes have been tested on the Windows HXCPP platform.
Interesting. I was looking for a feature to change a CONST value at runtime. I think storing fragment body and header would be easier for me than parsing, diassembling an reassembling the whole shader. Some shaders need to use CONST in a for loop because non-constant values are forbidden, but different values can provide a better accuracy depending on what has been set in the uniform (e.g: Glow, Outline...). So it's looking great.
That being said, if you have only tested on Windows. This need to be tested in HL, MAC, Android, iOS and HTML5 before being merged.
Also can you provide details on your issue on "some platforms", which platforms are your talking about?
i tested it on mac and i can confirm it works on mac too
@MasterEric This pull request makes android to crash, I think is because of glVersion
you added, gl version is different in android btw
@MasterEric This pull request makes android to crash, I think is because of
glVersion
you added, gl version is different in android btw
what glversion should be put to use for android?
Idk the exact version
You have to find out, is your pull request anyway
the glsl version for android is #version 300 es how i found out is because of the flxFixedShader https://github.com/YoshiCrafter29/YoshiCrafterEngine/blob/45ddea338a211ff2d05b7d85a3a2c38bb8ab287f/source/FlxFixedShader.hx#L55
That version is wrong
Took a bit of time today to fast forward the branch, as well as implement a couple fixes.
Mainly, glVersion
is now a string, and the value defaults to 300 es
on Android as suggested.
Hopefully this works for people, I've been having reports that AMD Radeon cards are having issues specifically.
Dude, the default version by openfl is 100
If you put 300 es it will broke everything
If you put 300 es it will broke everything
*break
Btw, apply that for enscripted and ios too, they use gl es too
Marked this PR as draft pending further changes, including:
- Fixes for crashes when setting glVersion too high (built-in fragment headers need to be migrated).
- Thorough testing on desktop, web, and Android to ensure default values are widely compatible (since nobody can agree what the correct values are supposed to be).
- A
@:glExtensions
annotation to resolve issue #2601.
I've been doing some more investigation into what GLSL versions actually support what.
I was previously under the assumption that 120
implemented the uniform
keyword, and that not using this was the cause of the crashes some users have experienced while using shaders.
However, I had actually misread the specification. uniform
variables are available in all versions of GLSL, with 120
being the first version to support shader initialization of uniform
variables, like so:
// This is valid in all versions of GLSL
uniform float iTime;
// This is only valid in GLSL 120 and above
uniform float iTime = 0.0;
120
is NOT actually necessary to run most shaders, and many of the shaders which are not compatible can easily be converted by performing the initialization outside of GLSL (i.e. in Haxe code). 100
is sufficient to run most shaders, and furthermore appears to be widely supported. In the event I find a use case or platform in which 100
is not supported, compile-time macros can be used to modify the default shader version.
If a specific shader needs a feature introduced in a later language version, they can increase the language version, keeping in mind that most platforms have a very limited range of support (and your only solid choices are 100
and 300 es
). It is recommended that you rewrite the shader if you need a language feature unavailable in 100
or 300 es
.
300 es
removes texture2D and some things that I forgot, 100 is the default version that openfl/lime uses because it still have these futures.
As i see in the commit, now it should work.
The feature was not removed. 300 es
removes texture2D
but replaces it with texture
.
By modifying the macro that builds the shaders, I have successfully tested and confirmed support for all GLSL versions on Windows Desktop.
100
is still a good default version to work with.
Btw, 300 es
isn't the only version that needs texture2D to be replaced there's 310 es
and 320 es
.
Btw,
300 es
isn't the only version that needs texture2D to be replaced there's310 es
and320 es
.
All versions after 300 es
require this replacement.
i get an error trying to build an fnf game for mac and here is the error:
actually nvm i fixed it
This PR is now ready and fully tested on a variety of platforms.
See more at my test workbench here: https://github.com/MasterEric/Flixel-GalaxyShaderWorkbench
EDIT: Make sure to use the build instructions to ensure the correct library versions are installed before testing.
With help from @JonnycatMeow I was able to test the workbench on their Mac platform. Notably, their version of OpenGL ONLY supports 110
and 120
. This may be significant for those looking to resolve compatibility issues.
bro can someone merge this please!!!!
The Sound modification seems pretty handy for streaming although is it on purpose that the samplerate is locked at 44100?
The Sound modification seems pretty handy for streaming although is it on purpose that the samplerate is locked at 44100?
This pull request is not related to sound.
This pull request is not related to sound.
Look on the Commits tab of this PR. You merged in a SampleDataEvent
commit, and maybe some other stuff. I mentioned this to you on Discord, but you never responded.
This pull request is not related to sound.
Look on the Commits tab of this PR. You merged in a
SampleDataEvent
commit, and maybe some other stuff. I mentioned this to you on Discord, but you never responded.
Thank you for informing me of this. I will re-review my branch, make appropriate fixes, and merge them ASAP so that review can continue.
It appears that changes related to other pull requests (#2534 and #2515) accidentally got included in the working branch for this PR. Those changes have now been removed, and the PR has additionally been fast-forwarded to match the target branch.
Please inform me here of any additional review changes.