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
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 (AemStones, AndrewAMD, gamers, Kingware), 1,679 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Diffuse Dynamic Light Shader #175456
12/31/07 04:25
12/31/07 04:25
Joined: Jun 2005
Posts: 656
G
Grafton Offline OP
User
Grafton  Offline OP
User
G

Joined: Jun 2005
Posts: 656
Can anyone help me change this simple diffuse shader so it works with a dynamic light instead of the sun?

I know I need to use "vecLightPos[1]" to create the eqivalent of "vecSunDir", but how?
Thanks for any help!

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 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, passed by the engine.
const float4 vecSunDir; // The sun direction vector.

texture entSkin1; // Color map.

sampler ColorMapSampler = sampler_state // Color map sampler.
{
Texture = <entSkin1>;
AddressU = Clamp;
AddressV = Clamp;
};

/***********************************************************************************************
/ Vertex Shader:
/***********************************************************************************************/
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)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);

// Transform the normal from object space to world space:
OutNormal = normalize(mul(InNormal,matWorld));

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


/***********************************************************************************************
/ Pixel Shader:
/***********************************************************************************************/
float4 DiffusePS( in float2 InTex: TEXCOORD0,
in float3 InNormal: TEXCOORD1) : COLOR
{
// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;

// Calculate the diffuse term:
float4 Diffuse = DiffuseIntensity * saturate(dot(-vecSunDir, normalize(InNormal)));
Diffuse *= SunColor;

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

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

/***********************************************************************************************
/ Technique:
/***********************************************************************************************/
technique DiffuseTechnique
{
pass P0
{
VertexShader = compile vs_2_0 DiffuseVS();
PixelShader = compile ps_2_0 DiffusePS();
}
}





Not two, not one.
Re: Diffuse Dynamic Light Shader [Re: Grafton] #175457
01/01/08 00:07
01/01/08 00:07
Joined: Jun 2005
Posts: 656
G
Grafton Offline OP
User
Grafton  Offline OP
User
G

Joined: Jun 2005
Posts: 656
Got it working the way I want!

Funny how you can't seem figure something out until you ask on the forum,
then wham, you figure it out!
When I make sure there is no stupid coding errors (hehe), I'll post my solution.


Not two, not one.

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