Posted: 12th Dec 2021 4:04
After I put a shader on my 3d objects they stop animating and there not rotated correctly.

odd.
Posted: 12th Dec 2021 6:15
more guessing (i guess).

outline shader applied:
Posted: 12th Dec 2021 6:22
Here are the shaders I am trying to use

Mask.ps

+ Code Snippet
// shader alpha mask for AGK
#ifdef GL_ES
	#ifdef GL_FRAGMENT_PRECISION_HIGH   
		precision highp float;
	#else
		precision mediump float;
	#endif
#endif

uniform sampler2D texture0;
varying vec2 uvVarying;
uniform vec4 agk_MeshDiffuse;
uniform vec4 MaskColor; // set the r,g,b (from 0.0 to 1.0) for the mask color

void main()
{
	gl_FragColor = (texture2D(texture0, uvVarying) * agk_MeshDiffuse);	
	if (gl_FragColor == MaskColor)  discard;
}


Mask.vs

+ Code Snippet
// Alpha mask Shader for AGK
uniform vec4 agk_MeshDiffuse;
uniform vec4 uvBounds0;
varying vec2 uvVarying;
varying vec3 posVarying;
attribute vec2 uv;
attribute vec3 position;

uniform mat4 agk_World;
uniform mat4 agk_ViewProj;

void main()
{ 	
	vec4 pos = agk_World * vec4(position,1.0);
	gl_Position = agk_ViewProj * pos;   
	posVarying = pos.xyz;	
	uvVarying = uv* uvBounds0.xy + uvBounds0.zw; 
}
Posted: 12th Dec 2021 6:59
that looks like blendman's shader? https://forum.thegamecreators.com/thread/216112#msg2577210

i've asked him to visit this thread to see if he can lend a hand (unless someone beats him to it )
Posted: 12th Dec 2021 7:11
i've asked him to visit this thread to see if he can lend a hand (unless someone beats him to it


Thank you, If I can get shaders working right these models will look super good.
Posted: 12th Dec 2021 9:31
Hi

I'm not very at shader, but, I have understand some little things .

When you use an animated shader, it's not the same code as for an "non-animated" shader.

If you want to know what is the code which is used for the default AppGameKit shader (for example, to know what is the code for a defaut animated shader (with fog, light,....), you can use the functions :

+ Code Snippet
txt1$ = GetObjectMeshVSSource(n,1) 
txt2$ = GetObjectMeshPSSource(n,1)
	
	
OpenToWrite(1,"shadervs.txt")
	WriteLine(1,txt1$)
	CloseFile(1)
	
OpenToWrite(1,"shaderps.txt")
	WriteLine(1,txt2$)
	CloseFile(1)
	


So you will get those kind of code (it's the default AppGameKit shader code, for an animated objet) :
Shader VS :
+ 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 mat4 agk_ViewProj;
attribute highp vec2 uv;
varying highp vec2 uvVarying;
uniform highp vec4 uvBounds0;

attribute highp vec4 boneweights;
attribute mediump vec4 boneindices;
uniform highp vec4 agk_bonequats1[28];
uniform highp vec4 agk_bonequats2[28];

highp vec3 transformDQ( highp vec3 p, highp vec4 q1, highp vec4 q2 )
{
    p += 2.0 * cross( q1.xyz, cross(q1.xyz, p) + q1.w*p );
    p += 2.0 * (q1.w*q2.xyz - q2.w*q1.xyz + cross(q1.xyz,q2.xyz));
    return p;
}

void main()
{ 
    uvVarying = uv * uvBounds0.xy + uvBounds0.zw;
    highp vec4 q1 = agk_bonequats1[ int(boneindices.x) ] * boneweights.x;
    q1 += agk_bonequats1[ int(boneindices.y) ] * boneweights.y;
    q1 += agk_bonequats1[ int(boneindices.z) ] * boneweights.z;
    q1 += agk_bonequats1[ int(boneindices.w) ] * boneweights.w;
    highp vec4 q2 = agk_bonequats2[ int(boneindices.x) ] * boneweights.x;
    q2 += agk_bonequats2[ int(boneindices.y) ] * boneweights.y;
    q2 += agk_bonequats2[ int(boneindices.z) ] * boneweights.z;
    q2 += agk_bonequats2[ int(boneindices.w) ] * boneweights.w;
    highp float len = 1.0/length(q1);
    q1 *= len;
    q2 = (q2 - q1*dot(q1,q2)) * len;
    highp vec4 pos = vec4( transformDQ(position,q1,q2), 1.0 );
    gl_Position = agk_ViewProj * pos;

    normalVarying = normal + 2.0*cross( q1.xyz, cross(q1.xyz,normal) + q1.w*normal );
    posVarying = pos.xyz;
    lightVarying = GetVSLighting( normalVarying, posVarying );
}



Shader PS :
+ Code Snippet
varying highp vec2 uvVarying;
uniform sampler2D texture0;
varying mediump vec3 normalVarying;
varying mediump vec3 lightVarying;
varying highp vec3 posVarying;
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );
uniform mediump vec4 agk_MeshDiffuse;
uniform mediump vec4 agk_MeshEmissive;

void main()
{ 
    mediump vec4 blendTex = vec4(1.0,1.0,1.0,1.0);
    mediump vec3 norm = normalize(normalVarying);
    mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying ); 
    mediump vec4 texColor = texture2D(texture0, uvVarying);
    gl_FragColor = texColor * blendTex * vec4(light,1.0) * agk_MeshDiffuse + agk_MeshEmissive;
    gl_FragColor.rgb = ApplyFog( gl_FragColor.rgb, posVarying );
   gl_FragColor = (texture2D(texture0, uvVarying) * agk_MeshDiffuse);  
    
}


So, to change your shader, tperh'aps this could work :
PS shader file :

+ Code Snippet
varying highp vec2 uvVarying;
uniform sampler2D texture0;
varying mediump vec3 normalVarying;
varying mediump vec3 lightVarying;
varying highp vec3 posVarying;
mediump vec3 GetPSLighting( mediump vec3 normal, highp vec3 pos );
mediump vec3 ApplyFog( mediump vec3 color, highp vec3 pointPos );
uniform mediump vec4 agk_MeshDiffuse;
uniform mediump vec4 agk_MeshEmissive;
uniform vec4 MaskColor;
void main()
{ 
    mediump vec4 blendTex = vec4(1.0,1.0,1.0,1.0);
    mediump vec3 norm = normalize(normalVarying);
    mediump vec3 light = lightVarying + GetPSLighting( norm, posVarying ); 
    mediump vec4 texColor = texture2D(texture0, uvVarying);
    gl_FragColor = texColor * blendTex * vec4(light,1.0) * agk_MeshDiffuse + agk_MeshEmissive;
    gl_FragColor.rgb = ApplyFog( gl_FragColor.rgb, posVarying );
	// gl_FragColor = (texture2D(texture0, uvVarying) * agk_MeshDiffuse);  
    if (gl_FragColor == MaskColor)  discard;
}


Tell me if it works

EDIT : of course, you have to use the shader VS (code) for animated onject too
Posted: 12th Dec 2021 9:50
Hi Blendman

No, it made my model scattered everywhere al over the screen. it was animated, but only half of him you could see, the top half was all scattered.