Normal-Mapping Shader (The Best @ vsps2.0)

Posted By: xXxGuitar511

Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 16:31

Here's a great NormalMapping shader compiled at vertex/pixel shader 2.0 using two passes. Download Here!

This shader started from Matt_Aufderheide's NM shader, then passed to Bloodline where he added more light passes, then to William where he added more features, and last but not least to xXxGuitar511 where he optimized, and added some additional features as well. The heart of this shader is its lighting algorithms, provided by Matt_Aufderheide.

The Final product is a NM shader which supports:
- Dynamic Sunlight
- 3 Dynamic Lights
- Static Lighting
- Specular Lighting
- Fog (mostly )
as well as:
- Great speeds
- adjust settings through material
- fully supports scripts "Customize" menu in WED


If you have any requests for this shader, such as adding more light passes, then just post them here. But remember, the more passes you add, the slower the shader will run!


  • Instructions for use:

    Advanced users:
    include <NM.wdl>;

    Beginning users:
    - Open your project in WED, then go to the [resources] tab.
    - Open the main script for your project. By default, this will have the same name as your map.
    - Scroll down a few lines until you find your [included] files. When you find these, at the end of the list, add the line: include <NM.wdl>;
    - Save your script, and then close it.
    - Apply the material mat_NM to the models you wish to have NM on.
    - Your done!


    For this shader to work, you MUST have a NormalMap in the second skin of your model. For a great tutorial on NM, look HERE.

    Note: Dynamic lighting only supports the light color, not direction. Therefore, A direction for static lighting must be "faked". The direction used for static lighting in this shader is the sun_dir.
  • Posted By: Machinery_Frank

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 16:47

    Thank you very much for this fantastic contribution.

    But you forgot to add the shader.

    And if you want to test it then you might play around with my latest contribution that fits perfectly to this contribution:
    http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/740985/an/0/page/0#Post740985

    Have fun!

    Here is one question of mine:
    How does it work with static lighting? I thought static lights do not really exist. They are just baked lightmaps in the level geometry.

    Requests? I have dozens of requests
    I could imagine a specular parallax / relief shader. Or what about multi-texturing for terrains that allow normal-mapping at the same time?

    Regards,
    Frank
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 17:01

    multitexturing could be real easy, ill see what i can do about adding it.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 17:05

    @Frank_G: Yeah, I saw (& used) your contribution. Thanks, it actually helped me very much!

    BumpMapping on terrains could be very slow. I've already made my own multitex shader (part of a project I'm going to sell), but it doesn't use normal maps. This would be easy to add, I'm just not sure how fast (or slow) it would run.

    BTW: yeah, I did forget to add the link, it's up now. I realized that right after I posted, lol.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 17:28

    Here's a few screenshots: Here!
    Posted By: frazzle

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 19:58

    TOP contribution Guitar !!
    Btw, thxn for the screenies, it gives the users a good impression of what this is capable
    This all results in a super 3 rating

    Cheers

    Frazzle
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 20:28

    Ha, thanks Frazzle...

    I'm basing future developments of shaders on the results of this contribution. This shader turned out very well. I was surprised at the speed I got from it. Most shaders I run will make the FPS crawl, with this (in the environment shown), I recieved approx 30-40 FPS. Not too bad for A6 rendering. When used with Sylex or Sphere, it should be great!

    I tried to describe how to implement it the best I could, because every shader topic I read, someone asks "How do I use it?".
    Posted By: Machinery_Frank

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 20:42

    Quote:

    @Frank_G:BumpMapping on terrains could be very slow. I've already made my own multitex shader (part of a project I'm going to sell), but it doesn't use normal maps. This would be easy to add, I'm just not sure how fast (or slow) it would run.




    Yes. Maybe you are right. I just noticed that all new games use normal mapping on terrain (e.g. Stalker does it). Stalker uses Normalmapping on every mesh in the game.

    But anyway. I will try this nice shader contribution with a new scene very soon.
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 20:43

    "Note: Dynamic lighting only supports the light color, not direction. Therefore, A direction for static lighting must be "faked". The direction used for static lighting in this shader is the sun_dir."

    Could you make it so that it react to the direction of dynamic lighting? By the way, I've now done some testing and this contribution is top notch, big thanks!!

    Quote:


    Yes. Maybe you are right. I just noticed that all new games use normal mapping on terrain (e.g. Stalker does it). Stalker uses Normalmapping on every mesh in the game.




    Yeah, I'm actually surprised Stalker doesn't run slower because of that. On the other hand the system requirements are huge.

    Cheers
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 21:34

    Quote:

    Could you make it so that it react to the direction of dynamic lighting?


    Dynamic lighting uses the position of the dyn light as it should ...

    Only static lighting must fake light direction. here's how it works:
    Static light positions are not stored, only the lightmaps they create. Therefore, to get the color of static lighting, you must simply use traces to get the colors from the lightmap around your model. This shader simply does a downward trace from the origin of the model, and passes the color to the shader. Since we do not know the position, we must tell the shader where to illuminate from. So I decided to use the suns position/angle for this.
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 21:51

    I see, well I think I'll simply turn all static lights into dynamic ones, I don't need that many anyways.

    Cheers
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/07 22:45

    well you could also read from the wmp file too, and when you go to publish you could easily just open the file and take out all the information but the lighting info, it should be pretty easy.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 00:31

    yes, I could...


    Would you be willing to pay me for such a script/plugin?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 01:20

    On the topic of NM on terrains, if anyone wants to provide me with 3 textures (Diffuse & NromalMaps), then I will test out my MultiTex shader with normalmapping...
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 02:49

    What size do you need?

    Cheers
    Posted By: MaxF

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 04:45

    Hi

    Why does the object look so dark and how can I change this.
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 05:26

    if i ever get some free time i could write the script to read the locations of lights in the level
    Posted By: Machinery_Frank

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 07:01

    Quote:

    On the topic of NM on terrains, if anyone wants to provide me with 3 textures (Diffuse & NromalMaps), then I will test out my MultiTex shader with normalmapping...




    Please add me on MSN or write me an email to:
    info [at] geppert-software [dot] de

    I am very grateful because of your contribution and I am willing to provide you every texture that you need with and without normal, height and spec maps.
    I could even help with a few test meshes, hints and ideas.

    It would be a pleasure to work together with you.
    Posted By: Mondivirtuali

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 12:04

    Thanks for the excellent contribution
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 12:51

    @All: Thank you all for your support and compliments. They are much appreciated.

    @PHeMoX: Any size will do. Preferably 512^2.

    @MaxF: Because I used a dark level - You can adjust the ambience, and use more lights as well.

    @Lostclimate: If your up for the challenge, then sure. We could work on such a project.

    @Frank_G: Thank you. I could use some textures. All the ones I've used so far were found scattered on the internet (yahoo! image search). I will add you as aoon as I get home.
    Posted By: mpdeveloper_B

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 14:50

    @Guitar: nice contribution, i'll look at it later

    @lostclimate: if you guys ever do get that working, it'd be a sweet contribution
    Posted By: Machinery_Frank

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 15:13

    Quote:

    @Guitar: nice contribution, i'll look at it later

    @lostclimate: if you guys ever do get that working, it'd be a sweet contribution




    I agree absolutely. If you need any help to create a tech demo then I would love to join you and help.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 15:28

    It would be a nice project. If you read the positions from thye WMP and saved them to a text file. Then loaded the positions from the text file into an array. Then create a light management system to tell which lights need to be passed to the shader.

    The only problem I see is when passing to the shader. For each light, you have to pass 7 variables (x, y, z, red, green, blue, range). I'm not sure what would be the best way to pass these to the shader though.
    Posted By: Loopix

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 17:47

    Woulden't that work with a vecSkill41 (for the position) and a mtlSkill1 via pixel_for_vec (for the colors)?

    ...and thanks for this great contribution!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/02/07 23:50

    i could, but then I'd have to use both (for light position and color), limiting me to one light passed to the shader...
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/03/07 03:43

    well i can read the colors directly from the file, so pixel for vec isnt really needed

    edit: I also wanted to add that its real easy to get info and write info to wmps, i made landscape block editor the first month i started using 3dgs seriously, but it didnt work out because it was to many wierd angles for the engine, and the lighting got all screwed up.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/03/07 14:04

    pixel_for_vec() would still be needed to convert the c-script values to float() vectors...
    Posted By: mpdeveloper_B

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/03/07 14:31

    Quote:

    Quote:

    @Guitar: nice contribution, i'll look at it later

    @lostclimate: if you guys ever do get that working, it'd be a sweet contribution




    I agree absolutely. If you need any help to create a tech demo then I would love to join you and help.




    it would also be cool to have a "template" made for any lighting shaders using this, if it would work, i'd like to use the code in my lighting shader, of course it still needs some work if you want "realistic" lighting....
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 13:58

    For the normal mapping on terrains, should the NM's be for each texture (tiled), or one NM for the whole terrain?
    Posted By: Machinery_Frank

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 14:23

    If you want to create big terrains then you must tile them for sure.
    Posted By: Anonymous

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 14:36

    when i use the shader the model is grey where the light not shine.

    sorry for ma bad english.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 14:36

    I wasn't sure if I should make it to use 1 high-res normal map for the whole terrain, or have a normal map for each tileable texture...

    Both effacts are nice. But it depends on the terrain i guess...


    I'm going to try it tileable first...
    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 18:57

    Hi!
    You already think about the next shader, I know, Iīm a little late.
    Just wanted to thank you for this wunderful NM-Shader! I still canīt believe it: it works! And it was really simple to apply. It didnīt crash my PC!
    I tested with Franks textures and it looks really great, not the usual stupid plastic look but really decent and realistic. Very nice texture. Great contribution by both you and Frank and all the others who helped with the creation. Iīm extremely happy, that I can adjust the material settings, so it fits very well into my outdoor environment (dynamic light changes).
    Posted By: Anonymous

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 19:38

    it looks like this


    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 20:46

    Not at my system, that looks more like the other normalmapping shader that was posted. It looks more like this:

    ackdoom

    Cheers
    Posted By: Anonymous

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/05/07 20:49

    it works now.
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 02:41

    well im still working on the script to load the positions and colors of the lights, even tho I absolutely hate file and string handling in 3dgs )))

    PS so far i just have it so you can open the file and read up to the spot that tells the colors.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 03:43

    OMG PHeMoX, that models f***ing nice! great use of the shader!
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 04:49

    Trying to figure out why part of the model is still flat looking and why it only looks detailed where it starts to shine.
    Great contribution by the way. especally for the noob I am


    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 06:11

    Quote:

    OMG PHeMoX, that models f***ing nice! great use of the shader!




    You can download that model on 'acknex unlimited', it's one of the many doom3 models available, but this demon one has the most detailed skins and normal map. (I think it's simply extracted from Doom3, not a copy). What's best it looks even better in motion,

    (big thanks for these models to Kai Kieschnick btw.)
    Direct download link: Doom3 Model Pack

    Cheers
    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 08:01

    One possibility might be, that the normal map was created based on the diffuse texture. I think the tools and plug ins, that create normal maps from 2D textures use the brightness values of the image. Often darker parts of the texture are lower, but in this case the spaces between the bricks are very bright, almost as bright as the bricks. So I would recommend - before creating the normal map - to make a greyscale copy of the texture and manually darken the parts between the bricks, to make sure, that the normal map has some depth (like a bumpmap).
    I would also use the alpha channel to control the specularity. Bricks are usually not very shiny ...
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 14:33

    OK cool. Found a tutorial on doing that at the AU site and looks much better now. Thank you
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 14:50

    OK got that problem fixed. I still noticed that it dont apply the effects of being raised. The textures I purchased did come with bumps. Is there a way in idiot terms to do these ?
    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 17:09

    Quote:

    I still noticed that it dont apply the effects of being raised.




    Well, I did some tests now, and I can confirm this, even when I create the normal map (or should I call it a DOT3 bump map) based on a greyscale texture, that has a lot of contrast (I use a little ATI tool for this). The 3D effect is only visible in areas with high specularity.
    Maybe for this shader the normal maps are better created with a different tool or procedure (maybe with 3D models)? I will try that.
    Or is there a line in the .fx file, that controls the strength of the 3D effect?


    There are some other things, that I noticed ...

    1) For outdoor stuff it would be great if the shader could react to changes of sun_color. At the moment I would have to adjust the material, but this works fine (like with predefined materials btw., so it is consistent).

    2) Objects with the NM material seem to be immune for shadows. I just tested with stencil shadows. Shadows are not rendered on the surface of the normalmapped models and the models also do not cast shadows.

    3) The shading on the faces - when they receive sun_light is not really realistic. There is a visible fall-off (on large faces). The sun_light however should not produce such a fall-off even if it looks nice sometimes

    All my tests were done in a model-based level without blocks and lightmapping.

    Anyway itīs a really nice and very useful shader!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 20:16

    1) sun_color isn't passed to the shader, but you can easily amke it so that the material values are set to the sun_color every frame. Just open the NM.wdl, go to the mat_NM_event() and add vec_set(mtl.specular_blue, sun_color);

    2) Stencil shaddows worked just fine for me...

    3) I thought I left out the attenuation on sunlight. I'll do some testing. Also, the large faces your using for testing, are the just faces, or actaully shapes. The vertice normal are interpolated, so the edges might think their facing away from the sun...

    4) Static lighting only works when their are blocks to read the lightmaps from. Only stencil shadows will work. The shadows are not controlled by the shader at all. stencil shadows also pass through objects, so use them carefully...
    Posted By: Slin

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 22:40

    Thank you for this very nice contribution!
    After playing around with this shader, I noticed that the c_trace slows the entity rendering speed down a lot.
    I havenīt a clue about shaders, but I remembered a ffp-bumpmapping effekt, wich was everytime as bright as the ground below it, or at least it seemed so.
    I took a closer look at it and found vecLight.
    I replaced your mtlSkill1 with vecLight and this looks all right in my testlevel (ok itīs a bit brighter then using the trace). So my question is, whatīs wrong with vecLight?

    Another thing wich interests me is c_scan cause in the manual it sais:
    Quote:


    c_scan (VECTOR* pos, ANGLE* dir, VECTOR* sector, var mode);
    [...]

    The following mode values can be set:
    [...]
    SCAN_LIGHTS Scans for static lights.
    [...]

    Modifies:
    you Pointer to the closest detected entity.
    result Distance to the closest detected object.
    target Position of the closest detected object.
    bounce Angle of the closest detected level camera position.
    tex_color Color of the closest detected static light.

    [...]





    Are these static lights those placed in WED?

    Thanks,
    Slin
    Posted By: TSG_Torsten

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/06/07 23:24

    Sorry for question,

    but is there anyway using this shader on normal map blocks?

    Because I like this shader and it would be great if there is anyway to use them on blocks.

    Greetings
    TSGames
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 01:09

    Is there a way to adjust this fog. I do not have it set in 3dgs period


    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 01:22

    Hi!
    You might simply uncomment these lines

    fog_color = 1;
    camera.fog_start = 5;
    camera.fog_end = 800;

    in the effect_startup function of the NM wdl. They were probably for testing.

    @ Guitar: I found out, whatīs causing the problem with stencil shadows. It has nothing to do with the shader. The problem is, as soon as thereīs a skin with alpha channel, the engine "thinks" itīs transparent and refuses to render stencil shadows. Well I need the alpha channel for specularity control. If I use a 24bit texture, the stencil shadows work, but I have too much specularity.
    I tried
    my.transparent = off;
    and my.flare = off;
    but it didnīt help. I think someone here in the forum has mentioned this problem sometime ago ...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 01:41

    @Slin: The c_scan() method only returns the color of the lightmap below the entity, not the lights position. I'm doing the same thing with c_trace(). I am using this method to light the model with static lights (as you can see). When I was working on the shader, I was getting horribly incorrect results with vecLight, therefore I wrote my own method for doing static lighting. I'll mess with it some more.

    @TSGames: It is possible, but not realistic. Shaders on WED blocks are TOO slow. This is why many developers are now creating thier levels with models.

    @foodstamp: Robotronic explained the problem. This was for testing, and I had forgotten to remove it. I'll remove it tonight.

    @Robotronic: Adjusting specularity by the alpha channel, should be the alpha channel of the normal map, not the diffuse map. I used stencil shadows in my testing, and had no problems, but I also was using a 24 bit tga for my diffuse map, therefore no alpha channel there. Only in my normal map. I may be wrong here, so please correct my if I am.

    @All: As always, the are some bugs that needed to be fixed. I'm going to update the code tonight, and then post it when it's working again. Thank you all for your comments, help, and kind gratitude...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 02:23

    Alright. This has been making me think for a while, and I'm not sure what to do.


    Should static lights be faked as dynamic lights, or used for "ambience" of the model when walking in certain areas? Both are useful, but I'm not sure which one to choose...
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 07:17

    'Faked as dynamic' looks by far the best. At the moment I've done some testing and I've simply checked 'dynamic' for all my lights in the level and it works rather well with this shader. Perhaps, I'll build a small (birds-eye perspective probably because of the dynamic lights) Doom3 clone game and it will show what I mean,

    Cheers
    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 11:03

    Well I used 24bit TGA for the diffuse map and 32bit TGA for the normal map.
    => no stencil shadows
    => normal map with decent specularity

    If I remove the normal map or reduce it to 24 bit
    => stencil shadows
    => no normal map or plastic look

    Engine version is last public beta (6.506) and my testobjects are just simple boxes (closed), placed on terrain and blocks.

    Well, doing some research it turned out, Iīm not the first one who has a problem with the automatic transparency thing in A6: link

    I guess it has something to do with this, because the manual recommends, that for stencil shadows the entities must not be transparent.
    Maybe these lines of code could solve this?

    ZWriteEnable=True;
    AlphaBlendEnable=False;
    AlphaTestEnable=True;

    These, of course, are just some ideas of a shader noob ...
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 15:48

    as far as the dynamic/ambient lights, definately dynamic, im also almost done with that map reader.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/07/07 23:08

    @Lostclimate: Nice, I can't wait...

    @Robotronic: I'g give your solution a try, but as I said, my [stencil & non-stencil] shadows are showing up, so I can't...

    I'm gonna leave the poll open a lil longer until i decide. I'd like to do a combination of both, because a sort of ambience is needed somehow...
    Posted By: William

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/08/07 02:32

    Quote:

    Well, doing some research it turned out, Iīm not the first one who has a problem with the automatic transparency thing in A6:




    http://www.conitec.net/beta/aentity-overlay.htm

    Ahh yes, the transparency problem, A7 solves this with the new my.overlay flag. It works great, I make good use of it already for my terrain shaders. If your using the beta you can try it out. This will fix alpha problems between the entity and other entities, but not necessarily within the entity itself. The lines you posted might also work.

    If your having problems where is seems like your normals flipped, make sure that your first texture for your entity(the non-normalmap) has no alpha map. I think the reason for this lies in the second pass where the lighting requires the blending/alpha transparency. If it has an alpha map then its almost like all the normals of the model flips. Mabye this is a shader problem? Or it might just be how it goes. I know when you make vegetation and the such you cannot have alpha transparency or the normals do the same thing. If you do put an alpha map for the first model, and turn off alphaBlendEnable for the second pass, then the lights do not show for that pass, but the normals do not flip.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/08/07 04:39

    As for static lights...

    I'm going to add a switch to enable/disable the checking for static lights. I'm having unusable results with vecLight, so I must use a trace, and pass the results to the shader. This trace can be slow, so I'm goin to add an option for it. I'll let you know which flag I'll put it on. All feedback is appreciated!
    Posted By: Robotronic

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/08/07 17:15

    I can just use the last public beta (A6.50.6) but itīs good to hear, that the transparency problem has been solved. I hope this overlay feature makes it into the next public update. Anyway, I was playing around with alphaBlendEnable & co. but it didnīt help. Most often my testcube just turned into something completely black.

    @ xXx Guitar: I think itīs a very good idea, to implement an option for static lights. Makes this great shader even better .
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/08/07 22:19

    @Robotronic: Thanks!

    And as for static lighting (again). Accoding to my above poll, I've decided I'm going to add an option [again] in the shader. You'll be able to use faking, ambience, or both...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/10/07 21:52

    Alright, I'm still working on this shader, and I just corrected a majot bug!

    I was calculating the tangents incorrectly. This means that the faces were being lit corectly, but the bumps were getting the light direction incorrectly. I have fixed it now. It's hard to tell the difference, but it makes a big improvment in look when you figure out what to look for!

    I still need to fix some of the lighting options, then I'll update the download and let you all know!
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/10/07 23:12

    Keep up the good work, you made me curious about the bug though,

    Cheers
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/12/07 02:43

    hey, i need help, how can i turn down or turn off your per-pixel shading, as it is wayyyy tooo dark for my game, i tried playing with the ambient and diffuse values, as it looks like there passed into the shader, but it isnt affecting anything, as far editing the shader yourself, all your color calculations are soooo messed up with so many multiplications and additions, i dont really want to screw with it.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/12/07 03:13

    it's actually vertex lit, and just pixel [normals coloring thing]

    Increasing the ambient flag in the shader should do it, but thats just temporary. The new version will allow you to adjust ambience through the models ambient var.

    The complicated multiplications are from Matt. There for calculating specular lighting...

    I'll try and get it uploaded tonight...
    Posted By: lostclimate

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/12/07 03:36

    alright thank you, im getting closer to that map light reader thing, sorry its taking so long, i just got a job and its really cutting down my coding time.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/12/07 04:04

    Yeah, I know what you mean...

    It's comming along though. I've gotten:
    tangents fixed.
    [model]alpha fixed.
    [model]ambient added.
    sun_color fix.
    flags for static light use (enable_fake & enable_ambient)
    ...all i can think of right now...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 04:32

    Alright. Next release is ALMOST done. In fact, i think it is done...

    My only problem now is that my "web host" has seemed to have disapeered, so ... yeah...

    I need someone to host it... PHeMoX, are you up for it again?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 04:36

    While your waiting, SOME MORE SCREENSHOTS! 'Cause we all love screenshots...

    BTW: The lighting on these two images are COMPLETELY DONE BY STATIC LIGHTING...




    Posted By: DoC

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 08:45

    holy ssss...hit o.o
    Posted By: frazzle

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 08:59

    That is indeed some nice work Guitar
    But I wonder, is it me or do I mis a shadow on the first image ??

    Cheers

    Frazzle
    Posted By: Pappenheimer

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 12:45

    I love such screenshots too!

    Are these already such with an alphachannel in the normal map? An alpha channel which manages the shinyness? Or, do I mix it up with something different?

    Quote:

    normal maps don't have to be glossy , most of the time you see this is here in the forum, where people don't create specular maps [alpha channel of normal map]. The specular channel controls the "glossy"ness



    Posted By: sPlKe

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 13:17

    bumb mapping =alpha channel height map
    normal mapping: second skin heught map (all colors)
    paralax mapping: second skin normal map and alpha channel gloss map

    i could be wrong about that however but thats the way i understood that?

    anyway, this shader is great... you could write a small introduction of how to set it up nicely, what to place in wed to get good results ect...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 16:50

    @Frazzle: yeah, you caught me, lol. I didn't notice/forgot...

    @Pappenheimer: Specular map/channel, and no, there isn't. I got those models from online (with normalmaps, but not specular), and I'm not artist on the computer, so I didn't make specular channels for them. I know, I'm a slacker, lol.

    Quote:

    Specular mapping: the perfect, mirror-like reflection of light (or sometimes other kinds of wave) from a surface, in which light from a single incoming direction is reflected into a single outgoing direction. Such behaviour is described by the law of reflection, which states that the direction of outgoing reflected light and the direction of incoming light make the same angle with respect to the surface normal; this is commonly stated as &#952;i = &#952;r.





    ALL YOU HAVE TO DO:

    Include the file <NM.wdl> into your main script.

    Attach the material to your model.

    (OPTIONAL) Customize the effects and options through the customize panel in WED (For NM.wdl).


    EDIT: It's ready, so I'll upload it as soon as I find someone to host it...
    Posted By: MadMark

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 20:33

    Looks great xXxGuitar511! Nice work.
    I think I'm going to have to read up on shaders and specular / bump mapping in 3DGS. Any pointers for tutorials or refernce?

    Cheers,
    Mark

    [EDIT] Just had a look at your website. Solitude looks incredible. Couldn't load the storyline page though.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/14/07 22:23

    Yeah, that was a project that kind of... died. lol.

    Thanks though. I actually didn't have a storyline, which is why it failed. I was just making random crap with to meaning to it.

    As for tutorials/fererence. IDK. I just went through other peoples code and figured out how it works. Thats how I learn. But a nice tutorial I did go through was by Excessus. His normal mapping shader gave me a good insight to how structs and methods worked...
    Posted By: sPlKe

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/15/07 22:53

    about hosting, i could do that!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/16/07 14:42

    Kool. I'll email it to you when I get home!

    It's only two small text files (NM.wdl & NM.fx).
    Posted By: sPlKe

    DOWNLOAD: Normal-Mapping Shader - 04/17/07 13:27

    CLICK ME
    Posted By: xXxGuitar511

    Re: DOWNLOAD: Normal-Mapping Shader - 04/17/07 16:03

    Alright, there it is as posted above by Spike!

    The final version of this release. All options can be set through the customize panel for the NM.wdl file.

    The two options at the top are for enabled/disabling Faking of dynamic lights and ambience by static lights.

    Diffuse directly adjusts the colors in the first skin. The Emissive values directly adjust the static light color found.


    EDIT: I also corrected the tangents input to the shader, so the lighting direction is now calculated correctly.
    Posted By: Puppeteer

    Re: DOWNLOAD: Normal-Mapping Shader - 04/17/07 16:06

    Thx!
    Nice one
    Posted By: frazzle

    Re: DOWNLOAD: Normal-Mapping Shader - 04/17/07 18:54

    Thxn you for your hard work on this Guitar !!
    We all really appriciate this to the full 100%
    Btw, thank you Spike for willing to be the host

    Cheers

    Frazzle
    Posted By: sPlKe

    Re: DOWNLOAD: Normal-Mapping Shader - 04/17/07 21:59

    im honored for hosting such a great work. and while this may sound disrespectfull, belive me its not. i am really honored because this piece of code is amazing!
    Posted By: xXxGuitar511

    Re: DOWNLOAD: Normal-Mapping Shader - 04/17/07 22:17

    Thanks again, all of you. Your compliments inspire me to contribute more!
    Posted By: PHeMoX

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/17/07 23:27

    Quote:

    I need someone to host it... PHeMoX, are you up for it again?




    Yeah, no problem, anytime. I've seen Spike hosts it now, but if you ever need to host 3dgs related things, just mail me.

    Good job on this contribution, very nice and helpful!

    Cheers
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/18/07 02:30

    Thanks PHeMoX, I will contact you soon I think, lol. Thank you...

    Also, check out my newest project in the UC, "Darkness". I'd love your opinion. As well as everyone elses!
    Posted By: Grafton

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/19/07 04:14

    This is a great contribution!
    Is there anyway to control how dark the shadowing is, or how bright the
    lighting? There is too much contrast between the two for my use.
    I tried adjusting the WDL custom settings in WED, but no luck.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/20/07 00:59

    No, but I guess I can make another release.

    I'll add another skill for shadow ambience & light ambience. Shouldn't be too hard at all...
    Posted By: Grafton

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/21/07 07:54

    That would be great xXxGuitar511, and really complete this shader.

    BTW, how dow I get this to work with dynamic lights? If I place one in wed,
    and make it dynamic/hi-res, it dosent seem to affect the model other than increase its diffuse brightness (no specular or shading), even with fake
    dynamic turned off.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/21/07 17:38

    setting the dynamic flag for wed lights doesn't work yet, it will still cast a static light.

    You have to actually use a model with a dynamic light action (Included in NM.wdl: DLight)
    Posted By: Grafton

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/21/07 23:47

    Yep, I tried the dlight action with a cube.mdl, set its _range (skill4)
    pretty high and put it almost on top of the normal mapped model, then changed
    "faked dynamics" to false, and all I can get is the diffuse lighting from the
    material. I tried for hours.

    Maybe there is something strange with either model? (the NM looks fantastic
    with faked dynamics on though).

    In any case, if you could find time to insert a multiplier for the ambient
    (shadowing) and one for the power of the lighting, so the two could be adjusted
    (contrast?) for different environments, that would be super useful!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/23/07 14:36

    I don't have the files with me, and I'm a lil busy ATM, but I'll try and get it done ASAP...

    It'll be pretty simple, I just need to figure out which inputs to use...
    - per model (vecSkill41)
    - per material (mtlSkill1)
    - per shader (float X)
    Posted By: marcwakefield

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/03/07 21:30

    Thank you for this Shader it is truly amazing and exactly what I was looking for.

    You can see how I used it below.

    I created both models in Hexagon as well as the textures, created the UV Map with Roadkill and made the normal map with Xnormal.

    This was really just my first attempt using a normal map in a game engine but I am quite happy with the results.


    No normal map: http://www.marcwakefield.co.uk/plainzombie.jpg

    With normal map: http://www.marcwakefield.co.uk/nmapzombie.jpg

    If any one would like the Zombie, let me know and I will upload the mdl.

    Marc Wakefield
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/03/07 22:46

    Looks Good...

    I recommend you add an alpha channel to your normal map though. You can use it to addjust the specularity (glossyness)...
    Posted By: Metal_Man

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 02:53

    Hello, this is probably some simple little problem I'm having because I am quite inexperienced with shaders. When I try to use the shader, I get some sort of "unexpected token" error with several "1f"'s separated by commas. How can I fix this?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 03:11

    Hmm... not sure. Can you tell if this is an acknex error, or a directx error?

    Make sure you only inlcude <NM.wdl>; into your main script. Include <NM.fx>; will mess everything up...

    Also, do you know if your graphics card supports VSPS 2.0 ?
    Posted By: Metal_Man

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 03:20

    Nevermind, I'm actually having a different problem. The other problem was from a different shader I forgot to remove first.

    I know how to fix the fog and stuff, but the entities I use it on are completely black.

    I don't know what my graphics card supports, I just know its some degree better than the integrated graphics. How can I tell if my graphics card supports the VSPS 2.0?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 04:31

    when your game runs, have it tell you what d3d_shaderversion is.

    the first two digits are the pixel shader version, and the second two digits are the pixel shader version...


    Shaders are designed to work with static lights. This one allows static lighting to be "faked" if you do the following steps:
    - open the [properties] tab in WED
    - go under scripts
    - right click on NM.wdl, and go to [customize]
    From here you can adjust the settings for the shader.
    - Ambience: for brightening the model with static lights
    - Faked Dyn: For faking dynamic lighting
    - Both can be used to get a very good effect with static lights...
    Posted By: bstudio

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 06:48

    Quote:


    the first two digits are the pixel shader version, and the second two digits are the pixel shader version...




    the second is the vertex
    question: can you use a specularity map with this shader?
    Posted By: Dutchie666

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 07:38

    Quote:

    I recommend you add an alpha channel to your normal map though. You can use it to addjust the specularity (glossyness)...




    thats a yes
    until i read that i did not plan to use this shader, but now i really wil.
    thank you guitar!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 13:17

    I've still got to make another update. Maybe this time I'll create some documentation

    The next update will feature:
    - use the [materials power] or [models albedo] value for adjusting overall specularity. Not sure which one I should use...
    - two skills for adjusting the ambience of light and shadows...
    Posted By: Metal_Man

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 15:44

    The program tells me that d3d_shaderversion is 2020, does that mean my graphics card supports VSPS 2.0?
    Posted By: Dutchie666

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 16:08

    jup, thats true...

    looking forward to the update xXxGuitar
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 16:11

    yes

    The only other things I can think of for why it's not working...

    - The first skin should be your regular skin. The second, your normalmap. You cannot use multiple skins for the first skin.
    - There are no lights. Make sure you have a dynamic ligt by your model. If it's still black, then the problem lies elsewhere.
    - ...
    Posted By: Dutchie666

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/04/07 16:37

    how is your map sun and shadow configured? i had a black model before, i lightened the shadows and sun and i saw the models good
    could be your problem too...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/05/07 05:11

    I'm not sure, but I think I might have left out the dynamic light calc's from the last shader posted. I'm not sure what I had done in that release.

    Either way, an update is comming soon [hopefully the last, but probably not]...
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/20/07 20:10

    Still a great shader but i am having a problem. I followed a normal map image tutorial and thats the end results in the engne.


    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/21/07 00:57

    also i have the sun and amdient light set to a bright color, there is a dynamic light .

    When I remove the shader def file it looks normal with no effects
    Posted By: tompo

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/21/07 21:56

    play with colors (specially emisive) in MED skin settings.
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/22/07 00:23

    ok thanks for that. Now I am back at teh problem of the surfaces not apperaing raised except for the shiney areas
    Posted By: erbismi

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/22/07 11:08

    I had the same problem, but I unticked the tickbox in MED skin settings for "material setup". After that it was BLOODY AWESOME!!!!!!!
    xXxGuitar511, why you are only rated 3 stars is completely beyond me, this is the best shader in 3DGS I have ever seen!
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/22/07 15:52

    Thank you i got it partially solved. Now I am having this problem.


    Posted By: erbismi

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/22/07 18:55

    There doesn't seem to be much of a problem, only that maybe the light is too bright. Try adjusting the material properties by customising NM.wdl in MED. I think most of the problem may be with the model and skins.
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/22/07 20:59

    Quote:

    There doesn't seem to be much of a problem, only that maybe the light is too bright. Try adjusting the material properties by customising NM.wdl in MED



    You mean in WED right ? What ones do I adjust ? I tried messing with em and either gets to bright or too dark.


    Quote:

    I think most of the problem may be with the model and skins.



    OK on this what would need to be done to the model ? I am using milkshape and as far as I know there is no light settings in milkshape unless I missed it.

    On the texture I have put my greyscale as low as it can get without it being all black.
    Posted By: erbismi

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/23/07 16:25

    Yeah i did mean in WED. Presuming the problem you identified is that the wall is too bright, just try lowering the specular values for NM.wdl, or just make the light a bit less bright. As far as the model goes, i believe you can also adjust specularity with the alpha channel of the normal map.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/28/07 17:33

    Thank you erbismi! And you are correct as well...

    BTW: For flat shading on surfaces, your faces must be unwelded at edges. Shaders interpolate the normals of vertices, which will give you strange lighting when the vertices meet at a corner (such as your building).

    You should unweld the faces where there should not be a smooth lighting between faces. I hope I've explained this well...
    Posted By: Blink

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/30/07 15:57

    the link isnt showing on the 1st page, is it still available? i would like to download it.
    Posted By: Blink

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/30/07 15:59

    nevermind, i was downloading from the wrong link,oooppps!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/30/07 16:44

    The newest version is the link in my signature...
    Posted By: fogman

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 06/10/07 09:00

    Quote:

    Shaders on WED blocks are TOO slow. This is why many developers are now creating thier levels with models.





    I very curious about the situation with the so called "static meshes", converted from blocks. I could imagine that shaders on static meshes are faster than on blocks.
    Can you give me some advise on how to apply this shader to static meshes? To fiddle around with d3d_automaterial seems probable, but I donīt have the knowledge for that.
    I would like to play around with the latest GS beta.

    This shader is brilliant, Iīve tested some of Franks textures, just awesome.
    But now the entire environment needs to fit in.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 06/10/07 17:13

    Static meshes are latest A7 beta, right? I'm limited to A6.6 Pro, so I can't really test it to help you...

    If I'm wrong, please let me know


    Either way, email me (email on profile) and I'll see what I can do...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 06/30/07 20:03

    Alright, I finally spent ~10 minutes doing an update for the shader...

    fixes:
    - Accidentally commented out first light on last release, it's uncommented now
    - Alpha transparency should work now...
    - Albedo property of model controls its specularity (glossyness) in addition to the alpha channel of the normal map
    - Ambient property of model works in addition to the material property.
    - removed an extra texture lookup, which might make the shader run a (little) bit faster, but who knows?...

    ...Thats about it really. I didn't do too much. The first light being skipped was the biggest problem. It's still running in 2 passes, with 3 dyn lights, sunlight, and static lighting. I can add more dyn lights if needed. PS2.0 limits me to 2 dyn lights per pass though.


    NM.ZIP
    Posted By: Mondivirtuali

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/11/07 21:19

    HI, me again
    I dl the trial of mudbox and I done a pair or test np,
    also I did some NP using 3dbrush, for compare both the software.
    The maps seems to be right:


    but , using both the softwares ,the final risults is not that right:
    Where in the highpoly models there are bumpies, the normal mapped models do shows indentations.
    Many details ,done with Mudbox ,are missed also.

    The shader seems to be works, there are some mistake in the detailing process.
    Posted By: EX Citer

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/12/07 05:38

    Thanks for the shader, xXxGuitar511! And thanks for hosting, Spike!
    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/16/07 03:18

    Tried it with Lite-c and it worked very nice with the Doompack

    NormalMap
    Code:
    //--------------------------------------------------------------
    // Normal Mapping Shader
    //
    // Matt_Aufderheide, Bloodline, William, xXxGuitar511
    // -------------------------------------------------------------
    // title: Normal Mapping Shader
    // text: -
    // -------------------------------------------------------------

    #include <acknex.h>
    #include <default.c>

    // entry: FX File:
    STRING* fxNM = "NM.fx";
    STRING* MyAppTitle = "Normal Mapping Shader";

    // section: Ambient Lighting:
    // enable: Faked Dynamics
    #define staFake
    // enable: Ambience
    #define staAmb

    MATERIAL* comics =
    {
    ambient_blue = 100;
    ambient_green = 100;
    ambient_red = 100;
    albedo = 0;
    }

    MATERIAL* mat_NM =
    {
    // section: Diffuse:
    // entry: Red
    diffuse_red = 255;
    // entry: Green
    diffuse_green = 255;
    // entry: Blue
    diffuse_blue = 255;

    // section: Ambient:
    // entry: Red
    ambient_red = 16.0;
    // entry: Green
    ambient_green = 16.0;
    // entry: Blue
    ambient_blue = 16.0;

    // // section: Sun:
    // // entry: Red
    // specular_red = 64.0;
    // // entry: Green
    // specular_green = 64.0;
    // // entry: Blue
    // specular_blue = 64.0;

    // section: Static Lighting:
    // entry: Red
    emissive_red = 255.0;
    // entry: Green
    emissive_green = 255.0;
    // entry: Blue
    emissive_blue = 255.0;
    //
    flags = tangent | enable_render;
    effect = fxNM;
    //event = checkLight;
    }


    function effect_startup()
    {
    effect_load(mat_NM, fxNM);
    //
    var SLF;
    while(1)
    {
    SLF = 0;
    #ifdef staAmb
    SLF += 1;
    #endif
    #ifdef staFake
    SLF += 2;
    #endif
    //
    vec_set(mat_NM.specular_blue, sun_color);
    mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888);
    wait(1);
    }
    }

    //function checkLight()
    //{
    // vec_set(temp, my.x);
    // temp.z -= floor_range;
    // c_trace(my.x, temp, ignore_me | scan_texture);
    // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888);
    //}

    #define _Red skill1
    #define _Green skill2
    #define _Blue skill3
    #define _Range skill4
    // action: Dynamic Light
    // text: -
    // skill1: Red 128
    // skill2: Green 128
    // skill3: Blue 128
    // skill4: Range 300
    action DLight()
    {
    my.red = my._Red;
    my.green = my._Green;
    my.blue = my._Blue;
    my.lightrange = my._Range;
    set(my,LIGHT);
    }

    void init_normal()
    {
    effect_startup();
    }


    action SpinMe()
    {
    while(1)
    {
    my.material = mat_NM;
    my.pan -= 2 * time_smooth;
    wait(1);
    }
    }

    void main()
    {
    fps_max = 60;
    video_mode = 6;
    video_window(vector(375,350,0),NULL,112,MyAppTitle);
    screen_color.blue = 125;
    level_load("normal.wmb");
    wait(2);
    init_normal();
    }


    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/16/07 18:59

    EXCiter: Actually I've gotten some webspace from AienHeretic...

    D3D: Thanks for testing it bro! Glad it will be usefull in A7 (if it's still needed), and that our users now know how to use it with Lite-C
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 04:38

    ok i have included the litc version in my main.c file of the car test level but it is not showung NM as a mat file when I do the properties. did i do something worong ?

    Code:
     //////////////////////////////////////////////////////////////
    // carlevel main.c: Load level,init physics, do camera control
    //////////////////////////////////////////////////////////////
    #include <acknex.h>
    #include <default.c>

    var camera_arc=100;
    //////////////////////////////////////////////////////////////

    function start_all();
    function zoom_cam();

    // global vars
    FONT* fontArial = "Arial#20b"; // truetype font
    ENTITY* pFocus; // camera will orbit around this entity
    var temp[3];
    var temp2[3];

    //////////////////////////////////////////////////////////////
    #include "NM.c"
    #include "physics_car.c" // <--- that's where the magic happens
    #include "startup01.c" // splash screen
    #include "cg_add.c" // Czeslaw Gorski actions
    //////////////////////////////////////////////////////////////


    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 05:02

    The mat_NM is already assigned when you attached the action SpinMe to the entity of your choice.
    You can also attach the DLight action to a dummy model if you like. Try:

    Code:
    //////////////////////////////////////////////////////////////
    // carlevel main.c: Load level,init physics, do camera control
    //////////////////////////////////////////////////////////////
    #include <acknex.h>
    #include <default.c>
    #include "physics_car.c" // <--- that's where the magic happens
    #include "startup01.c" // splash screen
    #include "cg_add.c" // Czeslaw Gorski actions
    #include "NM.c"
    //////////////////////////////////////////////////////////////

    var camera_arc=100;
    //////////////////////////////////////////////////////////////

    function start_all();
    function zoom_cam();

    // global vars
    FONT* fontArial = "Arial#20b"; // truetype font
    ENTITY* pFocus; // camera will orbit around this entity
    var temp[3];
    var temp2[3];


    Note: copy/paste the relevant code from NM.c to main.c, or clean the NM.c script before including it to the mainscript of the carlevel demo.
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 14:12

    OK so would i include the NM.c file into physics_car.c or would i need to copy certain parts of NM.c into the physics_car.c file


    i hate when the only programmer goes on vacation. Not that I cant learn anything. But it takes a bit for me to catch on to stuff
    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 14:30

    Try make backup of carlevel directory and replace all code in main.c with:

    Code:
    //////////////////////////////////////////////////////////////
    // carlevel main.c: Load level,init physics, do camera control
    //////////////////////////////////////////////////////////////
    //--------------------------------------------------------------
    // Normal Mapping Shader
    //
    // Matt_Aufderheide, Bloodline, William, xXxGuitar511
    // -------------------------------------------------------------
    // title: Normal Mapping Shader
    // text -
    // -------------------------------------------------------------

    #include <acknex.h>
    #include <default.c>

    var camera_arc=100;
    //////////////////////////////////////////////////////////////

    function start_all();
    function zoom_cam();

    // global vars
    FONT* fontArial = "Arial#20b"; // truetype font
    ENTITY* pFocus; // camera will orbit around this entity
    var temp[3];
    var temp2[3];

    //////////////////////////////////////////////////////////////
    #include "physics_car.c" // <--- that's where the magic happens
    #include "startup01.c" // splash screen
    #include "cg_add.c" // Czeslaw Gorski actions
    //////////////////////////////////////////////////////////////

    // NM SHADER CODE
    // section: Ambient Lighting:
    // enable: Faked Dynamics
    #define staFake
    // enable: Ambience
    #define staAmb

    // entry: FX File:
    STRING* fxNM = "NM.fx";
    // NM SHADER CODE

    STRING* levelname = "loop.wmb";
    ENTITY* sky = { type = "skycube+6.tga"; flags2 = SKY | CUBE | VISIBLE; }

    //////////////////////////////////////////////////////////////
    // camera control (orbit around pFocus, or chase camera or cockpit cam

    var camMode=-1; // 0:orbit, 1:chase, 2:cockpit, -1 disabled
    var rotspd=20; // cam movement speed
    var minang=5; var maxang=70; // orbit between 5-70 degrees and 300-3000 distance
    var mindist=200; var maxdist=3000;

    var cameraTPos[3]; // camera target position
    var cameraTAng[3]; // camera target angle

    #define KEY_CAMERA key_c // use this key to switch camera modes
    #define JOY_CAMERA joy_3

    // NM SHADER CODE
    MATERIAL* comics =
    {
    ambient_blue = 100;
    ambient_green = 100;
    ambient_red = 100;
    albedo = 0;
    }

    MATERIAL* mat_NM =
    {
    // section: Diffuse:
    // entry: Red
    diffuse_red = 255;
    // entry: Green
    diffuse_green = 255;
    // entry: Blue
    diffuse_blue = 255;

    // section: Ambient:
    // entry: Red
    ambient_red = 16.0;
    // entry: Green
    ambient_green = 16.0;
    // entry: Blue
    ambient_blue = 16.0;

    // // section: Sun:
    // // entry: Red
    // specular_red = 64.0;
    // // entry: Green
    // specular_green = 64.0;
    // // entry: Blue
    // specular_blue = 64.0;

    // section: Static Lighting:
    // entry: Red
    emissive_red = 255.0;
    // entry: Green
    emissive_green = 255.0;
    // entry: Blue
    emissive_blue = 255.0;
    //
    flags = tangent | enable_render;
    effect = fxNM;
    //event = checkLight;
    }


    function effect_startup()
    {
    effect_load(mat_NM, fxNM);
    //
    var SLF;
    while(1)
    {
    SLF = 0;
    #ifdef staAmb
    SLF += 1;
    #endif
    #ifdef staFake
    SLF += 2;
    #endif
    //
    vec_set(mat_NM.specular_blue, sun_color);
    mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888);
    wait(1);
    }
    }

    //function checkLight()
    //{
    // vec_set(temp, my.x);
    // temp.z -= floor_range;
    // c_trace(my.x, temp, ignore_me | scan_texture);
    // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888);
    //}

    #define _Red skill1
    #define _Green skill2
    #define _Blue skill3
    #define _Range skill4
    // action: Dynamic Light
    // text: -
    // skill1: Red 128
    // skill2: Green 128
    // skill3: Blue 128
    // skill4: Range 300
    action DLight()
    {
    my.red = my._Red;
    my.green = my._Green;
    my.blue = my._Blue;
    my.lightrange = my._Range;
    set(my,LIGHT);
    }

    void init_normal()
    {
    effect_startup();
    }


    action SpinMe()
    {
    while(1)
    {
    my.material = mat_NM;
    my.pan -= 2 * time_smooth;
    wait(1);
    }
    }
    // NM SHADER CODE

    //////////////////////////////////////////////////////////////
    function ControlCamera_startup()
    {
    // set fog and view params
    fog_color = 1;
    camera.fog_start=1000;
    camera.fog_end =1.2*camera.clip_far;
    camera.clip_near=25;

    // init level and wait for focus object (we will orbit around it)
    while(pFocus==NULL || camMode<0){wait(1);}

    // current distance from focus and ang
    var cam_dist=200;
    ANGLE cam_ang;
    // reset if previously rolled around
    cam_ang.pan= pFocus.pan-180;
    cam_ang.tilt=30;
    cam_ang.roll=0;

    while(1)
    {
    // for focus object (we will orbit around it)
    while(pFocus==NULL){wait(1);}

    if (camMode==0) // free orbit cam
    {
    reset(pFocus,INVISIBLE);
    //orbit
    if(mouse_right)
    {
    cam_ang.pan+=rotspd*mouse_force.x;
    cam_ang.tilt+=rotspd*mouse_force.y;
    cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang);
    }

    // zoom with mousewheel
    cam_dist-=integer(mickey.z);
    cam_dist=clamp(cam_dist,mindist,maxdist);

    // do some trig to find camera location and then aim it at pFocus
    camera.x=pFocus.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
    camera.y=pFocus.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
    camera.z=pFocus.z+sin(cam_ang.tilt)*cam_dist;
    vec_set(temp,pFocus.x);
    vec_sub(temp,camera.x);
    vec_to_angle(camera.pan,temp);
    }
    if (camMode==1) // chase cam
    {
    reset(pFocus,INVISIBLE);
    if(mouse_right)
    {
    // mouse moves head
    vecChaseAngOff.pan-=rotspd*mouse_force.x * time_step;
    vecChaseAngOff.tilt+=rotspd*mouse_force.y * time_step;
    vecChaseAngOff.pan=clamp(vecChaseAngOff.pan,-20,20);
    vecChaseAngOff.tilt=clamp(vecChaseAngOff.tilt,-20,20);
    }
    else
    {
    // return to center
    if(vecChaseAngOff.pan > 0.25) { vecChaseAngOff.pan -= 2* time_step; }
    if(vecChaseAngOff.pan < -0.25) { vecChaseAngOff.pan += 2* time_step; }
    if(vecChaseAngOff.tilt > 6) { vecChaseAngOff.tilt -= 2* time_step; }
    if(vecChaseAngOff.tilt < 5) { vecChaseAngOff.tilt += 2* time_step; }

    }

    vec_set(cameraTPos, vecChaseOffset); // move behind and up
    var offset;
    offset= clamp(0.01*linSpeed*linSpeed, -100,100);
    cameraTPos[0] -= offset; // offset by speed
    vec_rotate(cameraTPos, vector(ang(pFocus.pan),0,0));
    vec_add(cameraTPos, pFocus.x);

    // collide with any object in the way
    c_trace(pFocus.x,cameraTPos,
    (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_BACK",30,300,vector(123,123,200));
    }
    else
    {
    // make sure we don't 'clip' into walls next to us..
    vec_diff(temp,pFocus.x,cameraTPos);
    vec_normalize(temp,camera.clip_near);
    vec_rotate(temp,vector(90,0,0));
    vec_set(temp2,cameraTPos);
    vec_add(temp2,temp); // move out by the clip_near value
    c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_1",30,300,vector(123,123,200));
    }
    else
    {
    // rotate temp back the other dir twice as much..
    vec_rotate(temp,vector(-180,0,0));
    vec_set(temp2,cameraTPos);
    vec_add(temp2,temp); // move out by the clip_near value
    c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_2",30,300,vector(123,123,200));
    }
    }

    }

    // Smooth out transition...
    vec_diff(temp,cameraTPos,camera.x);
    var vscale = clamp((time_step*0.5),0.001,1);
    vec_scale(temp,vscale);
    vec_add(camera.x,temp);

    // calc angle from camera to target...
    vec_diff(temp,pFocus.x,cameraTPos);
    vec_to_angle(cameraTAng,temp); // camera target angle looks at focus center
    vec_add(cameraTAng, vecChaseAngOff.pan); // tweak it
    // Smooth out rotation...
    vec_diff(temp,cameraTAng,camera.pan);
    temp[0] = ang(temp[0]); // note! only pan is needed in this game!
    vec_scale(temp,vscale);
    vec_add(camera.pan,temp);
    // vec_set(camera.pan,cameraTAng.pan);
    }

    if (camMode==2) // cockpit view
    {
    //set(pFocus,INVISIBLE); // You might want to set this to on if using dashboard bitmap
    vec_set(camera.pan, pFocus.pan);
    vec_set(camera.x, pFocus.x);
    // raise seat and move to driver side
    vec_set(temp, vecDriverOffset);
    vec_rotate(temp, pFocus.pan);
    vec_add(camera.x, temp);
    }
    //toggle camera
    if (KEY_CAMERA || JOY_CAMERA) {
    while (KEY_CAMERA || JOY_CAMERA) { wait(1); }
    camMode+=1; if (camMode>2) { camMode=0; }
    // reset if previously rolled around
    vec_set(camera.pan, cam_ang);
    }
    wait(1);
    }
    }

    //////////////////////////////////////////////////////////////
    // assign this to terrain for multitexturing, uses 2nd skin as detail map
    action ffp_terr_detail()
    {
    detail_size = 16;
    }

    //////////////////////////////////////////////////////////////
    // assign this to MDLs when user is to drive on them
    action MakePoly()
    {
    set(my,POLYGON);
    }

    var StopWatchOn;

    function Stopwatch_startup()
    {
    while (1) {
    if (StopWatchOn)
    timerSeconds+= time_step/16;
    speed_and_time(); //cg
    wait(1);
    }
    }

    function ToggleStopwatch()
    {
    StopWatchOn = !StopWatchOn;
    }



    //////////////////////////////////////////////////////////////
    // main
    function main()
    {
    video_mode=7; //800x600
    shadow_stencil= ON;
    d3d_autotransparency = ON;
    vec_set(d3d_lodfactor,vector(35,60,75)); // default LOD switches

    on_t = ToggleStopwatch;
    on_f1 = help_me;
    on_h = EventImpact;
    on_i = EventHorn;

    cg_start();
    init_normal(); // NM SHADER
    wait(1);
    level_load(levelname);
    // show title screen and spin camera

    while(pFocus==NULL){wait(1);}

    // activate real camera
    camMode = 1;
    set(physics_panel,VISIBLE);
    }

    action Prop()
    {
    phent_settype(my, PH_RIGID, PH_BOX);
    phent_setdamping(my, 10, 30);
    }



    Now reload the cardemo level inside WED and attach the action SpinMe to the entity of choice. You can also add the dlight.mdl to the level and if i'm right the action Dlight will be attached by magic. Rebuild the level and run.

    Note: NM.fx,dlight.mdl must be in the carlevel directory.
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 15:01

    OK i am not the best explaining stuff. what i am attempting to do is use the shader on a car. So it allready has the carinit actiono selected. And of course it wont run without the carinit action being assigned

    Thank You
    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 15:12

    Tried to add the nm.c code to psysics_car.c and put init_normal(); in the main function of main.c, but that did not really worked, guess because the buggy has no normal map. So you must create one first and add it before apply the normal mapping shader onto the model.

    main.c
    Code:
    //////////////////////////////////////////////////////////////
    // carlevel main.c: Load level,init physics, do camera control
    //////////////////////////////////////////////////////////////
    #include <acknex.h>
    #include <default.c>

    var camera_arc=100;
    //////////////////////////////////////////////////////////////

    function start_all();
    function zoom_cam();

    // global vars
    FONT* fontArial = "Arial#20b"; // truetype font
    ENTITY* pFocus; // camera will orbit around this entity
    var temp[3];
    var temp2[3];

    //////////////////////////////////////////////////////////////
    #include "physics_car.c" // <--- that's where the magic happens
    #include "startup01.c" // splash screen
    #include "cg_add.c" // Czeslaw Gorski actions
    //////////////////////////////////////////////////////////////

    STRING* levelname = "loop.wmb";
    ENTITY* sky = { type = "skycube+6.tga"; flags2 = SKY | CUBE | VISIBLE; }

    //////////////////////////////////////////////////////////////
    // camera control (orbit around pFocus, or chase camera or cockpit cam

    var camMode=-1; // 0:orbit, 1:chase, 2:cockpit, -1 disabled
    var rotspd=20; // cam movement speed
    var minang=5; var maxang=70; // orbit between 5-70 degrees and 300-3000 distance
    var mindist=200; var maxdist=3000;

    var cameraTPos[3]; // camera target position
    var cameraTAng[3]; // camera target angle

    #define KEY_CAMERA key_c // use this key to switch camera modes
    #define JOY_CAMERA joy_3

    //////////////////////////////////////////////////////////////
    function ControlCamera_startup()
    {
    // set fog and view params
    fog_color = 1;
    camera.fog_start=1000;
    camera.fog_end =1.2*camera.clip_far;
    camera.clip_near=25;

    // init level and wait for focus object (we will orbit around it)
    while(pFocus==NULL || camMode<0){wait(1);}

    // current distance from focus and ang
    var cam_dist=200;
    ANGLE cam_ang;
    // reset if previously rolled around
    cam_ang.pan= pFocus.pan-180;
    cam_ang.tilt=30;
    cam_ang.roll=0;

    while(1)
    {
    // for focus object (we will orbit around it)
    while(pFocus==NULL){wait(1);}

    if (camMode==0) // free orbit cam
    {
    reset(pFocus,INVISIBLE);
    //orbit
    if(mouse_right)
    {
    cam_ang.pan+=rotspd*mouse_force.x;
    cam_ang.tilt+=rotspd*mouse_force.y;
    cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang);
    }

    // zoom with mousewheel
    cam_dist-=integer(mickey.z);
    cam_dist=clamp(cam_dist,mindist,maxdist);

    // do some trig to find camera location and then aim it at pFocus
    camera.x=pFocus.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
    camera.y=pFocus.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
    camera.z=pFocus.z+sin(cam_ang.tilt)*cam_dist;
    vec_set(temp,pFocus.x);
    vec_sub(temp,camera.x);
    vec_to_angle(camera.pan,temp);
    }
    if (camMode==1) // chase cam
    {
    reset(pFocus,INVISIBLE);
    if(mouse_right)
    {
    // mouse moves head
    vecChaseAngOff.pan-=rotspd*mouse_force.x * time_step;
    vecChaseAngOff.tilt+=rotspd*mouse_force.y * time_step;
    vecChaseAngOff.pan=clamp(vecChaseAngOff.pan,-20,20);
    vecChaseAngOff.tilt=clamp(vecChaseAngOff.tilt,-20,20);
    }
    else
    {
    // return to center
    if(vecChaseAngOff.pan > 0.25) { vecChaseAngOff.pan -= 2* time_step; }
    if(vecChaseAngOff.pan < -0.25) { vecChaseAngOff.pan += 2* time_step; }
    if(vecChaseAngOff.tilt > 6) { vecChaseAngOff.tilt -= 2* time_step; }
    if(vecChaseAngOff.tilt < 5) { vecChaseAngOff.tilt += 2* time_step; }

    }

    vec_set(cameraTPos, vecChaseOffset); // move behind and up
    var offset;
    offset= clamp(0.01*linSpeed*linSpeed, -100,100);
    cameraTPos[0] -= offset; // offset by speed
    vec_rotate(cameraTPos, vector(ang(pFocus.pan),0,0));
    vec_add(cameraTPos, pFocus.x);

    // collide with any object in the way
    c_trace(pFocus.x,cameraTPos,
    (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_BACK",30,300,vector(123,123,200));
    }
    else
    {
    // make sure we don't 'clip' into walls next to us..
    vec_diff(temp,pFocus.x,cameraTPos);
    vec_normalize(temp,camera.clip_near);
    vec_rotate(temp,vector(90,0,0));
    vec_set(temp2,cameraTPos);
    vec_add(temp2,temp); // move out by the clip_near value
    c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_1",30,300,vector(123,123,200));
    }
    else
    {
    // rotate temp back the other dir twice as much..
    vec_rotate(temp,vector(-180,0,0));
    vec_set(temp2,cameraTPos);
    vec_add(temp2,temp); // move out by the clip_near value
    c_trace(cameraTPos,temp2,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
    if(trace_hit == 1)
    {
    // offset from that target along the vector
    vec_set(cameraTPos,target);
    // offset from the wall along normal by the near clipping dist
    vec_normalize(normal,(camera.clip_near/2));
    vec_add(cameraTPos,normal);
    // draw_text("HIT_2",30,300,vector(123,123,200));
    }
    }

    }

    // Smooth out transition...
    vec_diff(temp,cameraTPos,camera.x);
    var vscale = clamp((time_step*0.5),0.001,1);
    vec_scale(temp,vscale);
    vec_add(camera.x,temp);

    // calc angle from camera to target...
    vec_diff(temp,pFocus.x,cameraTPos);
    vec_to_angle(cameraTAng,temp); // camera target angle looks at focus center
    vec_add(cameraTAng, vecChaseAngOff.pan); // tweak it
    // Smooth out rotation...
    vec_diff(temp,cameraTAng,camera.pan);
    temp[0] = ang(temp[0]); // note! only pan is needed in this game!
    vec_scale(temp,vscale);
    vec_add(camera.pan,temp);
    // vec_set(camera.pan,cameraTAng.pan);
    }

    if (camMode==2) // cockpit view
    {
    //set(pFocus,INVISIBLE); // You might want to set this to on if using dashboard bitmap
    vec_set(camera.pan, pFocus.pan);
    vec_set(camera.x, pFocus.x);
    // raise seat and move to driver side
    vec_set(temp, vecDriverOffset);
    vec_rotate(temp, pFocus.pan);
    vec_add(camera.x, temp);
    }
    //toggle camera
    if (KEY_CAMERA || JOY_CAMERA) {
    while (KEY_CAMERA || JOY_CAMERA) { wait(1); }
    camMode+=1; if (camMode>2) { camMode=0; }
    // reset if previously rolled around
    vec_set(camera.pan, cam_ang);
    }
    wait(1);
    }
    }

    //////////////////////////////////////////////////////////////
    // assign this to terrain for multitexturing, uses 2nd skin as detail map
    action ffp_terr_detail()
    {
    detail_size = 16;
    }

    //////////////////////////////////////////////////////////////
    // assign this to MDLs when user is to drive on them
    action MakePoly()
    {
    set(my,POLYGON);
    }

    var StopWatchOn;

    function Stopwatch_startup()
    {
    while (1) {
    if (StopWatchOn)
    timerSeconds+= time_step/16;
    speed_and_time(); //cg
    wait(1);
    }
    }

    function ToggleStopwatch()
    {
    StopWatchOn = !StopWatchOn;
    }



    //////////////////////////////////////////////////////////////
    // main
    function main()
    {
    video_mode=7; //800x600
    shadow_stencil= ON;
    d3d_autotransparency = ON;
    vec_set(d3d_lodfactor,vector(35,60,75)); // default LOD switches

    on_t = ToggleStopwatch;
    on_f1 = help_me;
    on_h = EventImpact;
    on_i = EventHorn;

    cg_start();
    init_normal(); // NM SHADER
    wait(1);
    level_load(levelname);
    // show title screen and spin camera

    while(pFocus==NULL){wait(1);}

    // activate real camera
    camMode = 1;
    set(physics_panel,VISIBLE);
    }

    action Prop()
    {
    phent_settype(my, PH_RIGID, PH_BOX);
    phent_setdamping(my, 10, 30);
    }



    psysics_car.c
    Code:
    //--------------------------------------------------------------
    // Normal Mapping Shader
    //
    // Matt_Aufderheide, Bloodline, William, xXxGuitar511
    // -------------------------------------------------------------
    // title: Normal Mapping Shader
    // text: -
    // -------------------------------------------------------------

    // entry: FX File:
    STRING* fxNM = "NM.fx";
    STRING* MyAppTitle = "Normal Mapping Shader";

    // section: Ambient Lighting:
    // enable: Faked Dynamics
    #define staFake
    // enable: Ambience
    #define staAmb

    MATERIAL* comics =
    {
    ambient_blue = 100;
    ambient_green = 100;
    ambient_red = 100;
    albedo = 0;
    }

    MATERIAL* mat_NM =
    {
    // section: Diffuse:
    // entry: Red
    diffuse_red = 255;
    // entry: Green
    diffuse_green = 255;
    // entry: Blue
    diffuse_blue = 255;

    // section: Ambient:
    // entry: Red
    ambient_red = 16.0;
    // entry: Green
    ambient_green = 16.0;
    // entry: Blue
    ambient_blue = 16.0;

    // // section: Sun:
    // // entry: Red
    // specular_red = 64.0;
    // // entry: Green
    // specular_green = 64.0;
    // // entry: Blue
    // specular_blue = 64.0;

    // section: Static Lighting:
    // entry: Red
    emissive_red = 255.0;
    // entry: Green
    emissive_green = 255.0;
    // entry: Blue
    emissive_blue = 255.0;
    //
    flags = tangent | enable_render;
    effect = fxNM;
    //event = checkLight;
    }


    function effect_startup()
    {
    effect_load(mat_NM, fxNM);
    //
    var SLF;
    while(1)
    {
    SLF = 0;
    #ifdef staAmb
    SLF += 1;
    #endif
    #ifdef staFake
    SLF += 2;
    #endif
    //
    vec_set(mat_NM.specular_blue, sun_color);
    mat_NM.skill1 = pixel_for_vec(nullvector, SLF*10, 8888);
    wait(1);
    }
    }

    //function checkLight()
    //{
    // vec_set(temp, my.x);
    // temp.z -= floor_range;
    // c_trace(my.x, temp, ignore_me | scan_texture);
    // mtl.skill1 = pixel_for_vec(tex_color, tex_light, 8888);
    //}

    #define _Red skill1
    #define _Green skill2
    #define _Blue skill3
    #define _Range skill4
    // action: Dynamic Light
    // text: -
    // skill1: Red 128
    // skill2: Green 128
    // skill3: Blue 128
    // skill4: Range 300
    action DLight()
    {
    my.red = my._Red;
    my.green = my._Green;
    my.blue = my._Blue;
    my.lightrange = my._Range;
    set(my,LIGHT);
    }

    void init_normal()
    {
    effect_startup();
    }


    /* action SpinMe()
    {
    while(1)
    {
    my.material = mat_NM;
    my.pan -= 2 * time_smooth;
    wait(1);
    }
    } */

    // END NORMALMAPPING SHADER

    //////////////////////////////////////////////////////////////
    // Car constants
    var maxTorque= 1000; //1200 // maximum torque applied to rear wheels
    var maxTorqueBrake=1000; // this will be applied to rear wheels when hitting brakes or handbrake
    var maxAngSpeed= 70; //70 // max. angular speed of wheels; max linear speed depends on wheel radius
    var massWheel= 30; // mass per wheel
    var massChassis= 10; // mass for chassis lighter than wheels so it doesn't tilt
    var fricWheel= 100; //100 // friction of wheels -god for "in the water"
    var fricChassis= 20; // friction of chassis (low to avoid getting stuck on ramps
    var dampChassis= 5; // damping lin/ang for chassis
    var dampWheel= 15; //15 // damping ang for wheels
    var suspensionERP= 95000; //90000; // how quickly shocks are reduced to correct position (100,000 max, 0: never)
    var suspensionCFM= 250; //500 // how far shocks can overshoot (0: never, 100,000 max)
    var jumpRechargeDelay=1.5; //1.5 // time before user is allowed to jump again in secs
    var jumpForce= 3000; //3000; // force multiplier for jumps
    var gravity=1800; //2000; // gravity along -Z axis
    var bDentCar=1; // when set to 1 deform car on impact

    //////////////////////////////////////////////////////////////
    // Steering constants
    var accelKeyboard=2; // acceleration multiplier for key control
    var accelSteering=3; // acceleration multiplier for steering key control
    VECTOR* joyNullzone = { x=20; y=20; } // 0..255 x and y direction center range for joystick

    //////////////////////////////////////////////////////////////
    // these values depend on MDL and WMP where car is located
    var vecUp[3]= {0,0,1}; // up axis, usually +Z
    var vecRight[3]= {0,-1,0}; // chassis right axis
    var vecHookOffset[3]= {0,-15,40}; // this is offset from chassis center where lifter hook will be installed
    var vecDriverOffset[3]= {-35,10,34}; // where camera will be located relative to chassis center (cockpit)
    var vecChaseOffset[3]= {-150,0,60}; // where camera will be located relative to chassis center (chase)
    ANGLE vecChaseAngOff; // angle tweak of the chase camera

    #define NUM_TRACKS 1 //400; // number of tire tracks
    #define CRASH_SPEED 100 // head-on impact above this speed causes wheels to come off
    //////////////////////////////////////////////////////////////
    // Controller setup

    #define KEY_FWD key_w // Forward
    #define KEY_BWD key_s // Backward
    #define KEY_LEFT key_a // Left
    #define KEY_RIGHT key_d // Right
    #define KEY_HORN key_h // Push horn
    #define KEY_LIFT key_l // Activate Lift
    #define KEY_JUMP key_e // Turbo Boost ;-)
    #define KEY_BRAKE key_space // Pull Handbrake

    var USE_GAMEPAD= 0; // Treat joystick as absolute device
    #define JOY_JUMP joy_1 // Turbo Boost ;-)
    #define JOY_BRAKE joy_2 // Pull Handbrake
    #define JOY_LIFT joy_4 // Activate lift
    #define JOY_HORN joy_5 // Push horn
    #define JOYRAW_Y joy_raw.y // Forward/Backward axis on joystick
    #define JOYRAW_X joy_raw.x // Left/right axis on joystick

    //////////////////////////////////////////////////////////////
    // physics global vars

    var DoShutdown=0; // set to 1 and wait a while before reloading level
    var DoSteering=1; // set to 1 to enable all controls 0 for pause

    var linSpeed; // car speed in XY
    var downSpeed; // car speed in Z direction
    var angSpeed; // current wheel angular speed along y axis of wheel
    var targetSpeed=0; // desired angular speed (if torque permits)
    var targetSteer=0; // desired steering angle

    ENTITY* pChassis; //our car objects
    ENTITY* pFL; ENTITY* pFR;
    ENTITY* pRL; ENTITY* pRR;
    ENTITY* pHook; // hook for lifting car up
    var wheelFL; var wheelFR; // constraint handles
    var wheelRL; var wheelRR;

    var handleLift=0; // handle to crane lifting up car
    var jumping=0; // time left in jump
    var hornPlaying=0; // on or off
    var brakePlaying=0; // on or off
    var wheelCounter=0; // # of initialized wheels

    var trackLen =20; // length of treadmark in quants
    var arrpTracks[NUM_TRACKS]; // cyclic buffer of track entities (handles)
    var currTrack=0; // current track number
    var lastPos[3]; // position of chassis in last frame
    var timerSeconds; // a simple stopwatch, can be removed
    //////////////////////////////////////////////////////////////////////////////////////////
    // Resources
    SOUND* engine_wav = "engine.wav"; // player's engine sound
    SOUND* horn_wav = "horn.wav"; // player's horn
    SOUND* crash_wav = "crash.wav"; // player's crashing sound
    SOUND* tires_wav = "tires.wav"; // tires squealing
    SOUND* flap_wav = "lp_flap.wav"; // tires squealing


    var hTireSnd_n; // handle to sound playing

    BMAP* bmpSmoke= "smoke.tga";

    //////////////////////////////////////////////////////////////////////////////////////////
    // Includes
    #include "physics_init.c" // all car init functions
    #include "physics_events.c" // all car event & particle functions

    //////////////////////////////////////////////////////////////////////////////////////////
    // Some status data
    var noTorque=0;
    /*
    PANEL* physics_panel = {
    pos_x = 200;
    pos_y = 4;
    flags=refresh;
    //digits = 0,20,8,fontArial,1,linSpeed; // car speed
    digits = 0,40,8,fontArial,1000,timerSeconds;
    }
    */
    /* cg
    text physics_text
    {
    pos_x=50; pos_y=24;
    flags = narrow, TRANSLUCENT;
    font= fontArial;

    strings=2;
    string= "Speed (km/h):", "Timer ['T'] (msec):";
    }
    */


    //////////////////////////////////////////////////////////////////////////////////////////
    // Car control

    function SpeedControl()
    {
    var direction;
    var usejoy=0;
    while (1)
    {
    if (DoShutdown) { return; } // quitting?
    if (!DoSteering) // currently pausing?
    {
    wait(1); continue;
    }

    if (JOYRAW_Y<-joyNullzone.y || JOYRAW_Y>joyNullzone.y)
    {
    // treat joystick as absolute device which is more
    // like a keyboard than a joystick
    if (USE_GAMEPAD) {
    usejoy=0; direction= -(JOYRAW_Y / 255);
    } else {
    usejoy=1; direction= -(JOYRAW_Y-joyNullzone.y)/(255-joyNullzone.y);
    }
    } else {
    usejoy=0; direction= (KEY_FWD-KEY_BWD);
    }
    // if we drive in one direction and want to change direction, apply brakes
    // (angSpeed>0 checks if rear wheel is turning forward
    // direction<0 checks if user hits reverse key
    if ((angSpeed>5 && direction<0) || (angSpeed<-5 && direction>0))
    {
    targetSpeed=0; // brake
    // press brakes quarter down when rolling at high speed
    if (abs(angSpeed)>0.25*maxAngSpeed)
    {
    phcon_setmotor(wheelRL, nullvector, vector(angSpeed*0.5, 0.5*maxTorqueBrake,0), nullvector);
    phcon_setmotor(wheelRR, nullvector, vector(angSpeed*0.5, 0.5*maxTorqueBrake,0), nullvector);
    if (abs(angSpeed)>0.50*maxAngSpeed)
    {
    EventBrake(); // braking sound
    }
    } else {
    // we're already slow- apply max. units brake torque
    phcon_setmotor(wheelRL, nullvector, vector(0, maxTorqueBrake,0), nullvector);
    phcon_setmotor(wheelRR, nullvector, vector(0, maxTorqueBrake,0), nullvector);
    }
    } else {
    var oldSpeed; oldSpeed= targetSpeed;
    // regular driving
    if (usejoy) {
    targetSpeed = maxAngSpeed*direction; //absolute value for stick
    } else {
    // speed up over time for keyboard (relative acceleration)
    targetSpeed += direction*accelKeyboard* time_step;
    }

    var torque; torque=maxTorque;
    // damp down speed over time if no key pressed
    if (!usejoy && direction==0)
    {
    targetSpeed *=1-(time_step*0.02); torque=maxTorque/2;
    if (abs(linSpeed)<20) // switch off opposing torque so we can roll down hills
    { torque=0; targetSpeed *=0.5;}
    } else {
    // use less torque to slow down or else we'll spin
    if (usejoy && abs(targetSpeed)<abs(angSpeed))
    {
    torque=maxTorque/2;
    //targetSpeed *=0.5;
    }

    }
    // max. reverse is 1/4 of forward speed
    targetSpeed= clamp(targetSpeed, -maxAngSpeed*0.25, maxAngSpeed);
    phcon_setmotor(wheelRL, nullvector, vector(targetSpeed, torque,0), nullvector);
    phcon_setmotor(wheelRR, nullvector, vector(targetSpeed, torque,0), nullvector);
    }
    if (KEY_BRAKE|| JOY_BRAKE) // handbrake
    {
    phcon_setmotor(wheelRL, nullvector, vector(0, maxTorqueBrake,0), nullvector);
    phcon_setmotor(wheelRR, nullvector, vector(0, maxTorqueBrake,0), nullvector);
    if (abs(linSpeed)>20)
    { EventBrake(); }// squeaky brakes
    }

    EventJump(); // check for jump
    EventLift(); //process lifting
    wait(1);
    }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // Continuously calculate wheel rotational speed and store in global var
    function UpdateSpeed()
    {
    while (wheelCounter<4) { wait(1); } //wait for wheels to be init'ed

    var players_engine; //handle for soundloop
    players_engine = snd_loop(engine_wav, 100,0); // play the engine sound in a loop
    snd_tune(players_engine, 80, 80, 0); //80% of real frequency

    // check the rotation of the rear tires
    var rotSign;
    if(pRL.pan != pRR.pan)
    {
    // assume that the wheels are twisted 180 deg from each other
    rotSign = -1;
    }
    else
    {
    rotSign = 1;
    }
    var angRL; var angRR;
    VECTOR vecLin;
    while(1) {
    if (DoShutdown) { // quitting?
    snd_stop (players_engine);
    return;
    }

    // get linear speed and tune engine sound
    phent_getvelocity(pChassis, vecLin, nullvector); //linear speed
    downSpeed= vecLin.z * 0.091; vecLin.z=0; // store Z separately
    linSpeed= vec_length(vecLin) * 0.091; // convert from quant/sec to kmh
    if (maxAngSpeed>0)
    {
    var freq; freq=300*abs(angSpeed)/maxAngSpeed;
    snd_tune(players_engine, 5, freq+80, 0); //80% of real frequency
    }

    // grab angular velocity vector from rear wheels
    phent_getangvelocity(pRL, temp); angRL=temp[1];
    phent_getangvelocity(pRR, temp); angRR=temp[1];
    // store largest one
    if (abs(angRL)>abs(angRR))
    { angSpeed= angRL; }
    else {angSpeed=rotSign * angRR; }

    wait(1);
    }
    }

    //////////////////////////////////////////////////////////////////////
    // the faster we go the more sensitive the car gets to steering. to make it easier for user
    // scale down his steering inputs the faster we go
    function CalcSteeringScale()
    {
    return (1-(abs(angSpeed)/(maxAngSpeed+60)));
    }

    function SteerControl()
    {
    var direction=0; //delta change
    var usejoy; //using joystick for input?
    while (1)
    {
    if (DoShutdown) { return; } // quitting?
    if (!DoSteering) // currently pausing?
    {
    wait(1); continue;
    }

    if (JOYRAW_X<-joyNullzone.x || JOYRAW_X>joyNullzone.x)
    {
    // treat gamepad as absolute device which is more
    // like a keyboard than a joystick
    if (USE_GAMEPAD) {
    usejoy=0; direction= (JOYRAW_X / 255);
    direction*= CalcSteeringScale();
    } else {
    // using joystick
    usejoy=1; direction= (JOYRAW_X-joyNullzone.x) / (255-joyNullzone.x);
    direction*= CalcSteeringScale();
    }
    } else {
    usejoy=0; direction= (KEY_RIGHT-KEY_LEFT);
    direction*= CalcSteeringScale();
    }

    // steering control
    if (0==usejoy)
    {
    targetSteer+= direction*accelSteering* time_step;
    } else {
    targetSteer= 30*direction;
    }
    targetSteer=clamp(targetSteer,-30,30);

    if ((angSpeed>maxAngSpeed*0.95) && abs(targetSteer)>7)
    {
    EventBrake(); // play squeaky tires
    }

    if (direction!=0)
    {
    phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
    phcon_setparams2(wheelFR, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
    } else {
    targetSteer*=1-(time_step*0.25);
    if (abs(targetSteer)<1) { targetSteer=0; } // force to 0
    phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
    phcon_setparams2(wheelFR, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
    }

    if (KEY_HORN || JOY_HORN)
    {
    EventHorn(); //sound horn
    }
    wait(1);
    }
    }

    /////////////////////////////////////////////////////////////////////////////////////////
    // CarControl: Assigning this to your car's chassis is all you have to do
    ////////////////////////////////////////////////////////////////////
    action CarInit()
    {
    // build a car and wait til all wheels are ready
    ChassisInit();
    //my.material = mat_metal;
    my.material = mat_NM; // Normal mapping shader

    while (wheelCounter<4) { wait(1); }
    UpdateSpeed(); // update rear wheel speed (continuous)
    SpeedControl();// change speed (continuous)
    SteerControl();// change heading (continuous)
    }


    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 17:38

    OK in main.c I added
    init_normal(); // NM SHADER


    Add the code to psysics_car.c

    No go on the body. I do have a normal map in the model
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 18:45

    Honestly, I've never used Lite-C. I've been pocrastinating for a while...

    You should be able to simpl include the script and in the car action, change the material to mat_nm;. I'm not sure why it's not showng up in the material menu...
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 18:52

    Quote:

    Honestly, I've never used Lite-C. I've been pocrastinating for a while...

    You should be able to simpl include the script and in the car action, change the material to mat_nm;. I'm not sure why it's not showng up in the material menu...




    Well since the body is already using the carinit action we cant assign it another action. I wish that coul be changed. So we have to include the script into a crurrent script. And seeing how I am a scripting idiot, i need to ask on here for help
    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 19:02

    The above script have already been changed and work with the carlevel demo on other models, but not so good on the buggy model. The two actions don't really mind because you can comment one out and put the other inside the init_car action.
    Posted By: foodstamp

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 19:14

    Quote:

    The above script have already been changed and work with the carlevel demo on other models, but not so good on the buggy model. The two actions don't really mind because you can comment one out and put the other inside the init_car action.




    Not feeling ungrateful but here is the model i am using. If you could test in your project.
    duster


    Also if there is a way for you to maybe upload the changed scripts. I could probably do better. Up to you though.

    Thank You
    Posted By: Blink

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/17/07 22:03

    i have a question. is there a shader that makes a model have a shiny metal look to it? i have a robot that has a golden plating, i would like it to appear metal. is that impossible to do? what will i have to do to make that possible?
    Posted By: D3D

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/18/07 03:26

    Do you have the lightsource close enough to the model? Try adding the dlight.mdl inside the level, just above the car (the dlight action is used by default) Download.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 07/19/07 22:59

    "shinyness" = specularity

    specularity is controlled by the alpha channel of the normalmap texture.

    A tex with full alpha will be shiny, so yes, this will make it shiny...
    Posted By: camelot22020

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/20/07 01:12

    I tried to implement this shader, and although I'm new to using shaders it seems to work. I applied the material to a basic flat box i modeled in MED and the bump map look and specularity work, however the model is evenly lit and seems to be completely ignoring the lights that are illuminating the level geometry surrounding the model. Any ideas as to why this is would be great. Also I didn't modify your shader code or anything like that, just applied it right away. Thanks!
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/20/07 16:50

    Shaders only react to dynamic lights properly.

    Though, in my shader I added the option to use the ambience created from static lighting. by right-clicking the script from the properties tab in WED, you can use the "customize" panel for editing shader options...
    Posted By: camelot22020

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/20/07 20:40

    I went into MED and changed the origin so it was more centered, i think part of the problem before was that the origin was inside level geometry. So now the models that I applied the shader to are picking up the dynamic lights, however it seems that the light is getting applied to the entire model evenly, as opposed to per polygon. If that made sense? I lined up 6 of the models and each one gets darker if it's farther from the light, but it's not gradual across the model, it's like each model is assigned a uniform brightness and all the polygons on the model get that brightness. So even though the models are right next to each other, there are visible seams because one is darker than the one before.


    EDIT: Actually on closer inspection, the light seems to be applied to the models evenly, it's just that at one of the edges for some reason it suddenly gets gradually darker. It's just the edge that's the problem. I have a couple of normal-mapped boxes lined up as walls and just a little bit before the edge of each box, it gets darker. any ideas?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/21/07 16:54

    It would be much easier to diagnose the problem if I could see it. Can you post some screenshots?

    Well, it's per vertex, and each vertex is lit by it's position; so the origin of the model only applies to static lighting. make sure that you are actually using a dynamic light, and not static lights (WED lights). Dynamic lights use an action (included in the file) for dynamic lights.

    Also, shaders interpolate the normals of the vertices (unless specified by shadeMode = flat;), so using block objects might return bad lighting.
    Posted By: camelot22020

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/21/07 20:47

    Now that you mention it, it sort of looks like the shader is trying to round the edge or something, make it look less flat. would this " shadeMode = flat;" thing get it to stop doing that? where would i put that line of code? thanks for your responses

    i'll try to post a screenshot, do you know what a good place to do that is?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/22/07 16:28

    Well, I hope you can follow this, as it's just a basic explanation:

    Open the effect script (*.fx);
    At the bottom, you'll find the technique;
    after that, goto the first & second passes. In each one, at the first line of each pass, add that line...

    Let me know how it works. If it doesn't, then I'll just add it for you...
    Posted By: garv3

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/25/07 23:23

    Is it somehow possible to apply this mapper to level blocks?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/26/07 17:08

    You'd have to modify it a little bit, but shaders on blocks are dead-slow...
    Posted By: Orange Brat

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/26/07 18:41

    According to a semi-recent post from jcl, shaders on blocks aren't slow. I'm guessing this has something to do with newer A7 implementation.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 09/26/07 22:54

    I'm not sure about A7, but in A6, they are deffinatly very slow.
    Posted By: botu

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 10/25/07 13:49

    hi!
    First thanx for this shader!
    I have just two questions about transparency.

    Here a screenshot of my game:
    http://users.skynet.be/fa085808/spec.jpg

    As you can see, the specularity is visible even the transparency is on.
    Do you have a solution in this case?

    My second question is :

    With your shader, is it possible to modify the Ambient, diffuse ans specular during the game?
    My idea is to load an image in memory witch represent shadows and lighting level of the ground, and use this image to change the levels of spec,amb,diff of object positioned for example in the shadow of a mountain or under trees.


    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 10/27/07 07:12

    Try reducing the specularity on the edges of the leaves. I'm not sure why this problem is occuring, but I'll look into it if I find time...

    As for the changing of properties, simply change the material settings (mat_NM)
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 00:22

    Big bump here...

    Wanted to start testing normal maps...

    Tried to load the shader and I get an error for line 54

    <flags = tangent | enable_render;>
    NM.wdl 54:3 error(0) Flag unknown |

    I see this character in 3 locations throughout the script... Is this a proper character to use? I'm suprised noone else got or mentioned) this error

    I'm using GS v6.31.4 which may be the problem, as it didn't recognize "time_step" either, which I just changed to "time"
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 04:00

    I don't think shader worked in A6.31; Try upgrading....

    ...the errors were from updated syntax, but you already figured that out
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 04:31

    Yea, I have the updates up to 6.6 Pro, but I had my reasons to stick to this version. But I can certainly test higher versions. I'll give it a shot
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 08:08

    Ok, with 6.4 it works . Mostly...

    How do you keep the sun from affecting the models? I tried everything i could think of... even set the model to 'unlit'.

    As it is, I have 2 models inside of a hollow block 'room'

    One model has a second skin and the normal mapping applied... the second model is 'plain' and is dark like the NM model should be.

    The sun set to '0,0,0,'

    Outside the 'room' is a static light so the level will be completely unlit.

    No matter what, the NM model is affected by the sun. Meaning it's always lit from the direction of the sun's settings.

    Worse yet, if i turn the ambient DOWN, even to -2 the model lights up very bright! But from 0.0 to 100.0 the ambient works like normal.

    I have no alpha channels on the diffuse or the normal map skins.

    How do I turn off the sun on normal mapping models?

    - Jason
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 14:14

    Right click on the "NM.fx" script from WED, and go to "customize". I setup a panel for adjusting properties. If you don't have this, I used the specular channel for sun lighting.
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/19/08 23:05

    Well... I only have the 'customize' option for the NM.wdl but not the NM.fx, and this is what I get, though I don't know if it's the proper panel you mention..




    Here I tried to turn the ambient to '0,0,0' (not in the picture)

    Now, if this is the wrong customize panel, where in the WDL do I adjust the specular so the sun doesnt effect the model?

    I see 3 places where specular is listed in the fx file...

    Line 17: float4 vecSpecular;

    Line 128: float4 sunOut = (inColor*sunDiff + sunSpec*gloss) * sunShadow * vecSpecular;

    Line 252: technique SpecularNormalMapping_20

    ... and in the NM.wdl in the
    "function effect_startup()"
    Line 75: vec_set(mat_NM.specular_blue, sun_color);

    So I guess the question is, where and what do I adjust for the sun not to affect the model?

    Thanks for this awesome shader!

    - Jason

    EDIT: The reason I think the sun shouldnt always effect a model is using Doom3 as an example. the indoor areas have no sun influence, and is all lit by dynamic lights.

    The sun has no place indoors. As for 'some' lighting, you have the fantastic 'fake dynamic' lighting implemented, which is great for indoors.

    It would be neat to have a feature implemented to choose between sun influence and no sun influence so if you have both indoor and outdoor portions in a level, you can use the same script.

    Just my 2 cents
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 00:44

    Yes, this is the panel.

    The models "specular" property controls its influence from the suns light.

    Adjusting specularity via the panel/material will control sun lighting for all models. Setting it from the models material manager will only control the model (model material settings are dominant over script material settings).
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 02:48

    Ok, I'm stupid... I don't see the word specular anywhere on this panel?

    I guess i'd rather control each model individually indeed anyway.

    I found the material editor in MED.... theres 2 skins (of course) the diffuse and the normal map. I looked at both the normal map and the diffuse skin, but the specular level is at 0 already. By default, everything is set at 0 except alpha which is 100%

    How do I make specular less than 0 ? or do I need to raise it to lower the sun's influence?

    Oh and which skin do I set the influence?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 03:10

    I guess I left sun light (specular) out of the panel, my mistake. Sorry for the confusion...

    When you open the models skin dialog, select the first skin (diffuse) and check it's material flag/checkbox. Then set specular to 0...

    I'f you'd like, I can add the sunlight option to the panel (as it should be) and just give you that...
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 04:25

    That would be awesome...

    I am going to test again in a new room... from scratch
    All this testing has confused me lol

    This is a great shader, all who contributed, you all should be proud!

    I DO ahve a question though...

    I havn't yet done any speed tests, and i know so little about shaders, but can the performance be increased in some way?

    Is there a 'minimum' number of passes that can be performed for normal mapping?
    Does the use of specular decrease the performance as well?

    As always, I'm shooting for low end systems, and want normal mapping, but it seems SOME specular is necessary for a great normal map effect...

    Or is this shader pretty optimized, and likely to run on lower end machines without much problem?

    Sorry for all the newbie questions, and i'll ahve more all the time, i'm dure

    Thanks for any input!
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 06:34

    see? already another question...

    I'm using the program 'CrazyBump'

    Normal maps have a direction of lighting to highlight the highs and lows...

    when i use a dynamic light on a wall with a brick texture, all the dynamic light does is light up the surface... however, the direction of light and shadow are completely independent of where the dynamic light is placed...

    the normal map seems to have lighting from the upper left corner... if i put a light at the bottm right corner, the highlight/shadow is still from the upper left Al the dynamic light does is brighten the surface, but doesnt create it's own highlight/shadow.

    Is this how normal maps are supposed to work? I would think that the dynamic light should decide where highlight and shadow will appear ona surface.

    Is this how it's supposed to be?

    EDIT: I just heard from another person that this shader wont let a dynamic light be the only source of light/shadow. That kinda sucks because a torch on a big wall should have the lighting centered and radiated from the torch.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/20/08 17:18

    Quote:

    I just heard from another person that this shader wont let a dynamic light be the only source of light/shadow.




    ...If the option is enabled, this shader will accept lighting from static lights if blocks are underneath; "faked ambience".

    I'll throw a shader together for you, just tell me exactly what you need from it. Ex: How many dynamic lights, sun light?, static lights (faked)?, specular highlights? fog support?, etc...
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/21/08 11:04

    I can't believe my post didnt show up

    here... on this wall you can see a lighting problem on the bottom right corner... it's not properly lit by the dynamic light... it's actually opposite.



    The problem is less noticable on a rough surface like this next picture.. but it's there on the upper left corner...



    The dynamic light has to be very close for it to work 'properly', but the outer edges of the light.. i dont know whats making the lighting act like that. Specular is off, so it's not the sun.

    Also, I tested it with the diffuse skin 'off' and the lighting is the exact same. So it's not the diffuse skin making it look like shadow.

    ---------------------

    My settings for both examples are the same:

    Diffuse Skin:
    Material Setup (box checked)
    Effect Setup (box un-checked)
    Texture (box checked)

    MaterialSetup catagory - Diffuse 255,255,255 - Ambient 23,23,23 - Specular 0,0,0 - Emissive 0,0,0 - Power 0 - Alpha 100

    -------------------
    Normal Map Skin:
    Material Setup (box un-checked)
    Effect Setup (box un-checked)
    Texture (box checked)


    I know it's not the sun affecting the models this time, because the sun isn't affecting the rest of the models surface, and is in a different direction from where the lights are highlighting the normal maps.

    My understanding of normal maps is that a dynamic light would create highlights/shadows using the dynamic light as the source. Here it's kinda just lighting the area and the normal map is getting it's lighting clues from i don't know where

    JCL had said he would have a shader for the latest level tutorials that accurately lights the pixels from a dynamic light, is this shader somehow different?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/21/08 17:08

    Send me your environment and I'll get it working for you by tomorrow...

    In the meantime, I'll make something up and test it...
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/22/08 03:10

    Free for all: Heres 3 normal maps, 512 x 512 24 bit TGA images.

    I didnt upload the diffuse textures because it's the lighting were trying to figure out...

    dimples

    rough brick

    flat brick

    Sorry for late responses, been busy lately... Thanks for any help!

    There's no doubt the normal mapping works great.... it's the lighting thats innacurate.
    Posted By: Frederick_Lim

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/22/08 10:02

    I want to download the test project, but the link broken.
    Posted By: DavidLancaster

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/25/08 12:30

    Any news about the broken link?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/25/08 17:46

    I guess my host has abandoned me... well, If I find time, I'll post another sample with another host...
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/26/08 00:40

    Just send it to me via hotmail... I'll host it. bluebeast440 (at) hotmail

    Any news about the lighting issues I had?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/26/08 03:52

    I'll just rewrite it if I can find time. I've been busy trying to find a programming job online, not that easy...

    The lighting issue you described sounds like problems with the tangent vector. I fixed this in the newest release of the shader. I'll start rewriting it as soon as I find time, then send it to you (hopefully tonight or tomorrow morning).

    Sorry for the inconvenience...
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/26/08 20:53

    @BlueBeast: I sent you the two FX files for testing. They are not complete yet, but they're enough for testing.

    @Everyone Else: Rewriting the shader. I've added another shader that does Per Pixel Normal Map Lighting. Both shaders are only supporting two specular lights squeezed into one pass. More will come...
    Posted By: BlueBeast

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/26/08 21:25

    Got the files, and i'll be testing in a day or two for sure

    I'll post the results when I do

    Thanks bunches!
    Posted By: halfpastundead

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 03/30/08 19:14

    I am not sure if I just don't get how to use shaders, but I am not sure how to use this.

    I have:
    1. included nm.wdl in my main script
    2. imported a mdl with diffuse map in skn1 and normal in skn2
    3. build and I get my model, no effects on it though.

    Am I doing something wrong here? what is nm_mat that is mentioned? Is that what my material has to be named? If so, how would I have more than 1 material if they are all named that?

    thanks in advance.
    Posted By: halfpastundead

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/01/08 15:19

    nevermind, I figured it out.

    It's funny how things can be right in front of your face and you won't see them.
    Posted By: TerryHan

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 04/27/08 15:33

    Any idea how to implement this shader with lightmap on a 2nd UV channel?
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 05/15/08 17:07

    If anyones still interested, I can do this... (lightmap on third texture)
    Posted By: jigalypuff

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 06/19/08 08:11

    i`m interested in such a shader, and sorry to bump an old post.
    Posted By: xXxGuitar511

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 06/21/08 00:39

    I've been away from GS for a while now, but if I can find time to get back into it, then I'll let you know...
    Posted By: Azrael85

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 10/04/08 10:19

    great work!!!
    but the links doesn't work frown
    someone could re-link the shaders link?
    Posted By: not_me

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 10/12/08 19:06

    Originally Posted By: PHeMoX
    Not at my system, that looks more like the other normalmapping shader that was posted. It looks more like this:

    ackdoom <img src="/ubbthreads/images/graemlins/tongue.gif" alt="" />

    Cheers


    that looks amazing!
    Posted By: Ayumi

    Re: Normal-Mapping Shader (The Best @ vsps2.0) - 12/14/08 21:59

    Can you upload it again, please?
    Oh, sry anyone has asked too-.-
    © 2024 lite-C Forums