Selaa lähdekoodia

[shgraph] added model space normal input, and fixed pbr input/outputs

Clement Espeute 1 vuosi sitten
vanhempi
commit
b130ccf7f1

+ 5 - 0
hide/view/shadereditor/ShaderEditor.hx

@@ -43,11 +43,14 @@ class PreviewShaderBase extends hxsl.Shader {
 		var transformedPosition : Vec3;
 		var projectedPosition : Vec4;
 		var transformedNormal : Vec3;
+		var fakeNormal : Vec3;
+
 
 		function __init__() {
 			relativePosition = vec3(input.position, 0.0);
 			transformedPosition = vec3(input.position, 0.0);
 			projectedPosition = vec4(input.position, 0.0, 0.0);
+			fakeNormal = vec3(0,0,-1);
 			transformedNormal = vec3(0,0,-1);
 		}
 	}
@@ -81,6 +84,8 @@ class Preview extends h2d.Bitmap {
 		this.blendMode = None;
 		var shaderBase = new PreviewShaderBase();
 		addShader(shaderBase);
+		var props = new h3d.shader.pbr.PropsValues();
+		addShader(props);
 	}
 
 }

+ 3 - 0
hrt/shgraph/ShaderGraph.hx

@@ -1063,6 +1063,9 @@ class Graph {
 							}
 
 							var inVar = getOutsideVar(nodeVar.v.name, nodeVar.v, true, false);
+							if (inVar.name == "input.normal" && includePreviews) {
+								inVar.name = "fakeNormal";
+							}
 
 							var shParam = Std.downcast(currentNode.instance, ShaderParam);
 							if (shParam != null) {

+ 5 - 8
hrt/shgraph/ShaderInput.hx

@@ -108,13 +108,6 @@ class ShaderInput extends ShaderNode {
 					t: flt
 				};
 		}
-		else if (variable.v.name == "projectedNormal") {
-			inVar.name == "transformedNormal";
-
-			//var expr = new MacroParser().parseExpr(macro var transformedNormal = vec4(transformedNormal, 1) * camera.viewProj;);
-			//final
-		}
-
 
 		return {expr: finalExpr, inVars: [{v:inVar, internal: true, isDynamic: false}], outVars:[{v:output, internal: false, isDynamic: false}], externVars: [], inits: []};
 	}
@@ -137,8 +130,12 @@ class ShaderInput extends ShaderNode {
 		"relativePosition" => {display: "Position (Object Space)", v: { parent: null, id: 0, kind: Local, name: "relativePosition", type: TVec(3, VFloat) }},
 		"transformedPosition" => {display: "Position (World Space)", v: { parent: null, id: 0, kind: Local, name: "transformedPosition", type: TVec(3, VFloat) }},
 		"projectedPosition" => {display: "Position (View Space)", v: { parent: null, id: 0, kind: Local, name: "projectedPosition", type: TVec(4, VFloat) }},
+		"normal" => {display: "Normal (Object Space)", v: { parent: null, id: 0, kind: Local, name: "input.normal", type: TVec(3, VFloat) }},
 		"transformedNormal" => {display: "Normal (World Space)", v: { parent: null, id: 0, kind: Local, name: "transformedNormal", type: TVec(3, VFloat) }},
-
+		"metalness" => {display: "Metalness", v: {parent: null,id: 0,kind: Local,name: "metalness",type: TFloat}},
+		"roughness" => {display: "Roughness", v: {parent: null, id: 0, kind: Local, name: "roughness", type: TFloat}},
+		"emissive" => {display: "Emissive", v: {parent: null, id: 0, kind: Local, name: "emissive", type: TFloat}},
+		"occlusion" => {display: "Occlusion", v: {parent: null, id: 0, kind: Local, name: "occlusion", type: TFloat}},
 		// "position" => {display: "Source Position", v: { parent: null, id: 0, kind: Input, name: "input.position", type: TVec(3, VFloat) }},
 		// "color" => 	{display: "Source Vertex Color", v: { parent: null, id: 0, kind: Input, name: "input.color", type: TVec(3, VFloat) }},
 		"uv" => {display: "Source UV", v: { parent: null, id: 0, kind: Input, name: "input.uv", type: TVec(2, VFloat) }},

+ 1 - 1
hrt/shgraph/ShaderNode.hx

@@ -26,7 +26,7 @@ class AlphaPreview extends hxsl.Shader {
 	}
 }
 
-typedef VariableDecl = {v: TVar, display: String};
+typedef VariableDecl = {v: TVar, display: String, ?vertexOnly: Bool};
 typedef AliasInfo = {?name : String, ?description : String, ?args : Array<Dynamic>};
 @:autoBuild(hrt.shgraph.Macros.autoRegisterNode())
 @:keepSub

+ 8 - 8
hrt/shgraph/ShaderOutput.hx

@@ -155,16 +155,16 @@ class ShaderOutput extends ShaderNode {
 	public static var availableOutputs : Map<String, ShaderNode.VariableDecl> = [
 		"_sg_out_color" => {display:"Pixel Color", v:{parent: null,id: 0,kind: Local,name: "_sg_out_color",type: TVec(3, VFloat)}},
 		"_sg_out_alpha" => {display:"Alpha", v:{parent: null,id: 0,kind: Local,name: "_sg_out_alpha",type: TFloat}},
-		"relativePosition" => {display:"Position (Object Space)", v:{parent: null,id: 0,kind: Local,name: "relativePosition",type: TVec(3, VFloat)}},
-		"transformedPosition" => {display:"Position (World Space)", v:{parent: null,id: 0,kind: Local,name: "transformedPosition",type: TVec(3, VFloat)}},
-		"projectedPosition" => {display: "Position (View Space)", v: { parent: null, id: 0, kind: Local, name: "projectedPosition", type: TVec(4, VFloat) }},
+		"relativePosition" => {display:"Position (Object Space)", vertexOnly: true, v:{parent: null,id: 0,kind: Local,name: "relativePosition",type: TVec(3, VFloat)}},
+		"transformedPosition" => {display:"Position (World Space)", vertexOnly: true, v:{parent: null,id: 0,kind: Local,name: "transformedPosition",type: TVec(3, VFloat)}},
+		"projectedPosition" => {display: "Position (View Space)", vertexOnly: true, v: { parent: null, id: 0, kind: Local, name: "projectedPosition", type: TVec(4, VFloat) }},
 		// Disabled because calculated UV need to be initialized in vertexShader for some reason
 		//"calculatedUV" => { display: "UV", v: { parent: null, id: 0, kind: Var, name: "calculatedUV", type: TVec(2, VFloat)}},
-		"transformedNormal" => { display: "Normal (World Space)", v: {parent: null, id: 0, kind: Local, name: "transformedNormal", type: TVec(3, VFloat)}},
-		"metalnessValue" => {display: "Metalness", v: {parent: null,id: 0,kind: Local,name: "metalnessValue",type: TFloat}},
-		"roughnessValue" => {display: "Roughness", v: {parent: null, id: 0, kind: Local, name: "roughnessValue", type: TFloat}},
-		"emissiveValue" => {display: "Emissive", v: {parent: null, id: 0, kind: Local, name: "emissiveValue", type: TFloat}},
-		"occlusionValue" => {display: "Occlusion", v: {parent: null, id: 0, kind: Local, name: "occlusionValue", type: TFloat}},
+		"transformedNormal" => { display: "Normal (World Space)", vertexOnly: true, v: {parent: null, id: 0, kind: Local, name: "transformedNormal", type: TVec(3, VFloat)}},
+		"metalness" => {display: "Metalness", v: {parent: null,id: 0,kind: Local,name: "metalness",type: TFloat}},
+		"roughness" => {display: "Roughness", v: {parent: null, id: 0, kind: Local, name: "roughness", type: TFloat}},
+		"emissive" => {display: "Emissive", v: {parent: null, id: 0, kind: Local, name: "emissive", type: TFloat}},
+		"occlusion" => {display: "Occlusion", v: {parent: null, id: 0, kind: Local, name: "occlusion", type: TFloat}},
 	];
 
 	override function loadProperties(props:Dynamic) {