Notifications
Clear all

[Closed] Custom shaderball rendering

 JHN

I tinkering with some ideas to create shaderballs for a tool I’m developing. And I’m wondering if anyone has done anything like that before.
The main issue is I want to create the shaderballs in whatever scene I have open, so I have to deal with the lights and some rendersettings obviously. But it’s all hacky’ish I think.

Something like this works:


(
	with redraw off
	(
		local lightStates = for l in lights where not isKindof l targetObject collect #(l, l.on)
		for l in lights where not isKindof l targetObject do l.on = false

		local zOffset = 0
		local sph = sphere pos:[0,0,offset] segments:24 material:(standardmaterial diffuse:(random black white))
		local cam = freecamera pos:[0,offset,80] rotation:(eulerToQuat (eulerAngles -90 0 0)) 
		local lght1 = omniLight pos:[40,-40,offset+40] multiplier:1.2
		local lght2 = omniLight pos:[-80,-80,offset-80] multiplier:.5
		local bm = render camera:cam outputwidth:80 outputheight:80 quiet:true vfb:off

		display bm
		
		delete s
		delete cam
		delete lght1
		delete lght2
		
		for l in lightStates do l[1].on = l[2]
	)
)

But that doesn’t include: exposure control, finalgather etc… many many settings still to temporary override. I’d like to know how others have handled this, suggestions are welcome! Basicly I’m hoping something can be build entirely in memory and rendered… but I wouldn’t know where to start.

Thanks,
-Johan

3 Replies

unfortunately , i can’t find it now !
Bobo did a RenderMaterial Function long time ago , it was part of his old SME , search the forum for material slot or something like that .

here it is


 try(destroyDialog test)Catch()
 (
 	global TestMapSamples 
 	
 	local lights_state = #()
 	local lights_array = #()
	local renderMaterial
 	fn collectLightsState = 
 	(
 		lights_state = #()
 		lights_array = for l in Lights where classof l != TargetObject collect l
 		for l in lights_array do 
 		(
 			try
 			(
 				append lights_state l.on
 				l.on = false
 			)
 			catch(append lights_state false)	
 		)
 	)
 	
 	fn restoreLightsState = 
 	(
 		for l = 1 to lights_array.count do 
 			try(lights_array[l].on = lights_state[l])catch()	
 	)
 	
 	fn renderMaterial mat size_x size_y=
 	(
 		if superclassof mat == Material then
 		(
 			disablesceneredraw()
 			with undo off
 			(
	local old_selection = selection as array
 	local visibleObjects = for o in objects where not o.isHidden collect o
	hide objects
 	collectLightsState()
	om1 = omniLight pos:[99900.0,99900.0,100300.0] multiplier:1.5
	om2 = omniLight pos:[100100.0,100000.0,99900.0] multiplier:2.0
	s = sphere pos:[100000.0,100000.0,100000.0] mapcoords:true segs:24
 	uvw_mod = uvwmap Channel:1
 	uvw_mod.mapType=2
 	addmodifier s uvw_mod 
 	s.material = mat
 	t_o = targetObject pos:[100000.0,100000.0,100000.0]
 	c = TargetCamera target:t_o
 	c.pos = [100000.0,100000.0-65,100030.0] 
	map_sample = render camera:c outputsize:[size_x,size_y] vfb:false
 	delete #(c,s,om1,om2)
 	unhide visibleObjects
 	select old_selection 
 	restoreLightsState()
 			)
 			enablesceneredraw()
 		)
 		else
 			map_sample = renderMap mat size:[size_x,size_y] scale:200
			map_sample 
 	)
 
rollout Test "test" --width:50 height:246
(
	
	bitmap bmp1 "Bitmap" width:50 height:50 

	
	on test open do (
		suspendEditing()				
		try(bmp1.bitmap = renderMaterial meditmaterials[1] 50 50)catch()
		ResumeEditing alwaysSuspend:true
		
							)
)

createdialog test 
)

 JHN

Hi Cyfer,

My proposed code is coincidentally almost the same, so I think that means I’m on the right track and should toggle just anything I need to a desirable state and switch back afterwards.

Thanks for posting that snippet! If there are more suggestions I’d be happy to know!

Thanks,
-Johan