-
Notifications
You must be signed in to change notification settings - Fork 433
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
openfl_TextureCoordv not returning correct values in ShaderFilters #2181
Comments
Did you get around to testing this with pure OpenFL? Shaders are more of an OpenFL than a Flixel feature, so Flixel doesn't really control the value of |
I did test in OpenFL and it worked, but I'm not sure my test was good. I'm having trouble finding the equivalent of the HaxeFlixel game and camera object in OpenFL. I think my OpenFL test was the equivalent of a sprite shader in Haxeflixel which is working like expected. I was going to track back the HaxeFlixel objects back and try to figure out what the OpenFL equivalent is. |
Maybe @jgranick has an idea what this could be. |
I think this is normal behaviour in OpenGL.
If you need to know in-frame coordinates, you can pass your own vec4 uniform (hmm... or rather an attribute is wanted?) with rect of the frame currently shown. Maybe |
@starry-abyss I think you are correct :) I'm still learning the whole "programmable graphics pipeline" thing. I think the behavior makes a ton of sense in a 3D world, so you get some unexpected behavior when using it in 2D.
That's what I ended up doing to work as a workaround. I added var rect = s.frame.uv;
shader.subTexturePosition.value = [rect.x, rect.y, rect.width, rect.height]; to my update code and writing a function in my shader uniform vec4 subTexturePosition;
vec2 subtextureCoord(vec2 coord)
{
float width = subTexturePosition.z - subTexturePosition.x;
float height = subTexturePosition.a - subTexturePosition.y;
float newX = (coord.x - subTexturePosition.x) / width;
float newY = (coord.y - subTexturePosition.y) / height;
return vec2(newX, newY);
}
void main()
{
vec2 subcoord = subtextureCoord(openfl_TextureCoordv);
if (subcoord.y > 0.5)
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
else
gl_FragColor =vec4(0.0,0.0,1.0,1.0);
} and it is working as expected. I don't think this will work when I'm trying to use a texture atlas with any rotated sprites though. That could get complicated, but Flixel obviously is handling this currently because the sprites animate correctly. I would think that if I have a 2D animated sprite it would be nice to have the shader values be only for the frame I am currently displaying, but I understand why it is not. I'm going to close this issue since it isn't an error (it just isn't doing what I expect). There is a definite error with the Camera filter when scrolling but I captured that in a different issue (#2194) |
Code snippet reproducing the issue:
Shader:
Playstate:
Observed behavior:
![image](https://user-images.githubusercontent.com/5286906/47197888-1e4fac00-d337-11e8-9df5-0627e9a8d005.png)
When calling openfl_TextureCoordv.x the left side of the screen is 0, but the right side of the screen is not 1. It resolves to something like .6 instead. openfl_TextureCoordv.y also has problems. The bottom half of the window should be red, but instead openfl_TextureCoordv.y > 0.5 is true about 10% of the way down.
Also, if you wait a few seconds or click on the screen, it will change by itself:
![image](https://user-images.githubusercontent.com/5286906/47198063-1fcda400-d338-11e8-8e0b-073f2d0ce940.png)
This is closer to the correct location, but still wrong.
If the shader is applied directly to a sprite it behaves correctly.
![image](https://user-images.githubusercontent.com/5286906/47198085-4390ea00-d338-11e8-8737-f938ec5e7a20.png)
I've tested in Chrome, Internet Explorer and Edge on the HTML5 target, and the Windows CPP target and they all have the same behavior. You can see a sample project here: http://codingadventure.net/html5/WeirdShader/
Expected behavior:
The bottom half of the screen should be red while the top half should be blue. It should not change.
The text was updated successfully, but these errors were encountered: