Posted: 12th Jul 2016 2:50
I'm trying a couple of the older shaders (Specifically the 3D toon shader and 3D water shader) and i just get a blank window. Is there something else i need to do?
Posted: 12th Jul 2016 6:05
Hi Blink0k,

I had the same issue, there were changes in build 2.0.15 to the light sources (if I understand it all correctly).
Here is a link to the forum post about it and the fix you need to make to the shader
https://forum.thegamecreators.com/thread/216523
Posted: 12th Jul 2016 6:41
Thanks Harlequin! Worked a treat
Posted: 12th Jul 2016 9:46
@MadBit : your example is great !! Thanks a lot.
But on my pc, the billboard doesn't work properly :
Posted: 12th Jul 2016 19:44
@All:
Thank you for your comments.

@Janbo:
Hey that's good. Thanks for that. I always look where can I optimize something.

@Blendman:
Hmm, that's hard to reproduce this error. The image what we see is from the executable that I have posted? Or have you compiled it again.
I notice also that your colors are different. And the frame rate is very low.
Has anyone the same error?
Posted: 12th Jul 2016 23:51
quick question;
Is there any documentation that describes shader values like agk_MeshDiffuse?
Posted: 13th Jul 2016 11:46
Shorts answer:no.

i have not found anything.
Posted: 13th Jul 2016 14:34
Or have you compiled it again.
I have compiled it again with agk 2.020.


I notice also that your colors are different.
For the colors it's normal, I have just add a second light (with red colors ) ^^. So no matter here

And the frame rate is very low.
Yes, I don't know if it's possible to optimize the shader more. My Pc is very slow (processor AMD E1-1200 dual core 1.4 Ghz, 5Go ram), so it's good for my test (my android tablet is much better ^^) but not to play some 3D games ^^.
Posted: 13th Jul 2016 18:39
inspired by Jack's billboard and animation shader

whohoo! I've infected you with the shader sharing virus! Great work

Currently I have not the time to check your code but is the normal mapping shader based on the standard AppGameKit lights? This would be awesome.
Posted: 13th Jul 2016 20:48
@Jack:
... is the normal mapping shader based on the standard AppGameKit lights?

Yes, indeed.

The only additional variable is for specular lighting.
+ Code Snippet
SetObjectShaderConstantByName	(OBJ_CYLINDER, "MaterialSpecColor", 0.5, 0.5, 0.5, 5.0)

First three values = how much the rgb values are reflected. Fourth value is hard the specular is. 1.0 very soft > 100.0 very hard.

And thank you for your virus,

@Blendman:
Please send me your executable and your changed source code. So i can test it.


EDIT:
uuups shader update
normal shader vs:
+ Code Snippet
// #version 330

// Input vertex data, different for all executions of this shader.
attribute	vec3	position;
attribute	vec3	normal;
attribute	vec2	uv;

uniform		mat4 	agk_ViewProj; 
uniform		mat3 	agk_WorldNormal; 
uniform		mat4 	agk_WorldViewProj; 
uniform		mat4 	agk_World;
uniform 	mat4	agk_View;

uniform		vec4	uvBounds0;

uniform  	vec3 	agk_LightAmbient;
uniform  	vec3 	agk_DLightDir;
uniform  	vec3 	agk_DLightColor;

// uniform		vec3	MaterialDiffuseColor;
// uniform		vec3	MaterialAmbientColor;
uniform		vec3	agk_MeshDiffuse;
uniform		vec3	agk_MeshAmbient;

// uniform		vec4	LightPos0;			// w component == range

varying		vec3	vs_normal;
// varying		vec3	vs_lpos;
varying		vec3 	vs_position;
varying		vec2	vs_uv;
varying		vec3	vs_adColor;

void main(void)  
{     
	vs_position = (agk_World * vec4(position, 1.0)).xyz;       
	vs_normal = normalize(agk_WorldNormal * normal);
	vs_uv = uv * uvBounds0.xy + uvBounds0.zw;
	
	// vs_adColor	= agk_LightAmbient * MaterialAmbientColor;
	vs_adColor	= agk_LightAmbient * agk_MeshAmbient;
	// vs_adColor	+= (agk_DLightColor * MaterialDiffuseColor) * max(dot(vs_normal,normalize(-agk_DLightDir)), 0.0);
	vs_adColor	+= (agk_DLightColor * agk_MeshDiffuse) * max(dot(vs_normal,normalize(-agk_DLightDir)), 0.0);

	// vs_lpos = (agk_World * vec4(LightPos0.xyz, 1.0)).xyz;
   gl_Position = agk_WorldViewProj * vec4(position, 1.0);  
}
          


So, with the performance .... I have tested it with an Intel E8400 Duo under Linux and runs at just over 200 FPS.

Maybe a driver problem ???

Please test this - by the billbord creation for the flam. Comment the line 'SetObjectShader' out. Have you the same fragments?
And check the line 'SetObjectUVScale' there must 1.0 divided by 8.0 and 1.0 divided by 4.0. (8 frames horizontal and 4 frames vertical).

normal shader ps:
+ Code Snippet
#define MAX_PLIGHTS	4

uniform		sampler2D	texture0;
uniform		sampler2D	texture1;
// uniform		sampler2D	texture2;

uniform		mat4 	agk_World;
// uniform		vec3 	CameraPos;

varying		vec3	vs_normal;
varying		vec3	vs_position; 
varying		vec2	vs_uv;
varying		vec3	vs_adColor;

 uniform vec3	agk_CameraPos;
// lights
uniform  vec3 agk_LightAmbient;
uniform  vec3 agk_DLightDir;
uniform  vec3 agk_DLightColor;

uniform  vec4 agk_PSLight1Pos;
uniform  vec3 agk_PSLight1Color;
uniform  vec4 agk_PSLight2Pos;
uniform  vec3 agk_PSLight2Color;
uniform  vec4 agk_PSLight3Pos;
uniform  vec3 agk_PSLight3Color;
uniform  vec4 agk_PSLight4Pos;
uniform  vec3 agk_PSLight4Color;

vec4	LightPos[MAX_PLIGHTS];
vec3	LightColor[MAX_PLIGHTS];


// uniform		vec3	MaterialDiffuseColor;
// uniform		vec3	MaterialAmbientColor;
uniform		vec4	MaterialSpecColor;		// w component == shininess
uniform		vec3	agk_MeshDiffuse;
uniform		vec3	agk_MeshAmbient;

mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );

// http://www.thetenthplanet.de/archives/1180
mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
{
    // get edge vectors of the pixel triangle
    vec3 dp1 = dFdx( p );
    vec3 dp2 = dFdy( p );
    vec2 duv1 = dFdx( uv );
    vec2 duv2 = dFdy( uv );
 
    // solve the linear system
    vec3 dp2perp = cross( dp2, N );
    vec3 dp1perp = cross( N, dp1 );
    vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
    vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
 
    // construct a scale-invariant frame 
    float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );
    return mat3( T * invmax, B * invmax, N );
}
 
vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord )
{
    // assume N, the interpolated vertex normal and 
    // V, the view vector (vertex to eye)
   vec3 map = texture2D(texture1, texcoord).xyz;
   if(dot(map, map) == 0.0)
   {
		return N;
   }
   
   // map = map * 255.0/127.0 - 128.0/127.0;
   map = map * 2.0 - 1.0;
   
    mat3 TBN = cotangent_frame(N, -V, texcoord);
    return normalize(TBN * map);
}

vec3 GetPSLightColor(vec3 n, vec3 p, vec3 c)
{
	// vec3 	N		= n;
	vec3	E 		= normalize(agk_CameraPos - p);
	// vec3	E 		= normalize(-p);
	vec3	N		= perturb_normal(n, p, vs_uv);

	vec3 C = c;

	float	specfac		= clamp(dot(reflect(agk_DLightDir, N), E), 0.0, 1.0);
	float 	shininess	= max(1.0, MaterialSpecColor.w);
	vec3	ISpecular	= vec3(0);
	vec3	ISpecularDL	= vec3(0);
	
	if( dot(-agk_DLightDir, N) > 0.0)
		ISpecularDL	= (agk_DLightColor * MaterialSpecColor.rgb) * pow(specfac,shininess);
	
	for(int i=0; i<MAX_PLIGHTS; i++)
	{
		if(dot(LightColor[i], LightColor[i]) == 0.0)
			continue;
		
		vec3	L		= LightPos[i].xyz - p;
		float	dist	= length(L);
		
		L 				= normalize(L);
		vec3	R 		= reflect(-L, N);
	 
		dist *= dist;
		float	dotNL = dot(N, L);
		float	OneRange = 1.0 / (LightPos[i].w * LightPos[i].w);
		float	atten = max(0.0, 1.0 - (dist*dist) * (OneRange*OneRange));
		atten *= atten;
		// float	atten = 1.0;

		// vec3	IDiffuse	= (LightColor[i] * MaterialDiffuseColor) * max(dotNL, 0.0);
		vec3	IDiffuse	= (LightColor[i] * agk_MeshDiffuse) * max(dotNL, 0.0);
		specfac				= dot(E, R);
		
		if(dotNL > 0.0 && specfac > 0.0)
		{
			ISpecular	= (LightColor[i] * MaterialSpecColor.rgb) * pow(specfac,shininess) * atten;// * dotNL;
		}

		C += ((atten*IDiffuse) + ISpecular);
	}
	
	return C + ISpecularDL;
}

void main (void) 
{
	LightColor[0] = agk_PSLight1Color;
	LightColor[1] = agk_PSLight2Color;
	LightColor[2] = agk_PSLight3Color;
	LightColor[3] = agk_PSLight4Color;
	
	LightPos[0] = agk_PSLight1Pos;
	LightPos[1] = agk_PSLight2Pos;
	LightPos[2] = agk_PSLight3Pos;
	LightPos[3] = agk_PSLight4Pos;

	// vec3 	N		= vs_normal;

	// vec3	IAmbient	= agk_LightAmbient * MaterialAmbientColor;
	// IAmbient			+= (agk_DLightColor * MaterialDiffuseColor) * max(dot(N,normalize(-agk_DLightDir)), 0.0);
	
	gl_FragColor = vec4(ApplyFog(GetPSLightColor(vs_normal, vs_position,vs_adColor) * texture2D(texture0, vs_uv).rgb, vs_position), 1.0);
}


use now agk material (agk_MeshDiffuse and agk_MeshAmbient).
Posted: 14th Jul 2016 11:33
@MadBit :
I think the matter for the billboard is the size of your images sprite-flame2.png or sprite-flame2.jpg which are 900*451.
Some card (like mine) need a squared image (512*512 for example).
I have converted sprite-flame2.jpg in 512*512 and the billboard is now ok .


For The code, it's exactly the same as yours + those 2 lines :
+ Code Snippet
	CreatePointLight(3, 5, 5, -10, 120, 255, 100, 50)
	SetPointLightMode(3,1)


For the performance, if I use (and the new shader vs/ps) :
+ Code Snippet
SetSyncRate(0, 0)

The FPS are from 60 (near the scene) to 230 (far the scene)

I use don't use SetSyncRate(0, 0), the performance are from 30 (near the scene like your screenshot) to 60 fps (far the scene) ^^.
Posted: 26th Jul 2016 15:18
Hello chaps. I've just recently picked up AppGameKit again and started working on a project that I never finished, my latest update is 2.0.14b and as I understand it some stuff has changed in shader code since then.

To put it shortly, is there any collected info/thread on what I need to change in my old shaders to make it work with the latest AGK2 update?

I realize I could probably have found this eventually by trawling the threads in the forum but, hey ho. Give some, receive some right


+ Code Snippet
Edit: Forum delivering as usual I see... christ on a bike
Posted: 26th Jul 2016 22:31
[Mod Edit: spam]
Posted: 27th Jul 2016 14:33
Gray Scale Shader..

+ Code Snippet
uniform sampler2D texture0;
varying highp vec2 uvVarying;
varying mediump vec4 colorVarying;
uniform float _Grey_Scale; 
void main()
{
		
    vec4 newcolour = texture2D(texture0, uvVarying);
    float gray = dot(newcolour.rgb, vec3(0.3, 0.59, 0.11)) ;
    vec4 newcolour2 = mix ( newcolour, vec4 ( gray,gray,gray,1.0 ),_Grey_Scale );
    gl_FragColor =vec4( newcolour2.r, newcolour2.g, newcolour2.b, newcolour.a )*colorVarying;

}


Use SetShaderConstantByName(ID , "_Grey_Scale",1.0,0,0,0) to set the scale of the grey from 0.0 - 1.0
Posted: 18th Sep 2016 12:57
@MadBit : your example is great !! Thanks a lot man.
but ones I open it on my phone I received this error (attached image)
Posted: 19th Sep 2016 8:41
Thank you.

To the problem:
OpenGL ES provides these functions available from version 3.0. Mobil devices initialized obviously a smaller version.
The solution is that the tangents and bi-tangent are pre computed for each vertex. Then passed together with the vertex buffer.

Or Paul allows the programmer to choose which GL version is supported.
Posted: 20th Sep 2016 10:01
@MadBit :Thanks for your reply ...
But ..Kindly post modified code ... because I'm very noob in Shaders programming '
Posted: 22nd Sep 2016 9:16
@Blendman normalmap2D

---------------------------
Message
---------------------------
Pixel shader 3D_NM.ps failed to compile: ERROR: 0:53: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:53: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:53: '+' : wrong operand types no operation '+' exists that takes a left-hand operand of type 'const int' and a right operand of type '4-component vector of float' (or there is no acceptable conversion)
ERROR: 0:53: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:53: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:53: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type '4-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion)


---------------------------
OK
---------------------------

than

---------------------------
Message
---------------------------
Pixel shader 3D_NM1.ps failed to compile: ERROR: 0:40: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:40: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:40: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type '3-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 0:40: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:40: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:40: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type '3-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 0:43: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:43: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:43: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'const int' and a right operand of type 'float' (or there is no acceptable conversion)
ERROR: 0:43: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:43: '=' : cannot convert from 'const int' to 'float'
ERROR: 0:59: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:59: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:59: '+' : wrong operand types no operation '+' exists that takes a left-hand operand of type 'const int' and a right operand of type '4-component vector of float' (or there is no acceptable conversion)
ERROR: 0:59: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:59: 'assign' : implict conversion between types allowed from GLSL 1.20
ERROR: 0:59: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type '4-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion)


---------------------------
OK
---------------------------

Intel HD 3000, but most of the other Shaders worked fine. What do I have to change to get it work?
Posted: 22nd Sep 2016 9:19
@GolWofael:
Ehmm, this is not a trivial task.

I mean, it is not a big deal to change the shader code. But the AppGameKit code is another thing.

1. First you need to copy the vertex buffer from your 3D object in a MemBlock, so you can read it.

2. Create a new MemBlock buffer. Which is large enough to hold, the vertex-coordinates (3 float), vertex normals (3 float), vertex UV coordinates (2 float), Vertex Tangents (3 float) and Vertex bi Tangents (3 float).

3. Copy the coordinates, normals and uv-coordinates in the new buffer and calculate the tangents and write them also in the buffer.

4. Bind the new buffer to your 3d-object.

I have already made Buffer manipulations in Tier 2 but not in Tier 1. I have currently not much time so I can't do it for you.

Sorry.
Posted: 22nd Sep 2016 20:17
You don't have access to OpenGL/Buffer in Tier1.

1 .So in Tier1, I would create a memblock from the object
2. Read the Vertex and UV data from it
3. Calculate the tangent and Bi-tangent
4. Leave everything as it is but pass the result as an array to the vertex shader
5. And access the current tangents Index with gl_VertexID as it is available in GLSL 1.10

I don't have time also