MGE Lighting

Post » Fri Aug 13, 2010 9:56 pm

In my researches I come to conclusion that with z-buffer and using existing hardware features, you can have shadows too. And there are plenty of shadowing methods to pick, from soft to hard.

"Depth buffer based custom shadow mapping..." :evil:

http://developer.download.nvidia.com/GPU_Programming_Guide/GPU_Programming_Guide_G80.pdf
There is information about z-buffer access, INTZ and RAWZ usage at page 58.



oooh, nice! this is what I was asking earlier in this 3d!
but aren't there some problems with the z-buffer in morrowind?
User avatar
Minako
 
Posts: 3379
Joined: Sun Mar 18, 2007 9:50 pm

Post » Fri Aug 13, 2010 7:29 pm

Current progress:
- Light position and range data supplied to hooked shaders in vector array pk_light_pos (range is in the w component, multiplied by GetEnabled to guarantee 0 if off)
- Light color is supplied to hooked shaders in vector array pk_light_col (rgba are components, floats)
- Data is only supplied to hooked texture shaders

I'm working on calculating the positions from current pixel to lights for intensity data.
However, I need to do more research. My current way requires over 100 instructions, meaning ps3.0.


I have some experiance hooking textures. Things I've concluded:

*Seems sky doesn't want to be hooked properly, tested once, not 100% certain about the fact.
*Does not work with Landscape textures applied to MW landscape 100% certain
*AVI works quite fine, so does some other formats
*Works fine with models. Models can even contain their transparency!
*ENB will crash any texture hook :/ not 100% certain of this either

Great work Peachykeen!



Got the hooks working. That isn't good though, means fixing land blending is harder and working the ground by shaders may not work.


A bit don't understand, peachykeen, sorry, u want to make bump mapping and normal mapping in Morrowind like in Oblivion O_O?
If yes - u will be my god, i give my word :) .
Waiting foryour answer!


Not like in Oblivion.
Like in STALKER:
http://image.com.com/gamespot/images/2007/192/942067_20070711_screen001.jpg
That tile wall is perfectly flat. The shader gives it depth. That's my goal (we'll see if it happens :) ).


In my researches I come to conclusion that with z-buffer and using existing hardware features, you can have shadows too. And there are plenty of shadowing methods to pick, from soft to hard.

"Depth buffer based custom shadow mapping..." :evil:

http://developer.download.nvidia.com/GPU_Programming_Guide/GPU_Programming_Guide_G80.pdf
There is information about z-buffer access, INTZ and RAWZ usage at page 58.


I'll check that out. I've been looking for the shadows (stencil buffer) so I can run a quick blur shader over it. Soft shadows with little FPS loss.
Finding it is a pain, however. My Radeon 9600 doesn't like either of those FourCCs, for example.

oooh, nice! this is what I was asking earlier in this 3d!
but aren't there some problems with the z-buffer in morrowind?


Not problems, not more than just how they're usually handled. Getting access to the video memory requires some tricky DirectX stuff.
User avatar
James Potter
 
Posts: 3418
Joined: Sat Jul 07, 2007 11:40 am

Post » Fri Aug 13, 2010 7:04 pm

you sure are fast, you're progress in this is just amazing.

- Data is only supplied to hooked texture shaders

I don't understand if this is a problem or not.
User avatar
Natasha Biss
 
Posts: 3491
Joined: Mon Jul 10, 2006 8:47 am

Post » Fri Aug 13, 2010 11:52 am

My progress, up to this point, has been fast because it's been simple work. If things start to get messy, it may slow down. I can't make any guarantees about anything, but I will do what I can.

As for being an issue, not really. It's only a choice, and there's no real point in supplying last (other than the sun) to fullscreen shaders. It won't do anyone too much good.
User avatar
Misty lt
 
Posts: 3400
Joined: Mon Dec 25, 2006 10:06 am

Post » Fri Aug 13, 2010 2:02 pm

Wow it really is true, the modding community is the life and soul of a games longevity!
User avatar
JR Cash
 
Posts: 3441
Joined: Tue Oct 02, 2007 12:59 pm

Post » Fri Aug 13, 2010 4:40 pm

Wow, like in Stalker, man u are my god! Make it, please, make it!
User avatar
Alexandra Ryan
 
Posts: 3438
Joined: Mon Jul 31, 2006 9:01 am

Post » Fri Aug 13, 2010 7:15 pm

I will double test and confirm my suspicions about hooking terrain textures and sky tonight.
Will get back here with info.
User avatar
Courtney Foren
 
Posts: 3418
Joined: Sun Mar 11, 2007 6:49 am

Post » Fri Aug 13, 2010 12:57 pm

MGE has already done so much to improve visuals in Morrowind... if you are able to figure out how to give it control of lighting/shadows, it'd be as huge a step as adding distant statics was!
User avatar
Chris Duncan
 
Posts: 3471
Joined: Sun Jun 24, 2007 2:31 am

Post » Fri Aug 13, 2010 1:55 pm

Current progress:
- Light position and range data supplied to hooked shaders in vector array pk_light_pos (range is in the w component, multiplied by GetEnabled to guarantee 0 if off)
- Light color is supplied to hooked shaders in vector array pk_light_col (rgba are components, floats)
- Data is only supplied to hooked texture shaders

I'm working on calculating the positions from current pixel to lights for intensity data.
However, I need to do more research. My current way requires over 100 instructions, meaning ps3.0.
-clip-

@peachykeen
Found http://www.gamesas.com/bgsforums/index.php?showtopic=925546&st=106# by Timeslip regarding why MGE doesn't currently provide lighting info to shaders.

Apparently an sm3.0 card will likely be needed in order to implement this.
User avatar
Alexis Acevedo
 
Posts: 3330
Joined: Sat Oct 27, 2007 8:58 pm

Post » Fri Aug 13, 2010 1:17 pm

Peachykeen, one question:
Do u planned to make shadow's from static object's?
User avatar
luis dejesus
 
Posts: 3451
Joined: Sun Aug 19, 2007 7:40 am

Post » Sat Aug 14, 2010 3:13 am

Edit: Progress:
- View and projection matrices now supplied to hooked scripts
- Working on a vertex shader that replaces the fixed function pipeline, but can't get it to work (with a vertex shader applied, which is required to get position, the entire poly disappears).
- Smooth (simple) lighting, for 8 lights, is possible in shader model 2.0
- Any advanced techniques, will require sm 3.0 (a reasonably new video card).


I've never played with vertex shaders before, so if anyone knows what they're doing... I'm checking to make sure the right matrices are being supplied and calculated.
If MGE isn't getting the right view and projection matrices (if they're for distant land only) then I'm going to have to add a hook for the D3DXGetPerspectiveMatrixLH or the function Morrowind uses. Or possibly hook the entire D3DX DLL. Which will take some time, if it's necessary. I know MGE has the matrices, but I don't know if they're right.

Edit2: Also, the technique is position-based lighting, diffuse on texture, with linear falloff by range. Disabled lights are not applied.

I will double test and confirm my suspicions about hooking terrain textures and sky tonight.
Will get back here with info.


Thanks.
I'd really like to be able to map the landscape. Blending maybe could be improved, possibly smooth lights between cells, detail and gloss (or even displacement) on the ground... Random/procedural decals... It'd be epic.


MGE has already done so much to improve visuals in Morrowind... if you are able to figure out how to give it control of lighting/shadows, it'd be as huge a step as adding distant statics was!


This will give it control of lighting, not shadows.



@peachykeen
Found http://www.gamesas.com/bgsforums/index.php?showtopic=925546&st=106# by Timeslip regarding why MGE doesn't currently provide lighting info to shaders.

Apparently an sm3.0 card will likely be needed in order to implement this.


I haven't gotten the pixel shader down, but I have crushed basic linear lighting (just barely) in ps2.0. My original solution used just over 100 instruction, but I got it under 64 with some tweaking (I think it's 61 for all 8 lights, lol).
Normal, bump, etc will certainly take ps 3.0. But I don't doubt it'll still be possible. From the beginning I expected this to take decent systems.


Peachykeen, one question:
Do u planned to make shadow's from static object's?


Making shadows takes more than hooking textures. I would have to find the shadow buffer. That's another quest entirely.
User avatar
Nims
 
Posts: 3352
Joined: Thu Jun 07, 2007 3:29 pm

Post » Fri Aug 13, 2010 1:32 pm

If you're pulling the view matrix from the global variables, again, it doesn't work like that. Each model is rendered with a different modelview transform, and you only need to call GetTransform to fetch it. Morrowind doesn't even use D3DX, I'm not sure where you got that idea from.

When it comes to lighting, are you handling directional lights properly as well as point lights? How about ambient, fogging, emissive materials, glow maps etc.? There's quite a bit to consider when you replace the fixed function pipe.
User avatar
Nikki Morse
 
Posts: 3494
Joined: Fri Aug 25, 2006 12:08 pm

Post » Fri Aug 13, 2010 9:41 pm

Making shadows takes more than hooking textures. I would have to find the shadow buffer. That's another quest entirely.

How-to-how, but u make great work! Good job with it! I'll be waiting for this every day!
User avatar
Blackdrak
 
Posts: 3451
Joined: Thu May 17, 2007 11:40 pm

Post » Sat Aug 14, 2010 2:11 am

Progress:
Light colors appear to be sent to model properly.

Screens and pixel shader sample:

Without any lights:
http://s4.photobucket.com/albums/y145/peachykeen000/lights/?action=view¤t=MGEScreenshot8.png
	float4 color = tex2D(s1, Tex);	return color;


With some:
http://i4.photobucket.com/albums/y145/peachykeen000/lights/MGEScreenshot7.png
	float4 color = tex2D(s1, Tex);	color.rgb *= pk_light_color[0];	color.rgb *= pk_light_color[1];		.....	color.rgb *= pk_light_color[7];	return color;


That code change was the only difference between the two screenshots. So obviously something is doing something. I just have to make sure it's the right things doing what I want.


If you're pulling the view matrix from the global variables, again, it doesn't work like that. Each model is rendered with a different modelview transform, and you only need to call GetTransform to fetch it. Morrowind doesn't even use D3DX, I'm not sure where you got that idea from.


Heh, thanks for that. If I may, any issues I have in the future, I'll send them your way. I don't know much at all as far as the internal workings of engines go. That's not my strong point. I will do some further research into that, though.
From what I heard before, to transform a model from world space to view space, though, you needed the view matrix. I've seen that done in a vertex shader, so what's different here, especially on Morrowind's end?

As for D3DX, I got that idea when I ran Morrowind (using MGE) through a couple debuggers (PE Explorer and CFF Explorer, I think it was). Both indicated that the MGE dll was loading D3DX_41, and (since most of Morrowind's d3d functions don't use imports that I can see) I wasn't sure if Morrowind was using it or just MGE. If you know that Morrowind doesn't use it, that'll help.

When it comes to lighting, are you handling directional lights properly as well as point lights? How about ambient, fogging, emissive materials, glow maps etc.? There's quite a bit to consider when you replace the fixed function pipe.


I'm not handling much of anything properly yet, but I'm still working on it. This is only a few days old, and I expect many many errors and issues before anything worthwhile comes out of it. Right now I'm making sure I've got the data going in, and working on replicating basic lighting. Then I'll take on mapping it and other such things.
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm

Post » Sat Aug 14, 2010 2:29 am

Cool work man!

Maybe it can be of help that the sun/sky can be turned off in exteriors? Check for the command in the console.
User avatar
Emmie Cate
 
Posts: 3372
Joined: Sun Mar 11, 2007 12:01 am

Post » Fri Aug 13, 2010 1:42 pm

That actually fits in well with the latest bit I found.

Apparently (unconfirmed) it's a single light DirectX 8 (hence, ps 2.0) normal shader using a standard normal map. Using the sun alone (it takes color and position), basic normal mapping may be possible of objects outside. Not complex, none of that fancyness, but I'm going to take a shot at normal mapping some of the walls as a first test of the shader and system.
User avatar
Phillip Hamilton
 
Posts: 3457
Joined: Wed Oct 10, 2007 3:07 pm

Post » Fri Aug 13, 2010 8:40 pm

Grand!

You are really diving deep into this stuff =)
User avatar
Chris Johnston
 
Posts: 3392
Joined: Fri Jul 07, 2006 12:40 pm

Post » Fri Aug 13, 2010 9:52 pm

A few more shots:
http://s4.photobucket.com/albums/y145/peachykeen000/lights/?action=view¤t=MGEScreenshot007.png

That one shows the texture (no normal map at this point) being used to change (by dot product) the normal of the texture. This is the compared to the sun vector, and (for display/testing) I turned it into a simple gray. It doesn't shift properly yet, but given how it changes when the sun moves, my vertex shader is passing the normals on properly. (btw, timescale 4000 is fun :P)

Another couple debugs:

Brightness and opacity by inverse distance:
http://i4.photobucket.com/albums/y145/peachykeen000/lights/MGEScreenshot003.png
(not how the near edge bit is darker, it wasn't set to a close curve, but did report position).
It seems, however, there may be an issue with one texture on many objects all getting the same values out of the pixel shader. I'm not sure if it's true, but does kinda make sense.

Finally:
http://i4.photobucket.com/albums/y145/peachykeen000/lights/MGEScreenshot004.png
Red and blue edited by sun.

I'm going to try to get FRAPS on that machine so I can provide video, and (when things get to an example-worthy state) I'll put up an example dll.
So far, no visible FPS hit with supplying extra data to hooked shaders. I've made a few dozen changes to the MGE dll.

In other news, finding the depth of the objects as rendering is hard. I'm working on editing the RenderIndexedPrimitive hook function to send depth to my own buffer, but Morrowind has serious artifacts, even using D32F (higher precision that default). I can get distant land depth easily, but depth of field is already implemented for that.

Finally, I'm plotting mods for a dripping blood golem type thing with hooked textures that drip blood constantly down (despite movement). That will be a long work to perfect the shader, but may be interesting. And, at Mireneye's idea, a possible wet-skin shader for when you come out of the water (more a cinematic thing that useful, but cool anyways). These are just plans, with a few formulas on paper, but that's it so far.

Things are going a bit slow, due to not having photoshop or NifSkope installed on that system. The first thing I normal map, if/when that's possible, will be the Seyda Neen house rocks (lower half). They will work well for an example.
User avatar
Michael Korkia
 
Posts: 3498
Joined: Mon Jul 23, 2007 7:58 pm

Post » Fri Aug 13, 2010 4:48 pm

can't wait to see this in action! :goodjob:

that blood golem sounds really interesting to me :)
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Fri Aug 13, 2010 1:18 pm

Good job man!
User avatar
Sun of Sammy
 
Posts: 3442
Joined: Mon Oct 22, 2007 3:38 pm

Post » Sat Aug 14, 2010 3:29 am

Lovely work, some awesome tests right there!

If you need something artistic like... Maybe that normal map.. or I could try to make animated blood/water dripping by rendering a 3ds max video you may ask for once you get there =)
User avatar
Flash
 
Posts: 3541
Joined: Fri Oct 13, 2006 3:24 pm

Post » Fri Aug 13, 2010 5:08 pm

can't wait to see this in action! :goodjob:

that blood golem sounds really interesting to me :)


I'm still working on the normal technique. It's being funny when the sun movies (brightest when the sun is pointing at it from above or below, needs to be filtered by dot product, I think), but seems to be rotating decently.

As for the golem, that will come after I get this working. It would also require hooks, but if I can get that shader working, it would be a nice effect.


Lovely work, some awesome tests right there!

If you need something artistic like... Maybe that normal map.. or I could try to make animated blood/water dripping by rendering a 3ds max video you may ask for once you get there =)


Ah, but you see, the blood/water will be procedural. That's how it will know to go down. The hooked shader will generate and drip the blood. It's possible, as seen here:
http://www.youtube.com/watch?v=z1IsxDQ5cPg

Yet another of the insane goals for MGE's hooking. Unfortunately, it will take further code changes still, taking this away from the main body of MGE. Not sure what to do there.

I may ask for help with other such things, not being too great of a general artist. We'll just have to see (I want to finish the code before I start to make mods off it).
User avatar
flora
 
Posts: 3479
Joined: Fri Jun 23, 2006 1:48 am

Post » Fri Aug 13, 2010 3:03 pm

Tantalising and intriguing stuff here, have there been any more developments in the past couple of weeks?
User avatar
evelina c
 
Posts: 3377
Joined: Tue Dec 19, 2006 4:28 pm

Post » Sat Aug 14, 2010 5:08 am

I've gotten all the light-related code in and I think a normal map shader working (affected by the sun only, but maps the surface based on the sun & normals), and I took a brief break to put more work into CnE after getting the normal mapping working.
The only problem is, while things shift a tad with the sun, I haven't figured out how to hook the normal map in yet properly, and you can't generate a normal map from a diffuse map at runtime. I'm thinking it'll involve loading that too.... Actually I think I just figured out the code for it! Something like when you load a texture, if it uses the normal map effect, load nTexturename.ext as well, and supply both. I'll test it later. If that works, then the code-side will be complete (that's the last bit to do). At that point it's a matter of cleaning it up and sending it out.
User avatar
Janeth Valenzuela Castelo
 
Posts: 3411
Joined: Wed Jun 21, 2006 3:03 am

Post » Sat Aug 14, 2010 1:27 am

I've gotten all the light-related code in and I think a normal map shader working (affected by the sun only, but maps the surface based on the sun & normals), and I took a brief break to put more work into CnE after getting the normal mapping working.
The only problem is, while things shift a tad with the sun, I haven't figured out how to hook the normal map in yet properly, and you can't generate a normal map from a diffuse map at runtime. I'm thinking it'll involve loading that too.... Actually I think I just figured out the code for it! Something like when you load a texture, if it uses the normal map effect, load nTexturename.ext as well, and supply both. I'll test it later. If that works, then the code-side will be complete (that's the last bit to do). At that point it's a matter of cleaning it up and sending it out.

Always something up your sleeve, huh =)
I want your jacket!

Good luck with the coding!
User avatar
Naazhe Perezz
 
Posts: 3393
Joined: Sat Aug 19, 2006 6:14 am

PreviousNext

Return to III - Morrowind