use a second uv-set on your models

Posted By: ventilator

use a second uv-set on your models - 05/24/07 13:58

mesh_plugin_demo.zip ~ 5mb

(the demo has a 777 polygon limitation and displays a demo message at each function call. if you would like to have an unlimited version you can write me a pm or email.)

this plugin makes it possible to use two uv-sets on your models. since the mdl7 format doesn't support two uv-sets, you will need two versions of your model. one with the first uv-set and one with the second uv-set. with the ent_loadseconduvset() function you can load the uvs of the second model into the second uv-set of the first model.

* the two models must have the same triangle count
* the vertices must be at the same positions
* the triangles must have the same vertex order
(these points usually are the case if you export them from the same application)
* the plugin requires engine version 6.6 or higher
* you can't use vec_for_mesh/vec_to_mesh anymore with a replaced mesh

the most common use of two uv-sets is light mapping. the example models and the script examples show how to use a baked light map on your models.

Code:
	you = ent_create("landscape.mdl", nullvector, 0); // load model with texture uv-set
you.material = mtl_lightmap; // assign light map material

tempentity = ent_create("landscape_lm.mdl", nullvector, 0); // load model with light map uv-set
ent_loadseconduvset(you, tempentity); // generate and assign a new mesh with both uv-sets
ent_remove(tempentity); // tempentity isn't needed anymore




Posted By: Nems

Re: use a second uv-set on your models - 05/24/07 20:35

Thanks Ventilator, I use a lot of terrain/model terrains at the moment so will apply this later when I need to.
Posted By: Pappenheimer

Re: use a second uv-set on your models - 05/24/07 22:28

You are actually a sort of pioneer, a pioneer of shadowmapping in 3DGS.

Thank you for that effort!
Posted By: Drew

Re: use a second uv-set on your models - 05/26/07 02:40

would you happen to have a compiled exe to share?

thanks!
Posted By: ventilator

Re: use a second uv-set on your models - 05/26/07 08:29

you could create an exe yourself for the demo. you just would need 6.6 from here. or do you not want to install 6.6 yet?
Posted By: Pappenheimer

Re: use a second uv-set on your models - 05/26/07 09:25

Quote:

or do you not want to install 6.6 yet?




I guess that's it - just the same what I thought, but I didn't dare to ask for this extra effort. Although, me, myself, I will install the 6.60 soon eventually.

In case, you make an exe, can you add an fps panel? (Don't hit me!)
Posted By: ventilator

Re: use a second uv-set on your models - 05/26/07 10:11

...i hate it that you can't edit your posts on this forum!

here is a version with exe: mesh_plugin_demo.exe ~5mb

keep in mind that it just is a quickly done test model which isn't that great. at some areas (especially the concrete borders of the road) the light map resolution is too low.

i have enabled f11. it's one 20000 polygon model. for performance it probably would be better to split it into < 5000 polygon models. with alt-enter and f5 you can try out fullscreen mode and different resolutions...
Posted By: Drew

Re: use a second uv-set on your models - 05/26/07 16:53

Thanks! Yes, I dont want to upgrade just yet, things always tend to break between versions...Im using a bunch of addons, sphere, intenseX...
Posted By: zazang

Re: use a second uv-set on your models - 05/27/07 01:50

Pardon me for my newbiness,but why cant we bake the shadows in the skin directly
and thus use a single skin ?
I mean what is the advantage of this plugin ?
Thanks.
zazang
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 05/27/07 02:36

you can but then you cannot have multiple uv maps (e.g. one huge skin for the shadows while other textures repeat and maintain their resolution)

So you can have a 128x128 pixel grass texture repeating, so it always looks 128x128. but then a single big image on top of that for shadows. This tool is mostly important for putting shadow maps on mdl entities without the huge memory hit that u get from baking your shadows directly onto huge textures
Posted By: zazang

Re: use a second uv-set on your models - 05/27/07 10:05

aha I see..thanks
Posted By: Pappenheimer

Re: use a second uv-set on your models - 05/27/07 17:00

Don't know wether this has been asked before:

How does a dynamic light influence these shadows?
Does it influence the shadwmap automatically, or by a special code, or not at all?
Posted By: ventilator

Re: use a second uv-set on your models - 05/27/07 17:09

how dynamic lighting gets mixed in depends on the material. i think my example material works exactly like the standard material that gets used for blocks. first the dynamic vertex lighting gets added to the light map and the result gets multiplied with the texture.
Posted By: Drew

Re: use a second uv-set on your models - 05/27/07 17:45

Is there amn option to not use A6's lighting at all?
I would create my lightmaps in Max or Gile(s) and import them into A6... just as an option, there are allot of reasons to use both..characters..

thanks
Posted By: ventilator

Re: use a second uv-set on your models - 05/27/07 17:55

to disable dynamic lighting try to change the example material to this:

Code:
material mtl_lightmap
{
skin1 = bmap_lightmap;

effect=
"
texture mtlSkin1;
texture entSkin1;

technique t0
{
pass p0
{
Texture[0]=<mtlSkin1>;
Texture[1]=<entSkin1>;

// light map
TexCoordIndex[0] = 1;
ColorArg1[0] = Texture;
ColorOp[0] = SelectArg1;

// multiply light map with texture
TexCoordIndex[1] = 0;
ColorArg1[1] = Texture;
ColorOp[1] = Modulate2x;
ColorArg2[1] = Current;
}
}
";
}


Posted By: DavidLancaster

Re: use a second uv-set on your models - 05/29/07 01:37

Hey Ventilator

Thanks so much for this plugin, it's very good!

I know I could look into this myself just wanted to see if you knew off the top of your head. Can 3DGS dynamic lights affect either the mesh or lightmapped model?

Thanks
Posted By: William

Re: use a second uv-set on your models - 05/29/07 04:12

Yeah, they can. Dynamic lights work fine.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 05/29/07 04:36

Why did I ask that when two posts above someone just asked the same question?



Thanks again Ventilator! This tool is going to help me out so much. Did you think of posting this in user contributions? It's a tool I thought would get more PR and would probably be seen more there...
Posted By: ventilator

Re: use a second uv-set on your models - 05/29/07 11:10

thanks for your comments!

i thought the third party tools forum is the most fitting one but you are right, it doesn't seem to be frequented that much. i will think about it...
Posted By: Samb

Re: use a second uv-set on your models - 05/31/07 01:59

well... here comes the ultimate question... how much?
Posted By: ventilator

Re: use a second uv-set on your models - 05/31/07 10:09

20€
Posted By: Samb

Re: use a second uv-set on your models - 05/31/07 21:02

thats.. not cheap
Posted By: ventilator

Re: use a second uv-set on your models - 05/31/07 21:31

it's... the result of my market research. if the price were much lower it will never compensate the time i have invested in it but of course everyone has to decide himself if it is worth it...
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 05/31/07 22:08

20 is super cheap!!!!!!!!!!
Posted By: William

Re: use a second uv-set on your models - 06/01/07 01:48

Yeah, 20 Euros is a steal. I hope everyone looks into this; it works great.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/02/07 14:56

Two things always bugged me with 3DGS and kept me looking elsewhere, performance and lack of mesh lightmapping.

Performance gets better with LOD, in comparison to other engines I've used, they do alot better on the performance side but lack 3DGS' "easy to script and put together a game" feature. Unless you want to fork out the $$$ for a really expensive engine which would beat all 3DGS' features...

A6's bsp has slow rendering, is hard to work with and very tedious to texture. Throwing together mesh levels and uv mapping them is so EASY. to be able to throw my level into giles and export its smooth lightmapping into 3DGS...Now I feel like I could make Twilight Princess in 3DGS...that's a nice feeling. *thinks of creating a TP level in 3DGS* *good feelings*

Ventilator has done something no one else has easily done, WED is supposedly going to have stable lightmapping, with WED lights affecting mesh surfaces. However unless this feature is implemented and robust with no bugs...I'm much more inclined to use a plugin like ventilators which is very stable, works with no strings attached.

So far, from what I understand, this is the only way to get lightmapped meshes into 3DGS (that isn't baked and we all know baking isn't great). This is the first of it's kinda, been desired and needed for years.

What Ventilator has done for the 3DGS community through this plugin, I am very grateful for. $20 is very cheap. I really believe this plugin deserves alot of PR, it completes 3DGS for me.
Posted By: ventilator

Re: use a second uv-set on your models - 06/03/07 13:02

thanks for your comments!

two screenshots of a gile[s] example model running in a6:







(provided by zapan)
Posted By: ulf

Re: use a second uv-set on your models - 06/03/07 13:28

good work ventilator! ill add this to my blog soon and use some of your pictures if its okay. have you thought about adding a little tutorial or setting up a small site for this tool yet?
Posted By: ventilator

Re: use a second uv-set on your models - 06/03/07 13:49

sure, you can use the pictures!

i think everything about how to use the plugin itself is covered in the examples.wdl already? do you mean a light map creation tutorial? i will think about that but for baking light maps i only used modo so far and i don't think there are many modo users here. maybe i will look how baking works in blender.
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 06/03/07 17:22

Those screenshots look fantastic!!!!!!!!!!!!!!!! Vent you deserve one of those crazy football victory things where a cheering crowd lifts you up and people are drinking beer from trophies and every thing

=)
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/04/07 01:42

Ventilator, I managed to get baking working in blender. I used a directional light for the sun, maybe it's how I uv mapped it but the baking turned out polygon/blockish. Not as nice as giles. Any hints?
Posted By: ventilator

Re: use a second uv-set on your models - 06/04/07 13:01

what do you mean with polygon/blockish? any screenshots? <edit> maybe you used [lightmap uvpack] for unwrapping (which doesn't seem to keep adjacent faces together where it makes sense)? [smart projections] worked better for me. </edit>



i played around with it too. render baking doesn't seem to support multi sampling yet in blender. other than that it works quite well though. you could bake a bigger image and scale it down or blur it a bit to get rid of the jaggies.

gile[s] also supports global illumination which blender can't bake into a texture yet.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/04/07 14:55

Yeah I was talking about the jaggedness If it's just as easy to blur it I'll do that I didn't know about that smart projections plugin! It works really well thank you

Another question. Is it possible to get surfaces with alpha to work with your second uv set plugin?
Posted By: ello

Re: use a second uv-set on your models - 06/04/07 15:23

Quote:


So far, from what I understand, this is the only way to get lightmapped meshes into 3DGS (that isn't baked and we all know baking isn't great).




isnt this baking, too? the shadowmap is baked, or what? can anyone explain to me what is better with using this texhnique above using a completely baked texture (including material settings and lighting) ?

i simply dont understand it, sorry
Posted By: Pappenheimer

Re: use a second uv-set on your models - 06/04/07 15:53

Quote:


Pardon me for my newbiness,but why cant we bake the shadows in the skin directly
and thus use a single skin ?
I mean what is the advantage of this plugin ?
Thanks.
zazang






Jetpack Monkeys answer:
Quote:

you can but then you cannot have multiple uv maps (e.g. one huge skin for the shadows while other textures repeat and maintain their resolution)

So you can have a 128x128 pixel grass texture repeating, so it always looks 128x128. but then a single big image on top of that for shadows. This tool is mostly important for putting shadow maps on mdl entities without the huge memory hit that u get from baking your shadows directly onto huge textures



Posted By: ventilator

Re: use a second uv-set on your models - 06/04/07 16:46

ello, have a look at the example level. how would you achieve the same texture resolution of the grass for example if you baked everything into one image? you would need a 8192x8192 image or something like that.

baking lighting and shadows requires that the uvs don't overlap. so you can't use tiling textures anymore if you don't have a second uv-set.

@david: how alpha gets handled depends on the material. what would you like to do?
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/04/07 23:31

My level would be comprised of 2 main models, the mesh (including collision) and the foliage. I want the foliage to be lightmapped but so far I'm not sure how to get the transparency to work (using the default material transparent areas turn out black). How would I go about getting the transparency to work? Thank you
Posted By: ventilator

Re: use a second uv-set on your models - 06/04/07 23:40

hm... you could post a simple example of your foliage model and its textures so that i (and others) can experiment with a material for it. i think i know how it would work with a shader but the confusing fixed function pipeline always takes lots of experimentation.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/05/07 00:25

I uploaded it here:

http://www.churness.com/axys/TGADemo.zip

It needs a dll, and I've just used your code base/setup as I haven't had time to strip it down. Let me know if you can help, it seems really abstract to me as I've never looked into shaders heaps Thank you
Posted By: ventilator

Re: use a second uv-set on your models - 06/05/07 00:51

i can't open that zip.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/05/07 02:17

Try again I reuploaded. And the tga texture part of the model is the small leaf part
Posted By: ello

Re: use a second uv-set on your models - 06/05/07 06:33

Quote:

ello, have a look at the example level. how would you achieve the same texture resolution of the grass for example if you baked everything into one image? you would need a 8192x8192 image or something like that.




yes, but if i bake the shadows and use detailmaps like gras and stone and blendmaps etc within a shader. i mean the baked shadow already provides a good uv-set and based on that i can tile the grass and other textures by using multipliers inside the shader code and in the end i take the shadowmap and multiply it. that should give the same results, right?
Posted By: Machinery_Frank

Re: use a second uv-set on your models - 06/05/07 08:36

Ello:
This might work in the case of a terrain with only one tiled texture like grass. But I can also map a sci-fi room with lots of tilable textures, many floor tiles, ceiling tiles, wall plates and columns with special textures. After that I create a second uv-set with a none-tilable uv-map and bake the shadows / static lighting into it. I can use even GI, Radiosity, area lights whatever I need.
At the end I combine both textures and uv-sets and could even live with 2 medium sized textures like 1024x1024.

Such a level could look beautiful and would render full speed. My only concern is how can I add normal-mapping to this scenario. If anybody finds a solution then this will be my favourite tool.

I still did not find the time to check this out. Have to finish some paid jobs. But I am still highly interested in that.
Posted By: ventilator

Re: use a second uv-set on your models - 06/05/07 12:37

Code:
	effect=
"
texture mtlSkin1;
texture entSkin1;

technique t0
{
pass p0
{
Texture[0]=<entSkin1>;
Texture[1]=<mtlSkin1>;
Texture[2]=<entSkin1>;

TexCoordIndex[0] = 0;
ColorArg1[0] = Texture;
ResultArg[0] = Temp;

// mix light map with dynamic lighting
TexCoordIndex[1] = 1;
ColorArg1[1] = Texture;
ColorOp[1] = AddSigned;
ColorArg2[1] = Diffuse;

AlphaArg1[1] = Temp;
AlphaOp[1] = SelectArg1;

// apply lighting to texture
TexCoordIndex[2] = 0;
ColorArg1[2] = Texture;
ColorOp[2] = Modulate2x;
ColorArg2[2] = Current;

MagFilter[2] = Linear;
MinFilter[2] = Linear;
MipFilter[2] = Linear;
}
}
";

this seems to work. not sure if it could be done with two texture stages only.

i think it would be better to separate it into two models (one with the opaque textures and one with the transparent ones) so that the engine can correctly render them in the opaque/transparent render passes.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/05/07 13:56

Thank you very much! It works well When I get the time I'll test it extensively with trees and foliage ^^
Posted By: ventilator

Re: use a second uv-set on your models - 06/05/07 23:44

i have programmed a function called supertrace() which offers this functionality: http://www.coniserver.net/ubbthreads/sho...true#Post745256

supertrace.zip ~ 500kb
it's a free separate plugin. to try out the example script extract the zip file to the directory with the mesh plugin demo.

with this function entities will be able to react to shadows below them. (another thing which wouldn't be possible if you just baked everything into one texture.)

it could also be helpful for other things.



it was a bit tricky to implement and it is experimental. i don't know if it is usable for real projects.








Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/06/07 04:24

FUDGE Ventilator. You've just made history, there is now no reason for myself to use bsp, apart from it being simpler to throw it all together in WED (but longer and more tedious in the long run). Please post this in user contribs! I only came upon this thread because I was looking at your blender tutorial and managed to see your signature ^^ Otherwise I don't normally look in third party forum.
Posted By: Machinery_Frank

Re: use a second uv-set on your models - 06/06/07 08:27

I am not sure if I did understand it well.

Is it meant to be used as follows? You trace with supertrace() to the texture beyond your position (choosing first or second uv-set) and you can get a color or the darkness of the shadow to make something like: hide in the shadows, warm up the player in the sun or program some dynamic over-exposures?
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/06/07 12:50

I'm probably saying something you might already know Frank...You get the darkness and color of the surface below a dynamic entity like the player and change it's ambient/color based on that. Otherwise if the player steps into a shadow it'll have the same ambient, but using this code you can change it's ambient because you can read from the shadow map below the player ^^
Posted By: msl_manni

Re: use a second uv-set on your models - 06/06/07 15:31

If I understand correctly then you are using Newton + Second_UV for your projects. That means that you have been able to implement the polygonal collision detection with Newton. Is it for Lite_c only or the whole package be used with c_script too. Please elaborate your plans about your project implementation, which seems to be very exciting.
Posted By: ventilator

Re: use a second uv-set on your models - 06/06/07 15:40

supertrace() and the second uv-set plugin work with c-script and lite-c.

my newton physics example (see lite-c contributions forum) only works with lite-c since wrapping all newton functions for c-script would be a bit a pain.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 06/07/07 14:07

Out of curiosity, would it be possible to use a 3rd uv set and scale it's uv to represent cloud shadows? Or would it work just as well to have a model of the level, with transparent cloud shadow map, and scale the uv of that model. ie the model would be independant of the shadow mapped one and slightly offset along the z axis? Or to get complex, could you possibly load up the cloud uv and write it over the lightmap uv by writing directly to the bmap, and scale it across dynamically?
Posted By: ventilator

Re: use a second uv-set on your models - 06/07/07 14:19

i don't think you would need a manually defined uv-set for that. for projecting clouds the uv-coordinates could be generated on the fly in the shader. for example just use the x and y coordinates of the vertices and scale and offset them a bit.
Posted By: EX Citer

Re: use a second uv-set on your models - 06/08/07 15:47

where I have to place the money? If anyone played around with this, hows the impact on the framerate (espacially on not so good pcs/notebooks).
Posted By: ventilator

Re: use a second uv-set on your models - 06/08/07 17:35

you can write me a pm or an email to the address which is mentioned in the example script.

did you play around with the demo? the example model should give an impression about performance. you could compare the frame rate with and without the light map and maybe with more copies of the model in the level.

(but keep in mind that for performance it probably would be more ideal to use several <~5000 polygon models instead of big models like the 20000 polygon one in the example.)
Posted By: Pedro_Amorim

Re: use a second uv-set on your models - 06/17/07 18:51

so. how do a n00b like me makes thing thing to work?
i already have the 2models to test.
and now what?
lol
im a n00b when it comes to c-script
Posted By: ventilator

Re: use a second uv-set on your models - 06/17/07 18:59

in the script you have to uncomment example1 and then look for the filenames of my example models and replace them with the filenames of your models.
Posted By: DavidLancaster

Re: use a second uv-set on your models - 07/06/07 14:27

Hey Ventilator

If I'm using your supertrace plugin I have to use the newton splash screen right???

New beta features being implemented:

A7 X When c_trace() hits a model entity in OBB mode, the tex_color vector is now set to the color of the texture pixel at the hit point. For this the texture must be a TGA image in 24 bit RGB or in 32 bit ARGB format.

A7 X When c_trace() hits a level block or a model entity in OBB mode, the predefined target_map pointer is set to the hit BMAP (the lightmap or the first entity skin), and the target_pos vector is set to the u,v coordinates of the hit point on the texture. This can be used to paint on the texture, add or remove shadows, or punch holes in targets with a gun.

What would this mean by adding or removing shadows to the texture surface? What would this mean for your supertrace plugin? Is your 2nd uv set and supertrace just made for A6?
Posted By: ventilator

Re: use a second uv-set on your models - 07/06/07 15:06

no, you don't have to show the newton splash screen. you just have to credit newton but you don't have to use the splash screen for that. please see the newton license.



these new c_trace features (which i have suggested in the future forum a while ago) can't replace supertrace() yet since the returned model uv-coordinates always are of the first uv-set.

jcl said that future versions will also be able to return the coordinates of the second uv-set and then supertrace() won't be needed anymore for a7.



i don't think there are any plans to support loading a second model uv-set in a7 so my mesh plugin will stay necessary for that.
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 07/10/07 02:25

Mwaah I love this plugin!

Vent, you had mentioned a kind of admittedly clumsy but quick way this could be hacked together with the obj-splitter, so I can light my huge (several hundred model) levels all together.. how should I go about doing this? (Right now I am just taking a few essential pieces and doing it by hand, but it would be so awesome to have the splitter and this working in tandem, just imagine)
Posted By: ventilator

Re: use a second uv-set on your models - 07/10/07 09:30

i simply could add an additional command line parameter which causes that each model filename gets a suffix like "_lm" and that the wmp export gets skipped.

i am not sure though how it would work on the maya side. do really all objects get a lightmap? is it possible to only export selected ones into the obj? what can be automated with mel? ...
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 07/10/07 15:06

That sounds like a very good idea.. or I could force the models to all have an _lm suffix in MEL with a renaming operation.. though then there would be duplicate models-- using the _lm suffix in the splitter is probably a more efficient idea.

Actually the really hairy part is generating the c-script to load all the different _lm meshes and their bmaps.. can you think of a good strategy to automate that? With so many objects, that is the restrictive barrier.

Thanks for the advice!
Posted By: ventilator

Re: use a second uv-set on your models - 07/11/07 11:12

Quote:

Actually the really hairy part is generating the c-script to load all the different _lm meshes and their bmaps.. can you think of a good strategy to automate that?


wouldn't this work with my example script which checks if the _lm files exist?
Posted By: DavidLancaster

Re: use a second uv-set on your models - 07/11/07 12:19

Quote:

Quote:

Actually the really hairy part is generating the c-script to load all the different _lm meshes and their bmaps.. can you think of a good strategy to automate that?


wouldn't this work with my example script which checks if the _lm files exists?



What about the memory leaks with creating the materials?

Is there any work arounds?

So...if I wanted to have say 5 levels, in each of my 5 levels I had a terrain mesh with a lightmap and I wanted to use the supertrace plugin. Would I have to have all 5 of those lightmaps loaded into memory at once? How would I go about having only 1 loaded into memory at a time?
Posted By: ventilator

Re: use a second uv-set on your models - 07/11/07 12:29

jcl has added a mtl_remove() function so if you correctly use mtl_remove() and bmap_remove() then there won't be a memory leak.

materials are so small though that the memory leak probably wouldn't do any harm. caring for the bitmaps is more important.



...
from the beta page:
Quote:

The handedness of the binormal is now stored in the 4th tangent coordinate of every vertex. This avoids shader problems with mirrored coordinates.


because of this change the current plugin version won't work anymore with the next engine release. the registered users will get an updated version.
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 07/11/07 12:34

Thanks, how silly of me to miss that, I have no idea how I didn't see it. You're right, that would absolutey be sufficient!

I can write a MEL script to select each polymesh, auto-unwrap it, add a texture and bake a shadow map to it, save the whole file as myname_lm.mb, then execute a modified version of the splitter with an -lm flag, without building a wmb ilke you mentioned, so that each _lm mdl has the same number prefix and name as the regular mdls. I am confident that I can script that first part in MEL. In that case, a version of the splitter which adds the _lm suffix/doesn't build a wmb would do the trick!

Would you mind adding that to the splitter, if it's not too much work? By the way, a little off-topic but I will mention it here in case you open up and work on the splitter.. could you add another feature? Because each object the splitter exports has a different numerical prefix to avoid conflict, it's difficult to make LOD for so many models.. a solution to this would be a lodgp_ prefix, an LOD group that works like regular groups (gp_) do already, but the level designer makes sure that the contents of each one have a models with the same name and appropriate numericial suffix (0-4) per normal LOD naming convention. Simply put, items in an lodgp_ would be in a normal group but not have that unique numerical prefix.

Thanks for everything, your tools have changed and improved my workflow a million times over

Posted By: ventilator

Re: use a second uv-set on your models - 07/11/07 14:01

here is the lite-c version of the example script in case anyone would like to run the plugin demo with lite-c. it should also work with the free lite-c edition.

save it as examples_litec.c and also create the file examples_litec.wdl which contains the line: plugindir = ".";

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



void ent_loadseconduvset(ENTITY* entity1, ENTITY* entity2);
void ent_exportmesh(ENTITY* entity, STRING* filename);
void ent_importmesh(ENTITY* entity, STRING* filename);



ENTITY* skycube =
{
type = "skycube+6.tga";
flags2 = SKY | CUBE | VISIBLE;
material = mat_sky;
}



void applylightmaps();
ENTITY* tempentity;



//----------------------------------------------------------------------------- mtl_lightmap

BMAP* bmap_lightmap = "landscape_lm.dds";

MATERIAL* mtl_lightmap =
{
skin1 = bmap_lightmap;

effect=
"
texture mtlSkin1;
texture entSkin1;

technique t0
{
pass p0
{
Texture[0]=<mtlSkin1>;
Texture[1]=<entSkin1>;

// mix light map with dynamic lighting
TexCoordIndex[0] = 1;
ColorArg1[0] = Texture;
ColorOp[0] = AddSigned;
ColorArg2[0] = Diffuse;

// apply lighting to texture
TexCoordIndex[1] = 0;
ColorArg1[1] = Texture;
ColorOp[1] = Modulate2x;
ColorArg2[1] = Current;
}
}
";
}



//----------------------------------------------------------------------------- main
void main()
{
video_mode = 8;

vec_set(mat_sky.emissive_blue, vector(20,20,20)); // make sky a bit brighter

wait(3);
level_load("");
wait(1);

vec_set(sky_color, vector(250, 175, 75));

vec_set(sun_angle, vector(-30, 35, 0));
sun_light = 10;

vec_set(camera.x, vector(300, 0, 200));
camera.pan = 180;



STRING* meshfilename = "landscape_lm.mesh";


/*
//-------------------- example 1

you = ent_create("landscape.mdl", nullvector, 0); // load model with texture uv-set
you.material = mtl_lightmap; // assign light map material

tempentity = ent_create("landscape_lm.mdl", nullvector, 0); // load model with light map uv-set
ent_loadseconduvset(you, tempentity); // generate and assign a new mesh with both uv-sets
ent_remove(tempentity); // tempentity isn't needed anymore

ent_exportmesh(you, meshfilename); // save mesh with both uv-sets for reuse
*/


//-------------------- example 2

// for very huge models ent_importmesh() probably is faster than ent_loadseconduvset().
// usually ent_loadseconduvset() should be fast enough though.

if(you) {ent_remove(you);}

you = ent_create("landscape.mdl", nullvector, 0); // load model with texture uv-set
you.material = mtl_lightmap; // assign light map material
ent_importmesh(you, meshfilename); // load and assign the previously saved mesh


/*
//-------------------- example 3

// applylightmaps() cycles through all entities in the level and applies a light map
// if the two "_lm" files exist for the entity.

if(you) {ent_remove(you);}

ent_create("landscape.mdl", nullvector, 0);
applylightmaps();
*/


while(!key_any) {wait(1);}
def_moveset(); // default camera movement
}



//----------------------------------------------------------------------------- example 3

var file_exists(STRING* filename)
{
var filehandle;
filehandle = file_open_read(filename);
if(filehandle)
{
file_close(filehandle);
return(1);
}
else
{
return(0);
}
}

STRING* tempstring1 = "#100";
STRING* tempstring2 = "#100";
MATERIAL* tempmaterial;

void applylightmaps()
{
you = ent_next(0);
while(you != 0)
{
str_for_entfile(tempstring1, you);
str_trunc(tempstring1, 4);
str_cpy(tempstring2, tempstring1);
str_cat(tempstring1, "_lm.mdl");
str_cat(tempstring2, "_lm.dds");

if(file_exists(tempstring1) && file_exists(tempstring2))
{
you.material = mtl_create(); // they should be removed again when changing the level
tempmaterial = you.material;
tempmaterial.effect = mtl_lightmap.effect;
tempmaterial.skin1 = bmap_create(tempstring2); // they should be removed again when changing the level

tempentity = ent_create(tempstring1, nullvector, 0);
ent_loadseconduvset(you, tempentity);
ent_remove(tempentity);
}

you = ent_next(you);
}
}


Posted By: ventilator

Re: use a second uv-set on your models - 07/11/07 14:07

Quote:

Would you mind adding that to the splitter, if it's not too much work? By the way, a little off-topic but I will mention it here in case you open up and work on the splitter.. could you add another feature? Because each object the splitter exports has a different numerical prefix to avoid conflict, it's difficult to make LOD for so many models.. a solution to this would be a lodgp_ prefix, an LOD group that works like regular groups (gp_) do already, but the level designer makes sure that the contents of each one have a models with the same name and appropriate numericial suffix (0-4) per normal LOD naming convention. Simply put, items in an lodgp_ would be in a normal group but not have that unique numerical prefix.


i will try to add the _lm option in the next days.

i am not sure if i understand the lod solution and if it would be easy to add but i will think about it.
Posted By: JetpackMonkey

Re: use a second uv-set on your models - 07/11/07 14:21

Quote:

Quote:

Would you mind adding that to the splitter, if it's not too much work? By the way, a little off-topic but I will mention it here in case you open up and work on the splitter.. could you add another feature? Because each object the splitter exports has a different numerical prefix to avoid conflict, it's difficult to make LOD for so many models.. a solution to this would be a lodgp_ prefix, an LOD group that works like regular groups (gp_) do already, but the level designer makes sure that the contents of each one have a models with the same name and appropriate numericial suffix (0-4) per normal LOD naming convention. Simply put, items in an lodgp_ would be in a normal group but not have that unique numerical prefix.


i will try to add the _lm option in the next days.

i am not sure if i understand the lod solution and if it would be easy to add but i will think about it.




thank yOU thank yOU!! Oh the lodgp_, it could just be like a regular group except it wouldn't put a number in front of its objects:

so a normal group like gp_amplifiers with the following objects
amp1.mdl
amp2.mdl
amp3.mdl

normally exports like this, by adding that numeric prefix
_234_amp1.mdl
_235_amp2.mdl
_236_amp3.mdl

but if it were in lodgp_amplifiers, I would manually create the reduced LOD files, and manually name the files with LOD numeric endings:

amp1_1.md
amp1_2.mdl
amp1_3.mdl
amp1_4.mdl


When running the splitter, it would recognize the lodgp_ and give em all the same numeric prefix:

_234_amp1_1.mdl
_234_amp1_2.mdl
_234_amp1_3.mdl
_234_amp1_4.mdl

Maybe there's a better solution tho?
Posted By: DavidLancaster

Re: use a second uv-set on your models - 07/12/07 12:19

Would you happen to know if mtl_remove will be in the next A6 beta or was JCL talking about A7? Thanks!
Posted By: JackShephard

Re: use a second uv-set on your models - 10/04/07 15:20

STRING* meshfilename = "landscape_lm.mesh";

.mesh in 3dgs? O.o
Posted By: ventilator

Re: use a second uv-set on your models - 10/16/07 07:13

here is the demo of the plugin for a7 (and lite-c): mesh_plugin_demo_a7.zip
it's important that you use this one for a7 and the one from the first post of this thread for a6! the reason is that the vertex format is different in a7 and so two different plugin versions are needed.

start examples_litec.c from SED. the c-script example currently doesn't work in a7 since there seems to be a strange problem with the function for showing messages. this doesn't affect the full version of the plugin though.



...and i decided to reduce the price to 10€!
Posted By: Samb

Re: use a second uv-set on your models - 10/16/07 14:44

Quote:


...and i decided to reduce the price to 10€!




SOLD!!!
well.. first I need money on my bankaccount.
but then SOLD!!!!
Posted By: Slin

Re: use a second uv-set on your models - 10/17/07 00:56

When I used the old demo version for this: http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/793529/Main/793085/#Post793529
it worked perfectly fine with A7.
Thanks for reducing the price and for the great plugin, now I only need to know how to have blender generating the lightmap for me and I will buy it as soon as I can find a use for it
Posted By: ventilator

Re: use a second uv-set on your models - 10/17/07 05:30

the first (beta?) versions of a7 still had the same vertex format as a6 but now it's different. it changed with 7.05.1 because of this:
Quote:

The handedness of the binormal is now stored in the 4th tangent coordinate of every vertex. This avoids shader problems with mirrored coordinates.




you could ask about baking light maps on the blender forum. i think someone there made a tutorial about it.
Posted By: ventilator

Re: use a second uv-set on your models - 11/07/07 13:12

the tangent flag can mess up a replaced mesh. i guess the engine still uses some data from the old mesh for tangent calculation and there is nothing i can do about it. if this happens this trick should help:

Code:
material mtl_normalmapping
{
// flags = tangent; // don't set the tangent flag here if you use a replaced mesh!
effect = "normalmapping.fx";
}

[...]

you = ent_create("model.mdl", nullvector, 0); // load model with texture uv-set
you.material = mtl_normalmapping;
mtl_normalmapping.tangent = on; // set the tangent flag only for one frame
wait(1);
mtl_normalmapping.tangent = off;

// load the second uv-set after disabling the tangent flag
// the tangents still are in the mesh

tempentity = ent_create("model_lm.mdl", nullvector, 0); // load model with light map uv-set
ent_loadseconduvset(you, tempentity); // generate and assign a new mesh with both uv-sets
ent_remove(tempentity); // tempentity isn't needed anymore





...
and another tip: you don't really have to use ent_exportmesh()/ent_importmesh(). these functions are only meant for the case when ent_loadseconduvset() is too slow (and i need them for the demo) but it usually shouldn't be too slow. before the release of the plugin i used a slow brute force algorithm for a while but i made it much faster for the release.
Posted By: Chris3D

Re: use a second uv-set on your models - 12/16/07 16:23

Hi ventilator!

How can I get an updated full version of the mesh plugin, I already bought the first version for 20 Euro, but now it doesn't work anymore with the new A7.06!

Greetings,
Chris
Posted By: ventilator

Re: use a second uv-set on your models - 12/17/07 13:33

i have sent you the a7 version...
Posted By: HeelX

Re: use a second uv-set on your models - 12/29/07 14:12

Is there an easy way to combine an arbitrary shader with the lightmapping? E.g. after everything has been calculated I simply but the color of the lightmap over it?

Cheers,
Christian
Posted By: ventilator

Re: use a second uv-set on your models - 12/29/07 14:37

yes, it is easy. you just have to pass the uvs of the second uv-set into the pixelshader, sample the light map and then apply it however you want. if your shader uses the tangent you have to use the trick above.
Posted By: HeelX

Re: use a second uv-set on your models - 12/29/07 18:58

I have no clue about this business. So, maybe you can help me out?
Posted By: ventilator

Re: use a second uv-set on your models - 12/29/07 19:07

here is a modification of taco cohen's normal mapping shader. the necessary additions are marked with #####.

Code:
/***********************************************************************************************
/ Copyright 2006 by Taco Cohen. All rights reserved
/***********************************************************************************************/

/***********************************************************************************************
/ Global Variables:
/***********************************************************************************************/
// Tweakables:
static const float AmbientIntensity = 1.1f; // The intensity of the ambient light.
static const float DiffuseIntensity = 1.0f; // The intensity of the diffuse light.
static const float SpecularIntensity = 2.0f; // The intensity of the specular light.
static const float SpecularPower = 14.5f; // The specular power. Used as 'glossyness' factor.
static const float4 SunColor = {0.9f, 0.9f, 0.9f, 1.0f}; // Color vector of the sunlight.

// Application fed data:
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4 vecAmbient; // Ambient color.
const float4 vecSunDir; // The sun direction vector.
const float4 vecViewPos; // View position.

texture entSkin1; // Color map.
sampler ColorMapSampler = sampler_state // Color map sampler.
{
Texture = <entSkin1>;
AddressU = Wrap;
AddressV = Wrap;
};

texture entSkin2; // Normal map.
sampler NormalMapSampler = sampler_state // Normal map sampler.
{
Texture = <entSkin2>;
AddressU = Wrap;
AddressV = Wrap;
};

texture mtlSkin1; // ##### light map
sampler LightMapSampler = sampler_state // ##### light map sampler.
{
Texture = <mtlSkin1>;
AddressU = Wrap;
AddressV = Wrap;
};


/***********************************************************************************************
/ Vertex Shader:
/***********************************************************************************************/
void NormalMapVS( in float4 InPos : POSITION,
in float3 InNormal : NORMAL,
in float2 InTex : TEXCOORD0,
in float2 InTex2 : TEXCOORD1, // ##### second uv-set
in float3 InTangent : TEXCOORD2,

out float4 OutPos : POSITION,
out float2 OutTex : TEXCOORD0,
out float2 OutTex2 : TEXCOORD3, // ##### second uv-set
out float3 OutViewDir: TEXCOORD1,
out float3 OutSunDir: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);

// Pass the texture coordinate to the pixel shader:
OutTex = InTex;

// ##### output second uv-set
OutTex2 = InTex2;

// Compute 3x3 matrix to transform from world space to tangent space:
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(InTangent, matWorld);
worldToTangentSpace[1] = mul(cross(InTangent, InNormal), matWorld);
worldToTangentSpace[2] = mul(InNormal, matWorld);

// Calculate the view direction vector in tangent space:
OutViewDir = normalize(mul(worldToTangentSpace, vecViewPos - mul(InPos, matWorld)));

// Calculate the light direction vector in tangent space:
OutSunDir = normalize(mul(worldToTangentSpace, -vecSunDir));
}


/***********************************************************************************************
/ Pixel Shader:
/***********************************************************************************************/
float4 NormalMapPS( in float2 InTex : TEXCOORD0,
in float3 InViewDir : TEXCOORD1,
in float3 InSunDir : TEXCOORD2,
in float2 InTex2 : TEXCOORD3) : COLOR // ##### second uv-set
{
// Read the normal from the normal map and convert from [0..1] to [-1..1] range
float3 BumpNormal = 2 * tex2D(NormalMapSampler, InTex) - 1;

// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;

// Calculate the diffuse term:
float4 Diffuse = DiffuseIntensity * saturate(dot(InSunDir, BumpNormal));
Diffuse *= SunColor;

// Calculate the reflection vector:
float3 R = normalize(2 * dot(BumpNormal, InSunDir) * BumpNormal - InSunDir);

// Calculate the specular term:
InViewDir = normalize(InViewDir);
float Specular = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;

// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);

// ##### fetch the light map color from the light map:
float4 Light = tex2D(LightMapSampler, InTex2);

// Calculate final color:
return (Ambient + Diffuse + Specular) * Color * (Light * 2); // #####
}

/***********************************************************************************************
/ Technique:
/***********************************************************************************************/
technique SpecularTechnique
{
pass P0
{
VertexShader = compile vs_2_0 NormalMapVS();
PixelShader = compile ps_2_0 NormalMapPS();
}
}


Posted By: HeelX

Re: use a second uv-set on your models - 12/30/07 00:19

Thanks! I will check it out!
Posted By: HeelX

Re: use a second uv-set on your models - 12/30/07 13:16

Many thanks! It is really easy to adopt it to other shaders. I took the phong normalmap - shader from the current A7 version and applied it:



One question, though: Now I have got specular areas even in dark areas like that:



I know that this doesn't have to do 100% with your plugin and should be handle in the shader, but is it possible to evaluate the darkness of the shadowmap and return then the _unprocessed_ pixel OR a less lit pixel? (theoretically) and if this is not too complicated or too much performance consuming.. - how would I have to achieve that?

Cheers and many many thanks!
Christian
Posted By: ventilator

Re: use a second uv-set on your models - 12/30/07 13:36

if you only use one light it can be fixed but i think if you use multiple lights it isn't easily possible to really solve this problem since you would have to know which light cast which shadow to handle specularity correctly. (maybe it would work by encoding the light ids in the alpha channel of the light map somehow but i don't know a light mapper which does this. )

i would experiment with thresholds or something like that. it should at least be possible to make it less noticable.

...
the recent realtime shadow mapping examples by jcl have the same problem if you use multiple lights.
Posted By: Machinery_Frank

Re: use a second uv-set on your models - 01/04/08 11:36

Great approach! I like it.

I think if the specularity is less bright in the shadow then it will be ok. There can be some specularity as long as the shadow is not completely dark. And if I understand it right then the specularity will also be less bright in the shadow. So it is fine.
Posted By: Pappenheimer

Re: use a second uv-set on your models - 01/04/08 12:12

I like the combination of shadow and shader as it can be seen in the pics.

Where did you make the shadowmap?
On the terrain it is brighter near the edges of the boxes, what is a bit irritating.
Posted By: HeelX

Re: use a second uv-set on your models - 01/04/08 17:27

Hi,

I made the meshes, the UV set and the lightmap in Cinema4D, the normalmaps with Crazybump. There are some parameters inside the shader I compiled for this and you can control and produce several "settings" for the shinyness of the normalmapped - surface.

Greetings from Barcelona,
Christian
Posted By: alfredm

Re: use a second uv-set on your models - 03/30/08 23:30

How to buy this plug ?
please give me your price and way to download it
Posted By: rvL_eXile

Re: use a second uv-set on your models - 05/05/10 15:08

Does anybody have this Plugin on your HDD? Please PM me
Posted By: PietroNifosi

Re: use a second uv-set on your models - 05/07/10 18:10

Isn't this plugin obsolete nowadays??
In MED I do use 2 uv sets (the second for shadowmap) without the need of this plugin
Posted By: Pappenheimer

Re: use a second uv-set on your models - 05/07/10 18:12

You are right.
His request was A6 related ...
© 2024 lite-C Forums