Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 10:32
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 604 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
shader snippets (2): pp-specular/diffuse, textured #131928
05/25/07 18:43
05/25/07 18:43
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
ok, here we go with another shader, as always, if you understand something about shaders please don't forget to comment on it. the shader supports one texture and 8 dynamic lights with colors, one texture (can easily be changed to support more than one). is now ps 2_a, not 3_0.

attenuation added, play with the exponent to get various interesting results. it's not physically correct (i think you should use log somehow), but a nice approximation.

Code:
float4x4 matWorldViewProj;
float4x4 matWorld;

float4 vecLightPos[8];
float4 vecLightColor[8];
float4 vecViewPos;

//------------------------------------
struct vertexInput {
float4 Position : POSITION0;
float3 Normal : NORMAL0;
float4 texCoord : TEXCOORD0;
};

struct vertexOutput {
float4 Position : POSITION0;
float4 texCoord : TEXCOORD0;
float4 pos : TEXCOORD1;

float3 posVec : TEXCOORD2;
float3 normalVec : TEXCOORD3;
};

struct pixelOutput {
float4 Color : COLOR0;
};

texture entSkin1;

sampler2D tex_sampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = None;
};

float4 ppLightCalc(float4 Color, float3 Position, float3 Normal, int i)
{
float4 ppLightCalc(float4 Color, float3 Position, float3 Normal, int i)
{
// direction towards light
float3 vecLight = vecLightPos[i].xyz - Position.xyz;
float3 dirLight = normalize(vecLight);

// diffuse lighting factor
float fDiff = clamp(dot(dirLight, Normal), 0, 1);

// direction towards view
float3 dirView = normalize(vecViewPos.xyz - Position.xyz);

// reflection vector for light
float3 reflection = reflect(-dirLight, Normal);

// specular lighting factor
float fSpec = pow(clamp(dot(reflection, dirView), 0, 1), 16);

// light color
float3 light = vecLightColor[i].rgb;

// attenuation
float attenuation = pow(clamp(1.0f - length(vecLight/vecLightPos[i].z), 0, 1), 0.5);

return float4(light*(fDiff*Color + fSpec)*attenuation, 1);
}
}

//------------------------------------
void VS(in vertexInput a, out vertexOutput b)
{
// transform position
b.Position = mul(a.Position, matWorldViewProj);

// position for pixel shader
b.pos = a.Position;

// get the position of the vertex in the world
b.posVec = mul(a.Position, matWorld).xyz;

// get normal
b.normalVec = mul(a.Normal, matWorld).xyz;

// texture coordinate
b.texCoord = a.texCoord;
}

void PS(in vertexOutput b, out pixelOutput c)
{
int i;

// ambient value
c.Color = float4(0, 0, 0, 0);

// per pixel diffuse and specular
for (i = 0; i < 8; i ++) {
c.Color += ppLightCalc(tex2D(tex_sampler, b.texCoord), b.posVec, b.normalVec, i);
}
}

//-----------------------------------
technique simple
{
pass p0
{
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_2_a PS();
}
}



screens in the next posting (still without attenuation, maybe you can post some shots...).

Last edited by Joey; 05/26/07 13:02.
Re: shader snippets (2): pp-specular/diffuse, text [Re: Joey] #131929
05/26/07 10:39
05/26/07 10:39
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
here are two shots. it's applied to mat_shaded and reduced to accept 4 dynamic lights (faster!). note that the level texture is on TEXCOORD1, not on TEXCOORD0 (shadowmap).




notice the perfectly smooth specular cones and the hard edges (due to a phong algorithm).

greetings, joey.

edit: next thing to do would be to adapt the lighting to attenuation. that's no problem though.

Last edited by Joey; 05/26/07 10:44.
Re: shader snippets (2): pp-specular/diffuse, text [Re: Joey] #131930
05/28/07 15:51
05/28/07 15:51
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
So this shader is applied to geometry and reacts to dynamic lights, correct?

From your statements, would it not then be possible to pass the texture and pre-rendered shadowmap to the shader then? Allowing to create a softer-(precompiled)-shadow system?


xXxGuitar511
- Programmer
Re: shader snippets (2): pp-specular/diffuse, text [Re: xXxGuitar511] #131931
05/28/07 15:55
05/28/07 15:55
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i'm not quite sure what you mean. the level texture is already passed on to the shader and it would be easy to include the pre-rendered shadowmap from the map compiler. but that would not make the static shadows better, currently the shader only creates better dynamic lighting.

i'm indeed about to write a shader which completely replaces the static shadow calculations by dynamic lighting and shadowing.

joey.

Re: shader snippets (2): pp-specular/diffuse, text [Re: Joey] #131932
05/28/07 15:58
05/28/07 15:58
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Thanks for the info and inspiration, I'm gonna try some random crap and when I find something I'll post it


xXxGuitar511
- Programmer
Re: shader snippets (2): pp-specular/diffuse, text [Re: Joey] #131933
05/28/07 21:54
05/28/07 21:54
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
Machinery_Frank Offline
Senior Expert
Machinery_Frank  Offline
Senior Expert

Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
Quote:

..and it would be easy to include the pre-rendered shadowmap from the map compiler.




Sure about that? How can you access this shadow map from map compiler? Is there a second texture with second uv-set?

What about FPS? As far as I checked shaders on level-geometry they produced less than 10 fps.


Models, Textures and Games from Dexsoft
Re: shader snippets (2): pp-specular/diffuse, text [Re: Machinery_Frank] #131934
05/28/07 22:04
05/28/07 22:04
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Quote:

Is there a second texture with second uv-set?




Yep,
entSkin2 and TEXCOORD0.

Re: shader snippets (2): pp-specular/diffuse, text [Re: Slin] #131935
05/29/07 06:06
05/29/07 06:06
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
As long as the shader is kept simple, it shouldn't impact the framerate too badly...

...Unlike the normal/parallax mapping shaders shown before... lol.


xXxGuitar511
- Programmer
Re: shader snippets (2): pp-specular/diffuse, text [Re: xXxGuitar511] #131936
05/29/07 11:36
05/29/07 11:36
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline OP
Expert
Joey  Offline OP
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
the level runs with decent 60 fps and 4 visible dynamic lights on a gf6600gt (1280x1024). lightrange something about 300 quants afaik.

Re: shader snippets (2): pp-specular/diffuse, text [Re: Joey] #131937
05/29/07 12:13
05/29/07 12:13
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
Machinery_Frank Offline
Senior Expert
Machinery_Frank  Offline
Senior Expert

Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
Interesting. Which version of Gamestudio did you use for that?

I tested it not only with a small level - I checked a bigger bsp level and even simple FFP-materials via auto-material produced less than 10 fps. The reason for that is: A6 sends every single polygon seperated to the graphics card when you use blocks. Models are faster because there it sends the complete model with all polygons and material at once to the GPU.

That will change with A7 though when you use the new options to compile meshes out of blocks.


Models, Textures and Games from Dexsoft
Page 1 of 2 1 2

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