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
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 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
Basic Shader? #406374
08/18/12 16:19
08/18/12 16:19
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline OP
Serious User
Rackscha  Offline OP
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
Hi,
Somehow iam currently failing at recreating the same renderbehaviour with shader, as it is without.

Rendering the texture is no problem, but how do i correctly use the ambient values? sunlightning etc?

even with the macros in default.fx i end up with wrong/odd look.


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Basic Shader? [Re: Rackscha] #406381
08/18/12 20:40
08/18/12 20:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
The lighting formulas are elaborated here:

http://www.conitec.net/beta/lighting.htm

Maybe this is of some help for you?


Always learn from history, to be sure you make the same mistakes again...
Re: Basic Shader? [Re: Uhrwerk] #406382
08/18/12 20:43
08/18/12 20:43
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
I once tried to emulate them but eventually failed. They aren't that magic anyway.

Re: Basic Shader? [Re: Hummel] #406384
08/18/12 22:18
08/18/12 22:18
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline OP
Serious User
Rackscha  Offline OP
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
mh okay, lets say i keep it simple:

[code]
float4 Test_PS(TVSOutput In): Color
{
return tex2D(ColorMapSampler, In.OutTex) * vecAmbient * vecColor;
}
[code]

I have a texture which should be influenced by ambient and entitycolor when LIGHT is set.

is this correct?


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Basic Shader? [Re: Rackscha] #406452
08/20/12 18:58
08/20/12 18:58
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Hi, I know your pangs well. I will try to find my code that interacts with, and accounts, for those things.
Eric

Re: Basic Shader? [Re: Steempipe] #406455
08/20/12 19:38
08/20/12 19:38
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
For an editor project, I created a terrain multitexturing shader, which I tweaked so that it looks like the GS terrain. It is sort of a hack but was the easiest way for me to achieve the same look.

First, I calculated the per vertex lighting in the Vertex Shader. I wrote a small Color Correction function, for which I found nice values by trial-and-error:

Code:
// ambient
Out.Color = fAmbient;

// add sunlight and up to 8 dynamic lights
for (int i = 0; i < 8; i++)
{
    float f = 0.0f;
    float d = dot(N, normalize(vecLightPos[i].xyz - P));
    if (d >= 0.f) 
        f = 2 * d * lightAttenuation(vecLightPos[i], P);
    
    Out.Color += vecLightColor[i] * f;
}

// color correction (contrast, saturation, brightness)
Out.Color.rgb = ColorCorrection(Out.Color.rgb, 0.5f, 1.0f, 2.5f);



The light attenuation function is this:

Code:
float lightAttenuation (float4 lightPos, float3 surfacePos)
{
    float fac = 0.f;
    
    if (lightPos.w > 0.f)
    {    
        float l = length(lightPos.xyz - surfacePos) / lightPos.w;
        if (l < 1.f)
            fac = saturate(1.f - l);
    }
    
    return fac;
}



and the Color Correction function is this (if I remember right, I posted this here some time ago):

Code:
// Simple color correction; adjusts contrast, saturation and brightness of a RGB color
float3 ColorCorrection (float3 color, float contrast, float saturation, float brightness)
{
    // color for 0% contrast (mean color intensity)
    float3 meanLuminosity = float3(0.5, 0.5, 0.5);
    
    // coeefficients to convert to greyscale; coeeficients taken from OpenCV, which
    // were derived from 'Adrian Ford, Alan Roberts. Colour Space Conversions.', which
    // can be found here: http://www.poynton.com/PDFs/coloureq.pdf
    //
    float3 rgb2greyCoeff = float3(0.299, 0.587, 0.114);
    
    // enbrighten color
    float3 brightened = color * brightness;
    
    // approximate color intensity by transforming rgb to grey
    float intensity = dot(brightened, rgb2greyCoeff);		
    
    // saturate (brightended) color
    float3 saturated = lerp(float3(intensity, intensity, intensity), brightened, saturation);
    
    // apply contrast to saturated color
    float3 contrasted = lerp(meanLuminosity, saturated, contrast);
    
    return(contrasted);
}



In the Pixel Shader, I calculated my blended multitexture color and then, I just do:

Code:
color *= In.Color;



If you do this for a terrain, you should get a similar lighting like the GS terrain. I don't know exactly, but I guess this works for models, too. Just make sure you use the appropriate material properties from mtl_terrain, mtl_model or whatever you wanna re-create.

Good luck!

Last edited by HeelX; 08/20/12 19:39.
Re: Basic Shader? [Re: HeelX] #406459
08/20/12 20:32
08/20/12 20:32
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline OP
Serious User
Rackscha  Offline OP
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
Thanks HeeIX

Last edited by Rackscha; 08/20/12 20:32.

MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development


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