Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 1,395 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Shader on World object ... #154874
09/17/07 17:15
09/17/07 17:15
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA
I tried apply bump.fx on world static object but UV mapping is wrong, where is problem. Result looks like on picture:



and used shader is here:


Code:
 



/***********************************************************************************************
/ Copyright 2006 by Taco Cohen. All rights reserved
/***********************************************************************************************/

/***********************************************************************************************
/ Global Variables:
/***********************************************************************************************/
// Tweakables:
static const float AmbientIntensity = 1.0f; // The intensity of the ambient light.
static const float DiffuseIntensity = 1.0f; // The intensity of the diffuse light.
static const float SpecularIntensity = 1.0f; // The intensity of the specular light.
static const float SpecularPower = 8.0f; // The specular power. Used as 'glossyness' factor.
static const float4 SunColor = {0.9f, 0.9f, 0.5f, 1.0f}; // Color vector of the sunlight.

// Application fed data:
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4 vecAmbient; // Ambient color.
const float4 vecSunDir; // The sun direction vector.
const float4 vecViewPos; // View position.

texture mtlSkin1; // Color map.
sampler ColorMapSampler = sampler_state // Color map sampler.
{
Texture = <mtlSkin1>;
//AddressU = Wrap;
//AddressV = Wrap;
};

texture mtlSkin2; // Normal map.
sampler NormalMapSampler = sampler_state // Normal map sampler.
{
Texture = <mtlSkin2>;
//AddressU = Wrap;
//AddressV = Wrap;
};


/***********************************************************************************************
/ Vertex Shader:
/***********************************************************************************************/
void NormalMapVS( in float4 InPos : POSITION,
in float3 InNormal : NORMAL,
in float2 InTex : TEXCOORD0,
in float3 InTangent : TEXCOORD3,

out float4 OutPos : POSITION,
out float2 OutTex : TEXCOORD0,
out float3 OutViewDir: TEXCOORD1,
out float3 OutSunDir: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);

// Pass the texture coordinate to the pixel shader:
OutTex = InTex;

// Compute 3x3 matrix to transform from world space to tangent space:
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(InTangent, matWorld);
worldToTangentSpace[1] = mul(cross(InTangent, InNormal), matWorld);
worldToTangentSpace[2] = mul(InNormal, matWorld);

// Calculate the view direction vector in tangent space:
OutViewDir = normalize(mul(worldToTangentSpace, vecViewPos - mul(InPos, matWorld)));

// Calculate the light direction vector in tangent space:
OutSunDir = normalize(mul(worldToTangentSpace, -vecSunDir));
}


/***********************************************************************************************
/ Pixel Shader:
/***********************************************************************************************/
float4 NormalMapPS( in float2 InTex : TEXCOORD0,
in float3 InViewDir : TEXCOORD1,
in float3 InSunDir : TEXCOORD2) : COLOR
{
// Read the normal from the normal map and convert from [0..1] to [-1..1] range
float3 BumpNormal = 2 * tex2D(NormalMapSampler, InTex) - 1;

// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;

// Calculate the diffuse term:
float4 Diffuse = DiffuseIntensity * saturate(dot(InSunDir, BumpNormal));
Diffuse *= SunColor;

// Calculate the reflection vector:
float3 R = normalize(2 * dot(BumpNormal, InSunDir) * BumpNormal - InSunDir);

// Calculate the specular term:
InViewDir = normalize(InViewDir);
float Specular = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;

// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);

// Calculate final color:
return (Ambient + Diffuse + Specular) * Color;
}

/***********************************************************************************************
/ Technique:
/***********************************************************************************************/
technique SpecularTechnique
{
pass P0
{
VertexShader = compile vs_2_0 NormalMapVS();
PixelShader = compile ps_2_0 NormalMapPS();
}
}



Re: Shader on World object ... [Re: AndyGFX] #154875
09/17/07 17:20
09/17/07 17:20
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
set the textures flat flag in WED or change this in the header of the vertexshader:
in float2 InTex : TEXCOORD0,
to:
in float2 InTex : TEXCOORD1,

Re: Shader on World object ... [Re: Slin] #154876
09/17/07 19:20
09/17/07 19:20
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA
thx. Work now OK.

But i have one question.

I tried a few your cool shaders, but on my static world object looks like vertex color and not as per-pixel lightning. (i have added dummy obj for light like you).

Re: Shader on World object ... [Re: AndyGFX] #154877
09/17/07 19:39
09/17/07 19:39
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
This effect uses the sun only and blocks using it aren´t effected by dynamic lights. But it uses per pixel lightening. And hey, these aren´t my shaders they where done by different people from this forum wich are having much more knowledge about shaders than I have
Thanks for everyone contributing great shaders
This one for example comes from a shadertutorial written by Excessus.

Re: Shader on World object ... [Re: Slin] #154878
09/17/07 20:11
09/17/07 20:11
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA
Ok.

And have you any tip for good (working) diffuse+normal+height+specular map shader with 1-3 lights?

Re: Shader on World object ... [Re: AndyGFX] #154879
09/17/07 20:16
09/17/07 20:16
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
You could try the one from xXx_Guitar, but I prefer the older versions of it. Or have a look at the one in the 3DGS Wiki. It is may a bit slower, but supports up to 6 lights and looks awsome

Slin

Re: Shader on World object ... [Re: Slin] #154880
09/17/07 21:12
09/17/07 21:12
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA
so. now i hawe working shader with 3 lights, but i need set for light range.

Is possible assign my.LightRange to vecLightPos[xyz].w?

Re: Shader on World object ... [Re: AndyGFX] #154881
09/17/07 21:19
09/17/07 21:19
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
It is already there

Re: Shader on World object ... [Re: Slin] #154882
09/17/07 21:26
09/17/07 21:26
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA


Uff. Long time experimenting. Result is here:



but i thing that a lot of FX shaders (HLSL) from this forum are writed very simple and only for preview. Then is problem fix it to normal work like in other engines. It's hard for me, because i have experiences with GLSL I like OpenGL more as DX

I must now fix a few variables and the i will post shader here.

Re: Shader on World object ... [Re: AndyGFX] #154883
09/17/07 22:42
09/17/07 22:42
Joined: Jun 2004
Posts: 21
SLOVAKIA
AndyGFX Offline OP
Newbie
AndyGFX  Offline OP
Newbie

Joined: Jun 2004
Posts: 21
SLOVAKIA
So here is working specular_bump shader for world with lightrange per light configured from WED.

P.S.: You dont need set brush face to FLAT now

DOWNLOAD Example



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