Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Baklazhan, Ayumi, Hanky27), 1,387 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
General Shader Questions #452304
06/09/15 00:48
06/09/15 00:48
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline OP
Serious User
DLively  Offline OP
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Hi There.

Im looking into shaders and im in need of some good tutorials. I've looked at whats available in the workshops and on the wiki and know some basic stuff.. Now I need some further tutorials to look at...

Can I use HLSL code from the net?

Why do shaders BOG up my frames per second?

Can I create basic shaders that don't eat fps?

How can I create a flashlight with shaders without having to use shade-c?

Are there any good bump map tutorials for 3dgs, besides the workshops?

EDIT: where can I find the bumpmap sample the workshop talks about, btw?

Last edited by DLively; 06/09/15 00:49.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: General Shader Questions [Re: DLively] #452326
06/09/15 13:34
06/09/15 13:34

M
Malice
Unregistered
Malice
Unregistered
M



Check the AUM for shader collections. You can examine the code. There are few left here working on great shader stuff.
With bumpmaps you will want a high res version of a model on 3dsmax to generate the normal map from, as the idea is the 2d normal map is holds greater detail then the low poly mesh.

I realize I haven't answered anything, but it's the best answers I have for the subject. I recently had a forum member make amazing shaders on a project of mine and I was lost trying to just read and follow the shader code. You will need a higher level math and math concepts.

EDIT: I know it's getting to sound like a broken record. But most the shader experts I asked for help from these last months have simply said - just use Unity

Last edited by Malice; 06/09/15 13:51.
Re: General Shader Questions [Re: ] #452328
06/09/15 15:11
06/09/15 15:11
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
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

Originally Posted By: DLively
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:

Code:
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):
Code:
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.

Last edited by Superku; 06/09/15 15:49.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: General Shader Questions [Re: Superku] #452332
06/09/15 17:47
06/09/15 17:47
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
http://rastertek.com/tutdx10.html is a good starting point for beginners. You don't need to read everything, only the shadercode examples and explanations. Of course the tutorials are written for DX10, not DX9. But this is not a huge problem once you understand how shaders are written. When you're done you can look into more advanced shaders on other websites or buy books about shader development and rendering techniques. All in all it's not an easy topic and will take a few weekends for reading and learning. If you don't know advanced mathematics it will be even a little bit harder to understand the ideas behind a shader implementation. But like Superku said,it's not necessary if you simply modify existing shaders. For a flashlight effect read tutorial 44.

Shadertool is a good node based tool for learning how to write shaders. Copy and paste Hlsl or Glsl into it, add some nodes for the input values and get instant results. Then try to manipulate the code by adding, removing or changing lines. You can get Shadertool on Steam, but wait until summer sale.

Re: General Shader Questions [Re: Ezzett] #452387
06/11/15 07:30
06/11/15 07:30
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
shader workshop is only a very basic start, I personally don't really like other available shader collections, especially hate the 3dgs built in shaders. as a start you can learn from them but imo they show a wrong and old approach. maybe shade-c evo is fine, but finally never digged deep into it (I think deferred rendering what it uses needs a little more experience than I have).

after the shader workshops I played a lot with the old shade-c packages, customized, simplified, corrected them by taking out only the parts I need. and I always read articles about only what I actually needed. I'm quite an experimental person, I enjoy best learning on the fly. e.g. the above mentioned rastertek page is fine, but try to find DX9 stuff, some DX10 and above examples could be useless sometimes. and I tested everything on real levels, not only with small test environments where a lot of bugs can stay hidden!

what I really found strange that I did not find any good comprehensive shader package (including sprites, grass, models, blocks/map-entities, trees, terrain, water, sky, triplanar object texturing, bone animation) for 3dgs featuring per pixel lighting and normal mapping supporting 8 dynamic lights including Sun properly, that utilizes 3dgs material system as it should (diffuse, ambient, specular, emissive, entity rgb). e.g. in general speculars are calculated with an equation having very unnatural results, and tangent space calculation required for normal mapping give you wrong result as you rotate an entity and rotate a light around it. even shader model 3 usage is a rare phenomenon, but it has its advantages over SM2.

so I created my little package available within MapBuilder (only the entity rgb is not yet set properly, what I never use). it has been tested a lot, rather visually than theoretically, made some really experimental things, and finally it works fine and effective, LOD is utilized, structured into multiple include files (3dgs supports it approx. since last update), you can set quality/performance in a commonly included file that affects all the shaders etc. shadowmapping could be less flickering but for my RTS game it is not bad. I can recommend it despite it is probably not the best package, but you can just take the necessary modules out of MapBuilder easily (I fixed it in last release). by the way, I never needed flashlight.


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1