Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] uniform agk_spritesize in fragment shader

Author
Message
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 28th May 2020 19:07 Edited at: 28th May 2020 19:08
I have a problem with the agk_spritesize uniform in a shader:

For example, if I create sprites with the following code:




And I set my fragment shader ("fshader-01.fs"):



My sprites end up like this:


The fragment shader makes it so that "65%" of the length of the sprite is red, and the rest is green.

What I want to get, is to specify a length on the sprite in real coordinates (not uv space). So I thought if I added the uniform agk_spritesize, I can use the x value of this vector.
My attempt is this:



What I expected, is that this would do so that any part of the sprite that is more than 125.0 "units" from 0.0, would be green.
However, the sprites end up completely red.

It looks like agk_spritesize.x (and agk_spritesize.y) is always zero.

Why is that, and what am I doing wrong?

The author of this post has marked a post as an answer.

Go to answer

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 28th May 2020 20:04
That's quite weird....I tried your shader on my laptop and it worked fine. The red area of the sprite always stays 125 pixels wide even when the sprite size is changed.

I then broadcast it to an android phone and that worked fine too...(Red area of 125 pixels wide with green after that even when the sprite is moved or its size is changed)

Very odd
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 28th May 2020 21:02
Ok, interesting.. I'm using AppGameKit studio V2020.04.16. What about you?
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 28th May 2020 21:23 Edited at: 28th May 2020 21:23




shader.ps
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 28th May 2020 21:32
Qugurun, I tested your example, but in my case the sprite is always green.
I will double check that I did it correctly, but it really looks like I'm always getting 0 from agk_spritesize...
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 28th May 2020 21:34 Edited at: 29th May 2020 06:00
GetRendererName() returns Vulkan. Are shaders supposed to work the same, even if its Vulkan or OpenGL?

EDIT:
If I set #renderer "Basic" it works!

Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 28th May 2020 21:40
It works on my laptop and pc with classic or studio.

It looks like you seem to have found the issue. (Vulkan renderer)

xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 29th May 2020 08:12 Edited at: 31st May 2020 20:28
Now the same issue in Tier 2; how would I do #define "Begin" #renderer "Basic" in Tier 2?
xtremi
5
Years of Service
User Offline
Joined: 26th Aug 2018
Location:
Posted: 2nd Jun 2020 07:42
This post has been marked by the post author as the answer.
I found out where to force OpenGL in Tier 2:

For Windows:
In Core.cpp, in the function int APIENTRY _tWinMain(...) the parameter rendererMode in agk::InitGraphics(...) can be set to AGK_RENDERER_MODE_ONLY_LOWEST.

For Android:
In Core.cpp, in the function void init(...) the parameter rendererMode in agk::InitGraphics(...) can be set to AGK_RENDERER_MODE_ONLY_LOWEST.

Login to post a reply

Server time is: 2024-03-28 17:18:14
Your offset time is: 2024-03-28 17:18:14