Render material polish property

Hi,
when creating custom materials i´d like to have rough/polished value as you get with the metal material in Rhino.
i can not find a property like that. i tried “shine” but that does not seem to do anything.
how would i create something like the rhino metal materials myself? Is that an extra class i did not find?

If you use RenderMaterial to create a new material, then you can set the parameters "shine" and "polish-amount" to your wanted value (in the range [0.00,1.00]).

For a metal to be a metal with the custom rendermaterial you need to have diffuse color set to black and reflectivity to 1.

To check the names you should fiddle with you can save a material to file and open it in a text editor. I like to create a metal first, then convert it to custom, and save that out. Open up and look at the <parameters> section.

How are you currently creating your materials? (Code snippet please).

hi @nathanletwory
here is the code:

var custom = new Rhino.DocObjects.Material();
            custom.Reflectivity = 1;
            custom.ReflectionColor = System.Drawing.Color.FromArgb(r[currIntOption], g[currIntOption], b[currIntOption]);
            custom.Transparency = fjMatTrans[currIntOption];
            custom.Shine = fjMatShine[currIntOption];
            custom.Name = matName[currIntOption];

            custom.CommitChanges();

            rm = RenderMaterial.CreateBasicMaterial(custom);

are “shine” and “polish-amount” two different properties?

There seems to be a difference between “Material” and “RenderMaterial” that i don’t get. Are they connected? Do i have to use both like i do in my code?

Rhino.DocObjects.Material is the old-style material. Rhino.Render.RenderMaterial is the new-style RDK material. I’d advise RenderMaterial over Material.

Here is a snippet in Python to create 10 metal materials with random roughness. Shine and Polish Amount are the inverse of roughness, so for a perfectly smooth metal you’d pass in 1.0 to both.

# Create 10 random metal-like materials
# using RenderMaterial

import Rhino
import System
import scriptcontext
import random

for i in range(0,10):
    m = Rhino.DocObjects.Material()
    m.Name = "Random Roughness Metal"
    
    shine = random.random()
    
    rm = Rhino.Render.RenderMaterial.CreateBasicMaterial(m)
    rm.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
    rm.SetParameter("diffuse", System.Drawing.Color.Black)
    rm.SetParameter("reflectivity", 1.0)
    rm.SetParameter("reflectivity-color", System.Drawing.Color.LightBlue)
    rm.SetParameter("shine", shine)
    rm.SetParameter("polish-amount", shine)
    rm.EndChange()
    
    scriptcontext.doc.RenderMaterials.Add(rm)

A test run yields:

1 Like

hi @nathanletwory
thank you very much! this helps a lot!

Hi Nathan,
I took your script as a basis to modify.

I can’t to assign a value of 50 for “shine”, but If I remove the line for i in range(0,10) then script stops working.
I managed to turn on the ChildSlot for the Environment, but I can’t assign a bitmap.
Do not scold much. I’m at the beginning of the way.

import System
import Rhino.Display
import Rhino.Render

import scriptcontext
import random

for i in range(1,2):
    m = Rhino.DocObjects.Material()
    m.Name = "New"
    context = Rhino.Render.RenderContent.ChangeContexts.Program


    rm = Rhino.Render.RenderMaterial.CreateBasicMaterial(m)
    rm.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
    rm.SetParameter("diffuse", Rhino.Display.Color4f(0.64,0.92,1,1))
    rm.SetChildSlotOn("shine", True, context)
    rm.SetParameter("shine", 50, context)
    rm.SetParameter("reflectivity", 0)
    rm.SetParameter("transparency", 0)

    rm.SetChildSlotAmount("environment-texture", 30, context)
    rm.SetParameter("environment-texture-on", True, context)
    rm.SetParameter("filename", r"C:\Program Files\Rhino 7\System\rhino_shaded_mode_emap_background.png")
    rm.EndChange()

    scriptcontext.doc.RenderMaterials.Add(rm)

You should put a number between 0.0 and 1.0. 1.0 equates to 100 in the GUI, so use 0.5 for 50.

Thanks - I have done as you suggest. It woks.
How to assign an Environment map?

You can check this tutorial: https://jesterking.github.io/rhipy/create_pbr_material_with_textures.html

Thank you but I can’t deal with it yet.
It doesn’t look like a script that I work on.
Completely different style and data types.

I opened the material with the environment in the text editor.
What to take for current script to assign an environment map?
I tried take different parts, but the environment map still not assigned.

Is missing type=string
<environment-texture type=string>C:\Program Files\Rhino 7\System\rhino_shaded_mode_emap_background.png</environment-texture>
<environment-texture-on type=bool>true</environment-texture-on>
<environment-texture-double-amount type=double>0.3</environment-texture-double-amount>
<environment-texture-amount type=double>0.3</environment-texture-amount>

and without environment.

<environment-texture type=/>|
<environment-texture-on type=bool>true</environment-texture-on>|
<environment-texture-double-amount type=double>0.3</environment-texture-double-amount>|
<environment-texture-amount type=double>0.3</environment-texture-amount>|

How add it to current script?

I tried to repeat your script, but for crate BasicMaterialType it not suitable. I tripped on pbr = sim.BasicMaterial
PBR is not supported it. I need the Custom material.

BasicMaterialType
import Rhino as rh
import Rhino.Render as rr
import Rhino.DocObjects as rd
import scriptcontext as sc

bitmap_texture_type_guid = rr.ContentUuids.BitmapTextureType
pbr_material_type_guid = rr.ContentUuids.BasicMaterialType
bmtex = rr.RenderContentType.NewContentFromTypeId(bitmap_texture_type_guid)
bmtex.Filename = "C:\Program Files\Rhino 7\System\rhino_shaded_mode_emap_background.png"
simtex = bmtex.SimulatedTexture(rr.RenderTexture.TextureGeneration.Allow)
pbr_rm = rr.RenderContentType.NewContentFromTypeId(pbr_material_type_guid)
sim = pbr_rm.SimulatedMaterial(rr.RenderTexture.TextureGeneration.Allow)
pbr = sim.BasicMaterial........
.............................................

Then I took your lesson “How To Change a Material By Code” on YouTube about ToString.
But the script doesn’t start.

Convert.ToString
import Rhino as rh
import Rhino.Render as rr
import Rhino.DocObjects as rd
import scriptcontext as sc

import System
import Rhino.Display
import Rhino.Render
import random

rm = [m for m in sc.doc.RenderMaterials][0]
m = Rhino.DocObjects.Material()
m.Name = "New"
context = Rhino.Render.RenderContent.ChangeContexts.Program

print(System.Convert.ToString(rm.GetParameter("environment-texture")))
print(System.Convert.ToInt32(rm.GetParameter("version")))

rm = Rhino.Render.RenderMaterial.CreateBasicMaterial(m)

rm.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
rm.SetParameter("version", 2)
rm.SetParameter("diffuse", Rhino.Display.Color4f(0.64,0.92,1,1))
rm.SetChildSlotOn("shine", True, context)
rm.SetParameter("shine", 0.5, context)
rm.SetParameter("reflectivity", 0)
rm.SetParameter("transparency", 0)

rm.SetChildSlotAmount("environment-texture", 30, context)
rm.SetParameter("environment-texture-on", True, context)
rm.SetParameter("filename", r"C:\Program Files\Rhino 7\System\rhino_shaded_mode_emap_background.png")
rm.EndChange()