1 /** 2 A material that uses a custom $(D Shader) program. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.shadermaterial; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.material; 25 import godot.resource; 26 import godot.reference; 27 import godot.shader; 28 /** 29 A material that uses a custom $(D Shader) program. 30 31 A material that uses a custom $(D Shader) program to render either items to screen or process particles. You can create multiple materials for the same shader but configure different values for the uniforms defined in the shader. 32 $(B Note:) Due to a renderer limitation, emissive $(D ShaderMaterial)s cannot emit light when used in a $(D GIProbe). Only emissive $(D SpatialMaterial)s can emit light in a $(D GIProbe). 33 */ 34 @GodotBaseClass struct ShaderMaterial 35 { 36 package(godot) enum string _GODOT_internal_name = "ShaderMaterial"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ Material _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("_shader_changed") GodotMethod!(void) _shaderChanged; 47 @GodotName("get_shader") GodotMethod!(Shader) getShader; 48 @GodotName("get_shader_param") GodotMethod!(Variant, String) getShaderParam; 49 @GodotName("property_can_revert") GodotMethod!(bool, String) propertyCanRevert; 50 @GodotName("property_get_revert") GodotMethod!(Variant, String) propertyGetRevert; 51 @GodotName("set_shader") GodotMethod!(void, Shader) setShader; 52 @GodotName("set_shader_param") GodotMethod!(void, String, Variant) setShaderParam; 53 } 54 /// 55 pragma(inline, true) bool opEquals(in ShaderMaterial other) const 56 { return _godot_object.ptr is other._godot_object.ptr; } 57 /// 58 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 59 { _godot_object.ptr = n; return null; } 60 /// 61 pragma(inline, true) bool opEquals(typeof(null) n) const 62 { return _godot_object.ptr is n; } 63 /// 64 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 65 mixin baseCasts; 66 /// Construct a new instance of ShaderMaterial. 67 /// Note: use `memnew!ShaderMaterial` instead. 68 static ShaderMaterial _new() 69 { 70 static godot_class_constructor constructor; 71 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ShaderMaterial"); 72 if(constructor is null) return typeof(this).init; 73 return cast(ShaderMaterial)(constructor()); 74 } 75 @disable new(size_t s); 76 /** 77 78 */ 79 void _shaderChanged() 80 { 81 Array _GODOT_args = Array.make(); 82 String _GODOT_method_name = String("_shader_changed"); 83 this.callv(_GODOT_method_name, _GODOT_args); 84 } 85 /** 86 87 */ 88 Ref!Shader getShader() const 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(Shader)(GDNativeClassBinding.getShader, _godot_object); 92 } 93 /** 94 Returns the current value set for this material of a uniform in the shader. 95 */ 96 Variant getShaderParam(in String param) const 97 { 98 checkClassBinding!(typeof(this))(); 99 return ptrcall!(Variant)(GDNativeClassBinding.getShaderParam, _godot_object, param); 100 } 101 /** 102 Returns `true` if the property identified by `name` can be reverted to a default value. 103 */ 104 bool propertyCanRevert(in String name) 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(bool)(GDNativeClassBinding.propertyCanRevert, _godot_object, name); 108 } 109 /** 110 Returns the default value of the material property with given `name`. 111 */ 112 Variant propertyGetRevert(in String name) 113 { 114 checkClassBinding!(typeof(this))(); 115 return ptrcall!(Variant)(GDNativeClassBinding.propertyGetRevert, _godot_object, name); 116 } 117 /** 118 119 */ 120 void setShader(Shader shader) 121 { 122 checkClassBinding!(typeof(this))(); 123 ptrcall!(void)(GDNativeClassBinding.setShader, _godot_object, shader); 124 } 125 /** 126 Changes the value set for this material of a uniform in the shader. $(B Note:) `param` must match the name of the uniform in the code exactly. 127 */ 128 void setShaderParam(VariantArg1)(in String param, in VariantArg1 value) 129 { 130 checkClassBinding!(typeof(this))(); 131 ptrcall!(void)(GDNativeClassBinding.setShaderParam, _godot_object, param, value); 132 } 133 /** 134 The $(D Shader) program used to render this material. 135 */ 136 @property Shader shader() 137 { 138 return getShader(); 139 } 140 /// ditto 141 @property void shader(Shader v) 142 { 143 setShader(v); 144 } 145 }