private bool AddGlobalIlluminationInvocation(Function vsMain, 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.vsOutDiffuse, Operand.OpSemantic.Out); vsMain.AddAtomInstance(curFuncInvocation); } else { if ((this.trackVertexColorType & TrackVertexColor.Ambient) == TrackVertexColor.Ambient) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.lightAmbientColor, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsDiffuse, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.derivedAmbientLightColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } if ((this.trackVertexColorType & TrackVertexColor.Emissive) == TrackVertexColor.Emissive) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.surfaceEmissiveCoilor, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAdd, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.surfaceEmissiveCoilor, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out); vsMain.AddAtomInstance(curFuncInvocation); } } return(true); }
public FunctionInvocation(FunctionInvocation other) { this.functionName = other.functionName; this.returnType = other.returnType; internalExecutionOrder = other.internalExecutionOrder; groupExecutionOrder = other.groupExecutionOrder; foreach (var op in other.operands) { this.operands.Add(op); } }
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); } }
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); } }
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); } } }
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 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 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 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); }
private bool AddIlluminationInvocation(LightParams curLightParams, Function vsMain, int groupOrder, ref int internalCounter) { FunctionInvocation curFuncInvocation = null; //Merge dffuse color with vertex color if need to if ((this.trackVertexColorType & TrackVertexColor.Diffuse) == TrackVertexColor.Diffuse) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.vsDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } //Merge specular color with vertex color if need to if (this.specularEnable && (this.trackVertexColorType & TrackVertexColor.Specular) == TrackVertexColor.Specular) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.vsDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } switch (curLightParams.Type) { case LightType.Directional: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLightDirectionDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightDirectionDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; case LightType.Point: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightPointDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightPointDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; case LightType.Spotlight: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightSpotDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (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, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightSpotDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (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, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; } 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(); } } }
/// <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); } } } } }
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 override bool AddFunctionInvocations(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function psMain = psProgram.EntryPointFunction; Function vsMain = vsProgram.EntryPointFunction; FunctionInvocation curFuncInvocation = null; //Calculate the position and size of the texture in the atlas in the vertex shader int groupOrder = ((int)FFPRenderState.FFPVertexShaderStage.VSTexturing - (int)FFPRenderState.FFPVertexShaderStage.VSLighting) / 2; int internalCounter = 0; for (int i = 0; i < TextureAtlasSampler.MaxTextures; i++) { if (this.isAtlasTextureUnits[i] == true) { Operand.OpMask textureIndexMask = Operand.OpMask.X; switch (i) { case 1: textureIndexMask = Operand.OpMask.Y; break; case 2: textureIndexMask = Operand.OpMask.Z; break; case 3: textureIndexMask = Operand.OpMask.W; break; } curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncAssign, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.vsTextureTable[i], Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInpTextureTableIndex, Operand.OpSemantic.In, (int)textureIndexMask, 1); curFuncInvocation.PushOperand(this.vsOutTextureDatas[i], Operand.OpSemantic.Out); vsMain.AddAtomInstance(curFuncInvocation); } } //sample the texture in the fragment shader given the extracted data in the pixel shader // groupOrder = (FFP_PS_SAMPLING + FFP_PS_TEXTURING) / 2; internalCounter = 0; var inpParams = psMain.InputParameters; var localParams = psMain.LocalParameters; Parameter psAtlasTextureCoord = psMain.ResolveLocalParameter(Parameter.SemanticType.Unknown, -1, "atlasCoord", GpuProgramParameters.GpuConstantType.Float2); for (int j = 0; j < TextureAtlasSampler.MaxTextures; j++) { if (this.isAtlasTextureUnits[j] == true) { //Find the texture coordinates texel and sampler from the original FFPTexturing Parameter texcoord = Function.GetParameterByContent(inpParams, (Parameter.ContentType) ((int)Parameter.ContentType.TextureCoordinate0 + j), GpuProgramParameters.GpuConstantType.Float2); Parameter texel = Function.GetParameterByName(localParams, this.paramTexel + j.ToString()); UniformParameter sampler = psProgram.GetParameterByType(GpuProgramParameters.GpuConstantType.Sampler2D, j); //TODO string addressUFuncName = GetAddressingFunctionName(this.textureAddressings[j].U); string addressVFuncName = GetAddressingFunctionName(this.textureAddressings[j].V); //Create a function which will replace the texel with the texture texel if ((texcoord != null) && (texel != null) && (sampler != null) && (addressUFuncName != null) && (addressVFuncName != null)) { //calculate the U value due to addressing mode curFuncInvocation = new FunctionInvocation(addressUFuncName, groupOrder, internalCounter++); curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.X); curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.X); psMain.AddAtomInstance(curFuncInvocation); //calculate the V value due to addressing mode curFuncInvocation = new FunctionInvocation(addressVFuncName, groupOrder, internalCounter++); curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, Operand.OpMask.Y); curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.Out, Operand.OpMask.Y); psMain.AddAtomInstance(curFuncInvocation); //sample the texel color curFuncInvocation = new FunctionInvocation(this.autoAdjustPollPosition ? SGXFuncAtlasSampleAutoAdjust : SGXFuncAtlasSampleNormal, groupOrder, internalCounter++); curFuncInvocation.PushOperand(sampler, Operand.OpSemantic.In); curFuncInvocation.PushOperand(texcoord, Operand.OpSemantic.In, (int)(Operand.OpMask.X | Operand.OpMask.Y)); curFuncInvocation.PushOperand(psAtlasTextureCoord, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.psInpTextureData[j], Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.psTextureSizes[j], Operand.OpSemantic.In); curFuncInvocation.PushOperand(texel, Operand.OpSemantic.Out); psMain.AddAtomInstance(curFuncInvocation); } } } return(true); }
private static bool FunctionInvocationLessThan(FunctionInvocation lhs, FunctionInvocation rhs) { if (lhs.operands.Count < rhs.operands.Count) { return(true); } if (lhs.operands.Count > rhs.operands.Count) { return(false); } for (int i = 0; i < lhs.operands.Count; i++) { var itLHSOps = lhs.operands[i]; var itRHSOps = rhs.operands[i]; if (itLHSOps.Semantic < itRHSOps.Semantic) { return(true); } if (itLHSOps.Semantic > itRHSOps.Semantic) { return(false); } var leftType = itLHSOps.Parameter.Type; var rightType = itRHSOps.Parameter.Type; if (Axiom.Core.Root.Instance.RenderSystems.ContainsKey("OpenGL ES 2") && Axiom.Core.Root.Instance.RenderSystem == Axiom.Core.Root.Instance.RenderSystems["OpenGL ES 2"]) { if (leftType == Graphics.GpuProgramParameters.GpuConstantType.Sampler1D) { leftType = Graphics.GpuProgramParameters.GpuConstantType.Sampler2D; } if (rightType == Graphics.GpuProgramParameters.GpuConstantType.Sampler1D) { rightType = Graphics.GpuProgramParameters.GpuConstantType.Sampler2D; } } //If a swizzle mask is being applied to the parameter, generate the GpuConstantType to //perform the parameter type comparison the way that the compiler will see it if ((Operand.GetFloatCount(itLHSOps.Mask) > 0 || (Operand.GetFloatCount(itRHSOps.Mask) > 0))) { if (Operand.GetFloatCount(itLHSOps.Mask) > 0) { leftType = (Graphics.GpuProgramParameters.GpuConstantType) (((int)itLHSOps.Parameter.Type - (int)itLHSOps.Parameter.Type) + Operand.GetFloatCount(itLHSOps.Mask)); } if (Operand.GetFloatCount(itRHSOps.Mask) > 0) { rightType = (Graphics.GpuProgramParameters.GpuConstantType) (((int)itRHSOps.Parameter.Type - (int)itRHSOps.Parameter.Type) + Operand.GetFloatCount(itRHSOps.Mask)); } } if (leftType < rightType) { return(true); } if (leftType > rightType) { return(false); } } return(false); }
private static bool FunctionInvocationCompare(FunctionInvocation x, FunctionInvocation y) { if (x.functionName != y.functionName) { return(false); } if (x.returnType != y.returnType) { return(false); } if (x.operands.Count != y.operands.Count) { return(false); } for (int i = 0; i < x.operands.Count; i++) { if (x.operands[i].Semantic != y.operands[i].Semantic) { return(false); } var leftType = x.operands[i].Parameter.Type; var rightType = y.operands[i].Parameter.Type; if (Axiom.Core.Root.Instance.RenderSystem.Name.Contains("OpenGL ES 2")) { if (leftType == Graphics.GpuProgramParameters.GpuConstantType.Sampler1D) { leftType = Graphics.GpuProgramParameters.GpuConstantType.Sampler2D; } if (rightType == Graphics.GpuProgramParameters.GpuConstantType.Sampler1D) { rightType = Graphics.GpuProgramParameters.GpuConstantType.Sampler2D; } } if (Operand.GetFloatCount(x.operands[i].Mask) > 0 || Operand.GetFloatCount(y.operands[i].Mask) > 0) { if (Operand.GetFloatCount(x.operands[i].Mask) > 0) { leftType = (Graphics.GpuProgramParameters.GpuConstantType)(int) x.operands[i].Parameter.Type - (int)x.operands[i].Parameter.Type + Operand.GetFloatCount(x.operands[i].Mask); } if (Operand.GetFloatCount(y.operands[i].Mask) > 0) { rightType = (Graphics.GpuProgramParameters.GpuConstantType)(int) y.operands[i].Parameter.Type - (int)y.operands[i].Parameter.Type + Operand.GetFloatCount(y.operands[i].Mask); } } if (leftType != rightType) { return(false); } } return(true); }
private void CacheDependencyFunctions(string libName) { if (this.cachedFunctionLibraries.ContainsKey(libName)) { return; //lib is already in cach } string libFileName = libName + ".glsles"; var dataStream = ResourceGroupManager.Instance.OpenResource(libFileName); var reader = new StreamReader(dataStream, Encoding.Default); var functionCache = new Dictionary <string, string>(); string line; while (!reader.EndOfStream) { line = reader.ReadLine(); //Ignore empty lines and comments if (line.Length > 0) { line = line.Trim(); if (line[0] == '/' && line[1] == '*') { bool endFound = false; while (!endFound) { //Get the next line line = reader.ReadLine(); //Skip empties if (line.Length > 0) { //Look for the ending sequence if (line.Contains("*/")) { endFound = true; } } } } else if (line.Length > 1 && line[0] != '/' && line[1] != '/') { //Break up the line. string[] tokens = line.Split(' ', '(', '\n', '\r'); //Cache #defines if (tokens[0] == "#define") { this.definesMap.Add(line, libName); continue; } // Try to identify a function definition // First, look for a return type if (IsBasicType(tokens[0]) && ((tokens.Length < 3) || tokens[2] != "=")) { string functionSig = string.Empty; string functionBody = string.Empty; FunctionInvocation functionInvoc = null; //Return type functionSig = tokens[0]; functionSig += " "; //Function name functionSig += tokens[1]; functionSig += "("; bool foundEndOfSignature = false; //Now look for all the paraemters, the may span multiple lines while (!foundEndOfSignature) { //Trim whitespace from both sides of the line line = line.Trim(); //First we want to get everything right of the paren string[] paramTokens; if (line.Contains('(')) { string[] lineTokens = line.Split(')'); paramTokens = lineTokens[1].Split(','); } else { paramTokens = line.Split(','); } foreach (var itParam in paramTokens) { functionSig += itParam; if (!itParam.Contains(')')) { functionSig += ","; } } if (line.Contains(')')) { foundEndOfSignature = true; } line = reader.ReadLine(); } functionInvoc = CreateInvocationFromString(functionSig); //Ok, now if we have founc the signature, iterate throug the file until we find the found //of the function bool foundEndOfBody = false; int braceCount = 0; while (!foundEndOfBody) { functionBody += line; if (line.Contains('{')) { braceCount++; } if (line.Contains('}')) { braceCount--; } if (braceCount == 0) { foundEndOfBody = true; //Remove first and last brace int pos = -1; for (int i = 0; i < functionBody.Length; i++) { if (functionBody[i] == '{') { pos = i; break; } } functionBody.Remove(pos, 1); this.functionCacheMap.Add(functionInvoc, functionBody); } functionBody += "\n"; line = reader.ReadLine(); } } } } } reader.Close(); }
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) { 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 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); }