Crystal Space
Welcome, Guest. Please login or register.
October 19, 2017, 05:07:24 am

Login with username, password and session length
Search:     Advanced search
9063 Posts in 2051 Topics by 77238 Members
Latest Member: Zenonbako488
* Home Help Search Login Register
  Show Posts
Pages: [1]
1  Crystal Space Development / Game Content Creation / Re: some question about how to use texture and light in blender ? on: September 04, 2008, 05:04:14 am
If you have your basic scene set up correctly then make sure you have relight set on the blender export settings.  If all your lights are non-dynamic and you have not ran relight then the lightmaps will not have been generated.  The first time you run a map with static lights you should always use the -relight option.  You can tell if light maps were generated by opening the world archive.  A cache folder will be added to the world zip archive if light mapping has been performed.  If there is no cache folder after you run the program then that means you need to run the program with the -relight option

If your scene is set up correctly, and you do have cached lightmaps then it is possible that the way your environment is scaled the lights arent actually reaching your objects.  To test this take one or all of your lights and change the distance paramater (under the blender light settings) to something bigger, like 1000.  You can simulate a single global light source, like a sun light in blender by placing that light and giving it a huge distance.  This should reach all of your meshes.  You will have to run the program with -relight each time you change you static light settings I believe in order for the lightmaps to update.  This will cause the app to load slower on the first run, but subsequent executions without relight will run faster because the light maps are cached and don't need to be regenerated.
2  Crystal Space Development / Game Content Creation / Simulating Photon Mapping in CS on: September 03, 2008, 04:03:28 am
I wasn't satisfied with the basic light map generation in CS so I have been generating my own lightmaps and radiosity.  This is a simple tutorial on how to do this.

here is a link to a screenshot of a basic photon map experiment in CS.

Terrain in Crystalspace


This looks like nothing special at first glance, it was just whipped up in a few minutes to serve as an example. If you pay careful attention to the curvatures of the terrain you will notice that this screenshot was taken in the shadow of the hill.  A single spotlight was used to light the entire scene.  Normally without some kind of second light or ambient adjustments the shadow areas would be totally black.  In this case there are very soft shadows bringing out all of the little details in an aesthetic way.

I will explain simply how this was done in a way to get the effects to work in crystal space, but I do suggest you familiarize yourself with blender radiosity first if you have no experience with it.

The concept behind radiosity or photon mapping is that in reality, light bounces off of objects. The objects absorb some of the light and repel other parts of the light which then continue bouncing around until they are finally absorbed or escape.  Photon mapping attempts to get more realistic effects by simulating the way light really works.  This is all great in concept and if you follow the blender tutorials you can get it to work.  The problem is when you try to expand the concept to large scenes or terrain.  Often your lighting will be totally wrong, or just wont look like the example you just completed. What is the trick?

Here is how it was done:

In blender start a new project and create an object or terrain which you want to have global lighting applied too.  REMOVE ANY LIGHTS FROM THE SCENE. Our base lighting will be generated using blenders radiosity tool.

When I first started playing with radiocity and terrains, I attempted to use emit objects like you would use a normal light.  In a closed in space, this might work just dandy, but terrain is normally out in the open and exposed.  This means that much of the light only bounces once and escapes.  In order to make radiosity work with terrain you need to scale the terrain down low so it is about as big as the default cube.   Then ad a cube mesh around the terrain so it is fully enclosed.  Remove one of the front faces of the enclosing mesh so you can see inside the box.  Reverse the normals on the box so the normals point in toward your terrain model.  Now create a light source object. I created a simple circle mesh plane and gave it a light yellowish material. (EDIT: The reason we put the terrain in a box is so the light can bounce off the walls and we get reflections back in the shadow area. Normally such reflections can occur off the atmosphere)

the yellow light, the terrain, and the box walls will need to have their emit and ambient values tweaked in order to get the right effect.  Radiocity does most of its light calculations assuming the majority of the light is coming from whatever object has the highest emit value (this is something I think)

Since the yellow circle is the primary light source it will have a higher emit value than the box or the terrain. 

make these changes under "shaders" in the materials buttons

circle:  emit=.4 ambient=.1
box: emit=.01 ambient = .1
terrain emit=.02 ambient = .1

now switch to the radiosity buttons.

drag the hemires slider all the way to the right (1000)

Make sure the circle, box, and terrain are selected.

Click the Gour button or ensure it is active

Click the collect meshes button.  All of the objects will turn white (im using the Apricot GLSL button so this may or may not happen in the regular version)

The collect meshes is confusing. At first I freaked out because everything was too bright and white.  I spent numerous attempts getting horrible lighting results because the system is not intuitive.  Once you clicked the "collect meshes" button, this basically merged the objects into one mesh.  Despite what the tutorial recommends, I do NOT put a limit in the max iterations.  I will explain the reason.

After clicking collect meshes, you will see a new set of buttons pop up over to the right.  One of the buttons says "GO".  Click it.

When the radiosity process starts, you will see a little blue square patch flying around the screen.  The scene will likely look like crap and you may get frustrated with the results.  Don't fret! there is still more to do!

Let the radiosity continue for 30 seconds or so and try not to look at the screen.

now hit the escape button and your radiocity process will cease.  Most likely you scene is too bright. 

Adjust the "mult" value, most likely bringing it down until your scene starts looking like you would expect.  if you lose your contrast or have too much contrast play around with the gamma also until you get the desired effect.    You might have to go back and forth adjusting gamma and mult several times until you have the general lighting effect you want.

Now leave the settings as is and click the "collect meshes" button again.  Click go again and just let the radiocity process continue until you have the effects you want.  The longer you let it run, the better the effect. This is the reason I told you to not add a max iterations.

When you are satisfied with the results, and ready to use the new settings permanently, then click "Replace Meshes"

One the screen your objects may get a checkerboard or corrupted look to them. Don't worry, this is only because you have these new meshes doubled up with your old ones.  Get your old meshes out of the way.  You will find that the box, the light and the terrain are now all one mesh.  Just delete the light and the box faces so you have only your original mesh. 

Getting it to work in Crystal Space:

You will find that your new mesh has a newly created material generated by the radiosity system. It also will have vertex colors which were not there before.  The vertex colors are primarily what was changed to give the photon mapping effect.

We now want to create a UV map (if you are unfamiliar with UV mapping read up on it because I am not going into detail about it here)

After creating a UV map, add a single spotlight as a global light source and tweak it until you have the results you want. You want the spotlight to shine from roughly the same direction that the radiocity emitter was coming from.    (BTW feel free to scale your terrain back up to full size) Once you have the spot lighting positioned as desired, go to the render buttons and bake to a full render.  Again, if you don't know about render baking, then read the tutorials you can find on the web. Everything I learned about blender I got from tutorials or playing around with it. You can too.

When you do a full render bake, essentially all of the spot light effects and the vertex lighting  produced by the photon mapping will be baked onto a texture image. 

Now, save the baked texture to your hard disk.  Delete any materials assigned to your terrain and add a fresh default material.  Go to the texture buttons and load your image you just baked off of your drive.  Go to the material buttons under Map Input.  Click on the UV button. This should make your texture fit the way it was mapped when you unwrapped.

Feel free to add other textures at this point, such as specular maps, alpha, normal maps or whatever.  Once you are done, export to crystalspace.
You might want to adjust the ambient value some but my screenshot was done without any crystalspace lights at all.  You can add further static lights and or dynamic lights to the scene and you should get a satisfying effect.

This technique can be used on indoor scenes with windows, using a light which is outside the window to cast really nice looking shadows and add realistic gradations to the walls.

Feel free to make suggestions for improvements or email me with any mistakes I made in the tutorial.

3  Crystal Space Development / Game Content Creation / Re: Questions on Models w/ Bones on: September 03, 2008, 02:26:17 am
So would it be recommended to just use frame-based animations instead of animating real-time with bones? I figure it will be easier (for the developers, me included), but would it allow for quality as good as skeletal animation?

Thanks again, I really appreciate it!

I have been using genmesh with armatures beautifully, exported directly from blender.  I have many very complex animations and complex character models.   I highly recommend it.  If you have an issue feel free to swing it by me.  I would use genmesh with armatures unless you just have some deformations which you cant get rid of.  In that case you can use vertex animations.   I do not like the xml based vertex animation importer due to the speed so I modified blender2crystal to generate raw c code instead.  I prefer to add my vertex animations to a code library rather than import them.  I am also working on my own config file format/code which will allow me to import only the vertexes I want to modify instead of keying the entire mesh. This allows me to use armatures for general animation and shapes for details like facial expressions and gestures without the overhead of complete mesh copies.

I can share the code but its just a simple hack for my current development environment and I have not cleaned it up or made it production quality yet.  It requires tweaking with each export since I wrote it in a hurry.

If you use armatures with lots of blender constraints and you have issues, just bake the animation and export the baked version.  My game im working on is designed to give a wide range of poses centered around roleplayers. If it works as planned then users will be able to design their own custom poses and animations without coding or requiring a 3d modeling program.

Here is a character I developed for the RP game I am making.  Yes that is a lightsaber on her belt Smiley
4  Crystal Space Development / Game Content Creation / Re: genMesh animation tutorial on: September 03, 2008, 02:18:31 am
Also another note.  I noticed some people complaining about their meshes not working in viewmesh.  I could be wrong but I was under the assumption that viewmesh was mainly for cal3d animations and it might not support the current armature genmesh impelementations. 

This information could be wrong but that was what I concluded when I looked into the code a while back. 
5  Crystal Space Development / Game Content Creation / Re: genMesh animation tutorial on: September 03, 2008, 02:05:59 am
Hello. This is my first post but I have been playing with crystal space and blender for a while now.  I normally try to figure stuff out myself so the solutions I offer may not be the "best" way. 

I have noticed allot of people having issues with genmesh and getting blender armature animations to work.  I had some of the same issues at first and it works beautifully for me now just exporting using the default settings and no changes except one minor tweak.

What I noticed was that when I generated my world folder, either only one animation would play or it would not play at all.  I was debugging and trying to find out what was going on.  What I found is that all of the animations you list will be exported fine in the armature file.  However, they do not seem to be attached to the meshfactory file.  I believe this is either the result of a bug in the version of blender2crystal, or it is an non-intuitive user interface issue.

If you just want to export genmesh armature animtations you can export them directly.  Just select the bone object and be sure you list all of the actions you want to be exported.  Unfortunately only the first action will be linked to the meshfactory.  To solve this what I did was I opened the meshfactory file and you will see something like this:

  <run script="walk"/>

It exported the "walk" action fine but the other actions are not listed.  If you try to use the skeleton api to access the other actions then you will get a null object for them and the program will crash.

to resolve this issue (not sure if this is the best way, but it is a quick fix)

add you other actions to the meshfactory file like this

  <run script="walk"/>
  <run script="anotheraction1"/>
  <run script="anotheraction2"/>
  <run script="anotheretc"/>

by linking these actions in the meshfactory file they will now be accessible programatically through the skeleton interface functions.

Here is some sample code which loads two animations programattically and changes what animation is playing:

use this at your own risk Smiley

        csRef<iMeshWrapper> lara=Engine->FindMeshObject("larabod"); // create a meshwrapper for the mesh named "larabod"

        //query for the generalmeshstate interface required in order to get the skeleton object
   csRef<iGeneralMeshState> genmesh_state (scfQueryInterface<iGeneralMeshState> (lara->GetMeshObject()));

        //create an animcontrol object also necessary for working with iSkeleton
   csRef<iGenMeshSkeletonControlState> animcontrol ( scfQueryInterface<iGenMeshSkeletonControlState> (       genmesh_state->GetAnimationControl ()));

        //create the actual skeleton object
   iSkeleton* skeleton = animcontrol->GetSkeleton ();
        // stop any animtations currently playing

        //get a pointer to the walk animation
   csRef<iSkeletonAnimation> walkanim=skeleton->FindAnimation("walk");
   walkanim->SetLoop(true);  //optional depending on if you want it to loop


        rinse and repeat. Take a look at the iSkeleton, and iSkeletonAnimation api list for more control. Essentially you should have complete control of your skeleton and animations without using cal3d. I have been impressed with the results. The playback is identical to what I expected.

Feel free to correct anything that should be optimized in my post as I am still learning crystal space myself.

Also feel free to email me if you have a specific problem. I will reply even if it is to tell you that I do not know or don't have time to deal with it.

Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.218 seconds with 17 queries.