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.

Newcomers DBPro Corner / I need some Assistance with Vertex Shaders

Author
Message
Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 24th May 2008 22:55 Edited at: 24th May 2008 23:58
Hey all!

I've been reading up on the Load Vertex Shader From File, and it sounds intriguing. Does anyone know where I can find a tutorial on how to write a Shader in a text file? or is there a program I could use for this? I was reading up on it and it seems like the effect I want to accomplish uses Per-Pixel Specular Mapping Shaders to give a gun a shiney updating surface.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th May 2008 16:52
It's just a plain text file - you could edit one in notepad if you wanted.

If it's 'how to write a shader' that you are after, then there's a sticky thread at the top of the DBPro forum you might want to read through - put a few hours aside for it because it's a long thread.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 25th May 2008 21:37
Okay cool, thanks for the response I'll check it out.
Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 26th May 2008 05:21 Edited at: 26th May 2008 05:45
Okay,

I grabbed FX Composer because that got better reviews than RenderMonkey did. I am now trying to figure out why my weapon is disappearing here is my code:



Can you tell me how to fix this? do I have to redraw something? or is there a lengthy process I'm missing?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th May 2008 11:36
Quote: "or is there a lengthy process I'm missing?"

No.

Can you try disabling the light mapping and then bump mapping in turn? I don't believe you can have more than a single effect active at one - they may both use shaders, and there is a limit of one shader per mesh.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 26th May 2008 21:56 Edited at: 26th May 2008 21:58
I just tried it, and my gun is still invisible.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th May 2008 23:00
Upload the media in a zip file and I (or someone else) can take a look at it. Debugging using the power of guesswork isn't my preferred method

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 26th May 2008 23:13 Edited at: 26th May 2008 23:33
Okay will do. The stuff has been uploaded

Attachments

Login to view attachments
Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 1st Jun 2008 22:01
Did you check it out Ian?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jun 2008 01:11 Edited at: 2nd Jun 2008 01:16
Not so far - I've been working on the latest release of my free set of plug-ins.

Why not take a look at them while I'm looking into this problem for you.

BTW, did I mention that they are free?

[EDIT]The media you uploaded appears to be missing 3 textures used in that code - lead.bmp, leadbump.tga and ak47bump.tga

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 2nd Jun 2008 22:39 Edited at: 2nd Jun 2008 22:48
Thats kinda weird, I included everything. Are you remembering to include the files into your Project files for this? I could have sworn I put them in there.

Edit: I guess I will upload these things again.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jun 2008 23:37 Edited at: 2nd Jun 2008 23:39
Nah, I didn't make a mistake with the file. The zip file you uploaded was only 67k, but this rar file is 1425k.

Anyway, I've got to the point where I think I know what's going on here ...

SET LIGHT MAPPING ON - fine
SET BUMP MAPPING ON - first shader
SET OBJECT SPECULAR POWER - does this have an effect without using SET OBJECT SPECULAR? Doesn't matter either way because ...
SET OBJECT EFFECT - overrides the bump map shader, and all other effects

Firstly, the first shader (bump mapping) is disabled by setting a new shader on the object (your phong.fx). Next, all the other stuff is ignored because your shader doesn't handle it.

As soon as you add a shader to an object you are replacing the fixed-function pipeline. When you do that, it becomes your responsibility to control the effects of lighting and the textures attached to your mesh. That doesn't appear to be happening with your shader.

One final thing is to remember that your gun isn't moving, so it won't be affected differently by the light - it's not attached to the camera, simply rendered as if the camera was placed at 0,0,0 and pointing down the z axis.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 3rd Jun 2008 08:26
How would I lock the gun onto the camera?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Jun 2008 01:27
Ok...


The number 1.42 is the approximate distance needed to travel at 45 degrees to get an x and z distance of 1 (simple pythagoras).

This:


Is directly equivalent to this:

... which you will know from your trig lessons. The NEWXANGLE/NEWZANGLE functions are convenience functions.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 4th Jun 2008 20:41 Edited at: 4th Jun 2008 20:48
Sweet! thanks dude. I will try this, I was searching through the code base and found a Code Snippet that was based on FPS movement which is pretty neat, but for some reason the setup in that Code Snippet makes my gun rotate weird when I move around, instead of the gun moving from side to side while turning whereas it does do that, but the rotation is completely off. The gun rotates at an angle when I turn, but I was able to fix it by changing a value. Yours is less complicated lol.

The way I swing is I try to find the easiest way to accomplish something, basically a way to be less complicated while taking in the thought of something looking cool.

Edit: Although this other code snippet, shows someone how to use Limbs which is neat, gives you more control I guess.
Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 4th Jun 2008 22:05
How would one go about setting up gun recoil?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Jun 2008 00:28
You can do that by moving the gun backwards a short distance and then back again over time.

I've looked at your model, and it's not well suited for the limb method without extra work. Normally, you would arrange to have limb 0 at the top of the hierarchyso that offsetting limb 0 would also offset the other limbs (a parent/child relationship).

With your model, there are 3 limbs, and all are at the top level of the hierarchy - that means that all 3 need to be offset. In addition, they already have an offset, so you need to apply an adjustment rather than simply setting them to the values you need.



It simplifies the maths (there is none now), and it probably slightly faster, although you wouldn't easily be able to time the difference.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 5th Jun 2008 05:25
How would I move it back overtime?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Jun 2008 22:42
For a gun firing, You'd want it to recoil fast when you fire moving backwards until it hits some sort of limit, then moving forwards again at a slower rate until it's back where it started, but having no 'hard stop' in the middle.

That describes the SIN function perfectly - just feed it an angle, ranging from 0 to 180, incrementing the angle each frame. Increment by a large number while the angle is less than 90, and a smaller number after that.

Here's the amended code:


I've also moved the gun forward a little to allow the effect to be seen a little more clearly.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 6th Jun 2008 01:32
This is cool, but the issue is this gun isn't resetting lol.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jun 2008 15:01
So fix it - that's what you set yourself up for by learning to program.

It worked for me.

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 7th Jun 2008 00:57
I must be bugging you lol.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jun 2008 02:48
Not really

One of the things that beginners don't actually consider is the amount of debugging they'll do while coding - you will spend more time modifying code than you will writing it in the first place, and relatively few pieces of that original code will remain unchanged or in their original locations.

So my advice to you is to get good at debugging. You can start with the problem you are having with that code, because it's still working fine for me

Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 7th Jun 2008 06:48 Edited at: 7th Jun 2008 07:34
So the the answer is right in front of my face huh?

Edit: Ack, I've been messing around with this for hours lol. Can't seem to figure this out.
Firos12
17
Years of Service
User Offline
Joined: 6th Aug 2007
Location:
Posted: 9th Jun 2008 07:14
I give up been trying to mess with things for a few days now. I can't seem to figure it out.

Login to post a reply

Server time is: 2024-11-25 04:48:59
Your offset time is: 2024-11-25 04:48:59