There aren't really any "general" tutorials as far as I'm aware. You have to understand the concept once, from there on you will/ should only have specific questions left (like how to implement a normal mapping shader?).
You can look at other HLSL code you find on the internet but you will have to adapt it to Gamestudio specifics.
This HLSL reference has helped me quite a bunch in the past: https://msdn.microsoft.com/en-us/library/ff471376(v=vs.85).aspx
Why do shaders BOG up my frames per second?
This isn't really a question you can hope to get a senseful answer to. It highly depends on the complexity of the shaders, if you are talking about object shaders, postprocessing or even multiple pp stages and so on.
Just understand that when you are writing let's say a postprocessing shader which is supposed to manipulate the camera(.bmap) result, a small little program will be executed for every pixel on the screen. It's pretty much like the following:
for(i = 0; i < screen_size.x; i++)
{
for(j = 0; j < screen_size.y; j++) pixel[i][j] = evaluate(i/screen_size.x,j/screen_size.x);
}
This means the color values on your screen, the array "pixel", is filled by executing a small program for each pixel on the screen. On a 1920x1080 resolution this means more than 2 million pixels.
When your graphics card is slow/ only has a few shading units this process can take a while, esp. when your "evaluate" functions are complex. Additionally, you will have to draw many pixels more than once, when you have overlapping polygons/ objects or multiple postprocessing stages.
Flashlights are not that easy to begin with, but contrary to what Malice wrote you don't need to know or understand or apply any kind of higher math for most shaders (most people don't really understand the stuff required for normal mapping shaders and similar themselves, you only need to understand when to apply what and how, read: copy paste).
What helps a lot though, and I'm not kidding, is to make yourself familiar with the dot product (
http://en.wikipedia.org/wiki/Dot_product ). Many things can be realized with the dot product and normals, not only lighting in shaders (diffuse, per pixel, 2D shadowmapping) but visibility calculations and other stuff in lite-C, too.
Writing a shader oftentimes only comes down to simple math and combinations of a few lines of code which even are similar most of the time.
I usually start my shaders (my Superku game uses about 400 different shaders so far) with a copy paste of this code (ok not this exact code because I don't have it right now on my laptop but you get the idea):
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4 vecViewDir; // The sun direction vector.
//float4 vecSkill41;
float fAmbient;
texture entSkin1; // Model texture
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
AddressU = Wrap;
AddressV = Wrap;
};
void DiffuseVS(
in float4 InPos: POSITION,
in float3 InNormal: NORMAL,
in float2 InTex: TEXCOORD0,
out float4 OutPos: POSITION,
out float2 OutTex: TEXCOORD0,
out float3 OutNormal: TEXCOORD1)
{
OutPos = mul(InPos, matWorldViewProj);
OutNormal = mul(InNormal, matWorld);
OutTex = InTex;
}
// Pixel Shader:
float4 DiffusePS(
in float2 InTex: TEXCOORD0,
in float3 InNormal: TEXCOORD1): COLOR
{
InNormal = normalize(InNormal);
float4 Diffuse = saturate(dot(-vecViewDir, InNormal));
float4 Color = tex2D(ColorMapSampler, InTex);
float4 final = (1.0+fAmbient)*Color*Diffuse;
return final;
}
// Technique:
technique DiffuseTechnique
{
pass P0
{
VertexShader = compile vs_3_0 DiffuseVS();
PixelShader = compile ps_3_0 DiffusePS();
}
}
I think this is a derivative of the diffuse shader of the shader tutorial. Now I adapt this shader to whatever I need. At first you can try to multiply the dot() product in the Diffuse line in the saturate() command with 2 or 3 or 4 which will give you sharper shadows and sometimes cooler lighting.
Once you understand that the vertex shader gets executed for every vertex, the pixel shader for every rasterized pixel of an object (independent of the texture resolutions), textures usually are only in the range of 0..1, the difference between wrap and clamp and some other stuff such as AlphaBlendEnable, you can get very, very far for your game from just modifying above template.