|
Basic Shader?
#406374
08/18/12 16:19
08/18/12 16:19
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
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: Hummel]
#406384
08/18/12 22:18
08/18/12 22:18
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
OP
Serious User
|
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: Steempipe]
#406455
08/20/12 19:38
08/20/12 19:38
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
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:
// 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:
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):
// 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: 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
OP
Serious User
|
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
|
|
|
|