Think I need the same tutorial I did come across this tho
https://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313
I did also use a online tool like shadertoy and shaderfrog that helped get a working shader with my small attempt
but I then had to make slight changes to the code to get to work in AppGameKit for example the following commands are a little different
with AppGameKit with my attempts using 2d shaders
uniform vec2 agk_resolution;
uniform float agk_time
uniform vec2 agk_spritesize;
uniform mat4 agk_World
uniform mat4 agk_ViewProj
gl_FragColor
I'm sure there are other differences but I really only played with others shaders and made a cheap and nasty blend type shader
in 3d which from my understanding couldn't be done in 2d like this and you can get the same effect by changing the transparency
of two sprites which was meant to give a morph like effect but happy to share
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
// create a sphere to see the texture
//CreateObjectSphere(1,20,40,60)
CreateObjectplane(1,512,768)
// set display properties
SetCameraRange( 1, 1.0, 50000 )
SetCameraPosition( 1, 0.0, 0.0, -1468.924 )
SetCameraLookAt( 1, 0.0, 0.0, 0.0, 0.0 )
// orientate camera
SetCameraRotation(1,0,0,0)
SetGenerateMipmaps(1)
LoadImage(1,"texture1.jpg") // no need for alpha with this one
LoadImage(2,"texture2.png") // with alpha ;)
CreatePointLight(1,-5,5,5,500,200,200,200)
// initial rotation values
// main loop
//SetObjectRotation(1,-60,-60,0.0)
SetObjectScale(1,4,2,2)
createShader()
LoadShader(3, "vertex.vs", "fragment.ps")
SetObjectShader(1,3)
SetObjectImage(1,2,0)
SetObjectImage(1,1,1)
perc#=.1:time#=Timer()
do
SetShaderConstantByName(3,"Percentage",perc#,0.0,0.0,0.0)
if perc#<=2.0 and time#>.1
perc#=perc#+.01
else
//SetObjectShader(1,3)
//SetObjectImage(1,3,0)
//SetObjectImage(1,4,1)
ResetTimer()
perc#=.1:time#=Timer()
endif
DrawObject( 1)
time#=Timer()
print(perc#)
sync()
loop
function createShader()
file = OpenToWrite("vertex.vs")
WriteLine(file,"attribute vec3 position;")
WriteLine(file,"attribute vec2 uv;")
WriteLine(file,"varying vec2 uvVarying;")
WriteLine(file,"uniform vec4 uvBounds0;")
WriteLine(file,"uniform mat4 agk_World;")
WriteLine(file,"uniform mat4 agk_ViewProj;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 pos = agk_World * vec4(position,1);")
WriteLine(file,"gl_Position = agk_ViewProj * pos;")
WriteLine(file,"uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(file,"}")
CloseFile(file)
file = OpenToWrite("fragment.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"uniform sampler2D texture1;")
WriteLine(file,"uniform float Percentage;")
WriteLine(file,"varying vec2 uvVarying;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"gl_FragColor = (texture2D(texture0, uvVarying) + (2.0*Percentage*texture2D(texture1, uvVarying))/2.0);")
//WriteLine(file,"gl_FragColor = gl_FragColor+(10.0/1.0*texture2D(texture1, uvVarying));")
WriteLine(file,"}")
CloseFile(file)
endfunction
fubar