@@ -42,7 +42,6 @@ const vector<string> DEFAULT_IMPORTS =
4242 " import ::anno::*" ,
4343 " import ::tex::*" ,
4444 " import ::mx::swizzle::*" ,
45- " import ::mx::cm::*" ,
4645 " using ::mx::core import *" ,
4746 " using ::mx::stdlib import *" ,
4847 " using ::mx::pbrlib import *" ,
@@ -273,9 +272,22 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
273272 // Get final result
274273 const string result = getUpstreamResult (outputSocket, context);
275274
275+ const TypeDesc* outputType = outputSocket->getType ();
276276 if (graph.hasClassification (ShaderNode::Classification::TEXTURE))
277277 {
278- emitLine (" color finalOutput__ = mk_color3(" + result + " )" , stage);
278+ if (outputType == Type::DISPLACEMENTSHADER)
279+ {
280+ emitLine (" float3 displacement__ = " + result + " .geometry.displacement" , stage);
281+ emitLine (" color finalOutput__ = mk_color3("
282+ " r: math::dot(displacement__, state::texture_tangent_u(0)),"
283+ " g: math::dot(displacement__, state::texture_tangent_v(0)),"
284+ " b: math::dot(displacement__, state::normal()))" , stage);
285+ }
286+ else
287+ {
288+ emitLine (" float3 displacement__ = float3(0.0)" , stage);
289+ emitLine (" color finalOutput__ = mk_color3(" + result + " )" , stage);
290+ }
279291
280292 // End shader body
281293 emitScopeEnd (stage);
@@ -289,13 +301,16 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
289301 " intensity : finalOutput__ * math::PI,\n "
290302 " mode : intensity_radiant_exitance\n "
291303 " )\n "
304+ " ),\n "
305+ " geometry: material_geometry(\n "
306+ " displacement : displacement__\n "
292307 " )\n "
293308 " );" ;
294309 emitBlock (textureMaterial, FilePath (), context, stage);
295310 }
296311 else
297312 {
298- emitLine (_syntax->getTypeSyntax (outputSocket-> getType () ).getName () + " finalOutput__ = " + result, stage);
313+ emitLine (_syntax->getTypeSyntax (outputType ).getName () + " finalOutput__ = " + result, stage);
299314
300315 // End shader body
301316 emitScopeEnd (stage);
0 commit comments