|
@@ -1,5 +1,16 @@
|
|
|
package hrt.prefab.pbr;
|
|
|
|
|
|
+import hrt.shader.SpecularColor;
|
|
|
+import hrt.shader.SpecularColor.SpecularColorAlbedo;
|
|
|
+import hrt.shader.SpecularColor.SpecularColorFlat;
|
|
|
+import hrt.shader.SpecularColor.SpecularColorTexture;
|
|
|
+
|
|
|
+enum abstract SpecularColorMode(String) {
|
|
|
+ var Albedo;
|
|
|
+ var Flat;
|
|
|
+ var Texture;
|
|
|
+}
|
|
|
+
|
|
|
class SpecularColor extends Prefab {
|
|
|
|
|
|
// Amount of dielectric specular reflection. Specifies facing (along normal) reflectivity in the most common 0 - 8% range.
|
|
@@ -10,6 +21,10 @@ class SpecularColor extends Prefab {
|
|
|
// and is provided for faking the appearance of materials with complex surface structure.
|
|
|
public var specularTint : Float = 0.0;
|
|
|
|
|
|
+ public var specularColorPath : String;
|
|
|
+ public var specularColorCustomValue : Int;
|
|
|
+ public var mode : SpecularColorMode = Albedo;
|
|
|
+
|
|
|
public function new(?parent) {
|
|
|
super(parent);
|
|
|
type = "specularColor";
|
|
@@ -19,12 +34,18 @@ class SpecularColor extends Prefab {
|
|
|
super.load(obj);
|
|
|
if( obj.specularTint != null ) specularTint = obj.specularTint;
|
|
|
if( obj.specular != null ) specular = obj.specular;
|
|
|
+ if( obj.specularColorCustomValue != null ) specularColorCustomValue = obj.specularColorCustomValue;
|
|
|
+ if( obj.mode != null ) mode = obj.mode;
|
|
|
+ if( obj.specularColorPath != null ) specularColorPath = obj.specularColorPath;
|
|
|
}
|
|
|
|
|
|
override function save() {
|
|
|
var obj : Dynamic = super.save();
|
|
|
obj.specularTint = specularTint;
|
|
|
obj.specular = specular;
|
|
|
+ obj.specularColorPath = specularColorPath;
|
|
|
+ obj.specularColorCustomValue = specularColorCustomValue;
|
|
|
+ obj.mode = mode;
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
@@ -37,6 +58,18 @@ class SpecularColor extends Prefab {
|
|
|
|
|
|
override function updateInstance( ctx : Context, ?propName : String ) {
|
|
|
for( m in ctx.local3d.getMaterials() ) {
|
|
|
+ var sca = m.mainPass.getShader(hrt.shader.SpecularColorAlbedo);
|
|
|
+ if( sca != null ) {
|
|
|
+ // No params
|
|
|
+ }
|
|
|
+ var scf = m.mainPass.getShader(hrt.shader.SpecularColorFlat);
|
|
|
+ if( scf != null ) {
|
|
|
+ scf.specularColorValue = h3d.Vector.fromColor(specularColorCustomValue);
|
|
|
+ }
|
|
|
+ var sct = m.mainPass.getShader(hrt.shader.SpecularColorTexture);
|
|
|
+ if( sct != null ) {
|
|
|
+ sct.specularColorTexture = ctx.loadTexture(specularColorPath);
|
|
|
+ }
|
|
|
var sc = m.mainPass.getShader(hrt.shader.SpecularColor);
|
|
|
if( sc != null ) {
|
|
|
sc.specular = specular;
|
|
@@ -46,9 +79,19 @@ class SpecularColor extends Prefab {
|
|
|
}
|
|
|
|
|
|
function refreshShaders( ctx : Context ) {
|
|
|
+
|
|
|
+ var sca = new SpecularColorAlbedo();
|
|
|
+ var scf = new SpecularColorFlat();
|
|
|
+ var sct = new SpecularColorTexture();
|
|
|
var sc = new hrt.shader.SpecularColor();
|
|
|
+
|
|
|
+ var specularColorTexture = specularColorPath != null ? ctx.loadTexture(specularColorPath) : null;
|
|
|
+
|
|
|
var o = ctx.local3d;
|
|
|
for( m in o.getMaterials() ) {
|
|
|
+ m.mainPass.removeShader(m.mainPass.getShader(SpecularColorAlbedo));
|
|
|
+ m.mainPass.removeShader(m.mainPass.getShader(SpecularColorFlat));
|
|
|
+ m.mainPass.removeShader(m.mainPass.getShader(SpecularColorTexture));
|
|
|
m.mainPass.removeShader(m.mainPass.getShader(hrt.shader.SpecularColor));
|
|
|
}
|
|
|
for( m in o.getMaterials() ) {
|
|
@@ -56,9 +99,13 @@ class SpecularColor extends Prefab {
|
|
|
if( m.mainPass.name != "forward" )
|
|
|
continue;
|
|
|
|
|
|
- if( m.mainPass.getShader(hrt.shader.SpecularColor) == null ) {
|
|
|
- m.mainPass.addShader(sc);
|
|
|
+ switch mode {
|
|
|
+ case Albedo: m.mainPass.addShader(sca);
|
|
|
+ case Flat: m.mainPass.addShader(scf);
|
|
|
+ case Texture: specularColorTexture == null ? m.mainPass.addShader(scf) : m.mainPass.addShader(sct);
|
|
|
}
|
|
|
+
|
|
|
+ m.mainPass.addShader(sc);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -72,16 +119,41 @@ class SpecularColor extends Prefab {
|
|
|
override function edit( ctx : EditContext ) {
|
|
|
super.edit(ctx);
|
|
|
|
|
|
+ var flatParams = '<dt>Color</dt><dd><input type="color" field="specularColorCustomValue"/></dd>';
|
|
|
+
|
|
|
+ var textureParams = '<dt>Color</dt><dd><input type="texturepath" field="specularColorPath"/>';
|
|
|
+
|
|
|
+ var albedoParams = '';
|
|
|
+
|
|
|
+ var params = switch mode {
|
|
|
+ case Albedo: albedoParams;
|
|
|
+ case Texture: textureParams;
|
|
|
+ case Flat: flatParams;
|
|
|
+ };
|
|
|
+
|
|
|
var props = new hide.Element('
|
|
|
<div class="group" name="Specular Color">
|
|
|
<dl>
|
|
|
- <dt>Tint</dt><dd><input type="range" min="0" max="1" field="specularTint"/></dd>
|
|
|
- <dt>Amount</dt><dd><input type="range" min="0" max="1" field="specular"/>
|
|
|
+ <dt>Reflection Amount</dt><dd><input type="range" min="0" max="1" field="specular"/>
|
|
|
+ <dt>Tint Amount</dt><dd><input type="range" min="0" max="1" field="specularTint"/></dd>
|
|
|
+ <dt>Color Mode</dt>
|
|
|
+ <dd>
|
|
|
+ <select field="mode">
|
|
|
+ <option value="Albedo">Albedo</option>
|
|
|
+ <option value="Flat">Flat</option>
|
|
|
+ <option value="Texture">Texture</option>
|
|
|
+ </select>
|
|
|
+ </dd>
|
|
|
+ ' + params + '
|
|
|
</dl>
|
|
|
</div>
|
|
|
');
|
|
|
|
|
|
ctx.properties.add(props, this, function(pname) {
|
|
|
+ if( pname == "mode" || pname == "specularColorPath" ) {
|
|
|
+ ctx.rebuildProperties();
|
|
|
+ refreshShaders(ctx.getContext(this));
|
|
|
+ }
|
|
|
ctx.onChange(this, pname);
|
|
|
});
|
|
|
}
|