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.

AppGameKit Classic Chat / Quad with shaders and SetGenerateMipMaps()

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th Apr 2019 23:32 Edited at: 10th Apr 2019 23:32
When i use a quad to implement a shader and SetGeneateBitmaps(1) it goes awol
Project attached

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th Apr 2019 23:58
not sure if this helps but commenting //SetGenerateMipmaps(1) and it looks fine
so might be the shader isn't taking advantage of the mipmaps but my knowledge of shaders is primitive
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 10th Apr 2019 23:59 Edited at: 11th Apr 2019 00:00
Change your pixel shader (pixel.ps) to be:



Notice the addition of vec4 textureBounds0

When mipmapping the texture has to be a power of 2 .....(1024,768 isnt a power of 2) so AppGameKit puts this on a 1024,1024 texture and needs the pixel shader to compensate for the extra data at the top an bottom of that image

Its not well documented (well not documented AT ALL really) but it is easily fixed....you could have also made the texture 1024,1024 to make it work too.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Apr 2019 00:45
Ggood to know.
Thank you very much

Quote: "Well not documented AT ALL really"

If i may ask. How are you privy to this information?
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 11th Apr 2019 11:56 Edited at: 11th Apr 2019 11:58
I could tell you.... but Id have to kill you

Seriously though, its common in every 3d engine to have ways of manipulating UV coordinates and the range of values they can use.

AGK Documentation wrote: "
Mipmapping
Using SetGenerateMipmaps(1) to turn mipmapping on uses 33% more memory for images than turning it off but it can remove filtering artifacts created when using high resolution images on 3D objects or on objects that are far away. Therefore it may be beneficial to turn it on for 3D apps even though it uses more memory. However any images loaded whilst this is turned on must be a power of 2 in size, i.e. the image width and height must one of the following values 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048. The image does not need to be square, i.e. it could be 1024x256."


https://www.appgamekit.com/documentation/tips.html

So.....the documentation does cover the fact that if you want to use mipmapping then your images should be a power of 2 in size.

What it doesnt state, is that you can use non power of 2 textures and mipmapping... BUT you just have to be careful especially with using your own shaders. You cant do any UV scrolling if you do this. A custom shader can be used as long as you use the textureBounds variable in your code so that it limits the UV coordinates to the actual sub area on the texture where your image is. You could even alter the UV coordinates of the quad to do the same thing if you wanted via a memblock. AppGameKit fills in the values for textureBounds automatically so you dont need to worry about what they are as long as you use it. Its like using a sub image on a 3d object. Only a small range of the 0-1.0 uv range is used on the 3d primative.

Its often easier to just resize the image externally to a power of 2 to get round this or use ResizeImage() in AppGameKit to do it. If its a power of 2 you dont need to do anything special.

You can look at the internally generated pixel shader code with commands in AppGameKit so you can see what it does and what variables are used to scale the UV's to what they should be if you wanted so you get to pick up on what to look for and what to do in a custom shader.

Login to post a reply

Server time is: 2024-11-23 01:34:55
Your offset time is: 2024-11-23 01:34:55