B Info Other Skyboxes (see posts 14 & 15)

Users who are viewing this thread

xenoargh

Grandmaster Knight
See last post for code :smile:




Basically, we have skyboxes in skyboxes.py.

They come with very helpful categories of when they're activated:
Code:
sf_day        = 0x00000000
sf_dawn       = 0x00000001
sf_night      = 0x00000002

sf_clouds_0   = 0x00000000
sf_clouds_1   = 0x00000010
sf_clouds_2   = 0x00000020
sf_clouds_3   = 0x00000030

And maybe, but not for sure:
Code:
sf_no_shadows = 0x10000000

But there doesn't seem to be a manual way to define what skybox gets used for a scene. 

In module_scenes, sf_indoors is supposed to turn skyboxes off, but it doesn't.  Nor does it turn the sun light off, like it's supposed to.  This is causing rendering problems indoors.

I know how to functionally turn the sun light off; I just have to use a custom skybox, shut down the sun and use a really neutral ambient, voila, we're just using point lights.  But I don't want that to happen at night, outdoors, for obvious reasons.

So I'm kind of stuck atm; I want to control which skybox is being used, but I'm not sure how to go about that.  Anybody know what I can do about that? 

The only solution I've seen to this thus far is to give up sf_dawn, and force the outdoors scenes to use day skies, while reserving sf_dawn for indoors. 

That would free up a category for my non-sun skyboxes for indoors.  If anybody has better solutions, it would be appreciated.
 
(2389, hdr_skybox_index, skybox_index)

2389?

You mean the function call is there, it's just not in header_operations?  :lol:

Then what, pray tell is 2388?
 
Yes. They added it in WFaS (and its module system) and also to Warband (but not its module system) in one of the latest updates.

There is no 2388 in Warband, but amongst the hidden operations are:
Code:
set_skybox                  = 2389 #(set_skybox, <non_hdr_skybox_index>, <hdr_skybox_index>)	#forces selected skybox for a scene, use -1 to disable 
set_startup_sun_light       = 2390 #(set_startup_sun_light, <r>, <g>, <b>)	#changes the sun light color
set_startup_ambient_light   = 2391 #(set_startup_ambient_light, <r>, <g>, <b>)	#changes the ambient light color
set_startup_ground_ambient_light = 2392 #(set_startup_ground_ambient_light, <r>, <g>, <b>)	#changes the ground ambient light color
 
Got some, interesting news about this.

Seems that interior scenes are, indeed, not using a sun color.  So I'm wrong; the documentation is right, go figure. 

They are, however, getting a value from the HDR skybox.

This is most interesting; amongst other things, it may actually be possible to get realtime reflections working for ordinary stuff; that color data is clearly there. 

But it also means that I need to mess with HDR and build a suitable "skybox" for interiors that doesn't feature much if any point-source boost.
 
After some work getting skyboxes into Module System as callable objects, setting them up and generally getting them going... it really appears that set_skybox to a skybox that doesn't use the sf_day/night/etc. tags does not actually work. 

It's referring to the right number, I'm not getting script errors... but nothing happens, the skybox stays at whatever Warband feels like.  My guess?  It's not "day" when I'm visiting the Tavern where I did some tests, and not populating that value leaves at zero, which is day's value.  Set_skybox, -1,-1 doesn't work as advertised, either, it gives a script error.  I'll try zeroes, see if that works.

So, dawn / sunset gets the axe, I'm guessing, and I'll have to regulate time in scenes manually; I hate to have to do it like that but whatever.
 
I'm unsure if you know this or not, but (scene_set_day_time, 23) from a ti_before_mission_start mission template trigger would set the skybox to the night version, about 7 for dawn/dusk, and 12 for day; you can also use set_global_cloud_amount at the same time to select different sf_clouds_ versions, but I don't know if that would mess with the world map weather in single player mods, as I've only ever used it in multi.

I haven't been able to change the skybox with the undocumented WFaS set_skybox operation either, so I suspect it doesn't work for warband - it is used in the WFaS module system, so presumably it works there.
 
scene_set_day_time is familiar to me from my scene editor thingie and I know it works just fine.  So it's pretty much down to implementation details and living without dawn / dusk if needbe. 

I doubt players will get too chuffed, especially if I throw in some new skies, now that I've been through the HDR wringer (it's not terribly hard to build the L16 data).
 
OK, more news.  It does actually work, I think.  I think I wasn't testing it right, is all  :lol:

I'm still tuning down the tonemapping and stuff; looks like I'm never going to get totally perfect interior lighting results but I can live with that.

Now... can it be masked, so that it never shows up at any time of the day...
 
Confirmed; it works, and you can mask it so that it's never picked at random.  Getting it all set up... not so fun.

Now I "just" need to figure out the how and why of getting the tones down a lot, but that should, in theory, just be a minor problem of tuning the RGB way down, as the exponent value is almost zero now anyhow.  It won't cure the problems totally, since some of it's shader stuff that works fine outdoors but is a little over-bright indoors and I don't think I can fix that without re-writing the lighting equations again... but it should help.
 
Finally  :roll:

Near point light:
interior_lighting01.jpg

Away from point lights:
interior_lighting02.jpg


I haven't tested enough to 100% say that it won't load this at random, but I don't think so; it's using a mask value, which doesn't appear to cause any issues.  At worst I go back to plan b, use time events and give up dawn / dusk.

Do note that you cannot get the same behavior out of Native, at least not without major adjustment; the original lighting system doesn't work the same way.
 
OK, I've tested it enough to be pretty sure about my results.

You can set_skybox as advertised, as in this example, where I'm setting up the interior lighting generically for interior scenes:

Code:
      (ti_before_mission_start, 0, 0, [], 
      [
		(try_begin),
			(this_or_next|eq, "$talk_context", tc_tavern_talk),
			(this_or_next|eq, "$talk_context", tc_merchants_house),
			(eq, "$talk_context", tc_court_talk),
			(set_skybox, sky_xenoargh_skybox_interior, sky_xenoargh_skybox_interior),
		(try_end),
	  ]),

You can use a mask value that prevents the engine from ever choosing the skybox:

Code:
sf_mask      = 0x00000003


You can call skyboxes in module_mission_templates, but it's non-trivial to set up and requires some Python hacking if you want to be able to freely edit them during a session.  I've fixed all that in my source, so here is the stock code with the appropriate modifications. 

*********************************************************************************

Here are instructions:

1.  Copy-pasta this code into your skyboxes.py file, putting it into the same place as the rest of your Module System files.  Do not keep any of the old code, you won't need it.

Code:
import string

from module_info import *

from process_common import *
#from process_operations import *

sf_day        = 0x00000000
sf_dawn       = 0x00000001
sf_night      = 0x00000002
sf_mask      = 0x00000003

sf_clouds_0   = 0x00000000
sf_clouds_1   = 0x00000010
sf_clouds_2   = 0x00000020
sf_clouds_3   = 0x00000030

sf_no_shadows = 0x10000000
sf_HDR        = 0x20000000  # this will generate HDR-shaded skyboxes, you should make a LDR version of your skybox for compatibility

# mesh_name, flags, sun_heading, sun_altitude, flare_strength, postfx, sun_color, hemi_color, ambient_color, (fog_start, fog_color),

# to generate new skybox textures with hdr option:
# hdr images are required to generate our RGBE coded skybox images


# To add a skybox, you should first edit this file and put new skyboxes.txt file into the "Data/" folder of your module. 
# The first "mesh_name" parameter is the name of the skybox mesh to be used for that entry. 
# You can check our meshes from the "skyboxes.brf" file with OpenBRF and copy them, 
# just replace the material's textures with yours. And you will also have to change the 
# specular color parameters for correct hdr rendering. of course specular color does not 
# corresponds to specular lighting, those parameters are used as compression values 
# for RGBE decoding and should be generated while you generate RGBE textures. 
# (specular.red = Scale component, specular.green = Bias component) 
# You can check our materials for the instances of this usage. 
#
# For skybox textures, we are using uncompressed *.hdr files to generate *_rgb.dds and *_exp.dds files. 
# its just a RGBE encoding of the skybox for hdr lighting. here is an example: 
# "skybox.dds" -> simple non-hdr (LDR) image, used when you dont use hdr (DXT1 format is good)
# "skybox_rgb.dds" -> RGB components of the HDR image (DXT1 format is preffered)
# "skybox_exp.dds" -> E (exponent) component of the HDR image (L16 format is good, you can use half resolution for this texture)
# We are using our own command line tool to generete those files from "skybox.hdr" image. 
# But you can generate them with some of the hdr-image editors too. The images should be gamma corrected and should not have mipmaps. 
# You can use Photoshop with DDS plug-ins or DirectX Texture Viewer to see the contents of our dds images. 
# 
# ..visit Taleworlds Forums for more information..

skyboxes = [

  ("skybox_cloud_1", sf_day|sf_clouds_1, 179.0, 52.0, 0.85, "pfx_sunny", (1.39*1.32,1.39*1.21,1.39*1.08), (0.0, 0.0, 0.0), (0.96*16.0/255,0.96*23.5/255,0.96*44.5/255), (300, 0xFF8CA2AD)),
  ("skybox_cloud_1", sf_day|sf_clouds_1|sf_HDR, 179.0, 52.0, 0.85, "pfx_sunny", (1.39*1.32,1.39*1.21,1.39*1.08), (0.0, 0.0, 0.0), (0.86*16.0/255,0.86*23.5/255,0.86*44.5/255), (300, 0xFF8CA2AD)),

  ("skybox_night_1", sf_night|sf_clouds_1, 152.0, 38.0, 0.0, "pfx_night", (1.0*17.0/255,1.0*21.0/255,1.0*27.0/255),(0.0,0.0,0.0), (0.9*5.0/255,0.9*5.0/255,0.9*15.0/255), (500, 0xFF152035)),
  ("skybox_night_1", sf_night|sf_clouds_1|sf_HDR, 152.0, 38.0, 0.0, "pfx_night", (1.0*17.0/255,1.0*21.0/255,1.0*27.0/255),(0.0,0.0,0.0), (0.45*5.0/255,0.45*5.0/255,0.45*15.0/255), (500, 0xFF152035)),
  ("skybox_night_2", sf_night|sf_clouds_3, 152.0, 38.0, 0.0, "pfx_night", (1.0*17.0/255,1.0*21.0/255,1.0*27.0/255),(0.0,0.0,0.0), (0.9*5.0/255,0.9*5.0/255,0.9*15.0/255), (500, 0xFF152035)),
  ("skybox_night_2", sf_night|sf_clouds_3|sf_HDR, 152.0, 38.0, 0.0, "pfx_night", (1.0*17.0/255,1.0*21.0/255,1.0*27.0/255),(0.0,0.0,0.0), (0.45*5.0/255,0.45*5.0/255,0.45*15.0/255), (500, 0xFF152035)),
  
  ("skybox_sunset_1", sf_dawn|sf_clouds_1, 180.0, 9.146, 0.7, "pfx_sunset", (230.0/220,120.0/220,37.0/220),(0.0,0.0,0.0), (14.5/210,21.0/210,40.0/210), (150, 0xFF897262)),
  ("skybox_sunset_1", sf_dawn|sf_clouds_1|sf_HDR, 180.0, 9.146, 0.7, "pfx_sunset", (230.0/220,120.0/220,37.0/220),(0.0,0.0,0.0), (14.5/210,21.0/210,40.0/210), (150, 0xFF897262)),
  
  ("skybox_cloud_2", sf_day|sf_clouds_2, 180.0, 19.17, 0.4, "pfx_cloudy", (0.8*0.9,0.8*0.85,0.8*0.75),(0.0,0.0,0.0), (0.8*40.0/255,0.8*46.5/255,0.8*77.0/255), (120, 0xFF607090)),
  ("skybox_cloud_2", sf_day|sf_clouds_2|sf_HDR, 180.0, 19.17, 0.4, "pfx_cloudy", (0.8*0.9,0.85*0.8,0.8*0.75),(0.0,0.0,0.0), (0.8*40.0/255,0.8*46.5/255,0.8*77.0/255), (120, 0xFF607090)),
  
  ("skybox_cloud_2", sf_day|sf_clouds_3|sf_no_shadows, 180.0, 19.17, 0.4, "pfx_overcast", (0.4,0.35,0.31),(0.0,0.0,0.0), (50.0/255,60.0/255,103.0/255), (120, 0xFF607090)),
  ("skybox_cloud_2", sf_day|sf_clouds_3|sf_no_shadows|sf_HDR, 180.0, 19.17, 0.4, "pfx_overcast", (0.4,0.35,0.31),(0.0,0.0,0.0), (50.0/255,60.0/255,103.0/255), (120, 0xFF607090)),
  
  ("skybox_clearday", sf_day|sf_clouds_0, 179.0, 80.0, 0.95, "pfx_sunny", (0.99*1.32,0.99*1.21,0.99*1.08), (0.0, 0.0, 0.0), (0.96*16.0/255,0.96*23.5/255,0.96*44.5/255), (300, 0xFF8CA2AD)),
  ("skybox_clearday", sf_day|sf_clouds_0|sf_HDR, 179.0, 80.0, 0.95, "pfx_sunny", (0.99*1.32,0.99*1.21,0.99*1.08), (0.0, 0.0, 0.0), (0.86*16.0/255,0.86*23.5/255,0.86*44.5/255), (300, 0xFF8CA2AD)),
#END OF SKYBOXES  
]



def save_python_header():
  file = open("./ID_skyboxes.py","w")
  for i_item in xrange(len(skyboxes)):
    file.write("sky_%s = %d\n"%(convert_to_identifier(skyboxes[i_item][0]),i_item))
  file.close()

def save_skyboxes():
  file = open(export_dir + "/data/skyboxes.txt","w")
  file.write("%d\n"%len(skyboxes))
  for skybox in  skyboxes:
    file.write("%s %d %f %f %f %s\n"%(skybox[0],skybox[1],skybox[2],skybox[3],skybox[4],skybox[5]))
    file.write(" %f %f %f "%skybox[6])
    file.write(" %f %f %f "%skybox[7])
    file.write(" %f %f %f "%skybox[8])
    file.write(" %f %d\n"%skybox[9])
  file.close()

print "Exporting skyboxes..."
save_python_header()
save_skyboxes()

2.  To make use of the above properly, you need some integer IDs for your other code to refer to.  So you need to create a blank text file called ID_skyboxes.py, to store the IDs.

3.  Next, you need to make some skybox art.  I'm not going to cover HDR image concepts in depth here, nor am I going to answer questions about that; if you want to use HDR images with all the bells and whistles, use the DirectX Texture tool to examine the Native images and do some homework on this subject.  Here are the basics, though:

A.  Make a copy of an existing sky sphere and material, and put them in a new BRF.

B. Make your diffuse image; this is a diffuse sky image, preferably distorted slightly to be correct after being applied to the sky sphere.  It and the other images must be seamless along the sides.

C.  Make your color shift image, or just use the diffuse twice and save memory; it can do some cool stuff to the colors but usually it's lost in the bloom, tbh.  Read up on HDR images to know how that works, but basically it's a super-saturated version of the diffuse source or a diffuse source that's been color-shifted.

D.  Make your exponent image, which is a 16-bit grayscale image used to make parts of the diffuse bloom more or less depending on the POV.

Technically this is optional, as you can use the Material used for night skies.  Technically, it doesn't need to be 16-bit.  But it looks smoother if it is.

Again, like the color shift image, this is something that can add a last bit of subtle reality but it's not vital.  Should be in the L16 format, because this is a 16-bit, floating-point texture; if you're going to try and make these, do some homework first but it's really not too hard.

E.  Save your new BRF, make some new code for your skybox in skyboxes.py.  Bear in mind that the settings there are non-trivial and require some experimentation to get right.

F.  Include your new BRF in your project as normal.

The engine doesn't appear to care about naming conventions for these textures, etc.

4.  Put the following into header_mission_templates.py:

Code:
from ID_skyboxes import *

5.  Go into your build batch file (unless you've renamed it, it's build_module.bat), and up at the top, put in the process line you need after the initial required items have been processed, like this:

Code:
@echo off
python process_init.py
python process_global_variables.py
python process_strings.py
python skyboxes.py

6. Lastly, in header_operations.py:

Code:
set_skybox					= 2389 #(set_skybox, <non_hdr_skybox_index>, <hdr_skybox_index>)	#forces selected skybox for a scene
#Must be run in ti_before_mission_start
set_startup_sun_light       = 2390 #(set_startup_sun_light, <r>, <g>, <b>)	
#changes the sun light color
#Must be run in ti_before_mission_start
set_startup_ambient_light   = 2391 #(set_startup_ambient_light, <r>, <g>, <b>)	
#changes the ambient light color
#Must be run in ti_before_mission_start
set_startup_ground_ambient_light = 2392 #(set_startup_ground_ambient_light, <r>, <g>, <b>)	#changes the ground ambient light color
#Must be run in ti_before_mission_start

Voila... now you can use set_skybox in module_mission_templates, put custom skyboxes into the game and keep the engine from randomly choosing them by using sf_mask instead of, for example, sf_day|sf_clouds_0.

 
I'm just glad I finally cracked skyboxes, the lack of variety has always bugged me and it's relatively easy to fix.  Now if I just had time to whip out a bunch of images  :lol:
 
Barabas said:
Don't you need to add this to header_operations.py?
Code:
lhs_operations += [
set_skybox
set_startup_sun_light
set_startup_ambient_light
set_startup_ground_ambient_light
]

Haven't actually tried myself yet, but it would seem logical.
I don't think so. Aren't LHS operations all "get" or "store" operations, storing a value to the 'left-hand-side'? These, as "set" operations don't store values.
 
Back
Top Bottom