1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Terrain & Shaders
#111731
02/12/07 08:03
02/12/07 08:03
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
I went to modify an existing multitexture terrain shader so that I could have dynamic lights affect the terrain, but I have no idea what I am doing. I have a lot of experience with programming, but I have never used shaders. I guess I just need to figure out where to start.
Currently I am using IceX2.0 to generate my terrain and I can't seem to figure out how to add the dynamic lighting to the shader.
In the end, I want to be able to create a HMP, have it textured, and have it be affected by dynamic lighting.
Any help would be appreciated, thanks a lot,
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: Terrain & Shaders
[Re: mbartman]
#111732
02/12/07 18:32
02/12/07 18:32
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
For example, I found this in the old wiki under a section about HLSL shaders, and it says, "For applying dynamic lights, use the following function:" That's all it says, and this seems to be the best explanation I can find, even though I don't know where to use it. PS It was late when I started this thread so I think I may have put it in the wrong forum, should be in scripting.. sorry Code:
float4 vecLightPos[8]; float4 vecLightColor[8]; float3 vecFalloff = float3(0.f, 0.f, 2.f); ... float4 DoPointLight(float3 P, float3 N, int i) { // calculate the light ray pointing from the light to the surface float3 D = (float3)vecLightPos[i]-P; // calculate the angle between surface and light ray float NdotL = dot(N,normalize(D)); // modulate the light by the surface angle float4 Color = vecLightColor[i] * NdotL;
// calculate the light attenuation factor, DX uses a really strange formula here float fac = 0.f; if (NdotL >= 0.f && vecLightPos[i].w > 0.f) { // get the distance factor float LD = length(D)/vecLightPos[i].w; #ifdef DXLIGHTING if (LD < 1.3f) fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD); #else // linear Lighting if (LD < 1.f) fac = 1.f - LD; #endif } return Color * fac; }
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: Terrain & Shaders
[Re: mbartman]
#111733
02/13/07 03:08
02/13/07 03:08
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
1) First off, bad place to post this. This belongs in the Shader section. 2) This is also in the Shader section (refrenced in part 1). So posting here is a double post, and not only that, but the wrong place to double post. HOWEVER... I know HLSL and have been messing with the terrain multi tex shader. IF YOU WANT, you can send me the IceX shader, and I will add dynamic lighting to it - free of charge 
xXxGuitar511 - Programmer
|
|
|
Re: Terrain & Shaders
[Re: xXxGuitar511]
#111734
02/13/07 03:43
02/13/07 03:43
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
Hey, I apologize again for posting this in the wrong section.. I was browsing the forums late last night and somehow I posted it here. On another note, I would love to learn to write HLSL shaders.. At the moment, I'm scavenging the net for tutorials and I'm also trying to learn from existing shaders in the community. Using this method, I've had a little success understanding how things work, but I am far from doing anything complicated.. I'm at work right now, but I will send you a message when I get home. I'd like to understand how your code works as well, if you don't mind explaining it to me when you're done  Thanks a lot,
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: Terrain & Shaders
[Re: mbartman]
#111735
02/13/07 04:00
02/13/07 04:00
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
HLSL took me a while to get into, but once I figured out the base of it, it wasn't too difficult. If you want, I can meet you on some IM service/software and give you a quick rundown of the framework for a simple shader. The hardest part (for me) is figuring out the lighting. I figured that you have to use a mix of the tangent and the normal (binormal). And the light attenuation/falloff is complicated too.
IDK - Just let me know and I'll help you out best I can.
xXxGuitar511 - Programmer
|
|
|
Re: Terrain & Shaders
[Re: xXxGuitar511]
#111736
02/13/07 04:08
02/13/07 04:08
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
That would be extremely helpful  Which IM service would be the most convenient for you? Right now I primarily use MSN, but I am willing to use any of them. Thanks a lot for your help, I really appreciate your willingness to help me learn
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: Terrain & Shaders
[Re: xXxGuitar511]
#111738
02/13/07 04:42
02/13/07 04:42
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
I'll add you as soon as I get home, my email is playboi_mike (at) hotmail.com just in case you screen your add's
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
|