Digital Art Zone

 
     
Shader Builder - How to Decouple Ambient from Diffuse
Posted: 16 April 2012 03:50 PM   [ Ignore ]
Active Member
Avatar
RankRank
Total Posts:  429
Joined  2007-10-08

A special thanks to ReDave and many others who contributed to this information. The original and full forum post can be viewed here:  Shader Builder - How to Decouple Ambient from Diffuse

Here’s a mini tutorial on how to decouple ambient from diffuse. You will loose tiling, AFAICT, and the shader doesn’t seem to load in Shader Mixer for further shader play, so all of that will have to be redone in Shader Builder.  :?
Shader Builder can be overwhelming with lots of windows with plenty of confusing stuff, but the procedure to decouple ambient is not painful at all.
The first pic shows the familiar state of affairs, of ambient slaved to diffuse.
Bring up Shader Builder (View->Tabs->Shader Builder). The active tab should say Catalog, below it is a panel labeled Shader Categories, and several shader categories are listed below it. Click on the one named Surface, if it isn’t the default. In the panel on the right you’ll see four icons, one of which is named DzPower. Right-click on it and select Duplicate Shader, and give it a name. I named it DzPower Ambient. Double click (or right click and select Edit Shader) on the newly created DzPower Ambient shader. A new window will appear with a number of squiggly lines going to and fro. Roughly in the middle of those lines will be a largish block named Plastic. Again either double click anywhere inside the block, or right click on it and select Edit Macro Instance. This will pop up yet another window. In the bottom part of this window are three tabs, named Global Code, Initialization Code and Evaluation Code. Click on the latter: you’ll see a short line that probably says (probably, because I edited it LOL ):
(§2§*(§6§+%+§5§+%)+%+§4§)
Cut the §6§+% part and paste it outside of the parentheses that are multiplied by §2§, such that it looks for example like this:
(§2§*(§5§+%)+§6§+%+%+§4§)
Ok, we’re done, click Accept. I clicked on Save Network just under the Atmosphere Code tab on the window with all the squiggly lines, then closed that window. Now we’re back at the Shader Builder main window, right click on your new shader and click on Apply to selected surface(s).
Final picture shows the result.

postimages/image_1_2081503.jpg

postimages/image_2_2081503.jpg

postimages/image_3_2081503.jpg

postimages/image_4_2081503.jpg

postimages/image_5_2081503.jpg

Profile
 
 
Posted: 23 April 2012 06:02 PM   [ Ignore ]   [ # 1 ]
Active Member
RankRank
Total Posts:  511
Joined  2003-10-09

Been wanting to do this for years. It will be handy when I can actually see the images.

Profile
 
 
Posted: 22 October 2012 02:37 PM   [ Ignore ]   [ # 2 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08

Glad to be of help GhostofMacbeth!
However the formulas haven’t been copied correctly. confused They should be respectively:
(§2§*(§6§+% 14%+§5§+% 15%)+% 16%+§4§)  (Note that there are no spaces between % and each number following it, but the forum code breaks ands shows just % if I leave them as they are).
and:
(§2§*((§5§+% 15%))+§6§+% 14%+% 16%+§4§)
The link to the old thread is http://forumarchive.daz3d.com/viewtopic.php?t=126939
I’ll try to make a tutorial with pictures from the most informative posts.

The links to the original screenshots are also broken in the OP, they are:
http://forumarchive.daz3d.com/postimages/origimage_1_2081503.jpg
http://forumarchive.daz3d.com/postimages/origimage_2_2081503.jpg
http://forumarchive.daz3d.com/postimages/origimage_3_2081503.jpg
http://forumarchive.daz3d.com/postimages/origimage_4_2081503.jpg
http://forumarchive.daz3d.com/postimages/origimage_5_2081503.jpg
I’m attaching the significant pictures. The ordering should be: picture ending with 2_2081503.jpg should come first, then 3_2081503.jpg then 4_2081503.jpg.

Image Attachments
origimage_2_2081503[1].jpgorigimage_3_2081503[1].jpgorigimage_4_2081503[1].jpgModified_Block.png
Profile
 
 
Posted: 15 January 2013 05:52 PM   [ Ignore ]   [ # 3 ]
Addict
Avatar
RankRankRankRank
Total Posts:  2945
Joined  2011-12-10

Stupid Question: Why?

Why would I want to decouple Ambient from Diffuse?

 Signature 

My DeviantArt Galleries
My ShareCG Gallery
OPENSUBDIV Testing and Discussion
3Delight Surface and Lighting Thread

Profile
 
 
Posted: 16 January 2013 08:30 AM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  13719
Joined  2003-10-09

So that you can do glow effects - for example, magma channels or glowing runes in dark rock. While the two are coupled the dark diffuse colour will limit the glow, which isn’t always desirable - and since Poser doesn’t multiply diffuse and ambient quite a few products use the ambient for glow technique.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 16 January 2013 09:09 AM   [ Ignore ]   [ # 5 ]
Addict
Avatar
RankRankRankRank
Total Posts:  2945
Joined  2011-12-10

OH! Kewlness, think that would work for things like lazers, gun flashes or other auras?

 Signature 

My DeviantArt Galleries
My ShareCG Gallery
OPENSUBDIV Testing and Discussion
3Delight Surface and Lighting Thread

Profile
 
 
Posted: 16 January 2013 11:07 AM   [ Ignore ]   [ # 6 ]
Addict
Avatar
RankRankRankRank
Total Posts:  4545
Joined  2007-09-13

Well, it’s a fun thing to play with that, does have a very practical use…and from the looks of a couple of recent threads, maybe needed.

 Signature 

1432 old posts

My ShareCG gallery.

Just because something costs a lot, doesn’t mean it’s the best…

It just means it’s expensive.

Profile
 
 
Posted: 16 January 2013 02:36 PM   [ Ignore ]   [ # 7 ]
Active Member
RankRank
Total Posts:  751
Joined  2003-10-09
wancow - 16 January 2013 09:09 AM

OH! Kewlness, think that would work for things like lazers, gun flashes or other auras?

Yes, it would.  That’s how I did “glowing” effects in Poser for years (where the ambient is a separate channel) and why I’ve been screaming for years for DAZ to “unslave” the ambient channel from the diffuse channel in DS.

Profile
 
 
Posted: 16 January 2013 02:45 PM   [ Ignore ]   [ # 8 ]
Addict
Avatar
RankRankRankRank
Total Posts:  2945
Joined  2011-12-10
blondie9999 - 16 January 2013 02:36 PM
wancow - 16 January 2013 09:09 AM

OH! Kewlness, think that would work for things like lazers, gun flashes or other auras?

Yes, it would.  That’s how I did “glowing” effects in Poser for years (where the ambient is a separate channel) and why I’ve been screaming for years for DAZ to “unslave” the ambient channel from the diffuse channel in DS.

Is that DAZ or 3Delight?

 Signature 

My DeviantArt Galleries
My ShareCG Gallery
OPENSUBDIV Testing and Discussion
3Delight Surface and Lighting Thread

Profile
 
 
Posted: 16 January 2013 06:52 PM   [ Ignore ]   [ # 9 ]
Active Member
RankRank
Total Posts:  511
Joined  2003-10-09

It is DAZ, I think. An old version had them split so you could do what we are talking about.

Profile
 
 
Posted: 16 January 2013 07:00 PM   [ Ignore ]   [ # 10 ]
Addict
Avatar
RankRankRankRank
Total Posts:  4545
Joined  2007-09-13
wancow - 16 January 2013 02:45 PM
blondie9999 - 16 January 2013 02:36 PM
wancow - 16 January 2013 09:09 AM

OH! Kewlness, think that would work for things like lazers, gun flashes or other auras?

Yes, it would.  That’s how I did “glowing” effects in Poser for years (where the ambient is a separate channel) and why I’ve been screaming for years for DAZ to “unslave” the ambient channel from the diffuse channel in DS.

Is that DAZ or 3Delight?

Well, sort of both…but it isn’t ‘slaved’ in 3Delight, so much as that’s how many of the surface shaders are written.  It used to be pretty much the common way of doing it.  When the basic DS stuff was written that’s the way it was done and that’s the way it’s stayed.  So without editing the shader or using a different one entirely, it’s ‘slaved’ in DS, especially since most DS users aren’t going to get ‘under the hood’ to actually change it, the change would have to come from DAZ itself. 

I’d like to see a basic DS surface shader that has a ‘twin’ with the Ambient decoupled already…

 Signature 

1432 old posts

My ShareCG gallery.

Just because something costs a lot, doesn’t mean it’s the best…

It just means it’s expensive.

Profile
 
 
Posted: 17 January 2013 08:24 AM   [ Ignore ]   [ # 11 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  13719
Joined  2003-10-09

Ideally a “Multiply Ambient through Diffuse” setting, like the oen we already have for specularity and opacity.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 21 January 2013 05:20 AM   [ Ignore ]   [ # 12 ]
Active Member
Avatar
RankRank
Total Posts:  803
Joined  2007-01-08
wancow - 15 January 2013 05:52 PM

Stupid Question: Why?

Why would I want to decouple Ambient from Diffuse?

When you make a render you have to add colours in some fashion. A visually oriented explanation would be something like this:
Put 255 red in your diffuse channel, and 255 green in Ambient.
Make sure both are at 100% strength.
Screenshot with yellow green sphere shows the OpenGL preview.
Screenshot with red sphere shows the 3Delight render of the same scene.


I thought you could force the DAZ default shader to give the same results if you left both Diffuse and Ambient Colour to white and applied a 1 pixel *1 pixel red texture to Diffuse and likewise 1 pixel * 1 pixel green texture in Ambient. But actually that doesn’t work and I don’t know why. Basically if you do that the OpenGL preview gives a perfectly red sphere (no diffuse to speak of), but the 3Delight render shows a red ball with very definite darkening towards the edges (i.e. a diffuse look). Still, it’s vastly less different than doing it the other way, and doesn’t require messing with shaders.

Image Attachments
NoShaderBuilder_OpenGL_RedDiffuse_GreenAmbient.pngNoShaderBuilder_3Delight_RedDiffuse_GreenAmbient.png
Profile
 
 
Posted: 03 January 2014 11:10 AM   [ Ignore ]   [ # 13 ]
Active Member
Avatar
RankRank
Total Posts:  371
Joined  2006-12-10

I realize this thread is over a year old now; so I apologize in advance for the necromancy, however since I’ve been reading / studying shader design lately, I wanted to comment on why one might want to leave the ambient channel just the way it is.

First, the Renderman engine (and the 3Delight implementation of such) intended the ambient channel to be used as “fill” light when a surface isn’t being lit by light shaders. Before global illumination, the ambient channel was a way to say “Even if nothing shines here, there is still light bouncing around the scene; so it needs something”.

Because it was intended to be background light, it was designed in most shaders (DAZ’s default shader included) to be overwhelmed by direct light within the scene. Decoupling ambient from diffuse will mean you need to pay close attention to the ambient surface settings or else risk overexposing your surfaces.

Second, keep in mind that if the content creator has created DAZ Studio specific settings, they have likely tested those settings with the shader in its default configuration. So while decoupling them may help with Poser materials and a more consistent translation of those settings to DS, you may do so at the risk of your DS materials. And since DS is smarter now about seeing DS specific settings even if the files are located in the Poser portion of the content library, you may not be aware of which settings you’re using.

I think at this point, if I wanted to achieve the special effects like the Poser folks do using the ambient channel, I’d remove all the ambient settings from my existing shader, and use Shader Mixer to blend the ambient information with the standard surface.

 Signature 

Feel free to read my 3D Tutorial collection, focusing mainly on the technical aspects of 3D rendering.

Profile
 
 
Posted: 03 January 2014 12:05 PM   [ Ignore ]   [ # 14 ]
Addict
Avatar
RankRankRankRank
Total Posts:  4545
Joined  2007-09-13
JonnyRay - 03 January 2014 11:10 AM

I think at this point, if I wanted to achieve the special effects like the Poser folks do using the ambient channel, I’d remove all the ambient settings from my existing shader, and use Shader Mixer to blend the ambient information with the standard surface.

That’s why I wanted a ‘standard’ without the Ambient…heck it could just be a brick in the brickyard.  Much more useful for ‘rolling your own’, if you don’t have to ‘deconstruct’ first.

 Signature 

1432 old posts

My ShareCG gallery.

Just because something costs a lot, doesn’t mean it’s the best…

It just means it’s expensive.

Profile