Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (EternallyCurious, Quad, vicknick), 700 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Waving Grass with Dynamic Light #471629
03/11/18 21:58
03/11/18 21:58
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
I am looking at the animTree.fx shader, and I am wondering if I can make it work with dynamic lighting. Right now, it works with sunlight, but if I turn on the character's flashlight (a dynamic light) all the trees/grass around me turn dark.

This page explains how to add dynamic lights to a shader: http://opserver.de/twik11/index.php?title=Shader_hints

However, if I add anything to it, it stops the waving animation. This is the part I'm trying to add:

Quote:
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;
}


I don't know much about shaders, so maybe I'm adding this code to the wrong section or in the wrong way. I tried the waving grass shader on the wiki, but that one looks even worse.

Has anyone made a waving grass shader that reacts properly to dynamic lights? Or would anyone know how to add this lighting effect to the existing animTree.fx shader?

Last edited by Dooley; 03/11/18 22:00.
Re: Waving Grass with Dynamic Light [Re: Dooley] #471641
03/12/18 13:42
03/12/18 13:42
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Can you show us the vertex shader portion of your animTree.fx shader? It may be where you are placing the dynamic light code thats causing the overwrite of the mesh manipulation

Re: Waving Grass with Dynamic Light [Re: jumpman] #471658
03/12/18 21:04
03/12/18 21:04
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
You know I just found the "Serious Grass" example in AUM58. It just adjusts the roll of the grass object, and that seems to work fine for what I need at this point.

I'm still interested in seeing if this approach will work, but it's not as urgent as it was yesterday.

I'm using the animTree.fx file that comes with GStudio7 in the "code" folder. I'm not sure if it comes in A8.

If you are interested in helping me figure it out (I have very little knowledge of how shaders work) I can send you the file...


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