Browse Source

Initial setup for shader connectors

Areloch 7 years ago
parent
commit
9ad2e18766

+ 54 - 0
Engine/source/shaderGen/HLSL/customFeatureHLSL.cpp

@@ -48,6 +48,9 @@ void CustomFeatureHLSL::processVert(Vector<ShaderComponent*> &componentList,
 	meta = new MultiLine;
 
 	mFeatureData = fd;
+	mComponentList = componentList;
+
+	mOutputState = VertexOutput;
 
 	if (mOwner->isMethod("processVertHLSL"))
 		Con::executef(mOwner, "processVertHLSL");
@@ -61,6 +64,9 @@ void CustomFeatureHLSL::processPix(Vector<ShaderComponent*> &componentList,
 	meta = new MultiLine;
 
 	mFeatureData = fd;
+	mComponentList = componentList;
+
+	mOutputState = PixelOutput;
 	
 	/*MultiLine *meta = new MultiLine;
 
@@ -322,6 +328,54 @@ void CustomFeatureHLSL::addVariable(String name, String type, String defaultValu
 	}
 }
 
+void CustomFeatureHLSL::addConnector(String name, String elementName, String type)
+{
+	// grab connector texcoord register
+	ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(mComponentList[C_CONNECTOR]);
+
+	//Get element
+	S32 element = -1;
+
+	if (elementName == String("RT_POSITION"))
+		element = RT_POSITION;
+	else if (elementName == String("RT_NORMAL"))
+		element = RT_NORMAL;
+	else if (elementName == String("RT_BINORMAL"))
+		element = RT_BINORMAL;
+	else if (elementName == String("RT_TANGENT"))
+		element = RT_TANGENT;
+	else if (elementName == String("RT_TANGENTW"))
+		element = RT_TANGENTW;
+	else if (elementName == String("RT_COLOR"))
+		element = RT_COLOR;
+	else if (elementName == String("RT_TEXCOORD"))
+		element = RT_TEXCOORD;
+	else if (elementName == String("RT_VPOS"))
+		element = RT_VPOS;
+	else if (elementName == String("RT_SVPOSITION"))
+		element = RT_SVPOSITION;
+	else if (elementName == String("RT_BLENDINDICES"))
+		element = RT_BLENDINDICES;
+	else if (elementName == String("RT_BLENDWEIGHT"))
+		element = RT_BLENDWEIGHT;
+
+	if (element == -1)
+	{
+		Con::errorf("CustomShaderFeatureHLSL::addConnector - Invalid element type %s", elementName.c_str());
+		return;
+	}
+
+	Var *connector = connectComp->getElement((RegisterType)element);
+	connector->setName(name);
+
+	if (mOutputState == VertexOutput)
+		connector->setStructName("OUT");
+	else if(mOutputState == PixelOutput)
+		connector->setStructName("IN");
+
+	connector->setType(type);
+}
+
 void CustomFeatureHLSL::writeLine(String format, S32 argc, ConsoleValueRef *argv)
 {
 	//do the var/arg fetching here

+ 11 - 0
Engine/source/shaderGen/HLSL/customFeatureHLSL.h

@@ -63,9 +63,19 @@ class CustomFeatureHLSL : public ShaderFeatureHLSL
 
 	Vector<VarHolder> mVars;
 
+	enum outputState
+	{
+		NoOutput,
+		VertexOutput,
+		PixelOutput
+	};
+
+	outputState mOutputState;
+
 public:
 	CustomShaderFeatureData* mOwner;
 
+	Vector<ShaderComponent*> mComponentList;
 	MaterialFeatureData mFeatureData;
 
 protected:
@@ -108,5 +118,6 @@ public:
 	void addVariable(String name, String type, String defaultValue);
 	void addSampler(String name, String type, U32 arraySize = 0);
 	void addTexture(String name, String type, String samplerState, U32 arraySize);
+	void addConnector(String name, String elementName, String type);
 	void writeLine(String format, S32 argc, ConsoleValueRef *argv);
 };

+ 5 - 0
Engine/source/shaderGen/customShaderFeature.cpp

@@ -104,6 +104,11 @@ void CustomShaderFeatureData::addTexture(String name, String type, String sample
 	mFeatureHLSL->addTexture(name, type, samplerState, arraySize);
 }
 
+void CustomShaderFeatureData::addConnector(String name, String elementName, String type)
+{
+	mFeatureHLSL->addConnector(name, elementName, type);
+}
+
 bool CustomShaderFeatureData::hasFeature(String name)
 {
 	return mFeatureHLSL->hasFeature(name);

+ 1 - 0
Engine/source/shaderGen/customShaderFeature.h

@@ -64,6 +64,7 @@ public:
 	void addUniform(String name, String type, String defaultValue, U32 arraySize);
 	void addSampler(String name, String type, U32 arraySize);
 	void addTexture(String name, String type, String samplerState, U32 arraySize);
+	void addConnector(String name, String elementName, String type);
 
 	bool hasFeature(String name);