MaterialX 1.39.2
Loading...
Searching...
No Matches
HwTransformNode.h
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_HWTRANSFORMNODE_H
7#define MATERIALX_HWTRANSFORMNODE_H
8
10
11MATERIALX_NAMESPACE_BEGIN
12
14class MX_GENSHADER_API HwTransformNode : public ShaderNodeImpl
15{
16 public:
17 void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const override;
18 void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
19
20 protected:
21 virtual const string& getMatrix(const string& fromSpace, const string& toSpace) const;
22 virtual const string& getModelToWorldMatrix() const = 0;
23 virtual const string& getWorldToModelMatrix() const = 0;
24 virtual string getHomogeneousCoordinate() const = 0;
25 virtual bool shouldNormalize() const { return false; }
26
27 virtual string getFromSpace(const ShaderNode&) const;
28 virtual string getToSpace(const ShaderNode&) const;
29
30 static const string FROM_SPACE;
31 static const string TO_SPACE;
32 static const string MODEL;
33 static const string OBJECT;
34 static const string WORLD;
35};
36
38class MX_GENSHADER_API HwTransformVectorNode : public HwTransformNode
39{
40 public:
41 static ShaderNodeImplPtr create();
42
43 protected:
44 const string& getModelToWorldMatrix() const override { return HW::T_WORLD_MATRIX; }
45 const string& getWorldToModelMatrix() const override { return HW::T_WORLD_INVERSE_MATRIX; }
46 string getHomogeneousCoordinate() const override { return "0.0"; }
47};
48
50class MX_GENSHADER_API HwTransformPointNode : public HwTransformVectorNode
51{
52 public:
53 static ShaderNodeImplPtr create();
54
55 protected:
56 string getHomogeneousCoordinate() const override { return "1.0"; }
57};
58
60class MX_GENSHADER_API HwTransformNormalNode : public HwTransformNode
61{
62 public:
63 static ShaderNodeImplPtr create();
64
65 protected:
66 const string& getModelToWorldMatrix() const override { return HW::T_WORLD_INVERSE_TRANSPOSE_MATRIX; }
67 const string& getWorldToModelMatrix() const override { return HW::T_WORLD_TRANSPOSE_MATRIX; }
68 string getHomogeneousCoordinate() const override { return "0.0"; }
69 bool shouldNormalize() const override { return true; }
70};
71
72MATERIALX_NAMESPACE_END
73
74#endif
Hardware shader generator base class.
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition Library.h:40
A context class for shader generation.
Definition GenContext.h:31
Generic transformation node for hardware languages.
Definition HwTransformNode.h:15
void emitFunctionCall(const ShaderNode &node, GenContext &context, ShaderStage &stage) const override
Emit the function call or inline source code for given node instance in the given context.
void createVariables(const ShaderNode &node, GenContext &context, Shader &shader) const override
Create shader variables needed for the implementation of this node (e.g.
Normal transform implementation for hardware languages.
Definition HwTransformNode.h:61
Point transform implementation for hardware languages.
Definition HwTransformNode.h:51
Vector transform implementation for hardware languages.
Definition HwTransformNode.h:39
Class containing all data needed during shader generation.
Definition Shader.h:33
Class representing a node in the shader generation DAG.
Definition ShaderNode.h:320
ShaderNodeImpl()
Protected constructor.
A shader stage, containing the state and resulting source code for the stage.
Definition ShaderStage.h:139