Tobias_Ripper:
Fixed your code and sent a zip back to you. Hope you can use if
Blendman:
Sure you can use light you just add these 2 lines to any fragment shader your want ( as the last 2 lines ):
vec3 fogColor = vec3(0.21,0.41,0.67);
gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), clamp(distToCamera/1500.0,0.00,1.00) );
Then you have fog on that shader.
I know that in the latest agk versions the names has changed , but the old light with fog look like this:
vertex:
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
uniform mat4 agk_WorldViewProj;
uniform mat3 agk_WorldNormal;
uniform vec3 agk_DLightDir;
uniform vec4 agk_DLightColor;
uniform vec4 agk_PLightColor;
uniform vec4 agk_PLightPos;
uniform vec4 uvBounds0;
varying vec2 uv0Varying;
varying vec3 lightcolor;
varying float distToCamera;
void main()
{
vec4 pos = agk_World * vec4(position,1);
gl_Position = agk_ViewProj * pos;
vec3 norm = agk_WorldNormal * normal;
uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;
vec3 dir = agk_PLightPos.xyz - pos.xyz;
norm = normalize(norm);
float atten = dot(dir,dir);
atten = clamp(agk_PLightPos.w/atten,0.0,1.0);
float intensity = dot(normalize(dir),norm);
intensity = clamp(intensity,0.0,1.0);
vec3 color = agk_PLightColor.rgb * intensity * atten;
lightcolor = color + clamp(dot(-agk_DLightDir,norm)*agk_DLightColor.rgb,0.3,1.0) ;
distToCamera = gl_Position.z;
}
fragment:
uniform sampler2D texture0;
uniform vec4 agk_MeshDiffuse;
uniform float lightfactor;
varying vec2 uv0Varying;
varying vec3 lightcolor;
varying float distToCamera;
void main()
{
vec3 fogColor = vec3(0.21,0.41,0.67);
gl_FragColor = texture2D(texture0, uv0Varying) * lightfactor * vec4(lightcolor,1) * agk_MeshDiffuse;
gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), clamp(distToCamera/1500.0,0.00,1.00) );
}
That will give you one directional light and one point light. and sure with fog. if it dont work you must use SetShaderConstantByName to set the variables to match the old agk shaders names
My windows box cpu burned , so i decided to use only my mac for some month to learn it better , so currently i use daz studio 4.8 , verto studio , blender ...
In this demo , most objects are auto placed , and the other i just walked around the terrain and wrote down the x,y,z for the objects.
culling is special for this demo , as it has many tile based terrains , so i have divided them into sections , so i hole section behind you is disabled and all object is not checked.
for the rest of the objects , it use a angle based culling to see if a object is visible , also it has a next check count , so objects that cant get visible within 10 sync dont get checked for the next 10 sync.
And it will add a random skip to objects that need to be checked, so they dont get checked in the same sync (even out the culling calculations ) , this way no more then around 40-50 objects is checked each sync , even if there are thousand of objects.
best regards Preben Eriksen,