public void Test_08_Ratio() { SymbolicExpression ident = new SymbolicExpression("symbolic"); Ratio <SymbolicValue> symbolicRatio = new Ratio <SymbolicValue>(ident); Assert.AreEqual("RATIO(symbolic)", symbolicRatio.ToString(), "Error in Ratio<SymbolicValue> from SymbolicExpression."); FunctionInvocation <int> f = new FunctionInvocation <int>( delegate(object[] parameters) { int sum = 0; foreach (object parameter in parameters) { sum += (int)parameter; } return(new NumericValue(sum)); }, 5, 7, 8); Ratio <Value> funcInvRatio = new Ratio <Value>(f); Assert.AreEqual("RATIO(<Test_08_Ratio>b__b(5,7,8))", funcInvRatio.ToString(), "Error in Ratio<Value> from FunctionInvocation<int>."); NumericExpression n = new NumericExpression(6.7); Percentage <NumericValue> numPerc = new Percentage <NumericValue>(n); Ratio <NumericValue> percNumRatio = new Ratio <NumericValue>(numPerc); Assert.AreEqual("RATIO(6.7%)", percNumRatio.ToString(), "Error in Ratio<NumericValue> from Percentage<NumericValue>."); }
public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation, [FromServices] IScriptJobHost scriptHost) { if (invocation == null) { return(BadRequest()); } FunctionDescriptor function = scriptHost.GetFunctionOrNull(name); if (function == null) { return(NotFound()); } ParameterDescriptor inputParameter = function.Parameters.First(p => p.IsTrigger); Dictionary <string, object> arguments = new Dictionary <string, object>() { { inputParameter.Name, invocation.Input } }; Task.Run(async() => { IDictionary <string, object> loggerScope = new Dictionary <string, object> { { "MS_IgnoreActivity", null } }; using (_logger.BeginScope(loggerScope)) { await scriptHost.CallAsync(function.Name, arguments); } }); return(Accepted()); }
public static object Defun(FunctionInvocation call) { var func = call.Args[1] as SymbolNode; var definedArgs = call.Args[2] as ConsNode; //ConsNode definedBody = call.Args[3] as ConsNode; ConsNode definedBody = WrapInProgn(call.Args, 3, call.StackFrame.Root); Scope creatorScope = call.StackFrame.Scope; LispFunc lispFunc = kall => { //if (kall.Args.Count - 1 < definedArgs.Args.Count) //{ // LispFunc curryFunc = MakeCurryCall(call, definedArgs, definedBody, kall); // return curryFunc; //} //else //{ Scope oldScope = kall.StackFrame.Scope; var newScope = new Scope(creatorScope); Utils.SetupArgs(definedArgs, kall, newScope); kall.StackFrame.Scope = newScope; //call the body object res = definedBody.Eval(kall.StackFrame); //tail recursion int recursions = 0; while (res is TailRecursionValue) { recursions++; var tail = res as TailRecursionValue; var tailCons = tail.Expression as ConsNode; newScope = new Scope(creatorScope); kall.Args = tailCons.Args; Utils.SetupArgs(definedArgs, kall, newScope); kall.StackFrame.Scope = newScope; res = definedBody.Eval(kall.StackFrame); } Utils.TearDownArgs(definedArgs, kall); kall.StackFrame.Scope = oldScope; return(res); //} }; call.StackFrame.Scope.SetSymbolValue(func.Name, lispFunc); // FunctionMeta meta = call.StackFrame.Root.GetFunctionMeta(lispFunc); // meta.ParameterCount = definedArgs.Args.Count; return(null); }
public static object Progn(FunctionInvocation call) { object res = null; string funcName = "progn"; call.Args.GetRange(1, call.Args.Count - 1).ForEach(arg => res = Utils.Eval(call.StackFrame, arg)); return(res); }
public static object EnsureNotLazy(FunctionInvocation call) { object res = Utils.Eval(call.StackFrame, call.Args[1]); res = Utils.Force(res); return(res); }
public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation, [FromServices] IScriptJobHost scriptHost) { if (invocation == null) { return(BadRequest()); } FunctionDescriptor function = scriptHost.GetFunctionOrNull(name); if (function == null) { return(NotFound()); } ParameterDescriptor inputParameter = function.Parameters.First(p => p.IsTrigger); Dictionary <string, object> arguments = new Dictionary <string, object>() { { inputParameter.Name, invocation.Input } }; // LiveLogs session id is used to show only contextual logs in the "Code + Test" experience. string sessionId = this.Request?.Headers[ScriptConstants.LiveLogsSessionAIKey]; using (System.Threading.ExecutionContext.SuppressFlow()) { Task.Run(async() => { IDictionary <string, object> loggerScope = new Dictionary <string, object> { { "MS_IgnoreActivity", null } }; using (_logger.BeginScope(loggerScope)) { if (!string.IsNullOrWhiteSpace(sessionId)) { // Current activity is null due to SuppressFlow. Start a new activity and set baggage so that it's included in the custom dimensions. Activity activity = new Activity($"{nameof(FunctionsController)}.Invoke"); activity?.Start(); activity?.AddBaggage(ScriptConstants.LiveLogsSessionAIKey, sessionId); try { await scriptHost.CallAsync(function.Name, arguments); } finally { activity?.Stop(); } } else { await scriptHost.CallAsync(function.Name, arguments); } } }); } return(Accepted()); }
public static object Format(FunctionInvocation call) { object[] args = call.Args.GetRange(2, call.Args.Count - 2).Select(arg => Utils.Eval(call.StackFrame, arg)).ToArray(); var format = Utils.Eval(call.StackFrame, call.Args[1]) as string; string res = string.Format(format, args); return(res); }
public async Task Invoke_CallsFunction() { var testFunctions = new Collection <FunctionDescriptor>(); string testFunctionName = "TestFunction"; string triggerParameterName = "testTrigger"; string testInput = Guid.NewGuid().ToString(); bool functionInvoked = false; var scriptHostMock = new Mock <IScriptJobHost>(); scriptHostMock.Setup(p => p.CallAsync(It.IsAny <string>(), It.IsAny <IDictionary <string, object> >(), CancellationToken.None)) .Callback <string, IDictionary <string, object>, CancellationToken>((name, args, token) => { // verify the correct arguments were passed to the invoke Assert.Equal(testFunctionName, name); Assert.Equal(1, args.Count); Assert.Equal(testInput, (string)args[triggerParameterName]); functionInvoked = true; }) .Returns(Task.CompletedTask); scriptHostMock.Setup(p => p.Functions).Returns(testFunctions); // Add a few parameters, with the trigger parameter last // to verify parameter order handling Collection <ParameterDescriptor> parameters = new Collection <ParameterDescriptor> { new ParameterDescriptor("context", typeof(ExecutionContext)), new ParameterDescriptor("log", typeof(TraceWriter)), new ParameterDescriptor(triggerParameterName, typeof(string)) { IsTrigger = true } }; testFunctions.Add(new FunctionDescriptor(testFunctionName, null, null, parameters, null, null, null)); FunctionInvocation invocation = new FunctionInvocation { Input = testInput }; var functionsManagerMock = new Mock <IWebFunctionsManager>(); var mockRouter = new Mock <IWebJobsRouter>(); var testController = new FunctionsController(functionsManagerMock.Object, mockRouter.Object, new LoggerFactory()); IActionResult response = testController.Invoke(testFunctionName, invocation, scriptHostMock.Object); Assert.IsType <AcceptedResult>(response); // The call is fire-and-forget, so watch for functionInvoked to be set. await TestHelpers.Await(() => functionInvoked, timeout : 3000, pollingInterval : 100); Assert.True(functionInvoked); }
public static object IsEmpty(FunctionInvocation call) { var list = Utils.Eval(call.StackFrame, call.Args[1]) as IEnumerable; foreach (object item in list) { return(false); } return(true); }
public static object Car(FunctionInvocation call) { var list = Utils.Eval(call.StackFrame, call.Args[1]) as IEnumerable; foreach (object item in list) { return(item); } return(null); //list was empty }
public static object Hash(FunctionInvocation call) { var res = new Hashtable(); foreach (ConsNode node in call.Args.GetRange(1, call.Args.Count - 1)) { object key = Utils.Eval(call.StackFrame, call.Args[0]); object value = Utils.Eval(call.StackFrame, call.Args[1]); res[key] = value; } return(res); }
public static object Include(FunctionInvocation call) { var path = Utils.Eval(call.StackFrame, call.Args[1]) as string; string code = ""; using (var sr = new StreamReader(path, Encoding.Default)) { code = sr.ReadToEnd(); } return(call.StackFrame.Root.Engine.EvaluateString(code, path)); }
public TestFunctionContext(FunctionDefinition functionDefinition, FunctionInvocation invocation) { FunctionDefinition = functionDefinition; _invocation = invocation; Features.Set <IFunctionBindingsFeature>(new TestFunctionBindingsFeature { OutputBindingsInfo = new DefaultOutputBindingsInfoProvider().GetBindingsInfo(FunctionDefinition) }); BindingContext = new DefaultBindingContext(this); }
protected override string InputParameterType(int i, Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(TypesHelper.DotNetTypeToXgrsType(action.RulePattern.Inputs[i])); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.InputVariables[i].Type); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(TypesHelper.DotNetTypeToXgrsType(seqDef.SeqInfo.ParameterTypes[i])); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(procDef.Inputs[i])); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(TypesHelper.DotNetTypeToXgrsType(procInvocationInterpreted.ProcedureDef.Inputs[i])); } } else if (invocation is FunctionInvocation) { FunctionInvocation funcInvocation = (FunctionInvocation)invocation; if (ownerType != null) { IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(funcDef.Inputs[i])); } else { SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation; return(TypesHelper.DotNetTypeToXgrsType(funcInvocationInterpreted.FunctionDef.Inputs[i])); } } throw new Exception("Internal error"); }
protected override int NumInputParameters(Invocation invocation, InheritanceType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(action.RulePattern.Inputs.Length); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.InputVariables.Length); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(seqDef.SeqInfo.ParameterTypes.Length); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(procDef.Inputs.Length); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(procInvocationInterpreted.ProcedureDef.Inputs.Length); } } else if (invocation is FunctionInvocation) { FunctionInvocation funcInvocation = (FunctionInvocation)invocation; if (ownerType != null) { IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name); return(funcDef.Inputs.Length); } else { SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation; return(funcInvocationInterpreted.FunctionDef.Inputs.Length); } } throw new Exception("Internal error"); }
public static object If(FunctionInvocation call) { object condition = Utils.Eval(call.StackFrame, call.Args[1]); if (Utils.IsTrue(condition)) { return(Utils.Eval(call.StackFrame, call.Args[2])); } else { return(Utils.Eval(call.StackFrame, call.Args[3])); } }
private FunctionContext CreateContext(FunctionDefinition definition = null, FunctionInvocation invocation = null) { invocation = invocation ?? new TestFunctionInvocation(id: "1234", functionId: "test"); // We're controlling the method via the IMethodInfoLocator, so the strings here don't matter. var parameters = _mockLocator.Object.GetMethod(string.Empty, string.Empty) .GetParameters() .Select(p => new FunctionParameter(p.Name, p.ParameterType)); definition = definition ?? new TestFunctionDefinition(parameters: parameters); return(new TestFunctionContext(definition, invocation)); }
public static object Is(FunctionInvocation call) { object target = Utils.Eval(call.StackFrame, call.Args[1]); var type = Utils.Eval(call.StackFrame, call.Args[2]) as Type; if (type.IsAssignableFrom(target.GetType())) { return(true); } else { return(false); } }
public static object Tail(FunctionInvocation call) { var ci = new CloneInfo(); ci.LocalIdentifiers = new List <string>(); ci.StackFrame = call.StackFrame; object clone = Utils.Clone(ci, call.Args[1]); var tail = new TailRecursionValue(clone); return(tail); }
private bool AddPsInvocations(Function psMain, int groupOrder) { FunctionInvocation funcInvocation = null; int internalCounter = 0; funcInvocation = new FunctionInvocation(SGXFuncInstancedViewportsDiscardOutOfBounds, groupOrder, internalCounter++); funcInvocation.PushOperand(this.psInMonitorsCount, Operand.OpSemantic.In); funcInvocation.PushOperand(this.psInMonitorIndex, Operand.OpSemantic.In); funcInvocation.PushOperand(this.psInPositionProjectiveSpace, Operand.OpSemantic.In); psMain.AddAtomInstance(funcInvocation); return(true); }
public static object While(FunctionInvocation call) { var condition = (bool)Utils.Eval(call.StackFrame, call.Args[1]); while (condition) { for (int i = 2; i < call.Args.Count; i++) { Utils.Eval(call.StackFrame, call.Args[i]); } condition = (bool)Utils.Eval(call.StackFrame, call.Args[1]); } return(null); }
static IExpression CreateFunctionInvocation( IFunctionInstance function, TextFileRange range, INamedExpressionTuple leftArguments, INamedExpressionTuple rightArguments) { var invocation = new FunctionInvocation { Function = function, Range = range, Left = AssignArguments(function.LeftArguments, leftArguments), Right = AssignArguments(function.RightArguments, rightArguments) }; return(invocation); }
public static object NewThread(FunctionInvocation call) { var func = Utils.Eval(call.StackFrame, call.Args[1]) as LispFunc; var args = new List <object>(); args.Add(new SymbolNode()); var kall = new FunctionInvocation(func, args, call.StackFrame.Root.StackFrame); var thread = new Thread(() => func(kall)); thread.IsBackground = true; thread.Priority = ThreadPriority.Lowest; return(thread); }
public static void TearDownArgs(ConsNode definedArgs, FunctionInvocation call) { //int i = 1; ////tear down args //foreach (IdentifierNode arg in definedArgs.Args) //{ // string argName = arg.Name; // if (argName.StartsWith("*")) // { // argName = argName.Substring(1); // call.StackFrame.PopSymbol(argName); // } // else if (argName.StartsWith("!")) // { // argName = argName.Substring(1); // call.StackFrame.PopSymbol(argName); // } // else if (argName.StartsWith("#")) // { // argName = argName.Substring(1); // call.StackFrame.PopSymbol(argName); // } // else if (argName.StartsWith("@")) // { // argName = argName.Substring(1); // call.StackFrame.PopSymbol(argName); // } // else if (argName.StartsWith(":")) // { // } // else // { // call.StackFrame.PopSymbol(argName); // } // i++; //} ////for (int j = i; j < call.Args.Count; j++) ////{ //// ValueNode node = call.Args[j]; //// string argName = string.Format("arg{0}", j); //// stack.PopSymbol(argName); ////} }
internal override bool CreateCpuSubPrograms(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; //Resolve world view proj matrix UniformParameter wvpMatrix = vsProgram.ResolveAutoParameterInt(Graphics.GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0); if (wvpMatrix == null) { return(false); } Function vsEntry = vsProgram.EntryPointFunction; //Resolve input position parameter Parameter positionIn = vsEntry.ResolveInputParameter(Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4); if (positionIn == null) { return(false); } //Resolve output position parameter Parameter positionOut = vsEntry.ResolveOutputParameter(Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionProjectiveSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4); if (positionOut == null) { return(false); } //Add dependency vsProgram.AddDependency(FFPRenderState.FFPLibTransform); var transformFunc = new FunctionInvocation(FFPRenderState.FFPFuncTransform, -1, 0); transformFunc.PushOperand(wvpMatrix, Operand.OpSemantic.In); transformFunc.PushOperand(positionIn, Operand.OpSemantic.In); transformFunc.PushOperand(positionOut, Operand.OpSemantic.Out); vsEntry.AddAtomInstance(transformFunc); return(true); }
public static object LessOrEqualTo(FunctionInvocation call) { var left = Utils.Eval(call.StackFrame, call.Args[1]) as IComparable; object tmpRight = Utils.Eval(call.StackFrame, call.Args[2]); object castRight = Convert.ChangeType(tmpRight, left.GetType()); var right = castRight as IComparable; if (left.CompareTo(right) <= 0) { return(true); } else { return(false); } }
public async Task Invoke_CallsFunction() { string testFunctionName = "TestFunction"; string triggerParameterName = "testTrigger"; string testInput = Guid.NewGuid().ToString(); bool functionInvoked = false; hostMock.Setup(p => p.CallAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >(), CancellationToken.None)) .Callback <string, Dictionary <string, object>, CancellationToken>((name, args, token) => { functionInvoked = true; // verify the correct arguments were passed to the invoke Assert.Equal(testFunctionName, name); Assert.Equal(1, args.Count); Assert.Equal(testInput, (string)args[triggerParameterName]); }) .Returns(Task.CompletedTask); // Add a few parameters, with the trigger parameter last // to verify parameter order handling Collection <ParameterDescriptor> parameters = new Collection <ParameterDescriptor> { new ParameterDescriptor("context", typeof(ExecutionContext)), new ParameterDescriptor("log", typeof(TraceWriter)), new ParameterDescriptor(triggerParameterName, typeof(string)) { IsTrigger = true } }; testFunctions.Add(new FunctionDescriptor(testFunctionName, null, null, parameters, null, null, null)); FunctionInvocation invocation = new FunctionInvocation { Input = testInput }; IActionResult response = testController.Invoke(testFunctionName, invocation); Assert.IsType <AcceptedResult>(response); // allow the invoke task to run await Task.Delay(200); Assert.True(functionInvoked); }
public static object Delay(FunctionInvocation call) { var ci = new CloneInfo(); ci.LocalIdentifiers = new List <string>(); ci.StackFrame = call.StackFrame; object clone = Utils.Clone(ci, call.Args[1]); var lazy = new LazyValue(() => { object result = Utils.Eval(call.StackFrame, clone); return(Utils.Force(result)); }); return(lazy); }
public void Test_05_FunctionInvocation() { FunctionInvocation <int> f = new FunctionInvocation <int>( delegate(object[] parameters) { int sum = 0; foreach (object parameter in parameters) { sum += (int)parameter; } return(new NumericValue(sum)); }, 5, 7, 8); Assert.AreEqual("20", f.GetValue().ToString(), "Error: wrong execution of delegate function in {0}", "FunctionInvocation<int>"); }
public static object Reverse(FunctionInvocation call) { var list = Utils.Eval(call.StackFrame, call.Args[1]) as IEnumerable; var res = new List <object>(); foreach (object item in list) { res.Add(item); } res.Reverse(); ConsNode resNode = Utils.NewCons(call.StackFrame.Root); resNode.Args = res; return(resNode); }
internal override bool CreateCpuSubPrograms( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; //Resolve world view proj matrix UniformParameter wvpMatrix = vsProgram.ResolveAutoParameterInt( Graphics.GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0 ); if ( wvpMatrix == null ) { return false; } Function vsEntry = vsProgram.EntryPointFunction; //Resolve input position parameter Parameter positionIn = vsEntry.ResolveInputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionObjectSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); if ( positionIn == null ) { return false; } //Resolve output position parameter Parameter positionOut = vsEntry.ResolveOutputParameter( Parameter.SemanticType.Position, 0, Parameter.ContentType.PositionProjectiveSpace, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); if ( positionOut == null ) { return false; } //Add dependency vsProgram.AddDependency( FFPRenderState.FFPLibTransform ); var transformFunc = new FunctionInvocation( FFPRenderState.FFPFuncTransform, -1, 0 ); transformFunc.PushOperand( wvpMatrix, Operand.OpSemantic.In ); transformFunc.PushOperand( positionIn, Operand.OpSemantic.In ); transformFunc.PushOperand( positionOut, Operand.OpSemantic.Out ); vsEntry.AddAtomInstance( transformFunc ); return true; }
private void AddPSModifierInvocation( Function psMain, int samplerIndex, Parameter arg1, Parameter arg2, int groupOrder, ref int internalCounter, int targetChanells ) { SourceModifier modType; int customNum; if ( GetSourceModifier( samplerIndex, out modType, out customNum ) == true ) { Parameter modifiedParam = null; string funcName = string.Empty; switch ( modType ) { case SourceModifier.Source1Modulate: funcName = "SGX_src_mod_modulate"; modifiedParam = arg1; break; case SourceModifier.Source2Modulate: funcName = "SGX_src_mod_modulate"; modifiedParam = arg2; break; case SourceModifier.Source1InvModulate: funcName = "SGX_src_mod_inv_modulate"; modifiedParam = arg1; break; case SourceModifier.Source2InvModulate: funcName = "SGX_src_mod_inv_modulate"; modifiedParam = arg2; break; default: break; } //add the function of the blend mode if ( funcName != string.Empty ) { Parameter controlParam = this.textureBlends[ samplerIndex ].ModControlParam; var curFuncInvocation = new FunctionInvocation( funcName, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( modifiedParam, Operand.OpSemantic.In, targetChanells ); curFuncInvocation.PushOperand( controlParam, Operand.OpSemantic.In, targetChanells ); curFuncInvocation.PushOperand( modifiedParam, Operand.OpSemantic.Out, targetChanells ); psMain.AddAtomInstance( curFuncInvocation ); } } }
internal bool AddPSIlluminationInvocation( LightParams curLightParams, Function psMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; //merge diffuse color with vertex color if need to if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) != 0 ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } //merge specular color with vertex color if need to if ( this.specularEnable && ( this.trackVertexColorType & TrackVertexColor.Specular ) != 0 ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } switch ( curLightParams.Type ) { case LightType.Directional: if ( this.specularEnable ) { curFuncInvocation = new FunctionInvocation( SGXFuncLightDirectionalDiffuseSpecular, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } else { curFuncInvocation = new FunctionInvocation( SGXFuncLightDirectionalDiffuse, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } break; case LightType.Point: if ( this.specularEnable ) { curFuncInvocation = new FunctionInvocation( SGXFuncLightPointDiffuseSpecular, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } else { curFuncInvocation = new FunctionInvocation( SGXFuncLightPointDiffuse, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } break; case LightType.Spotlight: if ( this.specularEnable ) { curFuncInvocation = new FunctionInvocation( SGXFuncLightSpotDiffuseSpecular, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.SpotParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.SpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.surfaceShininess, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); } else { curFuncInvocation = new FunctionInvocation( SGXFuncLightSpotDiffuse, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInViewPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.AttenuatParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.SpotParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.DiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } break; } return true; }
private bool AddPSGlobalIlluminationInvocation( Function psMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) == 0 && ( this.trackVertexColorType & TrackVertexColor.Emissive ) == 0 ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.derivedSceneColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } else { if ( ( this.trackVertexColorType & TrackVertexColor.Ambient ) != 0 ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.lightAmbientColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } else { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.derivedAmbientLightColor, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } if ( ( this.trackVertexColorType & TrackVertexColor.Emissive ) != 0 ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } else { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.surfaceEmissiveColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } } if ( this.specularEnable ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } return true; }
private void WriteProgramDependencies( StreamWriter stream, Program program ) { for ( int i = 0; i < program.DependencyCount; i++ ) { string curDependency = program.GetDependency( i ); CacheDependencyFunctions( curDependency ); } stream.WriteLine( "//-----------------------------------------------------------------------------" ); stream.WriteLine( "// PROGRAM DEPENDENCIES" ); stream.WriteLine(); var forwardDecl = new List<FunctionInvocation>(); var functionList = program.Functions; int itFunction = 0; Function curFunction = functionList[ 0 ]; var atomInstances = curFunction.AtomInstances; int itAtom = 0; int itAtomEnd = atomInstances.Count; //Now iterate over all function atoms for ( ; itAtom != itAtomEnd; itAtom++ ) { //Skip non function invocation atom if ( atomInstances[ itAtom ] is FunctionInvocation == false ) { continue; } var funcInvoc = atomInstances[ itAtom ] as FunctionInvocation; forwardDecl.Add( funcInvoc ); // Now look into that function for other non-builtin functions and add them to the declaration list // Look for non-builtin functions // Do so by assuming that these functions do not have several variations. // Also, because GLSL is C based, functions must be defined before they are used // so we can make the assumption that we already have this function cached. // // If we find a function, look it up in the map and write it out DiscoverFunctionDependencies( funcInvoc, forwardDecl ); } //Now remove duplicate declarations forwardDecl.Sort(); forwardDecl = forwardDecl.Distinct( new FunctionInvocation.FunctionInvocationComparer() ).ToList(); for ( int i = 0; i < program.DependencyCount; i++ ) { string curDependency = program.GetDependency( i ); foreach ( var key in this.definesMap.Keys ) { if ( this.definesMap[ key ] == curDependency ) { stream.Write( this.definesMap[ key ] ); stream.Write( "\n" ); } } } // Parse the source shader and write out only the needed functions foreach ( var it in forwardDecl ) { var invoc = new FunctionInvocation( string.Empty, 0, 0, string.Empty ); string body = string.Empty; //find the function in the cache foreach ( var key in this.functionCacheMap.Keys ) { if ( !( it == key ) ) { continue; } invoc = key; body = this.functionCacheMap[ key ]; break; } if ( invoc.FunctionName.Length > 0 ) { //Write out the funciton name from the cached FunctionInvocation stream.Write( invoc.ReturnType ); stream.Write( " " ); stream.Write( invoc.FunctionName ); stream.Write( "(" ); int itOperand = 0; int itOperandEnd = invoc.OperandList.Count; while ( itOperand != itOperandEnd ) { Operand op = invoc.OperandList[ itOperand ]; Operand.OpSemantic opSemantic = op.Semantic; string paramName = op.Parameter.Name; int opMask = op.Mask; GpuProgramParameters.GpuConstantType gpuType = GpuProgramParameters.GpuConstantType.Unknown; switch ( opSemantic ) { case Operand.OpSemantic.In: stream.Write( "in " ); break; case Operand.OpSemantic.Out: stream.Write( "out " ); break; case Operand.OpSemantic.InOut: stream.Write( "inout " ); break; default: break; } //Swizzle masks are onluy defined for types like vec2, vec3, vec4 if ( opMask == (int)Operand.OpMask.All ) { gpuType = op.Parameter.Type; } else { gpuType = Operand.GetGpuConstantType( opMask ); } //We need a valid type otherwise glsl compilation will not work if ( gpuType == GpuProgramParameters.GpuConstantType.Unknown ) { throw new Core.AxiomException( "Cannot convert Operand.OpMask to GpuConstantType" ); } stream.Write( this.gpuConstTypeMap[ gpuType ] + " " + paramName ); itOperand++; //Prepare for the next operand if ( itOperand != itOperandEnd ) { stream.Write( ", " ); } } stream.WriteLine(); stream.WriteLine( "{" ); stream.WriteLine( body ); stream.WriteLine( "}" ); stream.WriteLine(); } } }
protected virtual void AddPSBlendInvocations( Function psMain, Parameter arg1, Parameter arg2, Parameter texel, int samplerIndex, LayerBlendModeEx blendMode, int groupOrder, ref int internalCounter, int targetChannels ) { FunctionInvocation curFuncInvocation = null; switch ( blendMode.operation ) { case LayerBlendOperationEx.Add: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.AddSigned: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAddSigned, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.AddSmooth: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAddSmooth, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.BlendCurrentAlpha: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); if ( samplerIndex == 0 ) { curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In, Operand.OpMask.W ); } else { curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In, Operand.OpMask.W ); } curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.BlendDiffuseAlpha: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSubtract, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In, Operand.OpMask.W ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.BlendDiffuseColor: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.BlendManual: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, groupOrder, internalCounter ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( blendMode.blendFactor ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.BlendTextureAlpha: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( texel, Operand.OpSemantic.In, Operand.OpMask.W ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.DotProduct: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncDotProduct, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.Modulate: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.ModulateX2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulateX2, groupOrder, internalCounter ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.ModulateX4: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulateX4, groupOrder, internalCounter ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.Source1: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.Source2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendOperationEx.Subtract: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSubtract, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); break; } }
private bool AddPSInvocation( Program psProgram, int groupOrder, ref int internalCounter ) { Function psMain = psProgram.EntryPointFunction; FunctionInvocation curFuncInvocation = null; ShadowTextureParams splitParams0 = this.shadowTextureParamsList[ 0 ]; ShadowTextureParams splitParams1 = this.shadowTextureParamsList[ 1 ]; ShadowTextureParams splitParams2 = this.shadowTextureParamsList[ 2 ]; //Compute shadow factor curFuncInvocation = new FunctionInvocation( SGXFuncComputeShadowColor3, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psInDepth, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psSplitPoints, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams0.PSInLightPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams1.PSInLightPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams2.PSInLightPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams0.TextureSampler, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams1.TextureSampler, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams2.TextureSampler, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams0.InvTextureSize, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams1.InvTextureSize, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( splitParams2.InvTextureSize, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psLocalShadowFactor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); //Apply shadow factor on diffuse color curFuncInvocation = new FunctionInvocation( SGXFuncApplyShadowFactorDiffuse, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDerivedSceneColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psLocalShadowFactor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psLocalShadowFactor, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); //Apply shadow factor on specular color curFuncInvocation = new FunctionInvocation( SGXFuncModulateScalar, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psLocalShadowFactor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); //Assign the local diffuse to output diffuse curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); return true; }
private bool AddVSInvocation( Function vsMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation; //Output the vertex depth in camera space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsOutPos, Operand.OpSemantic.In, Operand.OpMask.Z ); curFuncInvocation.PushOperand( this.vsOutDepth, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //compute world space position foreach ( var it in this.shadowTextureParamsList ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( it.WorldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( it.VSOutLightPosition, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } return true; }
protected bool AddVSInvocation( Function vsMain, int groupOrder, int internalCounter ) { FunctionInvocation curFuncInvocation = null; //Construct TNB matrix. if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { curFuncInvocation = new FunctionInvocation( SGXFuncConstructTbnMatrix, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInTangent, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //Output texture coordinates curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsInTexcoord, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutTexcoord, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //computer world space position if ( this.vsWorldPosition != null ) { curFuncInvocation = new FunctionInvocation( SGXFuncTransformPosition, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.worldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsWorldPosition, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //compute the view vector if ( this.vsInPosition != null && this.vsOutView != null ) { //View vector in world space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSubtract, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.camPosWorldSpace, Operand.OpSemantic.In, ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.vsWorldPosition, Operand.OpSemantic.In, ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Transform to object space. curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.worldInvRotMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Transform to tangent space if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutView, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //output object space else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutView, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } } //Add per light functions for ( int i = 0; i < this.lightParamsList.Count; i++ ) { if ( AddVSIlluminationInvocation( this.lightParamsList[ i ], vsMain, groupOrder, ref internalCounter ) == false ) { return false; } } return true; }
internal bool AddVSIlluminationInvocation( LightParams curLightParams, Function vsMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; //Computer light direction in texture space. if ( curLightParams.Direction != null && curLightParams.VSOutDirection != null ) { //Transform to texture space. if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.VSOutDirection, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //Output object space else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( curLightParams.Direction, Operand.OpSemantic.In, ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( curLightParams.VSOutDirection, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } } //Transform light vector to target space if ( curLightParams.Position != null && curLightParams.VSOutToLightDir != null ) { //Compute light vector. curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSubtract, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( curLightParams.Position, Operand.OpSemantic.In, ( (int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.vsWorldPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Transform to object space curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.worldInvRotMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Tangent ) { curFuncInvocation = new FunctionInvocation( SGXFuncTranformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsTBNMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.VSOutToLightDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //Output object space else if ( this.normalMapSpace == RTShaderSystem.NormalMapSpace.Object ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.vsLocalDir, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( curLightParams.VSOutToLightDir, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } } return true; }
private void DiscoverFunctionDependencies( FunctionInvocation invoc, List<FunctionInvocation> depVector ) { string body = string.Empty; foreach ( var key in this.functionCacheMap.Keys ) { if ( invoc == key ) { continue; } body = this.functionCacheMap[ key ]; break; } if ( body != string.Empty ) { //Trim whitespace body = body.Trim(); string[] tokens = body.Split( '(' ); foreach ( var it in tokens ) { string[] moreTokens = it.Split( ' ' ); foreach ( var key in this.functionCacheMap.Keys ) { if ( key.FunctionName == moreTokens[ moreTokens.Length - 1 ] ) { //Add the function declaration depVector.Add( key ); DiscoverFunctionDependencies( key, depVector ); } } } } else { Axiom.Core.LogManager.Instance.DefaultLog.Write( "ERROR: Cached function not found " + invoc.FunctionName ); } }
protected bool AddPSNormalFetchInvocation( Function psMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; curFuncInvocation = new FunctionInvocation( SGXFuncFetchNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.normalMapSampler, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInTexcoord, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psNormal, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); return true; }
private void AddPositionCalculations( Function vsMain, ref int funcCounter ) { FunctionInvocation curFuncInvocation = null; if ( doBoneCalculations ) { if ( scalingShearingSupport ) { //Construct a scaling and shearing matrix based on the blend weights for ( int i = 0; i < WeightCount; i++ ) { //Assign the local param based on the current index of the scaling and shearing matrices curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramInScaleShearMatrices, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInIndices, Operand.OpSemantic.In, (int)IndexToMask( i ), 1 ); curFuncInvocation.PushOperand( this.paramTempFloat3x4, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Calculate the resultant scaling and shearing matrix based on the weigts given AddIndexedPositionWeight( vsMain, i, this.paramTempFloat3x4, this.paramTempFloat3x4, this.paramBlendS, ref funcCounter ); } //Transform the position based on the scaling and shearing matrix curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramBlendS, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.paramLocalBlendPosition, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //Assign the input position to the local blended position curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In, (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.paramLocalBlendPosition, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //Set functions to calculate world position for ( int i = 0; i < weightCount; i++ ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInIndices, Operand.OpSemantic.In, (int)IndexToMask( i ) ); curFuncInvocation.PushOperand( this.paramIndex1, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //multiply the index by 2 curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 2.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex1, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex1, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Add 1 to the index and assign as the second row's index curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex1, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex2, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Build the dual quaternion matrix curFuncInvocation = new FunctionInvocation( DualQuaternionSkinning.SGXFuncBuildDualQuaternionMatrix, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrices, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex1, Operand.OpSemantic.In, (int)Operand.OpMask.All, 1 ); curFuncInvocation.PushOperand( paramInWorldMatrices, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramIndex2, Operand.OpSemantic.In, (int)Operand.OpMask.All, 1 ); curFuncInvocation.PushOperand( this.paramTempFloat2x4, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); if ( correctAntipodalityHandling ) { AdjustForCorrectAntipodality( vsMain, i, ref funcCounter, this.paramTempFloat2x4 ); } //Calculate the resultant dual quaternion based based on the weights given AddIndexedPositionWeight( vsMain, i, this.paramTempFloat2x4, this.paramTempFloat2x4, this.paramBlendDQ, ref funcCounter ); } //Normalize the dual quaternion curFuncInvocation = new FunctionInvocation( DualQuaternionSkinning.SGXFuncNormalizeDualQuaternion, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramBlendDQ, Operand.OpSemantic.InOut ); vsMain.AddAtomInstance( curFuncInvocation ); //Calculate the blend position curFuncInvocation = new FunctionInvocation( DualQuaternionSkinning.SGXFuncCalculateBlendPosition, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramLocalBlendPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramBlendDQ, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Update from object to projective space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramOutPositionProj, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //update from object to world space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrices, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //update from object to projective space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramOutPositionProj, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
private void AddIndexedNormalRelatedWeight( Function vsMain, Parameter normalRelatedParam, Parameter normalWorldRelatedParam, int index, ref int funcCounter ) { FunctionInvocation curFuncInvocation; Operand.OpMask indexMask = IndexToMask( index ); //multiply position with world matrix and put into temporary param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrices, Operand.OpSemantic.In, (int)Operand.OpMask.All ); curFuncInvocation.PushOperand( paramInIndices, Operand.OpSemantic.In, (int)indexMask, 1 ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramTempFloat3, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //multiply temporary param with weight curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat3, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInWeights, Operand.OpSemantic.In, (int)indexMask ); curFuncInvocation.PushOperand( paramTempFloat3, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //check if on first iteration if ( index == 0 ) { //set the local param as the value of the world normal curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat3, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //add the local param as the value of the world normal curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat3, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
protected virtual void AddPSArgumentInvocations( Function psMain, Parameter arg, Parameter texel, int samplerIndex, LayerBlendSource blendSrc, ColorEx colorValue, Real alphaValue, bool isAlphaArgument, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; switch ( blendSrc ) { case LayerBlendSource.Current: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); if ( samplerIndex == 0 ) { curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); } else { curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); } curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Texture: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( texel, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Specular: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Diffuse: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( arg, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); break; case LayerBlendSource.Manual: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, groupOrder, internalCounter++ ); if ( isAlphaArgument ) { curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( alphaValue ), Operand.OpSemantic.In ); } else { curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.r ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.g ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.b ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( colorValue.a ), Operand.OpSemantic.In ); } curFuncInvocation.PushOperand( arg, Operand.OpSemantic.In ); psMain.AddAtomInstance( curFuncInvocation ); break; } }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { if ( this.fogMode == FogMode.None ) { return true; } Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; FunctionInvocation curFuncInvocation = null; int internalCounter = 0; //Per pixel fog if ( this.calcMode == CalcMode.PerPixel ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogDepth, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); curFuncInvocation.PushOperand( this.worldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutDepth, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); internalCounter = 0; switch ( this.fogMode ) { case FogMode.Exp: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogLinear, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; case FogMode.Exp2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogExp, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; case FogMode.Linear: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncPixelFogExp2, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); break; default: break; } curFuncInvocation.PushOperand( this.psInDepth, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } else //Per vertex fog { internalCounter = 0; switch ( this.fogMode ) { case FogMode.Exp: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogLinear, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; case FogMode.Exp2: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogExp, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; case FogMode.Linear: curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncVertexFogExp2, (int)FFPRenderState.FFPVertexShaderStage.VSFog, internalCounter++ ); break; default: break; } curFuncInvocation.PushOperand( this.worldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPos, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.fogParams, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutFogFactor, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); internalCounter = 0; curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLerp, (int)FFPRenderState.FFPFragmentShaderStage.PSFog, internalCounter++ ); curFuncInvocation.PushOperand( this.fogColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psInFogFactor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } return true; }
protected virtual void AddPSSampleTexelInvocation( TextureUnitParams textureUnitParams, Function psMain, Parameter texel, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; if ( textureUnitParams.TexCoordCalcMethod == TexCoordCalcMethod.ProjectiveTexture ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSamplerTextureProj, groupOrder, internalCounter++ ); } else { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncSampleTexture, groupOrder, internalCounter++ ); } curFuncInvocation.PushOperand( textureUnitParams.TextureSampler, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( textureUnitParams.PSInputTexCoord, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( texel, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); }
private bool AddVSFunctionInvocations( TextureUnitParams textureUnitParams, Function vsMain ) { FunctionInvocation texCoordCalcFunc = null; switch ( textureUnitParams.TexCoordCalcMethod ) { case TexCoordCalcMethod.None: if ( textureUnitParams.TextureMatrix == null ) { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( textureUnitParams.VSInputTexCoord, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } else { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncTransformTexCoord, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( textureUnitParams.TextureMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSInputTexCoord, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } break; case TexCoordCalcMethod.EnvironmentMap: case TexCoordCalcMethod.EnvironmentMapPlanar: if ( textureUnitParams.TextureMatrix == null ) { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFunGenerateTexcoordEnvSphere, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputNormal, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } else { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFunGenerateTexcoordEnvSphere, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.TextureMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputNormal, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } break; case TexCoordCalcMethod.EnvironmentMapReflection: if ( textureUnitParams.TextureMatrix == null ) { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncGenerateTexCoordEnvReflect, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputNormal, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputPos, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } else { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncGenerateTexCoordEnvReflect, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.TextureMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputNormal, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputPos, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } break; case TexCoordCalcMethod.EnvironmentMapNormal: if ( textureUnitParams.TextureMatrix == null ) { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncGenerateTexcoordEnvNormal, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputPos, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } else { texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncGenerateTexcoordEnvNormal, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldITMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.viewMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.TextureMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputNormal, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); } break; case TexCoordCalcMethod.ProjectiveTexture: texCoordCalcFunc = new FunctionInvocation( FFPRenderState.FFPFuncGenerateTexCoordProjection, (int)FFPRenderState.FFPVertexShaderStage.VSTexturing, textureUnitParams.TextureSamplerIndex ); texCoordCalcFunc.PushOperand( this.worldMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.TextureViewProjImageMatrix, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( this.vsInputPos, Operand.OpSemantic.In ); texCoordCalcFunc.PushOperand( textureUnitParams.VSOutputTexCoord, Operand.OpSemantic.Out ); break; } if ( texCoordCalcFunc != null ) { vsMain.AddAtomInstance( texCoordCalcFunc ); } return true; }
private void AddNormalRelatedCalculations( Function vsMain, Parameter normalRelatedParam, Parameter normalWorldRelatedParam, ref int funcCounter ) { FunctionInvocation curFuncInvocation; if ( doBoneCalculations ) { //set functions to calculate world normal for ( int i = 0; i < weightCount; i++ ) { AddIndexedNormalRelatedWeight( vsMain, normalRelatedParam, normalWorldRelatedParam, i, ref funcCounter ); } //update back the original position relative to the object curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInInvWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //update back the original position relative to the object curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
private FunctionInvocation CreateInvocationFromString( string input ) { string functionName, returnType; FunctionInvocation invoc = null; //Get the function name and return type var leftTokens = input.Split( '(' ); var leftTokens2 = leftTokens[ 0 ].Split( ' ' ); leftTokens2[ 0 ] = leftTokens2[ 0 ].Trim(); leftTokens2[ 1 ] = leftTokens2[ 1 ].Trim(); returnType = leftTokens2[ 0 ]; functionName = leftTokens2[ 1 ]; invoc = new FunctionInvocation( functionName, 0, 0, returnType ); string[] parameters; int lparen_pos = -1; for ( int i = 0; i < input.Length; i++ ) { if ( input[ i ] == '(' ) { lparen_pos = i; break; } } if ( lparen_pos != -1 ) { string[] tokens = input.Split( '(' ); parameters = tokens[ 1 ].Split( ',' ); } else { parameters = input.Split( ',' ); } for ( int i = 0; i < parameters.Length; i++ ) { string itParam = parameters[ i ]; itParam = itParam.Replace( ")", string.Empty ); itParam = itParam.Replace( ",", string.Empty ); string[] paramTokens = itParam.Split( ' ' ); // There should be three parts for each token // 1. The operand type(in, out, inout) // 2. The type // 3. The name if ( paramTokens.Length == 3 ) { Operand.OpSemantic semantic = Operand.OpSemantic.In; GpuProgramParameters.GpuConstantType gpuType = GpuProgramParameters.GpuConstantType.Unknown; if ( paramTokens[ 0 ] == "in" ) { semantic = Operand.OpSemantic.In; } else if ( paramTokens[ 0 ] == "out" ) { semantic = Operand.OpSemantic.Out; } else if ( paramTokens[ 0 ] == "inout" ) { semantic = Operand.OpSemantic.InOut; } //Find the internal type based on the string that we're given foreach ( var key in this.gpuConstTypeMap.Keys ) { if ( this.gpuConstTypeMap[ key ] == paramTokens[ 1 ] ) { gpuType = key; break; } } //We need a valid type otherwise glsl compilation will not work if ( gpuType == GpuProgramParameters.GpuConstantType.Unknown ) { throw new Core.AxiomException( "Cannot convert Operand.OpMask to GpuConstantType" ); } if ( gpuType == GpuProgramParameters.GpuConstantType.Sampler1D ) { gpuType = GpuProgramParameters.GpuConstantType.Sampler2D; } var p = new Parameter( gpuType, paramTokens[ 2 ], Parameter.SemanticType.Unknown, i, Parameter.ContentType.Unknown, 0 ); invoc.PushOperand( p, semantic, (int)Operand.OpMask.All, 0 ); } } return invoc; }
protected override bool AddFunctionInvocations( ProgramSet programSet ) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; FunctionInvocation curFuncInvocation = null; int internalCounter; //Create vertex shader color invocations Parameter vsDiffuse, vsSpecular; internalCounter = 0; if ( this.vsInputDiffuse != null ) { vsDiffuse = this.vsInputDiffuse; } else { vsDiffuse = vsMain.ResolveLocalParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, (int)FFPRenderState.FFPVertexShaderStage.VSColor, internalCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( vsDiffuse, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } if ( this.vsOutputDiffuse != null ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSColor, internalCounter++ ); curFuncInvocation.PushOperand( vsDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutputDiffuse, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } if ( this.vsInputSpecular != null ) { vsSpecular = this.vsInputSpecular; } else { vsSpecular = vsMain.ResolveLocalParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, (int)FFPRenderState.FFPVertexShaderStage.VSColor, internalCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( vsSpecular, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } if ( this.vsOutputSpecular != null ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSColor, internalCounter++ ); curFuncInvocation.PushOperand( vsSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutputSpecular, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } //Create fragment shader color invocations Parameter psDiffuse, psSpecular; internalCounter = 0; //Handle diffuse color if ( this.psInputDiffuse != null ) { psDiffuse = this.psInputDiffuse; } else { psDiffuse = psMain.ResolveLocalParameter( Parameter.SemanticType.Color, 0, Parameter.ContentType.ColorDiffuse, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin, internalCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( psDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } //Handle specular color if ( this.psInputSpecular != null ) { psSpecular = this.psInputSpecular; } else { psSpecular = psMain.ResolveLocalParameter( Parameter.SemanticType.Color, 1, Parameter.ContentType.ColorSpecular, Graphics.GpuProgramParameters.GpuConstantType.Float4 ); curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncConstruct, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin, internalCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 0.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( psSpecular, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } //Assign diffuse color if ( this.psOutputDiffuse != null ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin, internalCounter++ ); curFuncInvocation.PushOperand( psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutputDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } //Assign specular color if ( this.psOutputSpecular != null ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin, internalCounter++ ); curFuncInvocation.PushOperand( psSpecular, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutputSpecular, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } //Add specular to out color internalCounter = 0; if ( this.psOutputDiffuse != null && psSpecular != null ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, (int)FFPRenderState.FFPFragmentShaderStage.PSColorEnd, internalCounter++ ); curFuncInvocation.PushOperand( this.psOutputDiffuse, Operand.OpSemantic.In, ( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( psSpecular, Operand.OpSemantic.In, ( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); curFuncInvocation.PushOperand( this.psOutputDiffuse, Operand.OpSemantic.Out, ( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ) ); psMain.AddAtomInstance( curFuncInvocation ); } return true; }
private void AddIndexedPositionWeight( Function vsMain, int index, ref int funcCounter ) { Operand.OpMask indexMask = IndexToMask( index ); FunctionInvocation curFuncInvocation; var outputMask = (int)( Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z ); if ( paramInWorldMatrices.Type == GpuProgramParameters.GpuConstantType.Matrix_4X4 ) { outputMask = (int)Operand.OpMask.All; } //multiply posiiton with world matrix and put into temporary param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInIndices, Operand.OpSemantic.In, (int)indexMask, 1 ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.Out, outputMask ); vsMain.AddAtomInstance( curFuncInvocation ); //set w value of temporary param to 1 curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( ParameterFactory.CreateConstParamFloat( 1.0f ), Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.Out, (int)Operand.OpMask.W ); vsMain.AddAtomInstance( curFuncInvocation ); //multiply temporary param with weight curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncModulate, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInWeights, Operand.OpSemantic.In, (int)indexMask ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //check if on first iteration if ( index == 0 ) { //set the local param as the value of the world param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //add the local param as the value of the world param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramTempFloat4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
protected bool AddPSFinalAssignmentInvocation( Function psMain, int groupOrder, ref int internalCounter ) { var curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 1, internalCounter++ ); curFuncInvocation.PushOperand( this.psTempDiffuseColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 1, internalCounter++ ); curFuncInvocation.PushOperand( this.psDiffuse, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psOutDiffuse, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); if ( this.specularEnable ) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPFragmentShaderStage.PSColorBegin + 1, internalCounter++ ); curFuncInvocation.PushOperand( this.psTempSpecularColor, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.psSpecular, Operand.OpSemantic.Out ); psMain.AddAtomInstance( curFuncInvocation ); } return true; }
private void AddPositionCalculations( Function vsMain, ref int funcCounter ) { FunctionInvocation curFuncInvocation = null; if ( doBoneCalculations == true ) { //set functions to calculate world position for ( int i = 0; i < WeightCount; i++ ) { AddIndexedPositionWeight( vsMain, i, ref funcCounter ); } //update back the original position relative to the object curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInInvWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //update the projective position thereby filling the transform stage role curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramOutPositionProj, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //update from object to world space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramLocalPositionWorld, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //update from ojbect to projective space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldViewProjMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( paramOutPositionProj, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
protected bool AddVSInvocation( Function vsMain, int groupOrder, ref int internalCounter ) { FunctionInvocation curFuncInvocation = null; //transform normal in view space curFuncInvocation = new FunctionInvocation( SGXFuncTransformNormal, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.worldViewITMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInNormal, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutNormal, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Transform view space position if need to if ( this.vsOutViewPos != null ) { curFuncInvocation = new FunctionInvocation( SGXFuncTransformPosition, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( this.worldViewMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsInPosition, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.vsOutViewPos, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } return true; }
private void AddIndexedPositionWeight( Function vsMain, int index, Parameter worldMatrix, Parameter positionTempParameter, Parameter positionRelatedOutputParam, ref int funcCounter ) { Operand.OpMask indexMask = IndexToMask( index ); FunctionInvocation curFuncInvocation = null; //multiply position with world matrix and put into temporary param curFuncInvocation = new FunctionInvocation( SGXFuncBlendWeight, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWeights, Operand.OpSemantic.In, indexMask ); curFuncInvocation.PushOperand( worldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( positionTempParameter, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //check if on first iteration if ( index == 0 ) { //set the local param as the value of the world param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( positionTempParameter, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( positionRelatedOutputParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //add the local param as the value of the world param curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAdd, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( positionTempParameter, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( positionRelatedOutputParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( positionRelatedOutputParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
protected override void AddPSBlendInvocations( Function psMain, Parameter arg1, Parameter arg2, Parameter texel, int samplerIndex, Graphics.LayerBlendModeEx blendMode, int groupOrder, ref int internalCounter, int targetChannels ) { //Add the modifier invocation AddPSModifierInvocation( psMain, samplerIndex, arg1, arg2, groupOrder, ref internalCounter, targetChannels ); //Add the blending fucntion invocations BlendMode mode = GetBlendMode( samplerIndex ); if ( ( mode == BlendMode.FFPBlend ) || ( mode == BlendMode.Invalid ) ) { base.AddPSBlendInvocations( psMain, arg1, arg2, texel, samplerIndex, blendMode, groupOrder, ref internalCounter, targetChannels ); } else { //find the function name for the blend mode string funcName = string.Empty; for ( int i = 0; i < blendModes.Length; i++ ) { if ( blendModes[ i ].Type == mode ) { funcName = blendModes[ i ].FuncName; break; } } if ( funcName != string.Empty ) { var curFuncInvocation = new FunctionInvocation( funcName, groupOrder, internalCounter++ ); curFuncInvocation.PushOperand( arg1, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( arg2, Operand.OpSemantic.In, targetChannels ); curFuncInvocation.PushOperand( psOutDiffuse, Operand.OpSemantic.Out, targetChannels ); psMain.AddAtomInstance( curFuncInvocation ); } } }
private void AdjustForCorrectAntipodality( Function vsMain, int index, ref int funcCounter, Parameter tempWorldMatrix ) { FunctionInvocation curFuncInvocation = null; //Antipodality doesn't need to be adjusted for dq0 on itself (used as the basis of antipodality calculations) if ( index > 0 ) { curFuncInvocation = new FunctionInvocation( SGXFuncAntipodalityAdjustment, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); //This is the base dual quaternion dq0, which the antipodality calculations are based on curFuncInvocation.PushOperand( this.paramInitialDQ, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramTempFloat2x4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( tempWorldMatrix, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else if ( index == 0 ) { //Set the first dual quaternion as the initial dq curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramTempFloat2x4, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramInitialDQ, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
private void AddNormalRelatedCalculations( Function vsMain, Parameter normalRelatedParam, Parameter normalWorldRelatedParam, ref int funcCounter ) { FunctionInvocation curFuncInvocation = null; if ( doBoneCalculations ) { if ( scalingShearingSupport ) { //Calculate the adjoint transpose of the blended scaling and shearing matrix curFuncInvocation = new FunctionInvocation( DualQuaternionSkinning.SGXFuncAdjointTransposeMatrix, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramBlendS, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramTempFloat3x3, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Transform the normal by the adjoint transpose of the blended scaling and shearing matrix curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( this.paramTempFloat3x3, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //Need to normalize again after transforming the normal curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncNormalize, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.InOut ); vsMain.AddAtomInstance( curFuncInvocation ); } //Transform the normal according to the dual quaternion curFuncInvocation = new FunctionInvocation( DualQuaternionSkinning.SGXFuncCalculateBlendNormal, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( this.paramBlendDQ, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); //update back the original position relative to the object curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInInvWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } else { //update from object to world space curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncTransform, (int)FFPRenderState.FFPVertexShaderStage.VSTransform, funcCounter++ ); curFuncInvocation.PushOperand( paramInWorldMatrix, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalRelatedParam, Operand.OpSemantic.In ); curFuncInvocation.PushOperand( normalWorldRelatedParam, Operand.OpSemantic.Out ); vsMain.AddAtomInstance( curFuncInvocation ); } }
/// <summary> /// Generates local parameters for the split parameters and perform packing/unpacking operation using them. /// </summary> /// <param name="fun"> </param> /// <param name="progType"> </param> /// <param name="mergedParams"> </param> /// <param name="splitParams"> </param> /// <param name="localParamsMap"> </param> internal static void GenerateLocalSplitParameters( Function func, GpuProgramType progType, List<MergeParameter> mergedParams, List<Parameter> splitParams, Dictionary<Parameter, Parameter> localParamsMap ) { //No split params created. if ( splitParams.Count == 0 ) { return; } //Create the local parameters + map from source to local for ( int i = 0; i < splitParams.Count; i++ ) { Parameter srcParameter = splitParams[ i ]; Parameter localParameter = func.ResolveLocalParameter( srcParameter.Semantic, srcParameter.Index, "lssplit_" + srcParameter.Name, srcParameter.Type ); localParamsMap.Add( srcParameter, localParameter ); } int invocationCounter = 0; //Establish link between the local parameter to the merged parameter. for ( int i = 0; i < mergedParams.Count; i++ ) { var curMergeParameter = mergedParams[ i ]; for ( int p = 0; p < curMergeParameter.SourceParameterCount; p++ ) { Parameter srcMergedParameter = curMergeParameter.SourceParameter[ p ]; if ( localParamsMap.ContainsKey( srcMergedParameter ) ) { //Case it is the vertex shader -> assign the local parameter to the output merged parameter if ( progType == GpuProgramType.Vertex ) { var curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int) FFPRenderState.FFPVertexShaderStage. VSPostProcess, invocationCounter++ ); curFuncInvocation.PushOperand( localParamsMap[ srcMergedParameter ], Operand.OpSemantic.In, curMergeParameter.GetSourceParameterMask( p ) ); curFuncInvocation.PushOperand( curMergeParameter.GetDestinationParameter( (int)Operand.OpSemantic.Out, i ), Operand.OpSemantic.Out, curMergeParameter.GetDestinationParameterMask( p ) ); func.AddAtomInstance( curFuncInvocation ); } else if ( progType == GpuProgramType.Fragment ) { var curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncAssign, (int) FFPRenderState.FFPFragmentShaderStage. PSPreProcess, invocationCounter++ ); curFuncInvocation.PushOperand( curMergeParameter.GetDestinationParameter( (int)Operand.OpSemantic.In, i ), Operand.OpSemantic.In, curMergeParameter.GetDestinationParameterMask( p ) ); curFuncInvocation.PushOperand( localParamsMap[ srcMergedParameter ], Operand.OpSemantic.Out, curMergeParameter.GetSourceParameterMask( p ) ); func.AddAtomInstance( curFuncInvocation ); } } } } }