Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Need some help with equivalent code (XNA -> DGDK)

Author
Message
Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 8th Jan 2010 07:15 Edited at: 8th Jan 2010 08:18
Hey all,
I have recently come across some good shader tutorials, but they are written for XNA, not DGDK.

I was wondering if anyone knew any XNA and would be able to help me solve a problem, for a specular lighting shader.

The following code is the XNA command to pass the appropriate variable to the shader:


I understand most of it, what I just don't know is what the ViewVector should actually be!

The shader runs at the moment, but without the desired specular effect.

Thanks all!

EDIT:
Here is the shader code, I just realised it may help.



_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 8th Jan 2010 14:28
As the ViewVector is the cameraLocation subtracted from the cameraTarget position, it will give you the vector of the direction the camera is looking at.

You can pass a vector to a shader with dbSetEffectConstantVector().
But you'll have to use DarkGDKs built-in vector for the argument.
Look into the 3D Math section of the DarkGDK documentation.

Hope this helps you.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 8th Jan 2010 15:02
Yeah I had been playing around with the Vector commands, but is it a vector of xyz angles, or xyz positions?

I'll have a go with it now.
Thanks for the reply!

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 8th Jan 2010 15:13 Edited at: 8th Jan 2010 15:14
Neither/both, it's a direction, meaning the vector(3 floats) is normalized(has a magnitude of 1). For example, GDK uses a left handed axis where Y is up, so a vector pointing upwards would be exactly 0,1,0, one pointing to the right is 1,0,0 and forward is 0,0,1.

Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 8th Jan 2010 15:19
Thanks for explaining that darkcoder.

So, basically I have to find the distance between the two points, multiply it by the camera angle, transform it and normalise it and that should be it?

kaedroho
17
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 8th Jan 2010 19:13 Edited at: 8th Jan 2010 19:21
All you really need to do is create your view vector.

then set each value to:

x = - sin(Angle);
y = 0.0f;
z = - cos(Angle);

then normalise it.



A little explanation:

Firstly this bit:

view = Matrix.CreateLookAt(cameraLocation, cameraTarget, new Vector3(0, 1, 0));

You dont need a view matrix, so get rid of this.


Then:

viewVector = Vector3.Transform(cameraTarget - cameraLocation, Matrix.CreateRotationY(0));

As Matrix.CreateRotationY(0) always makes an identity matrix, the vector this function returns will always be the same as the vector you pass in. (this just makes viewVector = cameraTarget - cameraLocation)


Then:

viewvector can be calculated straight off like so:

x = Distance * sin(Angle);
y = Distance * 0.0f;
z = Distance * cos(Angle);


And as your normalising it later on, you dont need to multiply it by the distance. So you get this.

x = sin(Angle);
y = 0.0f;
z = cos(Angle);

Login to post a reply

Server time is: 2024-11-20 07:40:56
Your offset time is: 2024-11-20 07:40:56