Posted: 24th Feb 2018 9:03
this looks useful, yes!
Posted: 24th Feb 2018 12:07
Is there some progress in the A* shader? =) It would be awsome for RTS.

[s]I'm sorry, i'm wrestling with a strange problem on my shader pack shaders.
I'm getting "ERROR Implementation limit of 32 varying components exceeded" for IOS, but I can't find any shader with that amount of varying components [/s]

[Edit]
You have to complain publicly first, to fix the problem
By the way: Duplicated varyings can cause this error
Now I only get this error if I use SetObjectNormalMap
[/Edit]
Posted: 25th Feb 2018 7:48
@Jack: Could you please give an example of how I can use the grid shader?
What I've done so far is not working:
- Create a plane
- Rotate the plane 90 degrees on x-axis
- Create a shader using the default .vs, and the .ps you posted
- Create an image using the CreateImageColor(...) command
- Set the image above on the plane at stage 0
- Set the shader on the plane
Posted: 25th Feb 2018 16:25
Hello george,

* Create a plane with the size 1x1 - plane = CreateObjectPlane(1,1)
* scale the plane to your desired size, for example - SetObjectScale(plane,16.0,1.0,16.0)
* Then give it just a - SetObjectShaderConstantByName(plane, "Scale",16.0,16.0,0,0) - with the scale size of your plane, after you applied the shader
* Post a user friendly example and proove shots of your progress here, in order to help others

Maybe the color image should also be white (255,255,255,255)

the other steps you mentioned are correct


"


Thats why we got this board
Does SetObjectNormalMap add lines of code to custom shaders?
Posted: 25th Feb 2018 18:50
Thank you jack. It worked


Here is the critical part of the code: (the rest of the code is for the manipulation of camera)
+ Code Snippet
grid = CreateObjectPlane(1.0, 1.0)
SetObjectTransparency(grid, 1)
SetObjectImage(grid, grid_img, 0)
SetObjectRotation(grid, 90.0, 0.0, 0.0)
SetObjectScale(grid, 5.0, 5.0, 1.0)
grid_shader = LoadShader("grid.vs", "grid.ps")
SetObjectShader(grid, grid_shader)
SetObjectShaderConstantByName(grid, "Scale", 5.0, 5.0, 0.0, 0.0)


Here is the default .vs file for all those who are unfamiliar (like me) in shaders

+ Code Snippet
attribute highp vec3 position;
attribute mediump vec3 normal;

varying highp vec3 posVarying;
varying mediump vec3 normalVarying;
varying mediump vec3 lightVarying;

mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );

uniform highp mat3 agk_WorldNormal;
uniform highp mat4 agk_World;
uniform highp mat4 agk_ViewProj;

attribute highp vec2 uv;
varying highp vec2 uvVarying;
uniform highp vec4 uvBounds0;

void main()
{ 

	uvVarying = uv * uvBounds0.xy + uvBounds0.zw;
	highp vec4 pos = agk_World * vec4(position,1.0);
	gl_Position = agk_ViewProj * pos;
	mediump vec3 norm = normalize(agk_WorldNormal * normal);
	posVarying = pos.xyz;
	normalVarying = norm;
	lightVarying = GetVSLighting( norm, posVarying );

}
Posted: 4th Mar 2018 18:00
Hi Guys

What is the language we need to use to create the PS and VS files?

Eg, Can we use info from here for example?

https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)

We all must have started from somewhere, so any enlightening Wiki's tutorials from where you all learnt this incredible language would be most welcome



Thanks
Posted: 5th Mar 2018 18:52
I tried to run the grid shader (jack) in the tablet.
I got a message error:
"Error: Vertex shader and pixel shader failed to link: Error:input iMouse not declared in output from previous stage. Error: Linking failed. in main.agc at line 140"
Can anyone help me to make this shader compatible with mobile devices?
Posted: 5th Mar 2018 19:38
"

Cool. ?\_(?)_/?


This may work:
+ Code Snippet
bool onGridline(int distFrom, int spacing);
bool onSplitline(int distFrom, int spacing, int interval);
varying mediump vec2 uvVarying;
uniform highp vec2 Scale;
 
uniform sampler2D texture0;
  
varying highp vec3 posVarying;
varying mediump vec3 normalVarying;
 
varying mediump vec3 lightVarying;
  
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );
  
 
 
 
void main( )
{
 
 
    mediump vec3 norm = normalize(normalVarying);
    mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying ); 
     
    mediump vec3 color = texture2D(texture0, uvVarying).rgb * light;
    color = ApplyFog( color, posVarying );
     
    gl_FragColor = vec4(color,1.0);
 
    // Colours , used to return to fragColor depending on criteria.
    const vec4 cBackground = vec4(0.0,0.0,0.0,0.0);         // Background colour.
    const vec4 cOrigin = vec4(0.0,0.392,0.392,1.0);         // Frag is directly in line with mouse's X or Y.
    const vec4 cLargeSplit = vec4(0.392,0.18,0.004,1.0);    // Frag is on a large split line.
    const vec4 cMedSplit = vec4(0.449,0.449,0.449,1.0);     // Frag is on a medium split line.
    const vec4 cGridline = vec4(0.293,0.293,0.293,1.0);     // Frag is on a grid line.
     
    // Grid lines
    const int spacingStd = 10;          // Spacing of normal grid lines
    const int intervalLargeSplit = 10;  // On how many gridlines a large split occurs.
    const int intervalMedSplit = 5;     // On how many gridlines a medium split occurs.
    const float zoom = 1.0;         // Zoom level of the grid.
     
    // Effective spacing
    // This is the standard grid spacing, as an integer, once zoom has been applied.
    // We do this here and use this value later to avoid float rounding errors.
    int effGrid = int(floor((float(spacingStd) * zoom) + 0.2));
     
    // Convenience integer values for resolution and frag position.
    int fragX = int((uvVarying.x-0.5)*Scale.x*10.0+(uvVarying.x-0.5));
    int fragY = int((uvVarying.y-0.5)*Scale.y*10.0+(uvVarying.y-0.5));
 
     
    // The offsets to the original mouse position were found by trial and error.
    int mouseX = 0;
    int mouseY = 0;
     
    // Distance this frag is from the mouse position, in each axis.
    int xDistFrom = int(abs(float(mouseX - fragX)));
    int yDistFrom = int(abs(float(mouseY - fragY)));
     
    // ============================================================
     
    // If on same X or Y as mouse, paint with origin colour.
    if ( fragX == mouseX || fragY == mouseY )
    {
        gl_FragColor = gl_FragColor*cOrigin;
        return;
    }
     
    // If on grid line, decide which colour to paint.
    else if ( onGridline(xDistFrom, effGrid) || onGridline(yDistFrom, effGrid) )
    {
        // If on large split line, choose this first.
        if ( onSplitline(xDistFrom, effGrid, intervalLargeSplit) ||
             onSplitline(yDistFrom, effGrid, intervalLargeSplit))
        {
            gl_FragColor = gl_FragColor*cLargeSplit;
            return;
        }
         
        // Then check medium split line.
        else if ( onSplitline(xDistFrom, effGrid, intervalMedSplit) ||
             onSplitline(yDistFrom, effGrid, intervalMedSplit))
        {
            gl_FragColor = gl_FragColor*cMedSplit;
            return;
        }
         
        // Otherwise, return normal grid line colour.
        else
        {
            gl_FragColor = gl_FragColor*cGridline;
            return;
        }
    }
     
    // Fragment is not in line with any grid line - paint as background.
    gl_FragColor = gl_FragColor*vec4(0.0, 0.0, 0.0, 0.0);
}
 
 
bool onGridline(int distFrom, int spacing)
{
    return mod(float(distFrom), float(spacing)) == 0.0;
}
 
 
bool onSplitline(int distFrom, int spacing, int interval)
{
    int newSpacing = spacing * interval;
     
    return mod(float(distFrom), float(newSpacing)) == 0.0;
}

Posted: 5th Mar 2018 19:59
Thank you. It works now!
Posted: 5th Mar 2018 22:19
What is the language we need to use to create the PS and VS files?


The GLSL language is quite standard but there is a couple of changes in AGKs mainly syntax

The AGKS online help file is quite useful in explaining
https://www.appgamekit.com/documentation/guides/13_shaders.htm
Posted: 6th Mar 2018 19:58
Thanks Fubarpk - a very interesting article - got a few examples on there too for a learner
Posted: 10th Mar 2018 21:09
I have been trying to write a fullscreen 2d dissolving shader that subtracts 1 from each color channel
of a pixel until its reaches 0

now I understand this returns the color of a pixel at a certain location
vec2 Position = ( Position.xy / agk_resolution );
vec3 color = texture2D(texture0, Position).rbg;

but im unsure how i would apply this to change each pixel allowing it to change gradually through main
Posted: 10th Mar 2018 21:47
In a pixel shader i think it would go something like this;

+ Code Snippet
uniform sampler2D texture0;
 
void main()
{
    vec4 basecolor = texture2D(texture0, uvVarying);
     
    //-- alpha blend
	if (overcolor.r > 0.0) {
		basecolor.r--;
	}

	if (overcolor.g > 0.0) {
		basecolor.g--;
	}

	if (overcolor.b > 0.0) {
		basecolor.b--;
	}
	
    //-- minus to erase
    gl_FragColor = basecolor;
      
     
}
Posted: 10th Mar 2018 23:08
Are you sure you want to substract from all color channels ?

Anyway, this code is not tested:
+ Code Snippet
uniform sampler2D texture0;

varying mediump vec2 uvVarying;

void main()
{
    vec4 color = texture2D(texture0, uvVarying).rgb;
    color -= vec4(1.0/255.0); // (no branching) make 255 steps as the color in shaders go from 0 to 1
    color = clamp(color,0.0,1.0);
    gl_FragColor = color; 
}
Posted: 10th Mar 2018 23:48
Ah yes. I was thinking 0 - 255
Posted: 10th Mar 2018 23:53
yeh they both work for changing the colors once but I'm still having the problem

+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
 
LoadImage(1,"texture1.jpg") 

createShader()
CreateSprite(1,1)
LoadSpriteShader(1, "dissolve.ps")
SetSpriteShader( 1,1 )
resetTimer()
time#=Timer() 
do
	if Timer()>time#+1.5 
		resetTimer():time#=Timer()
	endif
	print (timer())
	sync()	

loop
 
function createShader()

file = OpenToWrite("dissolve.ps")
WriteLine(file,"uniform sampler2D texture0;")
WriteLine(file,"uniform float agk_time;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 color = texture2D(texture0, uvVarying).rgba;")
WriteLine(file,"if (agk_time>1.0){")
WriteLine(file,"color=color-vec4(100.0/255.0);") // (no branching) make 255 steps as the color in shaders go from 0 to 1
WriteLine(file,"color = clamp(color,0.0,1.0);")
WriteLine(file,"}")
WriteLine(file,"gl_FragColor = color;")
WriteLine(file,"}")
CloseFile(file)
endfunction


that flashes between the original texture and the darkened one but ideally I want to be able to set it to do a bit at a time
but it doesn't seem to be modifying the texture only the viewing every 1 second.
Posted: 11th Mar 2018 0:41
This works for me;
Pixel shader
+ Code Snippet
// Eraser shader from MATTY_H -AGK forum
// texture

uniform sampler2D texture0;
varying vec2 uvVarying;
uniform float agk_time;
 
void main()
{
    vec4 color = texture2D(texture0, uvVarying);
    // color.r -= (1.0/255.0); // (no branching) make 255 steps as the color in shaders go from 0 to 1
    color.r -= agk_time;
    color.g -= agk_time;
	color.b -= agk_time;
    color = clamp(color,0.0,1.0);
    gl_FragColor = color; 
}



AGK code
+ Code Snippet
sprite = CreateSprite(LoadImage("image.jpg"))

SetSpriteShader(sprite, LoadSpriteShader("fade.ps" ) )

do
	if Timer() > 1.0
		ResetTimer()
	endif
	
    Print( ScreenFPS() )
    Sync()
loop


I think the idea would be to reset the timer, add the shader and when the timer is > 1 then you know it will be faded out.
You could halve the speed by scaling the agk_time value. Something like this;
color.r -= (agk_time * .5);
And check if the timer is > 2
Posted: 11th Mar 2018 1:24
Thanks

I never thought of using the timer in the calculation like that
Posted: 11th Mar 2018 1:28
I guess if you wanted more control you could set a variable in the shader. You could implement things like easing then
Posted: 11th Mar 2018 3:21
but here it is dissolve or make colors brighter
+ Code Snippet
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 )
 
LoadImage(1,"texture1.jpg") 

createShader()
CreateSprite(1,1)
LoadSpriteShader(1, "dissolve.ps")
SetSpriteShader( 1,1 )
resetTimer()
do
	time#=Timer()
        //SetShaderConstantByName(1,"myColor",-time#-,time#,-time#,0.2) //this will make the channels brighter
	SetShaderConstantByName(1,"myColor",time#,time#,time#,0.2) //red green blue factor
	if Timer()>7.0 
		resetTimer()
	endif
	print (time#)
	sync()	

loop
 
function createShader()

file = OpenToWrite("dissolve.ps")
WriteLine(file,"uniform sampler2D texture0;")
//WriteLine(file,"uniform float agk_time;")
WriteLine(file,"varying mediump vec2 uvVarying;")
WriteLine(file,"uniform vec4 myColor;")
WriteLine(file,"void main()")
WriteLine(file,"{")
WriteLine(file,"vec4 color = texture2D(texture0, uvVarying).rgba;")
WriteLine(file,"//color=color-vec4(100.0/255.0);") // (no branching) make 255 steps as the color in shaders go from 0 to 1
WriteLine(file,"color.r-=(myColor.x*myColor.w);")
WriteLine(file,"color.g-=(myColor.y*myColor.w);")
WriteLine(file,"color.b-=(myColor.z*myColor.w);")
WriteLine(file,"color = clamp(color,0.0,1.0);") //restricts color range
WriteLine(file,"gl_FragColor = color;")
WriteLine(file,"}")
CloseFile(file)
endfunction


if you change the code in the program to read something like this it will gradually turn the screen to that color

+ Code Snippet
time#=Timer()
	r#=time#*(255/255) //red (colors you want divided by 255) 
	g#=time#*(255/255) //green
	b#=time#*(0/255) //Blue        makes yellow    rgb (255,255,0)
	SetShaderConstantByName(1,"myColor",-r#,-g#,-b#,0.2) //red green blue factor


and the reverse can be done like make a black screen merge in to your sprite similar but different to doing it with alpha
+ Code Snippet
time#=7-Timer()
	r#=time#
	g#=time#
	b#=time#  
	if timer()<7.0
		SetShaderConstantByName(1,"myColor",r#,g#,b#,0.2) //red green blue factor
	endif
	


The main problem I was having I wasn't declaring my variables to be uniform and ended trying so many crazy things
before I realized and the other issue I had was I didn't realize I had to keep changing the amount value to match
what I wanted, I thought I could just subtract a value and if I kept calling the shader it would keep doing it as the texture
would be modified boy was I wrong lol