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 / ShaderToy conversion issues

Author
Message
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th Nov 2017 19:57 Edited at: 30th Nov 2017 19:58
I've had some success at converting ShaderToy shaders to AGK.

See in the video where I get an unwanted effect whereby the shaded object texture doesn't move, like it's glued to screen co-ords rather than the object it's drawn on.
As I move the mouse, the shader output is stuck in the same relative space.

I get ShaderToy is more transportable to quad style shaders and I'm guessing it's to do with the agkworldproj (or one of those) vertex variables.

This is the basic vertex shader I'm using.
Am I missing something?



janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 30th Nov 2017 21:43
What are you using as UV coordinates ? because you don't provide them in the vertex shader.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th Nov 2017 22:52 Edited at: 30th Nov 2017 22:54
Here's the pixel shader.
The UV is from (appears to me) the screen resolution in gl_FragCoord.

I did try to add a texture0 and uvvarying but didn't see any results. I'm populating iresolution with 100,100,0,0 to get the result you see in the example.



It would be nice to get some more of the ShaderToy examples working.
One of the things that I haven't worked out yet is converting the use of the texture keyword, as it isn't supported by AGKs shader version.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 1st Dec 2017 11:45 Edited at: 1st Dec 2017 12:01
First off the AppGameKit equivalent of:
iResolution = vec2 agk_resolution;
iGlobalTime = float agk_time; there is also float agk_sintime so you could take that instead and save the sin/cos calculation...
gl_FragCoord = vec2 uvVarying; which you want to pass like this uvVarying = uv * uvBounds0.xy + uvBounds0.zw; from within your Vertex shader, you can then alter the uvBounds0 using SetObjectUVScale and SetObjectUVOffset.

So you switch to the above mentioned AppGameKit variables and remove the resolution devision then you alter the UVScale using SetObjectUVScale and you should be set.

Now the shader explanation:
It's creating a 3D noise Texture by calculating a 2D noise texture using a hash function.
This 3D Texture(not sure if its white noise) then is used for the alpha value of our final color.
But how does it animate ? Well the 3D Texture is created by layering several 2D Textures and the timer variable is scrolling through the layers.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st Dec 2017 23:17
Some nice pointers there Janbo. I'll see if I can adapt the shader accordingly.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 2nd Dec 2017 01:45
Meh.. first pass was rubbish. I'll try again tomorrow.
Fumbling about a bit I have to say.

I successfully replaced the agk_resolution but don't get what it means (its the screen res?)
Forgetting replacing / adapting the agk_sintime bit for now, but I just get an error or nothing appears when adding the uvVarying part.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 2nd Dec 2017 14:48 Edited at: 2nd Dec 2017 15:00
agk_resolution is the resolution of the render target whether its an image you render to or the screen buffer.
But actually, you don't want to replace iResolution you want to remove it entirely.
If you then replaced gl_FragCoord with uvVarying you need to pass it from the vertex shader to the fragment shader.
Actually it's not necessary to replace something at all, you could make it work with some magic calculations maybe even hard code it into the shader,
but you want to, because you don't want to pass so many uniforms to the shader and maybe even use the build in commands to alter some uniforms.
And thats why you want to pass uvVarying = uv * uvBounds0.xy + uvBounds0.zw; from the Vertex shader to the Fragment shader.
uvBounds0 is a uniform and is passed from AppGameKit to the "shader set" using SetObjectUVScale and SetObjectUVOffset.
uvBounds0.xy=SetObjectUVScale (you want to alter this)
uvBounds0.zw=SetObjectUVOffset

Not testet Code
VertexShader:

FragmentShader:
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 16th Dec 2017 20:38
Janbo, you are amazing, thank you.

That one post explained so much to me. It also worked fine!!

Login to post a reply

Server time is: 2024-09-30 11:25:32
Your offset time is: 2024-09-30 11:25:32