I have a building model in Blender created from python using vertices and faces. For making it look as realistic as possible, I want to render color on the outer face/outside walls of the room to be 'White' (lets say) and the inner face/inside walls of the room to be different (lets say yellow). I am using rgb color code to render the color but it applies same color to both inner and outer face. Is it possible to achieve different colors on both (inner and outer) faces ?
$\begingroup$
$\endgroup$
2
-
$\begingroup$ Not unless you add thickness to the walls by (for instance) adding and applying a solidify modifier which will create two faces. $\endgroup$– John EasonCommented Nov 26, 2021 at 9:34
-
1$\begingroup$ I am not sure if you want to do it with python and if it is possible to do with python but from a shader perspective, there is a node called Geometry, this node has value Backfacing that does exactly what you want, it gives one side one color/nodes and gives other side second color/nodes... It works way that value 1 is front and value 0 is back $\endgroup$– MikoCGCommented Nov 26, 2021 at 10:19
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
As MikoCG wrote in comments, you can use Geometry node's Backfacing output:
import bpy
from bpy import context as C, data as D
bpy.ops.mesh.primitive_plane_add()
plane = C.active_object
mat = D.materials.new("double.sided")
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links
mix = nodes.new('ShaderNodeMixRGB')
mix.inputs['Color1'].default_value = (1, 1, 1, 1)
mix.inputs['Color2'].default_value = (1, 1, 0, 1)
geo = nodes.new('ShaderNodeNewGeometry')
base_col = nodes['Principled BSDF'].inputs['Base Color']
links.new(mix.inputs['Fac'], geo.outputs['Backfacing'])
links.new(base_col, mix.outputs['Color'])
plane.data.materials.append(mat)