private void DefineFile(string path, DefineCollection defCol) { StreamReader sr = new StreamReader(path); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Length > 0) { string[] dividedLine = null;// = line.Split(parameterSplitCharacters, parameterUniterCharacters); for (int i = 1; i < dividedLine.Length; i++) { defCol.Add(dividedLine[i], dividedLine[0]); } } } sr.Close(); }
public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting) { return(new PassDescriptor { // Definition displayName = "TransparentDepthPrepass", referenceName = "SHADERPASS_DEPTH_ONLY", lightMode = "TransparentDepthPrepass", useInPreview = true, validPixelBlocks = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.Alpha, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, HDBlockFields.SurfaceDescription.DepthOffset, BlockFields.SurfaceDescription.NormalTS, BlockFields.SurfaceDescription.NormalWS, BlockFields.SurfaceDescription.NormalOS, BlockFields.SurfaceDescription.Smoothness, }, // Collections requiredFields = TransparentDepthPrepassFields, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = GenerateDefines(), keywords = CoreKeywords.HDBase, includes = GenerateIncludes(), }); DefineCollection GenerateDefines() { var defines = new DefineCollection { { RayTracingNode.GetRayTracingKeyword(), 0 } }; if (supportLighting) { defines.Add(CoreKeywordDescriptors.WriteNormalBufferDefine, 1, new FieldCondition(HDFields.DisableSSRTransparent, false)); } return(defines); } RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection { { RenderState.Blend(Blend.One, Blend.Zero) }, { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, { RenderState.ZWrite(ZWrite.On) }, { RenderState.Stencil(new StencilDescriptor() { WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, Ref = CoreRenderStates.Uniforms.stencilRefDepth, Comp = "Always", Pass = "******", }) }, }; if (!supportLighting) { renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal]")); renderState.Add(RenderState.ColorMask("ColorMask 0 1")); } return(renderState); } IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); if (supportLighting) { includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); if (supportLighting) { includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); return(includes); } }
public static PassDescriptor GenerateMotionVectors(bool supportLighting, bool supportForward) { return(new PassDescriptor { // Definition displayName = "MotionVectors", referenceName = "SHADERPASS_MOTION_VECTORS", lightMode = "MotionVectors", useInPreview = false, // Collections requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), defines = GenerateDefines(), pragmas = CorePragmas.DotsInstancedInV2Only, keywords = GenerateKeywords(), includes = GenerateIncludes(), }); DefineCollection GenerateDefines() { if (!supportLighting) { return(null); } var defines = new DefineCollection { { RayTracingNode.GetRayTracingKeyword(), 0 }, }; // #define WRITE_NORMAL_BUFFER for forward if (supportForward) { defines.Add(CoreKeywordDescriptors.WriteNormalBuffer, 1); } return(defines); } RenderStateCollection GenerateRenderState() { var renderState = new RenderStateCollection(); renderState.Add(CoreRenderStates.MotionVectors); if (!supportLighting) { renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1")); renderState.Add(RenderState.ColorMask("ColorMask 0 2")); } return(renderState); } KeywordCollection GenerateKeywords() { var keywords = new KeywordCollection { { CoreKeywords.HDBase }, { CoreKeywordDescriptors.WriteMsaaDepth }, { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, }; // #pragma multi_compile _ WRITE_NORMAL_BUFFER for deferred if (supportLighting && !supportForward) { keywords.Add(CoreKeywordDescriptors.WriteNormalBuffer); } return(keywords); } IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); if (supportLighting) { includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); if (supportLighting) { includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); } includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph); return(includes); } }
private void Preprocess(TextReader reader, string file, DefineCollection defCol, ICollection <string> lines, Stack <bool> ifStack) { int stackDepth = ifStack.Count; string line; bool include = ifStack.And(); while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line.Length > 0) { if (line[0] == '#') { string[] splitLine = StringExtensions.Split(line, parameterSplitCharacters, parameterUniterCharacters); //string[] splitLine = StringHelper.DivideLine(line); switch (splitLine[0].ToLower()) { case define: if (include) { if (splitLine.Length > 1) { if (splitLine[1].Equals(defineFile)) { string path = IOHelpers.FindFile(file, splitLine[2]); if (!string.IsNullOrEmpty(path)) { IOHelpers.DefineFile(path, defCol); } else { messageHandler.AddFileNotFoundError(file, line, splitLine[2]); } } else { int indexBeg = splitLine[1].IndexOf('('); int indexEnd = splitLine[1].IndexOf(')'); if (indexBeg >= 0 && indexEnd >= 0 && indexBeg < indexEnd) { string parametersList = splitLine[1].Substring(indexBeg + 1, indexEnd - indexBeg - 1); string[] parameters = parametersList.Split(','); string original = splitLine[1].Substring(0, indexBeg); for (int i = 0; i < parameters.Length; i++) { parameters[i] = parameters[i].Trim(); } defCol.Add(original, splitLine[2], parameters); } else if (indexBeg == -1 && indexEnd == -1) { if (splitLine.Length > 2) { defCol.Add(splitLine[1], splitLine[2]); } else { defCol.Add(splitLine[1], ""); } } else { messageHandler.AddError(define + " is improperly defined: " + line); } } } else { messageHandler.AddNotEnoughParametersError(file, line, define, 1); } } break; case unDefine: if (include) { if (splitLine.Length > 1) { defCol.Remove(splitLine[1]); } else { messageHandler.AddNotEnoughParametersError(file, line, unDefine, 1); } } break; case includeFile: if (include) { if (splitLine.Length > 1) { string path = IOHelpers.FindFile(file, splitLine[1]); if (!string.IsNullOrEmpty(path)) { string moreText = File.ReadAllText(path); moreText = this.RemoveComments(moreText); lines.Add("{"); using (StringReader newReader = new StringReader(moreText)) { Preprocess(newReader, path, defCol, lines, ifStack); //Preprocess(moreText, path, defCol, lines, ifStack); } lines.Add("}"); } else { messageHandler.AddFileNotFoundError(file, line, splitLine[1]); } } else { messageHandler.AddNotEnoughParametersError(file, line, includeFile, 1); } } break; case includeBinary: if (include) { if (splitLine.Length > 1) { string path = IOHelpers.FindFile(file, splitLine[1]); if (!string.IsNullOrEmpty(path)) { byte[] data = File.ReadAllBytes(path); StringBuilder newLine = new StringBuilder("CODE"); for (int i = 0; i < data.Length; i++) { newLine.Append(data[i].ToHexString(" 0x")); } lines.Add(newLine.ToString()); } else { messageHandler.AddFileNotFoundError(file, line, splitLine[1]); } } else { messageHandler.AddNotEnoughParametersError(file, line, includeBinary, 1); } } break; case ifDefined: if (splitLine.Length > 1) { ifStack.Push(defCol.ContainsName(splitLine[1])); include = ifStack.And(); } else { messageHandler.AddNotEnoughParametersError(file, line, ifDefined, 1); } break; case ifNotDefined: if (splitLine.Length > 1) { ifStack.Push(!defCol.ContainsName(splitLine[1])); include = ifStack.And(); } else { messageHandler.AddNotEnoughParametersError(file, line, ifNotDefined, 1); } break; case ifElse: bool top = ifStack.Pop(); ifStack.Push(!top); include = ifStack.And(); break; case ifEnd: ifStack.Pop(); include = ifStack.And(); break; case "#org": lines.Add(line.Substring(1)); messageHandler.AddWarning("#ORG no longer exists. Use ORG instead."); break; default: messageHandler.AddError(splitLine[0] + " is not usable preprocessor command: " + line); break; } } else if (include) { string[] newLines = line.Split(extraLineSplitters); for (int i = 0; i < newLines.Length; i++) { lines.Add(newLines[i]); } } } } if (ifStack.Count != stackDepth) { messageHandler.AddWarning("#IFDEF stack unbalanced in file " + file + "."); } }