shaders is just a program that runs on every vertex of your model or every pixel of your texture. Shaders are responsible for computing correct vector positions and get correct colors from the image and stretch them over the vertexes it computed. You are using “shades” right now just the default ones which mimic the pre-shader pipe line. Before the program to compute all that was in hardware now you can upload that program to the GPU. The shader program must be very simple in order to run very fast.
example of a simple shader:
//Cg
//
//Cg profile arbvp1 arbfp1
void vshader(float4 vtx_position : POSITION,
float4 vtx_color : COLOR,
in uniform float4x4 mat_modelproj,
out float4 l_position : POSITION,
out float4 l_color : COLOR)
{
l_position=mul(mat_modelproj, vtx_position);
l_color = vtx_color;
}
void fshader(float4 l_color: COLOR,
in uniform float4 k_glow,
in uniform float4 k_team,
out float4 o_color: COLOR0)
{
o_color = l_color;
}
example of a complex shader:
//Cg
//
//Cg profile arbvp1 arbfp1
void vshader(
in uniform float4x4 mat_modelproj,
in uniform float4x4 inv_modelview,
in float4 vtx_position : POSITION,
in float3 vtx_normal : NORMAL,
in float2 vtx_texcoord0 : TEXCOORD0,
in float3 vtx_tangent0 : TANGENT,
in float3 vtx_binormal0 : BINORMAL,
out float4 l_position : POSITION, // needed for the gfx card
out float4 l_vertPos : TEXCOORD6,
out float3 l_normal : TEXCOORD1,
out float2 l_uv : TEXCOORD2,
out float3 l_tangent : TEXCOORD3,
out float3 l_binormal : TEXCOORD4,
out float3 l_eyeVec : TEXCOORD5
)
{
l_position=mul(mat_modelproj, vtx_position);
l_uv=vtx_texcoord0;
l_eyeVec = mul(inv_modelview,float4(0., 0., 0., 1.)) - l_position;
l_vertPos = vtx_position;
l_normal = vtx_normal;
l_uv = vtx_texcoord0;
l_tangent = vtx_tangent0;
l_binormal = vtx_binormal0;
}
#define Delta 500
void fshader(
// from vshader
in float4 l_vertPos : TEXCOORD6,
in float3 l_normal : TEXCOORD1,
in float2 l_uv : TEXCOORD2,
in float3 l_tangent : TEXCOORD3,
in float3 l_binormal : TEXCOORD4,
in float3 l_eyeVec : TEXCOORD5,
// texture units
in uniform sampler2D tex_0 : TEXUNIT0,
in uniform sampler2D tex_1 : TEXUNIT1,
// from inputs
in uniform float4 k_glow,
in uniform float4 k_team,
// from lighting
in uniform float4 mspos_sun : c7,
in uniform float4 k_sunDef : c8,
in uniform float4 mspos_light1 : c9,
in uniform float4 k_light1Def : c10,
in uniform float4 mspos_light2 : c11,
in uniform float4 k_light2Def : c12,
in uniform float4 mspos_light3 : c13,
in uniform float4 k_light3Def : c14,
// out put color to the screen
out float4 o_color : COLOR
)
{
// load our texture stages
float4 texRgba=tex2D(tex_0, l_uv);
float4 texBstg=tex2D(tex_1, l_uv);
float4 hullColor = (1-texBstg.g)*texRgba + k_team*texBstg.g ;
float3 halfVec = normalize( l_eyeVec + l_normal );
o_color = float4(0,0,0,0);
float spec = texBstg.y;
// diffinitons
float3 lightvec;
float distance;
float attenuate;
float3 conv_lightvec;
float slant;
float ndotl;
float ndoth;
float4 out_color;
// sun light
lightvec = normalize((float3)mspos_sun - l_vertPos);
conv_lightvec.x = dot(l_tangent, lightvec);
conv_lightvec.y = -dot(l_binormal, lightvec);
conv_lightvec.z = dot(l_normal, lightvec);
slant = tex2D(tex_1, l_uv+float2(conv_lightvec.x,conv_lightvec.y)/Delta ).x - tex2D(tex_1, l_uv).x;
l_normal += .1*normalize(float3(conv_lightvec.x,conv_lightvec.y,slant));
l_normal = normalize(l_normal);
out_color = hullColor*k_sunDef*k_sunDef.a ;
ndotl = max( saturate(dot( lightvec, l_normal )), 0.0 );
ndoth = (ndotl > 0.0) ? pow(max( dot( halfVec, l_normal ), 0.0 ), 128.) : 0.0;
o_color += ndotl*out_color + ndoth*out_color*spec;
lightvec = ((float3)mspos_light1 - l_vertPos);
distance = k_light1Def.w/length(lightvec);
attenuate = saturate(30.0 / (15.0 + distance));
lightvec = normalize(lightvec);
ndotl = max( dot( lightvec, l_normal ), 0.0 );
ndoth = (ndotl > 0.0) ? pow(max( dot( halfVec, l_normal ), 0.0 ), 128.) : 0.0;
out_color = hullColor*attenuate*k_light1Def*k_light1Def.a;
o_color += ndotl*out_color + ndoth*out_color*spec;
lightvec = ((float3)mspos_light2 - l_vertPos);
distance = k_light2Def.w/length(lightvec);
attenuate = saturate(30.0 / (15.0 + distance));
lightvec = normalize(lightvec);
ndotl = max( dot( lightvec, l_normal ), 0.0 );
ndoth = (ndotl > 0.0) ? pow(max( dot( halfVec, l_normal ), 0.0 ), 128.) : 0.0;
out_color = hullColor*attenuate*k_light2Def*k_light2Def.a;
o_color += ndotl*out_color + ndoth*out_color*spec;
/*
lightvec = ((float3)mspos_light3 - l_vertPos);
distance = k_light3Def.w/length(lightvec);
attenuate = saturate(30.0 / (15.0 + distance));
lightvec = normalize(lightvec);
ndotl = max( dot( lightvec, l_normal ), 0.0 );
ndoth = (ndotl > 0.0) ? pow(max( dot( halfVec, l_normal ), 0.0 ), 128.) : 0.0;
out_color = hullColor*attenuate*k_light3Def*k_light3Def.a;
o_color += ndotl*out_color + ndoth*out_color*spec;
*/
o_color += o_color*slant*3;
// compute correct glow
if ( k_glow.w > 0.1 )
o_color = texBstg.w*hullColor;
else if ( texBstg.w > 0.1 )
o_color = o_color + texBstg.w*hullColor;
o_color.a = texRgba.a;
//o_color = float4(l_normal,1);
//o_color = float4(l_uv,0,1);
//o_color = float4(l_tangent,1);
//o_color = float4(l_binormal,1);
}
So you must use the shader to draw any thing even if you dont load it your self the card loads it for you. Without shader nothing can be drawn so you must use it to make a river or any thing else.
Normlay you put NPC in a call and create the class which created every thing else you tell it.
You are on your own with camera code there is many camera samples on the forum and the code you have is too complicated.
You pack the strings before you send them over the net. I recommend struct module. You give it format and arguments it gives you a string back . Then you can extract the args if you know the format. Some people use Pickle to do this but pickle is a big security risk (i can take over your machine by sending the right string) there is other pickle like modules around which are secure - one of them i wrote.