ZBrushCentral

Rotating Sun lights

Firstly a special thanks to David Ikeda for the insight his material baker script has given me.

I am writing a script that will allow me to rotate my tool around the y axis by a specific angle using the gyro and then have the lights rotate the same amount (simulating a rotation of camera rather than a tool rotation). This works perfectly for all lights apart from the sun light. As a work around i can Use the light placement sliders and then switch to the point light and back to the sun light. This updates the sun lights position and works fine for small angles however it reaches a maximum angle of 63.4 degrees from the centre.

(from what i can tell the direction of the sun light is that of the line drawn from the x and y placement co-ordinates on a -.5 z plane through the origin)

The light placement window however seems to be independant, extremely accurate and can position the sun light anywhere around the model. Is there any to control the light placement this way numerically via a script? or any other way to make the sun light rotate around and even behind the tool?

Thanks in advance

Attachments

max rotation.jpg

You can set the light position directly:


[VarDef,xPos,0]
[VarDef,yPos,0]

[IButton,Get,,
	[VarSet,xPos,[IGet,Light:LightPlacement]]
	[VarSet,yPos,[IGetSecondary,Light:LightPlacement]]
]

[IButton,Set,,
	[ISet,Light:LightPlacement,xPos,yPos]	
]

[IButton,BackFrontLight-Toggle,,
	[IKeyPress,1024,[IClick,Light:LightPlacement]]//simulated ALT+click
	[ISet,Light:LightPlacement,xPos,yPos]	
]

EDIT: There’s no way (that I know of) of getting whether the light is ‘front’ or ‘back’, so you would simply have to keep track of this.

Hey Marcus thanks for the help, i used that new technique on the sun lights and i managed to create a script that could rotate all the way around. This unfortunately made another problem very apparent.

When the sun is rotated, simply by changing the x postision, the y position distorts away towards the top (or bottom if positioned below the centre) I have illustrated this in the jpg attatched. The orange shows the way the light is conrolled and the blue shows the actual lighting applied.

Unfortunately this seems to be instrinsic to the way zbrush calculates the suns direction. The equation to correct this doesnt seem like an easy one either, and some angles cant even be reached when the y values get larger.

The relationship between the x position and azimuthal angle isnt quite linear either, speeding up in the centre and sides. :frowning:

A way to control the lights using spherical co-ordinates would be a godsend… maybe in the next version :wink:

Attachments

rotation problem.jpg

ecyor,

one kludged solution that occurred to me when trying something similar was to create a table of sorts that would contain values determined by eye rather than by calculation?

Sven

ecyor,

I think I’d be inclined to follow Svengali’s suggestion and create a look-up table. It seems that ZBrush adjusts the input values, so (for example) if you input 1,1 ZBrush sets .7071,.7071. As Sine/Cosine (45) that seems reasonable but input .7071,.7071 and those inputs are adjusted too. As you say, there’s no easy formula - at least my math is not up to it.

You might consider writing a script to help you create a table. Here’s the sort of thing which might help. This sends the light in circles, which I know is not what you want but it was all I had time for. The light paths are rather wobbly when you get close to a radius of 1 as my interpolation algorithm is not sufficient but perhaps it will give you some ideas.

The script saves the output to a file named “LightPos_Output.txt” to the same location as the script.

Note: It would be straightforward to adapt the script to output values assigned to list variables which you could paste into a script.

HTH,

Hey guys thanks for the advice, and thanks a lot for that script marcus it really helped me to understand the memory blocks :smiley: I modified that script to show what it was zbrush was actually doing to the co-ordinates that got typed in. The results from this are shown in the JPEG bellow. From here i think one could inverse the resulting array to make a look up table (or just figure out the formula… :idea: ) I have run out of time however so i am unfortuantely going to leave this puzzle incomplete.

Even with a table it still leaves the problem that there are angles completely unreachable by the sun lights with this current system.

From what i can see the best solution for my workflow would be to bake the lighting onto the model using davids script and doing a bunch of touch ups on the texture to try and get the desired look… or learn how to render in another app :confused:

Attachments

table of values.jpg