Help wth 2 lights. [SOLVED]

Evak

02-10-2007 00:55:21

I gave one of my shaders to our coder and asked for a simple way to add an extra light that even I as a non coder can follow and use to test other shaders.

What I got back was a material file with 2 passes add blended with a seperate light in each.

material 1UV
{
technique
{
pass
{
ambient 0.7 0.7 0.7 1
diffuse 0.7 0.7 0.7 1
specular 0.9 0.9 0.9 1 20

vertex_program_ref NormalMap+Shiny_vs
{
param_named_auto camPosObj camera_position_object_space
param_named_auto lightPosObj light_position_object_space 0
param_named_auto wvp worldviewproj_matrix
}

fragment_program_ref NormalMap+Shiny_ps
{
param_named ShineValue float 0.25
param_named_auto lightColor light_diffuse_colour 0
}

texture_unit
{
texture_alias Map #4
texture texture_sand.bmp
}

texture_unit
{
texture_alias Map #5
texture N_cobblestones_ati.dds
}
}
pass
{
ambient 0.7 0.7 0.7 1
diffuse 0.7 0.7 0.7 1
specular 0.9 0.9 0.9 1 20
scene_blend add

vertex_program_ref NormalMap+Shiny_vs
{
param_named_auto camPosObj camera_position_object_space
param_named_auto lightPosObj light_position_object_space 1
param_named_auto wvp worldviewproj_matrix
}

fragment_program_ref NormalMap+Shiny_ps
{
param_named ShineValue float 0.25
param_named_auto lightColor light_diffuse_colour 1
}

texture_unit
{
texture_alias Map #4
texture texture_sand.bmp
}

texture_unit
{
texture_alias Map #5
texture N_cobblestones_ati.dds
}
}
}

}


This does seem to work, only problem is its coded, and I'm wondering how I can duplicate this without a .material file and using a .program file and ofusion shader parameter editor, letting ofusion create the material for me.

The .program file looks like this:


vertex_program NormalMap+Shiny_vs hlsl
{
source NormalMap+Shiny.hlsl
entry_point v
target vs_2_0

default_params
{

param_named_auto wvp WORLDVIEWPROJ_MATRIX
param_named_auto camPosObj CAMERA_POSITION_OBJECT_SPACE
param_named_auto lightPosObj LIGHT_POSITION_OBJECT_SPACE 0
}
}

fragment_program NormalMap+Shiny_ps hlsl
{
source NormalMap+Shiny.hlsl
entry_point f
target ps_2_0


default_params
{
param_named_auto lightColor LIGHT_DIFFUSE_COLOUR 0
param_named ShineValue float 0.25
}
}


Do I have to make 2 seperate .program files one for each shader pass with different light numbers?

param_named_auto lightPosObj light_position_object_space 1
param_named_auto lightColor light_diffuse_colour 1


Is it possible to get these parameters to share a single program file. And not have to change the original shader source code?

Not really sure how to proceed. Naturaly this is not the most efficient way, but using 2 passes seems like it will be the easiest way for a non programmer to test converted shaders.

Murcho

02-10-2007 03:21:50

I'm pretty sure the best way will be to modify the shader to take two lights as input and send the light data through in one pass. I know it won't be the easiest for a non coder but I'm fairly certain it will be the best option in the long run.

If the shader is setup to take both lights as parameters then they will both come up int the oFusion shader parameter editor.

Sorry but I don't think shaders were meant to be easy for non coders (I'm just starting out with them myself and there is just so much to learn!).

Evak

02-10-2007 03:30:26

yeah, I can get one of our coders to add lights in the pass. But since I'm using shaderFX which is an artist tool, and can't actually code them myself. Been trying to find a methodical approach for testing purposes.

Naturaly once we had established that one of my shaderFX shaders was for keeps I'd have one of them optimize it for me and put it in one pass where possible.

Evak

02-10-2007 05:35:06

BTW I figured it out, didn't have to change the .program file or shader source to get the two passes to behave. Just the blend modes between the two passes and the parameter editor values for position and color so it would read the color and position from the max lights :).

Murcho

02-10-2007 09:08:15

Looks sweet mate.

I'm doing the shaders for our current project and have been doing them in RM and then writing all my own material and program files (sigh, working without the internet in class makes it slow).

I hadn't seen shaderFX before this post, so can I ask is it a good tool to use with oFusion? May make things a little more streamlined than the current pipeline for shaders.

Evak

02-10-2007 09:31:48

direct support for shaderFX is planned for the next major release of Ofusion. I posted a video I was given of an early version of it running with ofusion in another thread.

ShaderFX is really easy for artists to create a variety of shaders, still needs some hand tweaking to get optimal results but its a great node based realtime WYSIWYG shader creation tool.

Costs $250 though, and untill the ofusion support comes out, you have to translate the FX files yourself.

Lioric

02-10-2007 16:05:23

You dont need to add passes for each light you want to be added to the material

That is what the "Once Per Light" parameter and its options are for, when enabled, the pass will be iterated n times, once per each light, where n is the number of lights you define in for the pass (and you can define the type of light that will affect this pass)

Depending on your shader, probably you might need to first set an ambient pass, and then the lighting pass that will be iterated, this pass must be blended over the previous scene colors

For best performance, the less passes is better, if you can (and you scene can be setup) its better to have a single pass with a fixed number of lights in the shader, and you scene objects must be influenced by this number of lights all the time, similar to the Monster shader that uses a fixed number of lights (using defines this can be modified)

Evak

02-10-2007 16:34:49

hmm, I tried using the lighting settings for the passes early on with my shaderFX shader but didn't see anything happening that suggested it would work.

I'll take another look at it and see if I can find anything.

Evak

02-10-2007 17:43:35

OK got liorics suggestion working, and its very nice indeed. I am using a fixed function pass for ambient at the moment because adding the lights and blending without the ambient pass makes it looks like you have a lot of ambient light.

I had to set the depth bias to 1 in the shader pass for the fixed function ambient to work, the material also works fine with additive stencil lighting.

looks very cool and is much easier than the multipass way :)

here's a pic of 3 lights handled automaticly by ofusion, without changing my shader code or .program file at all.



I get more impressed with ofusions material setup every time I I look into it. So many choices and ways of doing things that I could never try if I was writing scripts.