├── .gitattributes
├── .gitignore
├── README.md
├── lib
└── CppNet.dll
└── src
├── HlslParser.Tests
├── HlslParser.Tests.csproj
├── HlslParserTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── Shaders
│ ├── FxDis
│ │ ├── readme.txt
│ │ ├── test.hlsl
│ │ └── test.knowngood
│ ├── HlslCrossCompiler
│ │ ├── ds5
│ │ │ ├── basic.hlsl
│ │ │ └── basic.knowngood
│ │ ├── hs5
│ │ │ └── basic.hlsl
│ │ ├── ps4
│ │ │ ├── fxaa.hlsl
│ │ │ └── primID.hlsl
│ │ ├── ps5
│ │ │ ├── conservative_depth.hlsl
│ │ │ ├── interface_arrays.hlsl
│ │ │ ├── interfaces.hlsl
│ │ │ └── sample.hlsl
│ │ ├── readme.txt
│ │ ├── vs4
│ │ │ ├── mov.hlsl
│ │ │ ├── multiple_const_buffers.hlsl
│ │ │ └── switch.hlsl
│ │ └── vs5
│ │ │ ├── any.hlsl
│ │ │ ├── const_temp.hlsl
│ │ │ ├── mad_imm.hlsl
│ │ │ ├── mov.hlsl
│ │ │ └── sincos.hlsl
│ ├── Internal
│ │ ├── Textures.hlsl
│ │ └── Textures.knowngood
│ └── Sdk
│ │ ├── Direct3D11
│ │ ├── AdaptiveTessellationCS40
│ │ │ ├── TessellatorCS40_EdgeFactorCS.hlsl
│ │ │ ├── TessellatorCS40_NumVerticesIndicesCS.hlsl
│ │ │ ├── TessellatorCS40_ScatterIDCS.hlsl
│ │ │ ├── TessellatorCS40_TessellateIndicesCS.hlsl
│ │ │ ├── TessellatorCS40_TessellateVerticesCS.hlsl
│ │ │ ├── TessellatorCS40_common.hlsl
│ │ │ └── TessellatorCS40_defines.h
│ │ ├── BC6HBC7EncoderDecoder11
│ │ │ ├── BC6HDecode.hlsl
│ │ │ ├── BC6HEncode.hlsl
│ │ │ ├── BC7Decode.hlsl
│ │ │ └── BC7Encode.hlsl
│ │ ├── BasicCompute11
│ │ │ └── BasicCompute11.hlsl
│ │ ├── CascadedShadowMaps11
│ │ │ ├── RenderCascadeScene.hlsl
│ │ │ └── RenderCascadeShadow.hlsl
│ │ ├── ComputeShaderSort11
│ │ │ └── ComputeShaderSort11.hlsl
│ │ ├── ContactHardeningShadows11
│ │ │ └── ContactHardeningShadows11.hlsl
│ │ ├── DDSWithoutD3DX11
│ │ │ └── DDSWithoutD3DX.hlsl
│ │ ├── DecalTessellation11
│ │ │ ├── AdaptiveTessellation.hlsl
│ │ │ └── DecalTessellation11.hlsl
│ │ ├── DetailTessellation11
│ │ │ ├── AdaptiveTessellation.h
│ │ │ ├── DetailTessellation11.hlsl
│ │ │ ├── POM.hlsl
│ │ │ ├── Particle.hlsl
│ │ │ └── shader_include.h
│ │ ├── DynamicShaderLinkage11
│ │ │ ├── DynamicShaderLinkage11_LightPSH.h
│ │ │ ├── DynamicShaderLinkage11_MaterialPSH.h
│ │ │ ├── DynamicShaderLinkage11_PS.hlsl
│ │ │ ├── DynamicShaderLinkage11_PSBuffers.h
│ │ │ └── DynamicShaderLinkage11_VS.hlsl
│ │ ├── FluidCS11
│ │ │ ├── FluidCS11.hlsl
│ │ │ └── FluidRender.hlsl
│ │ ├── HDRToneMappingCS11
│ │ │ ├── BrightPassAndHorizFilterCS.hlsl
│ │ │ ├── DumpToTexture.hlsl
│ │ │ ├── FilterCS.hlsl
│ │ │ ├── FinalPass.hlsl
│ │ │ ├── PSApproach.hlsl
│ │ │ ├── ReduceTo1DCS.hlsl
│ │ │ ├── ReduceToSingleCS.hlsl
│ │ │ └── skybox11.hlsl
│ │ ├── NBodyGravityCS11
│ │ │ ├── NBodyGravityCS11.hlsl
│ │ │ └── ParticleDraw.hlsl
│ │ ├── PNTriangles11
│ │ │ ├── AdaptiveTessellation.hlsl
│ │ │ └── PNTriangles11.hlsl
│ │ ├── SimpleBezier11
│ │ │ └── SimpleBezier11.hlsl
│ │ ├── SubD11
│ │ │ └── SubD11.hlsl
│ │ └── VarianceShadows11
│ │ │ ├── 2DQuadShaders.hlsl
│ │ │ ├── RenderVarianceScene.hlsl
│ │ │ └── RenderVarianceShadow.hlsl
│ │ ├── DirectX SDK EULA.txt
│ │ └── readme.txt
└── packages.config
├── HlslParser.sln
└── HlslParser
├── HlslGrammar.nitra
├── HlslParser.nproj
└── Properties
└── AssemblyInfo.n
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | [Rr]eleases/
14 | x64/
15 | x86/
16 | build/
17 | bld/
18 | [Bb]in/
19 | [Oo]bj/
20 |
21 | # Roslyn cache directories
22 | *.ide/
23 |
24 | # MSTest test Results
25 | [Tt]est[Rr]esult*/
26 | [Bb]uild[Ll]og.*
27 |
28 | #NUNIT
29 | *.VisualState.xml
30 | TestResult.xml
31 |
32 | # Build Results of an ATL Project
33 | [Dd]ebugPS/
34 | [Rr]eleasePS/
35 | dlldata.c
36 |
37 | *_i.c
38 | *_p.c
39 | *_i.h
40 | *.ilk
41 | *.meta
42 | *.obj
43 | *.pch
44 | *.pdb
45 | *.pgc
46 | *.pgd
47 | *.rsp
48 | *.sbr
49 | *.tlb
50 | *.tli
51 | *.tlh
52 | *.tmp
53 | *.tmp_proj
54 | *.log
55 | *.vspscc
56 | *.vssscc
57 | .builds
58 | *.pidb
59 | *.svclog
60 | *.scc
61 |
62 | # Chutzpah Test files
63 | _Chutzpah*
64 |
65 | # Visual C++ cache files
66 | ipch/
67 | *.aps
68 | *.ncb
69 | *.opensdf
70 | *.sdf
71 | *.cachefile
72 |
73 | # Visual Studio profiler
74 | *.psess
75 | *.vsp
76 | *.vspx
77 |
78 | # TFS 2012 Local Workspace
79 | $tf/
80 |
81 | # Guidance Automation Toolkit
82 | *.gpState
83 |
84 | # ReSharper is a .NET coding add-in
85 | _ReSharper*/
86 | *.[Rr]e[Ss]harper
87 | *.DotSettings.user
88 |
89 | # JustCode is a .NET coding addin-in
90 | .JustCode
91 |
92 | # TeamCity is a build add-in
93 | _TeamCity*
94 |
95 | # DotCover is a Code Coverage Tool
96 | *.dotCover
97 |
98 | # NCrunch
99 | _NCrunch_*
100 | .*crunch*.local.xml
101 |
102 | # MightyMoose
103 | *.mm.*
104 | AutoTest.Net/
105 |
106 | # Web workbench (sass)
107 | .sass-cache/
108 |
109 | # Installshield output folder
110 | [Ee]xpress/
111 |
112 | # DocProject is a documentation generator add-in
113 | DocProject/buildhelp/
114 | DocProject/Help/*.HxT
115 | DocProject/Help/*.HxC
116 | DocProject/Help/*.hhc
117 | DocProject/Help/*.hhk
118 | DocProject/Help/*.hhp
119 | DocProject/Help/Html2
120 | DocProject/Help/html
121 |
122 | # Click-Once directory
123 | publish/
124 |
125 | # Publish Web Output
126 | *.[Pp]ublish.xml
127 | *.azurePubxml
128 | # TODO: Comment the next line if you want to checkin your web deploy settings
129 | # but database connection strings (with potential passwords) will be unencrypted
130 | *.pubxml
131 | *.publishproj
132 |
133 | # NuGet Packages
134 | *.nupkg
135 | # The packages folder can be ignored because of Package Restore
136 | **/packages/*
137 | # except build/, which is used as an MSBuild target.
138 | !**/packages/build/
139 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
140 | #!**/packages/repositories.config
141 |
142 | # Windows Azure Build Output
143 | csx/
144 | *.build.csdef
145 |
146 | # Windows Store app package directory
147 | AppPackages/
148 |
149 | # Others
150 | sql/
151 | *.Cache
152 | ClientBin/
153 | [Ss]tyle[Cc]op.*
154 | ~$*
155 | *~
156 | *.dbmdl
157 | *.dbproj.schemaview
158 | *.pfx
159 | *.publishsettings
160 | node_modules/
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file
166 | # to a newer Visual Studio version. Backup files are not needed,
167 | # because we have git ;-)
168 | _UpgradeReport_Files/
169 | Backup*/
170 | UpgradeLog*.XML
171 | UpgradeLog*.htm
172 |
173 | # SQL Server files
174 | *.mdf
175 | *.ldf
176 |
177 | # Business Intelligence projects
178 | *.rdl.data
179 | *.bim.layout
180 | *.bim_*.settings
181 |
182 | # Microsoft Fakes
183 | FakesAssemblies/
184 |
185 | # =========================
186 | # Operating System Files
187 | # =========================
188 |
189 | # OSX
190 | # =========================
191 |
192 | .DS_Store
193 | .AppleDouble
194 | .LSOverride
195 |
196 | # Icon must end with two \r
197 | Icon
198 |
199 | # Thumbnails
200 | ._*
201 |
202 | # Files that might appear on external disk
203 | .Spotlight-V100
204 | .Trashes
205 |
206 | # Directories potentially created on remote AFP share
207 | .AppleDB
208 | .AppleDesktop
209 | Network Trash Folder
210 | Temporary Items
211 | .apdisk
212 |
213 | # Windows
214 | # =========================
215 |
216 | # Windows image file caches
217 | Thumbs.db
218 | ehthumbs.db
219 |
220 | # Folder config file
221 | Desktop.ini
222 |
223 | # Recycle Bin used on file shares
224 | $RECYCLE.BIN/
225 |
226 | # Windows Installer files
227 | *.cab
228 | *.msi
229 | *.msm
230 | *.msp
231 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HlslParser
2 | ==========
3 |
4 | HlslParser is a SM5.0 HLSL parser for .NET. The grammar and parser are built using JetBrains'
5 | [Nitra](https://github.com/JetBrains/Nitra) project.
6 | Currently, it only parses HLSL code into an AST. Once Nitra adds support for it
7 | (planned for a future milestone), I plan to extend HlslParser to support full
8 | HLSL intellisense in Visual Studio.
9 |
10 | HlslParser is currently capable of parsing most / all of the sample shaders in the Direct3D SDK,
11 | as well as several other shaders - see the [test suite](src/HlslParser.Tests/Shaders).
12 |
13 | (On a nerd note, Nitra makes it possible to define the grammar in a nice concise way; so far, I prefer it to
14 | other parser generators that I've used. [Here is the HLSL grammar file](src/HlslParser/HlslGrammar.nitra).)
15 |
16 | Usage
17 | -----
18 |
19 | ```csharp
20 | var sourceSnapshot = new SourceSnapshot(sourceCode);
21 | var parserHost = new ParserHost();
22 | var compilationUnit = HlslGrammar.CompilationUnit(sourceSnapshot, parserHost);
23 |
24 | Assert.That(compilationUnit.IsSuccess, Is.True);
25 |
26 | var parseTree = compilationUnit.CreateParseTree();
27 | var parsedCode = parseTree.ToString();
28 | ```
29 |
30 | Prerequisites
31 | -------------
32 |
33 | Because HlslParser is based on Nitra, you'll need to install the following before you can
34 | build HlslParser on your own machine:
35 |
36 | 1. [Nemerle](http://nemerle.org/Downloads)
37 | 2. [Nitra](http://nemerle.org/nitra-builds/)
38 |
39 | I haven't built an HLSL preprocessor. Instead, I make use of the Direct3D HLSL preprocessor, through SharpDX.
40 | SharpDX requires a specific DirectX runtime, so if you want to run the
41 | HlslParser test suite, you'll need to install that too:
42 |
43 | * [DirectX June 2010 Redistributable Runtime](http://www.microsoft.com/en-us/download/details.aspx?id=8109)
44 |
45 | License
46 | -------
47 |
48 | HlslParser is released under the [MIT License](http://www.opensource.org/licenses/MIT).
--------------------------------------------------------------------------------
/lib/CppNet.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgjones/hlsl-parser-nitra/8b78d4eb24364f5d647e9cbe71f45df036b45c46/lib/CppNet.dll
--------------------------------------------------------------------------------
/src/HlslParser.Tests/HlslParser.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}
8 | Library
9 | Properties
10 | HlslParser.Tests
11 | HlslParser.Tests
12 | v4.5
13 | 512
14 | 740e4da5
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\..\lib\CppNet.dll
36 |
37 |
38 |
39 | ..\packages\NUnit.2.6.3\lib\nunit.framework.dll
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | PreserveNewest
59 |
60 |
61 | PreserveNewest
62 |
63 |
64 | PreserveNewest
65 |
66 |
67 | PreserveNewest
68 |
69 |
70 | PreserveNewest
71 |
72 |
73 | PreserveNewest
74 |
75 |
76 | PreserveNewest
77 |
78 |
79 | PreserveNewest
80 |
81 |
82 | PreserveNewest
83 |
84 |
85 | PreserveNewest
86 |
87 |
88 | PreserveNewest
89 |
90 |
91 | PreserveNewest
92 |
93 |
94 | PreserveNewest
95 |
96 |
97 | PreserveNewest
98 |
99 |
100 | PreserveNewest
101 |
102 |
103 | PreserveNewest
104 |
105 |
106 | PreserveNewest
107 |
108 |
109 | PreserveNewest
110 |
111 |
112 | PreserveNewest
113 |
114 |
115 |
116 |
117 | {8e98d01e-2e3f-4503-a338-40cb79ce39c6}
118 | HlslParser
119 |
120 |
121 |
122 |
123 |
124 |
125 | PreserveNewest
126 |
127 |
128 | PreserveNewest
129 |
130 |
131 | PreserveNewest
132 |
133 |
134 | PreserveNewest
135 |
136 |
137 | PreserveNewest
138 |
139 |
140 | PreserveNewest
141 |
142 |
143 | PreserveNewest
144 |
145 |
146 | PreserveNewest
147 |
148 |
149 | PreserveNewest
150 |
151 |
152 | PreserveNewest
153 |
154 |
155 | PreserveNewest
156 |
157 |
158 | PreserveNewest
159 |
160 |
161 | PreserveNewest
162 |
163 |
164 | PreserveNewest
165 |
166 |
167 | PreserveNewest
168 |
169 |
170 | PreserveNewest
171 |
172 |
173 | PreserveNewest
174 |
175 |
176 | PreserveNewest
177 |
178 |
179 | PreserveNewest
180 |
181 |
182 | PreserveNewest
183 |
184 |
185 | PreserveNewest
186 |
187 |
188 | PreserveNewest
189 |
190 |
191 | PreserveNewest
192 |
193 |
194 | PreserveNewest
195 |
196 |
197 | PreserveNewest
198 |
199 |
200 | PreserveNewest
201 |
202 |
203 | PreserveNewest
204 |
205 |
206 | PreserveNewest
207 |
208 |
209 | PreserveNewest
210 |
211 |
212 | PreserveNewest
213 |
214 |
215 | PreserveNewest
216 |
217 |
218 | PreserveNewest
219 |
220 |
221 | PreserveNewest
222 |
223 |
224 | PreserveNewest
225 |
226 |
227 | PreserveNewest
228 |
229 |
230 | PreserveNewest
231 |
232 |
233 | PreserveNewest
234 |
235 |
236 | PreserveNewest
237 |
238 |
239 | PreserveNewest
240 |
241 |
242 | PreserveNewest
243 |
244 |
245 | PreserveNewest
246 |
247 |
248 | PreserveNewest
249 |
250 |
251 | PreserveNewest
252 |
253 |
254 | PreserveNewest
255 |
256 |
257 | PreserveNewest
258 |
259 |
260 | PreserveNewest
261 |
262 |
263 | PreserveNewest
264 |
265 |
266 | PreserveNewest
267 |
268 |
269 | PreserveNewest
270 |
271 |
272 | PreserveNewest
273 |
274 |
275 |
276 |
277 |
278 |
285 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/HlslParserTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using CppNet;
7 | using Nitra;
8 | using NUnit.Framework;
9 |
10 | namespace HlslParser.Tests
11 | {
12 | [TestFixture]
13 | public class HlslParserTests
14 | {
15 | [TestCaseSource("GetTestShaders")]
16 | public void CanParseShader(string testFile, string knownGoodFile)
17 | {
18 | // Preprocess test code using CppNet.
19 | var sourceCode = Preprocess(File.ReadAllText(testFile), testFile);
20 |
21 | // Parse test code.
22 | var sourceSnapshot = new SourceSnapshot(sourceCode);
23 | var parserHost = new ParserHost();
24 | var compilationUnit = HlslGrammar.CompilationUnit(sourceSnapshot, parserHost);
25 |
26 | // Check for parse errors.
27 | if (!compilationUnit.IsSuccess)
28 | {
29 | throw new Exception(string.Join(Environment.NewLine,
30 | compilationUnit.GetErrors().Select(x => string.Format("Line {0}, Col {1}: {2}{3}{4}",
31 | x.Location.StartLineColumn.Line, x.Location.StartLineColumn.Column, x.Message,
32 | Environment.NewLine, x.Location.Source.GetSourceLine(x.Location.StartPos).GetText()))));
33 | }
34 |
35 | Assert.That(compilationUnit.IsSuccess, Is.True);
36 |
37 | // Get pretty-printed version of parse tree.
38 | var parseTree = compilationUnit.CreateParseTree();
39 | var parsedCode = parseTree.ToString();
40 |
41 | // Compare pretty-printed parse tree with known good version
42 | // (if known good version exists).
43 | if (File.Exists(knownGoodFile))
44 | {
45 | var knownGoodCode = File.ReadAllText(knownGoodFile).Replace("\r\n", "\n");
46 | Assert.That(parsedCode.Replace("\r\n", "\n"), Is.EqualTo(knownGoodCode));
47 | }
48 | }
49 |
50 | private static IEnumerable GetTestShaders()
51 | {
52 | return Directory.GetFiles("Shaders", "*.hlsl", SearchOption.AllDirectories)
53 | .Select(x => new TestCaseData(x, Path.ChangeExtension(x, ".knowngood")));
54 | }
55 |
56 | private static string Preprocess(string effectCode, string filePath)
57 | {
58 | var fullPath = Path.GetFullPath(filePath);
59 |
60 | var pp = new Preprocessor();
61 |
62 | pp.EmitExtraLineInfo = false;
63 | pp.addFeature(Feature.LINEMARKERS);
64 | pp.setQuoteIncludePath(new List { Path.GetDirectoryName(fullPath) });
65 |
66 | pp.addInput(new StringLexerSource(effectCode, true, fullPath));
67 |
68 | var result = new StringBuilder();
69 |
70 | var endOfStream = false;
71 | while (!endOfStream)
72 | {
73 | var token = pp.token();
74 | switch (token.getType())
75 | {
76 | case Token.EOF:
77 | endOfStream = true;
78 | break;
79 | case Token.CCOMMENT:
80 | case Token.CPPCOMMENT:
81 | break;
82 | default:
83 | var tokenText = token.getText();
84 | if (tokenText != null)
85 | result.Append(tokenText);
86 | break;
87 | }
88 | }
89 |
90 | return result.ToString();
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("HlslParser.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("HlslParser.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("52cf51f5-0e3a-4035-a6bc-60660b51e564")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/FxDis/readme.txt:
--------------------------------------------------------------------------------
1 | From FXDIS:
2 | http://code.google.com/p/fxdis-d3d1x/
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/FxDis/test.hlsl:
--------------------------------------------------------------------------------
1 | cbuffer cbuf0
2 | {
3 | float4 cool;
4 | int4 zeek;
5 | int2 arr[127];
6 | };
7 |
8 | sampler samp0;
9 | sampler samp1;
10 | Texture2D tex0;
11 | TextureCube tex1;
12 | Texture3D tex2;
13 | Texture2DMS tex3;
14 | Texture2D tex4[6];
15 |
16 | float4 blah2( float4 cool )
17 | {
18 | for ( int i = 0; i < (int)cool.x; i++ )
19 | {
20 | for ( int j = 0; j < (int)cool.y; j++ )
21 | {
22 | cool += tex0.SampleGrad( samp0, float2( i, j ), 1.5f, 4.1f );
23 | }
24 | }
25 | cool += cool + float4(1.1, 2.2, 3.3, 4.4);
26 | cool *= 55566.2;
27 |
28 | uint val;
29 | tex0.GetDimensions(0, cool.x, val, cool.z);
30 | cool.y = val;
31 | cool.zw *= GetRenderTargetSamplePosition(asuint(cool.y));
32 | cool += countbits(asuint(cool));
33 | cool += reversebits(asuint(cool));
34 |
35 | if (cool.x == 2)
36 | abort();
37 |
38 | if (cool.z % 4 == 0)
39 | printf("%0 is fine!", cool.z);
40 | else
41 | printf("%0 is not %1 fine!", cool.z, cool.x);
42 |
43 | if (cool.z % 3 == 0)
44 | errorf("%0 is invalid", cool.z);
45 |
46 | return cool;
47 | }
48 |
49 | float4 blah( float4 cool )
50 | {
51 |
52 | for ( int i = 0; i < (int)cool.x; i++ )
53 | {
54 | for ( int j = 0; j < (int)cool.y; j++ )
55 | {
56 | cool += tex0.SampleGrad( samp0, float2( i, j ), 1.5f, 4.1f ) + blah2(cool);
57 | }
58 | }
59 | cool += cool + float4(1.1, 2.2, 3.3, 4.4);
60 |
61 | return cool;
62 | }
63 |
64 | float4 VS(
65 | uint instanceID : SV_InstanceID,
66 | uint vertexID : SV_VertexID) : SV_Position
67 | {
68 | return float4(instanceID, vertexID, 1, 1);
69 | }
70 |
71 | float4 PS(
72 | float4 t0 : TEXCOORD0,
73 | float4 t1 : TEXCOORD1_centroid,
74 | float4 p0 : SV_POSITION,
75 | uint rtai : SV_RenderTargetArrayIndex,
76 | float cullDist : SV_CullDistance,
77 | uint vai : SV_ViewportArrayIndex,
78 | uint sIndex : SV_SampleIndex,
79 | bool frontFace : SV_IsFrontFace,
80 | float clipDist : SV_ClipDistance,
81 | uint coverage : SV_Coverage,
82 | uint primitiveID : SV_PrimitiveID
83 | ) : SV_TARGET
84 | {
85 | float j = (uint)p0.x + dot(t0, float4(0,1,2,3)) + t1.x + (zeek.y ^ 2);
86 | for ( int i = 0; i < 10; i++ )
87 | {
88 | j += i * (1.0f/(i+(1.001))) + sqrt( j );
89 | if (j < 0)
90 | break;
91 | }
92 | j += 3;
93 | j += rtai;
94 | j += cullDist;
95 | j += vai;
96 | j += vai | sIndex;
97 | j += sIndex;
98 | if (frontFace)
99 | j += 4;
100 | j += clipDist;
101 | j += coverage;
102 | j += primitiveID;
103 | int q = (int)j;
104 | if ( q < 0 )
105 | {
106 | q ^= 50;
107 | }
108 | else if ( q > 5 )
109 | {
110 | q &= 2222;
111 | }
112 | else
113 | {
114 | q -= arr[q];
115 | }
116 |
117 | j += cool.x + cool.y + cool.z + cool.w;
118 | j += tex0.Sample( samp0, float2( 0.125f, 5.0f ) ).x;
119 | j += tex0.Sample( samp1, float2( 0.777f, 1234.5f ) ).x;
120 | j += tex1.Sample( samp0, float3( 0.125f, 5.0f, 1.0 ) ).x;
121 | j += tex2.Sample( samp0, float3( 0.125f, 5.0f, 1.0 ) ).z;
122 | j += tex3.Load( int2( 0.125f, 5.0f ), 0, 1 ).x;
123 | j += tex0.SampleBias( samp0, float2( j, 1/j ), -15 ).y;
124 |
125 | j += tex4[0].Sample( samp0, int2( 0, 5 ) ).z;
126 | j += tex4[1].Sample( samp0, int2( 0, 5 ) ).z;
127 |
128 | float x[8];
129 | float y[4];
130 | float z[4];
131 |
132 | y[3] = q;
133 | z[2] = q;
134 | y[2] = j;
135 | z[1] = j;
136 | q &= 556677;
137 | x[0] = q;
138 | z[0] = q;
139 |
140 | q |= 42;
141 | x[1] = q;
142 | z[3] = q;
143 | q >>= 76;
144 | y[1] = q;
145 | x[2] = q;
146 | q <<= 22;
147 | uint qu = q;
148 | qu ^= q;
149 | x[3] = qu;
150 | y[0] = qu;
151 | qu >>= 3;
152 | x[4] = qu;
153 | qu <<= 2;
154 | x[5] = qu;
155 | qu ^= arr[qu];
156 | x[6] = qu;
157 | qu &= arr[qu & 127];
158 | x[7] = qu;
159 | j += arr[qu+66].y * arr[qu+1].x;
160 | x[7] += j;
161 |
162 | i += x[(int)q & 7];
163 | q += x[(int)i & 7];
164 | i += y[(int)q & 7];
165 | i += z[(int)q & 7];
166 |
167 | return float4(i,q,j*.2,qu + .5f) + blah( float4(i, q, j, qu));
168 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/FxDis/test.knowngood:
--------------------------------------------------------------------------------
1 | cbuffer cbuf0
2 | {
3 | float4 cool;
4 | int4 zeek;
5 | int2 arr[127];
6 | };
7 | sampler samp0;
8 | sampler samp1;
9 | Texture2D tex0;
10 | TextureCube tex1;
11 | Texture3D tex2;
12 | Texture2DMS tex3;
13 | Texture2D tex4[6];
14 | float4 blah2(float4 cool)
15 | {
16 | for (int i = 0; i < (int) cool.x; i++)
17 | {
18 | for (int j = 0; j < (int) cool.y; j++)
19 | {
20 | cool += tex0.SampleGrad(samp0, float2(i, j), 1.5f, 4.1f);
21 | }
22 | }
23 | cool += cool + float4(1.1, 2.2, 3.3, 4.4);
24 | cool *= 55566.2;
25 | uint val;
26 | tex0.GetDimensions(0, cool.x, val, cool.z);
27 | cool.y = val;
28 | cool.zw *= GetRenderTargetSamplePosition(asuint(cool.y));
29 | cool += countbits(asuint(cool));
30 | cool += reversebits(asuint(cool));
31 | if (cool.x == 2)
32 | abort();
33 | if (cool.z % 4 == 0)
34 | printf("%0 is fine!", cool.z);
35 | else
36 | printf("%0 is not %1 fine!", cool.z, cool.x);
37 | if (cool.z % 3 == 0)
38 | errorf("%0 is invalid", cool.z);
39 | return cool;
40 | }
41 | float4 blah(float4 cool)
42 | {
43 | for (int i = 0; i < (int) cool.x; i++)
44 | {
45 | for (int j = 0; j < (int) cool.y; j++)
46 | {
47 | cool += tex0.SampleGrad(samp0, float2(i, j), 1.5f, 4.1f) + blah2(cool);
48 | }
49 | }
50 | cool += cool + float4(1.1, 2.2, 3.3, 4.4);
51 | return cool;
52 | }
53 | float4 VS(uint instanceID : SV_InstanceID, uint vertexID : SV_VertexID) : SV_Position
54 | {
55 | return float4(instanceID, vertexID, 1, 1);
56 | }
57 | float4 PS(float4 t0 : TEXCOORD0, float4 t1 : TEXCOORD1_centroid, float4 p0 : SV_POSITION, uint rtai : SV_RenderTargetArrayIndex, float cullDist : SV_CullDistance, uint vai : SV_ViewportArrayIndex, uint sIndex : SV_SampleIndex, bool frontFace : SV_IsFrontFace, float clipDist : SV_ClipDistance, uint coverage : SV_Coverage, uint primitiveID : SV_PrimitiveID) : SV_TARGET
58 | {
59 | float j = (uint) p0.x + dot(t0, float4(0, 1, 2, 3)) + t1.x + (zeek.y ^ 2);
60 | for (int i = 0; i < 10; i++)
61 | {
62 | j += i * (1.0f / (i + (1.001))) + sqrt(j);
63 | if (j < 0)
64 | break;
65 | }
66 | j += 3;
67 | j += rtai;
68 | j += cullDist;
69 | j += vai;
70 | j += vai | sIndex;
71 | j += sIndex;
72 | if (frontFace)
73 | j += 4;
74 | j += clipDist;
75 | j += coverage;
76 | j += primitiveID;
77 | int q = (int) j;
78 | if (q < 0)
79 | {
80 | q ^= 50;
81 | }
82 | else
83 | if (q > 5)
84 | {
85 | q &= 2222;
86 | }
87 | else
88 | {
89 | q -= arr[q];
90 | }
91 | j += cool.x + cool.y + cool.z + cool.w;
92 | j += tex0.Sample(samp0, float2(0.125f, 5.0f)).x;
93 | j += tex0.Sample(samp1, float2(0.777f, 1234.5f)).x;
94 | j += tex1.Sample(samp0, float3(0.125f, 5.0f, 1.0)).x;
95 | j += tex2.Sample(samp0, float3(0.125f, 5.0f, 1.0)).z;
96 | j += tex3.Load(int2(0.125f, 5.0f), 0, 1).x;
97 | j += tex0.SampleBias(samp0, float2(j, 1 / j), -15).y;
98 | j += tex4[0].Sample(samp0, int2(0, 5)).z;
99 | j += tex4[1].Sample(samp0, int2(0, 5)).z;
100 | float x[8];
101 | float y[4];
102 | float z[4];
103 | y[3] = q;
104 | z[2] = q;
105 | y[2] = j;
106 | z[1] = j;
107 | q &= 556677;
108 | x[0] = q;
109 | z[0] = q;
110 | q |= 42;
111 | x[1] = q;
112 | z[3] = q;
113 | q >>= 76;
114 | y[1] = q;
115 | x[2] = q;
116 | q <<= 22;
117 | uint qu = q;
118 | qu ^= q;
119 | x[3] = qu;
120 | y[0] = qu;
121 | qu >>= 3;
122 | x[4] = qu;
123 | qu <<= 2;
124 | x[5] = qu;
125 | qu ^= arr[qu];
126 | x[6] = qu;
127 | qu &= arr[qu & 127];
128 | x[7] = qu;
129 | j += arr[qu + 66].y * arr[qu + 1].x;
130 | x[7] += j;
131 | i += x[(int) q & 7];
132 | q += x[(int) i & 7];
133 | i += y[(int) q & 7];
134 | i += z[(int) q & 7];
135 | return float4(i, q, j * .2, qu + .5f) + blah(float4(i, q, j, qu));
136 | }
137 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ds5/basic.hlsl:
--------------------------------------------------------------------------------
1 | struct HS_CONSTANT_OUTPUT
2 | {
3 | float edges[2] : SV_TessFactor;
4 | };
5 |
6 | struct HS_OUTPUT
7 | {
8 | float3 cpoint : CPOINT;
9 | };
10 |
11 | struct DS_OUTPUT
12 | {
13 | float4 position : SV_Position;
14 | };
15 |
16 | [domain("isoline")]
17 | DS_OUTPUT main(HS_CONSTANT_OUTPUT input, OutputPatch op, float2 uv : SV_DomainLocation)
18 | {
19 | DS_OUTPUT output;
20 |
21 | float t = uv.x;
22 |
23 | float3 pos = pow(1.0f - t, 3.0f) * op[0].cpoint + 3.0f * pow(1.0f - t, 2.0f) * t * op[1].cpoint + 3.0f * (1.0f - t) * pow(t, 2.0f) * op[2].cpoint + pow(t, 3.0f) * op[3].cpoint;
24 |
25 | output.position = float4(pos, 1.0f);
26 |
27 | return output;
28 | }
29 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ds5/basic.knowngood:
--------------------------------------------------------------------------------
1 | struct HS_CONSTANT_OUTPUT
2 | {
3 | float edges[2] : SV_TessFactor;
4 | };
5 | struct HS_OUTPUT
6 | {
7 | float3 cpoint : CPOINT;
8 | };
9 | struct DS_OUTPUT
10 | {
11 | float4 position : SV_Position;
12 | };
13 | [domain("isoline")]
14 | DS_OUTPUT main(HS_CONSTANT_OUTPUT input, OutputPatch op, float2 uv : SV_DomainLocation)
15 | {
16 | DS_OUTPUT output;
17 | float t = uv.x;
18 | float3 pos = pow(1.0f - t, 3.0f) * op[0].cpoint + 3.0f * pow(1.0f - t, 2.0f) * t * op[1].cpoint + 3.0f * (1.0f - t) * pow(t, 2.0f) * op[2].cpoint + pow(t, 3.0f) * op[3].cpoint;
19 | output.position = float4(pos, 1.0f);
20 | return output;
21 | }
22 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/hs5/basic.hlsl:
--------------------------------------------------------------------------------
1 | struct VS_OUTPUT
2 | {
3 | float3 cpoint : CPOINT;
4 | };
5 |
6 | struct HS_CONSTANT_OUTPUT
7 | {
8 | float edges[2] : SV_TessFactor;
9 | };
10 |
11 | struct HS_OUTPUT
12 | {
13 | float3 cpoint : CPOINT;
14 | };
15 |
16 | HS_CONSTANT_OUTPUT HSConst()
17 | {
18 | HS_CONSTANT_OUTPUT output;
19 |
20 | output.edges[0] = 1.0f; // Detail factor (see below for explanation)
21 | output.edges[1] = 8.0f; // Density factor
22 |
23 | return output;
24 | }
25 |
26 | [domain("isoline")]
27 | [partitioning("integer")]
28 | [outputtopology("line")]
29 | [outputcontrolpoints(4)]
30 | [patchconstantfunc("HSConst")]
31 | HS_OUTPUT main(InputPatch ip, uint id : SV_OutputControlPointID)
32 | {
33 | HS_OUTPUT output;
34 | output.cpoint = ip[id].cpoint;
35 | return output;
36 | }
37 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ps4/primID.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct PS_INPUT
3 | {
4 | uint PrimID : SV_PrimitiveID;
5 | };
6 |
7 | float4 main( PS_INPUT input ) : SV_Target
8 | {
9 | float4 colour;
10 | float fPrimID = input.PrimID;
11 | colour.r = fPrimID;
12 | colour.g = 2 * fPrimID;
13 | colour.b = (1.0/64.0) * fPrimID;
14 | colour.a = (1.0/32.0) * fPrimID;
15 | return colour;
16 | }
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ps5/conservative_depth.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct PS_INPUT
3 | {
4 | float4 colour : COLOR0;
5 | float depth : DEPTH;
6 | };
7 |
8 | struct PS_OUTPUT_GE
9 | {
10 | float colour : SV_Target;
11 | float depth : SV_DepthGreaterEqual;
12 | };
13 |
14 | struct PS_OUTPUT_LE
15 | {
16 | float colour : SV_Target;
17 | float depth : SV_DepthLessEqual;
18 | };
19 |
20 |
21 | PS_OUTPUT_GE DepthGreaterThan( PS_INPUT Input )
22 | {
23 | PS_OUTPUT_GE Output;
24 |
25 | Output.colour = Input.colour;
26 | Output.depth = Input.depth;
27 |
28 | return Output;
29 | }
30 |
31 | PS_OUTPUT_LE DepthLessThan( PS_INPUT Input )
32 | {
33 | PS_OUTPUT_LE Output;
34 |
35 | Output.colour = Input.colour;
36 | Output.depth = Input.depth;
37 |
38 | return Output;
39 | }
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ps5/interface_arrays.hlsl:
--------------------------------------------------------------------------------
1 |
2 | interface iChangeColour
3 | {
4 | float3 ChangeColour(float3 colour);
5 | };
6 |
7 | class cDoubleColour : iChangeColour
8 | {
9 | float3 ChangeColour(float3 colour) {
10 | return colour * float3(2, 2, 2);
11 | }
12 | };
13 |
14 | class cHalfColour : iChangeColour
15 | {
16 | float3 ChangeColour(float3 colour) {
17 | return colour / float3(2, 2, 2);
18 | }
19 | };
20 |
21 |
22 | class cUnchangedColour : iChangeColour
23 | {
24 | float3 ChangeColour(float3 colour) {
25 | return colour;
26 | }
27 | };
28 |
29 | interface iAlpha
30 | {
31 | float ChooseAlpha();
32 | };
33 |
34 | class OneAlpha : iAlpha
35 | {
36 | float ChooseAlpha() {
37 | return 1.0;
38 | }
39 | };
40 |
41 | class TwoThirdsAlpha : iAlpha
42 | {
43 | float ChooseAlpha() {
44 | return 0.66;
45 | }
46 | };
47 |
48 | struct PS_INPUT
49 | {
50 | float3 Colour : COLOR0;
51 | };
52 |
53 | iChangeColour gAbstractColourChanger[2];
54 | iChangeColour gAbstractColourChangerB;
55 | iAlpha gAlphaChooser[3];
56 |
57 | int alphaIndex;
58 |
59 | float4 main( PS_INPUT Input ) : SV_TARGET
60 | {
61 | float3 ModifiedColour = gAbstractColourChanger[1].ChangeColour(Input.Colour);
62 | ModifiedColour = gAbstractColourChangerB.ChangeColour(ModifiedColour);
63 |
64 | return float4(ModifiedColour,gAlphaChooser[alphaIndex].ChooseAlpha());
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ps5/interfaces.hlsl:
--------------------------------------------------------------------------------
1 |
2 | interface iChangeColour
3 | {
4 | float3 ChangeColour(float3 colour);
5 | };
6 |
7 | class cDoubleColour : iChangeColour
8 | {
9 | float3 ChangeColour(float3 colour) {
10 | return colour * float3(2, 2, 2);
11 | }
12 | };
13 |
14 | class cHalfColour : iChangeColour
15 | {
16 | float3 ChangeColour(float3 colour) {
17 | return colour / float3(2, 2, 2);
18 | }
19 | };
20 |
21 |
22 | class cUnchangedColour : iChangeColour
23 | {
24 | float3 ChangeColour(float3 colour) {
25 | return colour;
26 | }
27 | };
28 |
29 | interface iAlpha
30 | {
31 | float ChooseAlpha();
32 | };
33 |
34 | class OneAlpha : iAlpha
35 | {
36 | float ChooseAlpha() {
37 | return 1.0;
38 | }
39 | };
40 |
41 | class TwoThirdsAlpha : iAlpha
42 | {
43 | float ChooseAlpha() {
44 | return 0.66;
45 | }
46 | };
47 |
48 | struct PS_INPUT
49 | {
50 | float3 Colour : COLOR0;
51 | };
52 |
53 | iChangeColour gAbstractColourChanger;
54 | iChangeColour gAbstractColourChangerB;
55 | iAlpha gAlphaChooser;
56 |
57 | float4 main( PS_INPUT Input ) : SV_TARGET
58 | {
59 | float3 ModifiedColour = gAbstractColourChanger.ChangeColour(Input.Colour);
60 | ModifiedColour = gAbstractColourChangerB.ChangeColour(ModifiedColour);
61 |
62 | return float4(ModifiedColour,gAlphaChooser.ChooseAlpha());
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/ps5/sample.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct PS_INPUT
3 | {
4 | float4 TexC : TEXCOORD0;
5 | };
6 | SamplerState TextureSampler
7 | {
8 | Filter = MIN_MAG_MIP_LINEAR;
9 | AddressU = Wrap;
10 | AddressV = Wrap;
11 | };
12 |
13 | Texture2D TextureBase;
14 | Texture2D TextureDetail;
15 |
16 | float4 main( PS_INPUT input ) : SV_Target
17 | {
18 | float4 base = TextureBase.Sample(TextureSampler, input.TexC);
19 | float4 detail = TextureDetail.Sample(TextureSampler, input.TexC);
20 | return base * detail;
21 | }
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/readme.txt:
--------------------------------------------------------------------------------
1 | From HLSLCrossCompiler by James Jones:
2 | https://github.com/James-Jones/HLSLCrossCompiler
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs4/mov.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | VS_OUTPUT main( in float4 vPosition : POSITION )
8 | {
9 | VS_OUTPUT Output;
10 |
11 | Output.Position = vPosition;
12 |
13 | return Output;
14 | }
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs4/multiple_const_buffers.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | float4 Albedo : COLOR0;
6 | };
7 |
8 | cbuffer transformsA
9 | {
10 | float4x4 modelview;
11 | int unusedTestA;
12 | }
13 | cbuffer transformsB
14 | {
15 | int unusedTestB;
16 | float4x4 projection;
17 | }
18 |
19 | //default/global cbuffer
20 | float4 diffuse;
21 |
22 | VS_OUTPUT main( in float4 vPosition : POSITION )
23 | {
24 | VS_OUTPUT Output;
25 |
26 | float4x4 mvp = modelview * projection;
27 |
28 | Output.Position = mul(vPosition, mvp);
29 | Output.Albedo = diffuse;
30 |
31 | return Output;
32 | }
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs4/switch.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | float4 Colour : COLOR0;
6 | };
7 |
8 | int SwitchValue;
9 |
10 | VS_OUTPUT main( in float4 vPosition : POSITION )
11 | {
12 | VS_OUTPUT Output;
13 |
14 |
15 | Output.Position = vPosition;
16 |
17 | switch(SwitchValue)
18 | {
19 | case 0:
20 | {
21 | Output.Colour = float4(1, 0, 0, 1);
22 | break;
23 | }
24 | case 1:
25 | {
26 | Output.Colour = float4(1, 1, 0, 1);
27 | break;
28 | }
29 | default:
30 | {
31 | Output.Colour = float4(1, 1, 1, 1);
32 | break;
33 | }
34 | }
35 |
36 | return Output;
37 | }
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs5/any.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | VS_OUTPUT main( in float4 vPosition : POSITION )
8 | {
9 | VS_OUTPUT Output;
10 |
11 | if(any(vPosition))
12 | {
13 | vPosition.z = 2.0;
14 | }
15 |
16 | Output.Position = vPosition;
17 |
18 | return Output;
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs5/const_temp.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | row_major float4x4 mWorldViewProj;
8 |
9 | VS_OUTPUT main( in float4 vPosition : POSITION, in float4 vTexCoord : TEXCOORD0 )
10 | {
11 | VS_OUTPUT Output;
12 |
13 | Output.Position = mul(vPosition, mWorldViewProj) + vTexCoord;
14 |
15 | return Output;
16 | }
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs5/mad_imm.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | VS_OUTPUT main( in float4 vPosition : POSITION, in float4 vTexCoord : TEXCOORD0 )
8 | {
9 | VS_OUTPUT Output;
10 | float4 Offset;
11 |
12 | Offset.x = 0.1;
13 | Offset.y = 0.2;
14 | Offset.z = 0.3;
15 | Offset.w = 0.4;
16 |
17 | Output.Position = vPosition + Offset * vTexCoord;
18 |
19 | return Output;
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs5/mov.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | VS_OUTPUT main( in float4 vPosition : POSITION )
8 | {
9 | VS_OUTPUT Output;
10 |
11 | Output.Position = vPosition;
12 |
13 | return Output;
14 | }
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/HlslCrossCompiler/vs5/sincos.hlsl:
--------------------------------------------------------------------------------
1 |
2 | struct VS_OUTPUT
3 | {
4 | float4 Position : SV_Position;
5 | };
6 |
7 | float angle;
8 |
9 | VS_OUTPUT main( in float4 vPosition : POSITION )
10 | {
11 | VS_OUTPUT Output;
12 | float cos;
13 |
14 | vPosition.x = sin(angle*2);
15 | sincos(angle, vPosition.w, cos);
16 |
17 | vPosition.z += cos;
18 |
19 | Output.Position = vPosition;
20 |
21 | return Output;
22 | }
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Internal/Textures.hlsl:
--------------------------------------------------------------------------------
1 | struct VertexShaderInput
2 | {
3 | float4 pos : POSITION;
4 | float2 tex : TEXCOORD;
5 | };
6 |
7 | struct PixelShaderInput
8 | {
9 | float4 pos : SV_POSITION;
10 | float2 tex : TEXCOORD;
11 | };
12 |
13 | float Scalar1;
14 | int Scalar2;
15 |
16 | float2 Vector1;
17 | int4 Vector2;
18 | vector Vector3;
19 |
20 | matrix Matrix1;
21 | float1x2 Matrix2;
22 | int2x3 Matrix3;
23 | bool4x2 Matrix4;
24 | matrix Matrix5;
25 |
26 | float4x4 WorldViewProjection;
27 |
28 | Texture2D Picture;
29 | Texture2D PictureTyped;
30 | SamplerState PictureSampler;
31 | SamplerComparisonState PictureSamplerComparison;
32 |
33 | Texture2DMS PictureMS;
34 |
35 | PixelShaderInput VS(VertexShaderInput input)
36 | {
37 | PixelShaderInput output = (PixelShaderInput) 0;
38 |
39 | output.pos = mul(input.pos, WorldViewProjection);
40 | output.tex = input.tex;
41 |
42 | return output;
43 | }
44 |
45 | float4 PS(PixelShaderInput input) : SV_Target
46 | {
47 | float lod = Picture.CalculateLevelOfDetail(PictureSampler, input.tex);
48 | float lodUnclamped = Picture.CalculateLevelOfDetailUnclamped(PictureSampler, input.tex);
49 | float4 gathered = Picture.Gather(PictureSampler, input.tex, int2(0, 1));
50 |
51 | int width, height, numLevels;
52 | Picture.GetDimensions(1, width, height, numLevels);
53 |
54 | float2 samplePos = PictureMS.GetSamplePosition(0);
55 |
56 | float4 loaded = PictureMS.Load(int2(25, 10), 1, int2(0, 1));
57 |
58 | float4 sampled = Picture.Sample(PictureSampler, input.tex);
59 | float4 sampleBias = Picture.SampleBias(PictureSampler, input.tex, 0.5);
60 | float4 sampleCmp = Picture.SampleCmp(PictureSamplerComparison, input.tex, 0.4);
61 | float4 sampleCmpLevelZero = Picture.SampleCmpLevelZero(PictureSamplerComparison, input.tex, 0.6);
62 | float4 sampleGrad = Picture.SampleGrad(PictureSampler, input.tex, 0.1, 0.2);
63 | float4 sampleLevel = Picture.SampleLevel(PictureSampler, input.tex, 1.5);
64 |
65 | return float4(lod, lodUnclamped, width, height)
66 | + gathered
67 | + float4(samplePos, 0, 0)
68 | + sampled
69 | + sampleBias
70 | + sampleCmp
71 | + sampleCmpLevelZero
72 | + sampleGrad
73 | + sampleLevel;
74 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Internal/Textures.knowngood:
--------------------------------------------------------------------------------
1 | struct VertexShaderInput
2 | {
3 | float4 pos : POSITION;
4 | float2 tex : TEXCOORD;
5 | };
6 | struct PixelShaderInput
7 | {
8 | float4 pos : SV_POSITION;
9 | float2 tex : TEXCOORD;
10 | };
11 | float Scalar1;
12 | int Scalar2;
13 | float2 Vector1;
14 | int4 Vector2;
15 | vector Vector3;
16 | matrix Matrix1;
17 | float1x2 Matrix2;
18 | int2x3 Matrix3;
19 | bool4x2 Matrix4;
20 | matrix Matrix5;
21 | float4x4 WorldViewProjection;
22 | Texture2D Picture;
23 | Texture2D PictureTyped;
24 | SamplerState PictureSampler;
25 | SamplerComparisonState PictureSamplerComparison;
26 | Texture2DMS PictureMS;
27 | PixelShaderInput VS(VertexShaderInput input)
28 | {
29 | PixelShaderInput output = (PixelShaderInput) 0;
30 | output.pos = mul(input.pos, WorldViewProjection);
31 | output.tex = input.tex;
32 | return output;
33 | }
34 | float4 PS(PixelShaderInput input) : SV_Target
35 | {
36 | float lod = Picture.CalculateLevelOfDetail(PictureSampler, input.tex);
37 | float lodUnclamped = Picture.CalculateLevelOfDetailUnclamped(PictureSampler, input.tex);
38 | float4 gathered = Picture.Gather(PictureSampler, input.tex, int2(0, 1));
39 | int width, height, numLevels;
40 | Picture.GetDimensions(1, width, height, numLevels);
41 | float2 samplePos = PictureMS.GetSamplePosition(0);
42 | float4 loaded = PictureMS.Load(int2(25, 10), 1, int2(0, 1));
43 | float4 sampled = Picture.Sample(PictureSampler, input.tex);
44 | float4 sampleBias = Picture.SampleBias(PictureSampler, input.tex, 0.5);
45 | float4 sampleCmp = Picture.SampleCmp(PictureSamplerComparison, input.tex, 0.4);
46 | float4 sampleCmpLevelZero = Picture.SampleCmpLevelZero(PictureSamplerComparison, input.tex, 0.6);
47 | float4 sampleGrad = Picture.SampleGrad(PictureSampler, input.tex, 0.1, 0.2);
48 | float4 sampleLevel = Picture.SampleLevel(PictureSampler, input.tex, 1.5);
49 | return float4(lod, lodUnclamped, width, height) + gathered + float4(samplePos, 0, 0) + sampled + sampleBias + sampleCmp + sampleCmpLevelZero + sampleGrad + sampleLevel;
50 | }
51 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/AdaptiveTessellationCS40/TessellatorCS40_EdgeFactorCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: TessellatorCS40_EdgeFactorCS.hlsl
3 | //
4 | // The CS to compute edge tessellation factor acoording to current world, view, projection matrix
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | // http://jgt.akpeters.com/papers/akeninemoller01/tribox.html
10 | bool planeBoxOverlap(float3 normal, float d, float3 maxbox)
11 | {
12 | float3 vmin = maxbox, vmax = maxbox;
13 | [unroll]
14 | for (int q = 0;q <= 2; ++ q)
15 | {
16 | if (normal[q] > 0.0f)
17 | {
18 | vmin[q] *= -1;
19 | }
20 | else
21 | {
22 | vmax[q] *= -1;
23 | }
24 | }
25 | if (dot(normal, vmin) + d > 0.0f)
26 | {
27 | return false;
28 | }
29 | if (dot(normal, vmax) + d >= 0.0f)
30 | {
31 | return true;
32 | }
33 |
34 | return false;
35 | }
36 |
37 | /*======================== X-tests ========================*/
38 | bool AXISTEST_X01(float3 v0, float3 v2, float3 boxhalfsize, float2 ab, float2 fab)
39 | {
40 | float p0 = ab.x * v0.y - ab.y * v0.z;
41 | float p2 = ab.x * v2.y - ab.y * v2.z;
42 | float min_v = min(p0, p2);
43 | float max_v = max(p0, p2);
44 | float rad = dot(fab, boxhalfsize.yz);
45 | return (min_v < rad) && (max_v > -rad);
46 | }
47 |
48 | bool AXISTEST_X2(float3 v0, float3 v1, float3 boxhalfsize, float2 ab, float2 fab)
49 | {
50 | float p0 = ab.x * v0.y - ab.y * v0.z;
51 | float p1 = ab.x * v1.y - ab.y * v1.z;
52 | float min_v = min(p0, p1);
53 | float max_v = max(p0, p1);
54 | float rad = dot(fab, boxhalfsize.yz);
55 | return (min_v < rad) && (max_v > -rad);
56 | }
57 |
58 | /*======================== Y-tests ========================*/
59 | bool AXISTEST_Y02(float3 v0, float3 v2, float3 boxhalfsize, float2 ab, float2 fab)
60 | {
61 | float p0 = -ab.x * v0.x + ab.y * v0.z;
62 | float p2 = -ab.x * v2.x + ab.y * v2.z;
63 | float min_v = min(p0, p2);
64 | float max_v = max(p0, p2);
65 | float rad = dot(fab, boxhalfsize.xz);
66 | return (min_v < rad) && (max_v > -rad);
67 | }
68 |
69 | bool AXISTEST_Y1(float3 v0, float3 v1, float3 boxhalfsize, float2 ab, float2 fab)
70 | {
71 | float p0 = -ab.x * v0.x + ab.y * v0.z;
72 | float p1 = -ab.x * v1.x + ab.y * v1.z;
73 | float min_v = min(p0, p1);
74 | float max_v = max(p0, p1);
75 | float rad = dot(fab, boxhalfsize.xz);
76 | return (min_v < rad) && (max_v > -rad);
77 | }
78 |
79 | /*======================== Z-tests ========================*/
80 | bool AXISTEST_Z12(float3 v1, float3 v2, float3 boxhalfsize, float2 ab, float2 fab)
81 | {
82 | float p1 = ab.x * v1.x - ab.y * v1.y;
83 | float p2 = ab.x * v2.x - ab.y * v2.y;
84 | float min_v = min(p1, p2);
85 | float max_v = max(p1, p2);
86 | float rad = dot(fab, boxhalfsize.xy);
87 | return (min_v < rad) && (max_v > -rad);
88 | }
89 |
90 | bool AXISTEST_Z0(float3 v0, float3 v1, float3 boxhalfsize, float2 ab, float2 fab)
91 | {
92 | float p0 = ab.x * v0.x - ab.y * v0.y;
93 | float p1 = ab.x * v1.x - ab.y * v1.y;
94 | float min_v = min(p0, p1);
95 | float max_v = max(p0, p1);
96 | float rad = dot(fab, boxhalfsize.xy);
97 | return (min_v < rad) && (max_v > -rad);
98 | }
99 |
100 | bool triBoxOverlap(float3 boxcenter,float3 boxhalfsize,float3 triverts0, float3 triverts1, float3 triverts2)
101 | {
102 | /* use separating axis theorem to test overlap between triangle and box */
103 | /* need to test for overlap in these directions: */
104 | /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
105 | /* we do not even need to test these) */
106 | /* 2) normal of the triangle */
107 | /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
108 | /* this gives 3x3=9 more tests */
109 |
110 | /* This is the fastest branch on Sun */
111 | /* move everything so that the boxcenter is in (0,0,0) */
112 | float3 v0 = triverts0 - boxcenter;
113 | float3 v1 = triverts1 - boxcenter;
114 | float3 v2 = triverts2 - boxcenter;
115 |
116 | /* compute triangle edges */
117 | float3 e0 = v1 - v0; /* tri edge 0 */
118 | float3 e1 = v2 - v1; /* tri edge 1 */
119 | float3 e2 = v0 - v2; /* tri edge 2 */
120 |
121 | /* Bullet 3: */
122 | /* test the 9 tests first (this was faster) */
123 | float3 fe = abs(e0);
124 | if (!AXISTEST_X01(v0, v2, boxhalfsize, e0.zy, fe.zy)
125 | || !AXISTEST_Y02(v0, v2, boxhalfsize, e0.zx, fe.zx)
126 | || !AXISTEST_Z12(v1, v2, boxhalfsize, e0.yx, fe.yx))
127 | {
128 | return false;
129 | }
130 |
131 | fe = abs(e1);
132 | if (!AXISTEST_X01(v0, v2, boxhalfsize, e1.zy, fe.zy)
133 | || !AXISTEST_Y02(v0, v2, boxhalfsize, e1.zx, fe.zx)
134 | || !AXISTEST_Z0(v0, v1, boxhalfsize, e1.yx, fe.yx))
135 | {
136 | return false;
137 | }
138 |
139 | fe = abs(e2);
140 | if (!AXISTEST_X2(v0, v1, boxhalfsize, e2.zy, fe.zy)
141 | || !AXISTEST_Y1(v0, v1, boxhalfsize, e2.zx, fe.zx)
142 | || !AXISTEST_Z12(v1, v2, boxhalfsize, e2.yx, fe.yx))
143 | {
144 | return false;
145 | }
146 |
147 | /* Bullet 1: */
148 | /* first test overlap in the {x,y,z}-directions */
149 | /* find min, max of the triangle each direction, and test for overlap in */
150 | /* that direction -- this is equivalent to testing a minimal AABB around */
151 | /* the triangle against the AABB */
152 |
153 | float3 min_v = min(min(v0, v1), v2);
154 | float3 max_v = max(max(v0, v1), v2);
155 | if ((min_v.x > boxhalfsize.x || max_v.x < -boxhalfsize.x)
156 | || (min_v.y > boxhalfsize.y || max_v.y < -boxhalfsize.y)
157 | || (min_v.z > boxhalfsize.z || max_v.z < -boxhalfsize.z))
158 | {
159 | return false;
160 | }
161 |
162 | /* Bullet 2: */
163 | /* test if the box intersects the plane of the triangle */
164 | /* compute plane equation of triangle: normal*x+d=0 */
165 | float3 normal = cross(e0, e1);
166 | float d = -dot(normal, v0); /* plane eq: normal.x+d=0 */
167 | if (!planeBoxOverlap(normal, d, boxhalfsize))
168 | {
169 | return false;
170 | }
171 |
172 | return true; /* box and triangle overlaps */
173 | }
174 |
175 |
176 | Buffer InputVertices : register(t0);
177 | RWStructuredBuffer EdgeFactorBufOut : register(u0);
178 |
179 | cbuffer cb
180 | {
181 | row_major matrix g_matWVP;
182 | float2 g_tess_edge_length_scale;
183 | int num_triangles;
184 | float dummy;
185 | }
186 |
187 | [numthreads(128, 1, 1)]
188 | void CSEdgeFactor( uint3 DTid : SV_DispatchThreadID )
189 | {
190 | if (DTid.x < num_triangles)
191 | {
192 | float4 p0 = mul(InputVertices[DTid.x*3+0], g_matWVP);
193 | float4 p1 = mul(InputVertices[DTid.x*3+1], g_matWVP);
194 | float4 p2 = mul(InputVertices[DTid.x*3+2], g_matWVP);
195 | p0 = p0 / p0.w;
196 | p1 = p1 / p1.w;
197 | p2 = p2 / p2.w;
198 |
199 | float4 factor;
200 | // Only triangles which are completely inside or intersect with the view frustum are taken into account
201 | if ( triBoxOverlap( float3(0, 0, 0.5), float3(1.02, 1.02, 0.52), p0.xyz, p1.xyz, p2.xyz ) )
202 | {
203 | factor.x = length((p0.xy - p2.xy) * g_tess_edge_length_scale);
204 | factor.y = length((p1.xy - p0.xy) * g_tess_edge_length_scale);
205 | factor.z = length((p2.xy - p1.xy) * g_tess_edge_length_scale);
206 | factor.w = min(min(factor.x, factor.y), factor.z);
207 | factor = clamp(factor, 0, 9);
208 | } else
209 | {
210 | factor = 0;
211 | }
212 |
213 | EdgeFactorBufOut[DTid.x] = factor;
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/AdaptiveTessellationCS40/TessellatorCS40_NumVerticesIndicesCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: TessellatorCS40_NumVerticesIndicesCS.hlsl
3 | //
4 | // The CS to compute number of vertices and triangles to be generated from edge tessellation factor
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #include "TessellatorCS40_common.hlsl"
10 |
11 | StructuredBuffer InputEdgeFactor : register(t0);
12 | RWStructuredBuffer NumVerticesIndicesOut : register(u0);
13 |
14 | cbuffer cbCS : register(b1)
15 | {
16 | uint4 g_param;
17 | }
18 |
19 | [numthreads(128, 1, 1)]
20 | void CSNumVerticesIndices( uint3 DTid : SV_DispatchThreadID )
21 | {
22 | if (DTid.x < g_param.x)
23 | {
24 | float4 edge_factor = InputEdgeFactor[DTid.x];
25 |
26 | PROCESSED_TESS_FACTORS_TRI processedTessFactors;
27 | int num_points = TriProcessTessFactors(edge_factor, processedTessFactors, g_partitioning);
28 |
29 | int num_index;
30 | if (0 == num_points)
31 | {
32 | num_index = 0;
33 | }
34 | else if (3 == num_points)
35 | {
36 | num_index = 4;
37 | }
38 | else
39 | {
40 | int numRings = ((processedTessFactors.numPointsForOutsideInside.w + 1) / 2); // +1 is so even tess includes the center point, which we want to now
41 |
42 | int4 outsideInsideHalfTessFactor = int4(ceil(processedTessFactors.outsideInsideHalfTessFactor));
43 | uint3 n = NumStitchTransition(outsideInsideHalfTessFactor, processedTessFactors.outsideInsideTessFactorParity);
44 | num_index = n.x + n.y + n.z;
45 | num_index += TotalNumStitchRegular(true, DIAGONALS_MIRRORED, processedTessFactors.numPointsForOutsideInside.w, numRings - 1) * 3;
46 | if( processedTessFactors.outsideInsideTessFactorParity.w == TESSELLATOR_PARITY_ODD )
47 | {
48 | num_index += 4;
49 | }
50 | }
51 |
52 | NumVerticesIndicesOut[DTid.x] = uint2(num_points, num_index);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/AdaptiveTessellationCS40/TessellatorCS40_ScatterIDCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: TessellatorCS40_ScatterIDCS.hlsl
3 | //
4 | // The CS to scatter vertex ID and triangle ID
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 | StructuredBuffer InputScanned : register(t0);
9 | RWStructuredBuffer TriIDIndexIDOut : register(u0);
10 |
11 | cbuffer cbCS : register(b1)
12 | {
13 | uint4 g_param;
14 | }
15 |
16 | [numthreads(128, 1, 1)]
17 | void CSScatterVertexTriIDIndexID( uint3 DTid : SV_DispatchThreadID )
18 | {
19 | if (DTid.x < g_param.x)
20 | {
21 | uint start = InputScanned[DTid.x-1].x;
22 | uint end = InputScanned[DTid.x].x;
23 |
24 | for ( uint i = start; i < end; ++i )
25 | {
26 | TriIDIndexIDOut[i] = uint2(DTid.x, i - start);
27 | }
28 | }
29 | }
30 |
31 | [numthreads(128, 1, 1)]
32 | void CSScatterIndexTriIDIndexID( uint3 DTid : SV_DispatchThreadID )
33 | {
34 | if (DTid.x < g_param.x)
35 | {
36 | uint start = InputScanned[DTid.x-1].y;
37 | uint end = InputScanned[DTid.x].y;
38 |
39 | for ( uint i = start; i < end; ++i )
40 | {
41 | TriIDIndexIDOut[i] = uint2(DTid.x, i - start);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/AdaptiveTessellationCS40/TessellatorCS40_TessellateVerticesCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: TessellatorCS40_TessellateVerticesCS.hlsl
3 | //
4 | // The CS to tessellate vertices
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #include "TessellatorCS40_common.hlsl"
10 |
11 | StructuredBuffer InputTriIDIndexID : register(t0);
12 | StructuredBuffer InputEdgeFactor : register(t1);
13 |
14 | struct TessedVertex
15 | {
16 | uint BaseTriID;
17 | float2 bc;
18 | };
19 | RWStructuredBuffer TessedVerticesOut : register(u0);
20 |
21 | cbuffer cbCS : register(b1)
22 | {
23 | uint4 g_param;
24 | }
25 |
26 | void PlacePointIn1D(PROCESSED_TESS_FACTORS_TRI processedTessFactors, int ctx_index, int pt, out float location, int parity)
27 | {
28 | int numHalfTessFactorPoints = int(ceil(processedTessFactors.outsideInsideHalfTessFactor[ctx_index]));
29 |
30 | bool bFlip;
31 | if( pt >= numHalfTessFactorPoints )
32 | {
33 | pt = (numHalfTessFactorPoints << 1) - pt;
34 | if( TESSELLATOR_PARITY_ODD == parity )
35 | {
36 | pt -= 1;
37 | }
38 | bFlip = true;
39 | }
40 | else
41 | {
42 | bFlip = false;
43 | }
44 |
45 | if( pt == numHalfTessFactorPoints )
46 | {
47 | location = 0.5f;
48 | }
49 | else
50 | {
51 | unsigned int indexOnCeilHalfTessFactor = pt;
52 | unsigned int indexOnFloorHalfTessFactor = indexOnCeilHalfTessFactor;
53 | if( pt > processedTessFactors.outsideInsideSplitPointOnFloorHalfTessFactor[ctx_index] )
54 | {
55 | indexOnFloorHalfTessFactor -= 1;
56 | }
57 | float locationOnFloorHalfTessFactor = indexOnFloorHalfTessFactor * processedTessFactors.outsideInsideInvNumSegmentsOnFloorTessFactor[ctx_index];
58 | float locationOnCeilHalfTessFactor = indexOnCeilHalfTessFactor * processedTessFactors.outsideInsideInvNumSegmentsOnCeilTessFactor[ctx_index];
59 |
60 | location = lerp(locationOnFloorHalfTessFactor, locationOnCeilHalfTessFactor, frac(processedTessFactors.outsideInsideHalfTessFactor[ctx_index]));
61 |
62 | if( bFlip )
63 | {
64 | location = 1.0f - location;
65 | }
66 | }
67 | }
68 |
69 | [numthreads(128, 1, 1)]
70 | void CSTessellationVertices( uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex )
71 | {
72 | uint id = DTid.x;
73 | //uint id = Gid.x * 128 + GI; // Workaround for some CS4x preview drivers
74 |
75 | if ( id < g_param.x )
76 | {
77 | uint tri_id = InputTriIDIndexID[id].x;
78 | uint vert_id = InputTriIDIndexID[id].y;
79 |
80 | float4 outside_inside_factor = InputEdgeFactor[tri_id];
81 |
82 | PROCESSED_TESS_FACTORS_TRI processedTessFactors;
83 | int num_points = TriProcessTessFactors(outside_inside_factor, processedTessFactors, g_partitioning);
84 |
85 | float2 uv;
86 | if (3 == num_points)
87 | {
88 | if (0 == vert_id)
89 | {
90 | uv = float2(0, 1);
91 | }
92 | else if (1 == vert_id)
93 | {
94 | uv = float2(0, 0);
95 | }
96 | else
97 | {
98 | uv = float2(1, 0);
99 | }
100 | }
101 | else
102 | {
103 | if (vert_id < processedTessFactors.insideEdgePointBaseOffset)
104 | {
105 | // Generate exterior ring edge points, clockwise starting from point V (VW, the U==0 edge)
106 |
107 | int edge;
108 | if (vert_id < processedTessFactors.numPointsForOutsideInside.x - 1)
109 | {
110 | edge = 0;
111 | }
112 | else
113 | {
114 | vert_id -= processedTessFactors.numPointsForOutsideInside.x - 1;
115 | if (vert_id < processedTessFactors.numPointsForOutsideInside.y - 1)
116 | {
117 | edge = 1;
118 | }
119 | else
120 | {
121 | vert_id -= processedTessFactors.numPointsForOutsideInside.y - 1;
122 | edge = 2;
123 | }
124 | }
125 |
126 | int p = vert_id;
127 | int endPoint = processedTessFactors.numPointsForOutsideInside[edge] - 1;
128 | float param;
129 | int q = (edge & 0x1) ? p : endPoint - p; // whether to reverse point order given we are defining V or U (W implicit):
130 | // edge0, VW, has V decreasing, so reverse 1D points below
131 | // edge1, WU, has U increasing, so don't reverse 1D points below
132 | // edge2, UV, has U decreasing, so reverse 1D points below
133 | PlacePointIn1D(processedTessFactors, edge,q,param, processedTessFactors.outsideInsideTessFactorParity[edge]);
134 | if (0 == edge)
135 | {
136 | uv = float2(0, param);
137 | }
138 | else if (1 == edge)
139 | {
140 | uv = float2(param, 0);
141 | }
142 | else
143 | {
144 | uv = float2(param, 1 - param);
145 | }
146 | }
147 | else
148 | {
149 | // Generate interior ring points, clockwise spiralling in
150 |
151 | uint index = vert_id - processedTessFactors.insideEdgePointBaseOffset;
152 | uint ring = 1 + (((3 * processedTessFactors.numPointsForOutsideInside.w - 6) - sqrt(sqr(3 * processedTessFactors.numPointsForOutsideInside.w - 6) - 4 * 3 * index)) + 0.001f) / 6;
153 | index -= 3 * (processedTessFactors.numPointsForOutsideInside.w - ring - 1) * (ring - 1);
154 |
155 | uint startPoint = ring;
156 | uint endPoint = processedTessFactors.numPointsForOutsideInside.w - 1 - startPoint;
157 | if (index < 3 * (endPoint - startPoint))
158 | {
159 | uint edge = index / (endPoint - startPoint);
160 | uint p = index - edge * (endPoint - startPoint) + startPoint;
161 |
162 | int perpendicularAxisPoint = startPoint;
163 | float perpParam;
164 | PlacePointIn1D(processedTessFactors, 3, perpendicularAxisPoint, perpParam, processedTessFactors.outsideInsideTessFactorParity.w);
165 | perpParam = perpParam * 2 / 3;
166 |
167 | float param;
168 | int q = (edge & 0x1) ? p : endPoint - (p - startPoint); // whether to reverse point given we are defining V or U (W implicit):
169 | // edge0, VW, has V decreasing, so reverse 1D points below
170 | // edge1, WU, has U increasing, so don't reverse 1D points below
171 | // edge2, UV, has U decreasing, so reverse 1D points below
172 | PlacePointIn1D(processedTessFactors, 3, q,param, processedTessFactors.outsideInsideTessFactorParity.w);
173 | // edge0 VW, has perpendicular parameter U constant
174 | // edge1 WU, has perpendicular parameter V constant
175 | // edge2 UV, has perpendicular parameter W constant
176 | const unsigned int deriv = 2; // reciprocal is the rate of change of edge-parallel parameters as they are pushed into the triangle
177 | if (0 == edge)
178 | {
179 | uv = float2(perpParam, param - perpParam / deriv);
180 | }
181 | else if (1 == edge)
182 | {
183 | uv = float2(param - perpParam / deriv, perpParam);
184 | }
185 | else
186 | {
187 | uv = float2(param - perpParam / deriv, 1 - (param - perpParam / deriv + perpParam));
188 | }
189 | }
190 | else
191 | {
192 | if( processedTessFactors.outsideInsideTessFactorParity.w != TESSELLATOR_PARITY_ODD )
193 | {
194 | // Last point is the point at the center.
195 | uv = 1 / 3.0f;
196 | }
197 | }
198 | }
199 | }
200 |
201 | TessedVerticesOut[id].BaseTriID = tri_id;
202 | TessedVerticesOut[id].bc = uv;
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/AdaptiveTessellationCS40/TessellatorCS40_defines.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: TessellatorCS40_defines.h
3 | //
4 | // This file defines common constants which are included by both CPU code and shader code
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #define MAX_FACTOR 16
10 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/BasicCompute11/BasicCompute11.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: BasicCompute11.hlsl
3 | //
4 | // This file contains the Compute Shader to perform array A + array B
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #ifdef USE_STRUCTURED_BUFFERS
10 |
11 | struct BufType
12 | {
13 | int i;
14 | float f;
15 | #ifdef TEST_DOUBLE
16 | double d;
17 | #endif
18 | };
19 |
20 | StructuredBuffer Buffer0 : register(t0);
21 | StructuredBuffer Buffer1 : register(t1);
22 | RWStructuredBuffer BufferOut : register(u0);
23 |
24 | [numthreads(1, 1, 1)]
25 | void CSMain( uint3 DTid : SV_DispatchThreadID )
26 | {
27 | BufferOut[DTid.x].i = Buffer0[DTid.x].i + Buffer1[DTid.x].i;
28 | BufferOut[DTid.x].f = Buffer0[DTid.x].f + Buffer1[DTid.x].f;
29 | #ifdef TEST_DOUBLE
30 | BufferOut[DTid.x].d = Buffer0[DTid.x].d + Buffer1[DTid.x].d;
31 | #endif
32 | }
33 |
34 | #else // The following code is for raw buffers
35 |
36 | ByteAddressBuffer Buffer0 : register(t0);
37 | ByteAddressBuffer Buffer1 : register(t1);
38 | RWByteAddressBuffer BufferOut : register(u0);
39 |
40 | [numthreads(1, 1, 1)]
41 | void CSMain( uint3 DTid : SV_DispatchThreadID )
42 | {
43 | #ifdef TEST_DOUBLE
44 | int i0 = asint( Buffer0.Load( DTid.x*16 ) );
45 | float f0 = asfloat( Buffer0.Load( DTid.x*16+4 ) );
46 | double d0 = asdouble( Buffer0.Load( DTid.x*16+8 ), Buffer0.Load( DTid.x*16+12 ) );
47 | int i1 = asint( Buffer1.Load( DTid.x*16 ) );
48 | float f1 = asfloat( Buffer1.Load( DTid.x*16+4 ) );
49 | double d1 = asdouble( Buffer1.Load( DTid.x*16+8 ), Buffer1.Load( DTid.x*16+12 ) );
50 |
51 | BufferOut.Store( DTid.x*16, asuint(i0 + i1) );
52 | BufferOut.Store( DTid.x*16+4, asuint(f0 + f1) );
53 |
54 | uint dl, dh;
55 | asuint( d0 + d1, dl, dh );
56 |
57 | BufferOut.Store( DTid.x*16+8, dl );
58 | BufferOut.Store( DTid.x*16+12, dh );
59 | #else
60 | int i0 = asint( Buffer0.Load( DTid.x*8 ) );
61 | float f0 = asfloat( Buffer0.Load( DTid.x*8+4 ) );
62 | int i1 = asint( Buffer1.Load( DTid.x*8 ) );
63 | float f1 = asfloat( Buffer1.Load( DTid.x*8+4 ) );
64 |
65 | BufferOut.Store( DTid.x*8, asuint(i0 + i1) );
66 | BufferOut.Store( DTid.x*8+4, asuint(f0 + f1) );
67 | #endif // TEST_DOUBLE
68 | }
69 |
70 | #endif // USE_STRUCTURED_BUFFERS
71 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/CascadedShadowMaps11/RenderCascadeShadow.hlsl:
--------------------------------------------------------------------------------
1 |
2 | //--------------------------------------------------------------------------------------
3 | // File: RenderCascadeShadow.hlsl
4 | //
5 | // The shader file for the RenderCascadeScene sample.
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 |
10 |
11 | //--------------------------------------------------------------------------------------
12 | // Globals
13 | //--------------------------------------------------------------------------------------
14 | cbuffer cbPerObject : register( b0 )
15 | {
16 | matrix g_mWorldViewProjection : packoffset( c0 );
17 | };
18 |
19 | //--------------------------------------------------------------------------------------
20 | // Input / Output structures
21 | //--------------------------------------------------------------------------------------
22 | struct VS_INPUT
23 | {
24 | float4 vPosition : POSITION;
25 | };
26 |
27 | struct VS_OUTPUT
28 | {
29 | float4 vPosition : SV_POSITION;
30 | };
31 |
32 | //--------------------------------------------------------------------------------------
33 | // Vertex Shader
34 | //--------------------------------------------------------------------------------------
35 | VS_OUTPUT VSMain( VS_INPUT Input )
36 | {
37 | VS_OUTPUT Output;
38 |
39 | // There is nothing special here, just transform and write out the depth.
40 | Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
41 |
42 | return Output;
43 | }
44 |
45 |
46 | VS_OUTPUT VSMainPancake( VS_INPUT Input )
47 | {
48 | VS_OUTPUT Output;
49 | // after transform move clipped geometry to near plane
50 | Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
51 | //Output.vPosition.z = max( Output.vPosition.z, 0.0f );
52 | return Output;
53 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/ComputeShaderSort11/ComputeShaderSort11.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: ComputeShaderSort11.hlsl
3 | //
4 | // This file contains the compute shaders to perform GPU sorting using DirectX 11.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #define BITONIC_BLOCK_SIZE 512
10 |
11 | #define TRANSPOSE_BLOCK_SIZE 16
12 |
13 | //--------------------------------------------------------------------------------------
14 | // Constant Buffers
15 | //--------------------------------------------------------------------------------------
16 | cbuffer CB : register( b0 )
17 | {
18 | unsigned int g_iLevel;
19 | unsigned int g_iLevelMask;
20 | unsigned int g_iWidth;
21 | unsigned int g_iHeight;
22 | };
23 |
24 | //--------------------------------------------------------------------------------------
25 | // Structured Buffers
26 | //--------------------------------------------------------------------------------------
27 | StructuredBuffer Input : register( t0 );
28 | RWStructuredBuffer Data : register( u0 );
29 |
30 | //--------------------------------------------------------------------------------------
31 | // Bitonic Sort Compute Shader
32 | //--------------------------------------------------------------------------------------
33 | groupshared unsigned int shared_data[BITONIC_BLOCK_SIZE];
34 |
35 | [numthreads(BITONIC_BLOCK_SIZE, 1, 1)]
36 | void BitonicSort( uint3 Gid : SV_GroupID,
37 | uint3 DTid : SV_DispatchThreadID,
38 | uint3 GTid : SV_GroupThreadID,
39 | uint GI : SV_GroupIndex )
40 | {
41 | // Load shared data
42 | shared_data[GI] = Data[DTid.x];
43 | GroupMemoryBarrierWithGroupSync();
44 |
45 | // Sort the shared data
46 | for (unsigned int j = g_iLevel >> 1 ; j > 0 ; j >>= 1)
47 | {
48 | unsigned int result = ((shared_data[GI & ~j] <= shared_data[GI | j]) == (bool)(g_iLevelMask & DTid.x))? shared_data[GI ^ j] : shared_data[GI];
49 | GroupMemoryBarrierWithGroupSync();
50 | shared_data[GI] = result;
51 | GroupMemoryBarrierWithGroupSync();
52 | }
53 |
54 | // Store shared data
55 | Data[DTid.x] = shared_data[GI];
56 | }
57 |
58 | //--------------------------------------------------------------------------------------
59 | // Matrix Transpose Compute Shader
60 | //--------------------------------------------------------------------------------------
61 | groupshared unsigned int transpose_shared_data[TRANSPOSE_BLOCK_SIZE * TRANSPOSE_BLOCK_SIZE];
62 |
63 | [numthreads(TRANSPOSE_BLOCK_SIZE, TRANSPOSE_BLOCK_SIZE, 1)]
64 | void MatrixTranspose( uint3 Gid : SV_GroupID,
65 | uint3 DTid : SV_DispatchThreadID,
66 | uint3 GTid : SV_GroupThreadID,
67 | uint GI : SV_GroupIndex )
68 | {
69 | transpose_shared_data[GI] = Input[DTid.y * g_iWidth + DTid.x];
70 | GroupMemoryBarrierWithGroupSync();
71 | uint2 XY = DTid.yx - GTid.yx + GTid.xy;
72 | Data[XY.y * g_iHeight + XY.x] = transpose_shared_data[GTid.x * TRANSPOSE_BLOCK_SIZE + GTid.y];
73 | }
74 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DDSWithoutD3DX11/DDSWithoutD3DX.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DDSWithoutD3DX.hlsl
3 | //
4 | // The HLSL file for the DDSWithoutD3DX sample for the Direct3D 11 device
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 |
10 | //--------------------------------------------------------------------------------------
11 | // Constant Buffers
12 | //--------------------------------------------------------------------------------------
13 | cbuffer cbPerObject : register( b0 )
14 | {
15 | matrix g_mWorldViewProjection : packoffset( c0 );
16 | matrix g_mWorld : packoffset( c4 );
17 | }
18 |
19 | cbuffer cbPerFrame : register( b1 )
20 | {
21 | float3 g_vLightDir : packoffset( c0 );
22 | };
23 |
24 | //-----------------------------------------------------------------------------------------
25 | // Textures and Samplers
26 | //-----------------------------------------------------------------------------------------
27 | Texture2D g_txDiffuse : register( t0 );
28 | SamplerState g_samLinear : register( s0 );
29 |
30 | //--------------------------------------------------------------------------------------
31 | // shader input/output structure
32 | //--------------------------------------------------------------------------------------
33 | struct VS_INPUT
34 | {
35 | float4 Position : POSITION; // vertex position
36 | float3 Normal : NORMAL; // this normal comes in per-vertex
37 | float2 TextureUV : TEXCOORD0;// vertex texture coords
38 | };
39 |
40 | struct VS_OUTPUT
41 | {
42 | float4 Position : SV_POSITION; // vertex position
43 | float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
44 | float2 TextureUV : TEXCOORD0; // vertex texture coords
45 | };
46 |
47 | //--------------------------------------------------------------------------------------
48 | // This shader computes standard transform and lighting
49 | //--------------------------------------------------------------------------------------
50 | VS_OUTPUT RenderSceneVS( VS_INPUT input )
51 | {
52 | VS_OUTPUT Output;
53 | float3 vNormalWorldSpace;
54 |
55 | // Transform the position from object space to homogeneous projection space
56 | Output.Position = mul( input.Position, g_mWorldViewProjection );
57 |
58 | // Transform the normal from object space to world space
59 | vNormalWorldSpace = normalize(mul(input.Normal, (float3x3)g_mWorld)); // normal (world space)
60 |
61 | // Calc diffuse color
62 | Output.Diffuse.rgb = max(0.3,dot(vNormalWorldSpace, g_vLightDir)).rrr;
63 | Output.Diffuse.a = 1.0f;
64 |
65 | // Just copy the texture coordinate through
66 | Output.TextureUV = input.TextureUV;
67 |
68 | return Output;
69 | }
70 |
71 | //--------------------------------------------------------------------------------------
72 | // This shader outputs the pixel's color by modulating the texture's
73 | // color with diffuse material color
74 | //--------------------------------------------------------------------------------------
75 | float4 RenderScenePS( VS_OUTPUT In ) : SV_TARGET
76 | {
77 | // Lookup mesh texture and modulate it with diffuse
78 | return g_txDiffuse.Sample( g_samLinear, In.TextureUV ) * In.Diffuse;
79 | }
80 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DecalTessellation11/AdaptiveTessellation.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: AdaptiveTessellation.hlsl
3 | //
4 | // These utility functions are typically called by the hull shader patch constant function
5 | // in order to apply adaptive levels of tessellation, and cull patches altogether if
6 | // back facing or outside the view frustum
7 | //
8 | // Contributed by the AMD Developer Relations Team
9 | //
10 | // Copyright (c) Microsoft Corporation. All rights reserved.
11 | //--------------------------------------------------------------------------------------
12 |
13 |
14 | //--------------------------------------------------------------------------------------
15 | // Returns the dot product between the viewing vector and the patch edge
16 | //--------------------------------------------------------------------------------------
17 | float GetEdgeDotProduct (
18 | float3 f3EdgeNormal0, // Normalized normal of the first control point of the given patch edge
19 | float3 f3EdgeNormal1, // Normalized normal of the second control point of the given patch edge
20 | float3 f3ViewVector // Normalized viewing vector
21 | )
22 | {
23 | float3 f3EdgeNormal = normalize( ( f3EdgeNormal0 + f3EdgeNormal1 ) * 0.5f );
24 |
25 | float fEdgeDotProduct = dot( f3EdgeNormal, f3ViewVector );
26 |
27 | return fEdgeDotProduct;
28 | }
29 |
30 |
31 | //--------------------------------------------------------------------------------------
32 | // Returns the screen space position from the given world space patch control point
33 | //--------------------------------------------------------------------------------------
34 | float2 GetScreenSpacePosition (
35 | float3 f3Position, // World space position of patch control point
36 | float4x4 f4x4ViewProjection, // View x Projection matrix
37 | float fScreenWidth, // Screen width
38 | float fScreenHeight // Screen height
39 | )
40 | {
41 | float4 f4ProjectedPosition = mul( float4( f3Position, 1.0f ), f4x4ViewProjection );
42 |
43 | float2 f2ScreenPosition = f4ProjectedPosition.xy / f4ProjectedPosition.ww;
44 |
45 | f2ScreenPosition = ( f2ScreenPosition + 1.0f ) * 0.5f * float2( fScreenWidth, -fScreenHeight );
46 |
47 | return f2ScreenPosition;
48 | }
49 |
50 |
51 | //--------------------------------------------------------------------------------------
52 | // Returns the distance of a given point from a given plane
53 | //--------------------------------------------------------------------------------------
54 | float DistanceFromPlane (
55 | float3 f3Position, // World space position of the patch control point
56 | float4 f4PlaneEquation // Plane equation of a frustum plane
57 | )
58 | {
59 | float fDistance = dot( float4( f3Position, 1.0f ), f4PlaneEquation );
60 |
61 | return fDistance;
62 | }
63 |
64 |
65 | //--------------------------------------------------------------------------------------
66 | // Returns a distance adaptive tessellation scale factor (0.0f -> 1.0f)
67 | //--------------------------------------------------------------------------------------
68 | float GetDistanceAdaptiveScaleFactor(
69 | float3 f3Eye, // Position of the camera/eye
70 | float3 f3EdgePosition0, // Position of the first control point of the given patch edge
71 | float3 f3EdgePosition1, // Position of the second control point of the given patch edge
72 | float fMinDistance, // Minimum distance that maximum tessellation factors should be applied at
73 | float fRange // Range beyond the minimum distance where tessellation will scale down to the minimum scaling factor
74 | )
75 | {
76 | float3 f3MidPoint = ( f3EdgePosition0 + f3EdgePosition1 ) * 0.5f;
77 |
78 | float fDistance = distance( f3MidPoint, f3Eye ) - fMinDistance;
79 |
80 | float fScale = 1.0f - saturate( fDistance / fRange );
81 |
82 | return fScale;
83 | }
84 |
85 |
86 | //--------------------------------------------------------------------------------------
87 | // Returns the orientation adaptive tessellation factor (0.0f -> 1.0f)
88 | //--------------------------------------------------------------------------------------
89 | float GetOrientationAdaptiveScaleFactor (
90 | float fEdgeDotProduct, // Dot product of edge normal with view vector
91 | float fSilhouetteEpsilon // Epsilon to determine the range of values considered to be silhoutte
92 | )
93 | {
94 | float fScale = 1.0f - abs( fEdgeDotProduct );
95 |
96 | fScale = saturate( ( fScale - fSilhouetteEpsilon ) / ( 1.0f - fSilhouetteEpsilon ) );
97 |
98 | return fScale;
99 | }
100 |
101 |
102 | //--------------------------------------------------------------------------------------
103 | // Returns the screen resolution adaptive tessellation scale factor (0.0f -> 1.0f)
104 | //--------------------------------------------------------------------------------------
105 | float GetScreenResolutionAdaptiveScaleFactor(
106 | float fCurrentWidth, // Current render window width
107 | float fCurrentHeight, // Current render window height
108 | float fMaxWidth, // Width considered to be max
109 | float fMaxHeight // Height considered to be max
110 | )
111 | {
112 | float fMaxArea = fMaxWidth * fMaxHeight;
113 |
114 | float fCurrentArea = fCurrentWidth * fCurrentHeight;
115 |
116 | float fScale = saturate( fCurrentArea / fMaxArea );
117 |
118 | return fScale;
119 | }
120 |
121 |
122 | //--------------------------------------------------------------------------------------
123 | // Returns the screen space adaptive tessellation scale factor (0.0f -> 1.0f)
124 | //--------------------------------------------------------------------------------------
125 | float GetScreenSpaceAdaptiveScaleFactor (
126 | float2 f2EdgeScreenPosition0, // Screen coordinate of the first patch edge control point
127 | float2 f2EdgeScreenPosition1, // Screen coordinate of the second patch edge control point
128 | float fMaxEdgeTessFactor, // Maximum edge tessellation factor
129 | float fTargetEdgePrimitiveSize // Desired primitive edge size in pixels
130 | )
131 | {
132 | float fEdgeScreenLength = distance( f2EdgeScreenPosition0, f2EdgeScreenPosition1 );
133 |
134 | float fTargetTessFactor = fEdgeScreenLength / fTargetEdgePrimitiveSize;
135 |
136 | fTargetTessFactor /= fMaxEdgeTessFactor;
137 |
138 | float fScale = saturate( fTargetTessFactor );
139 |
140 | return fScale;
141 | }
142 |
143 |
144 | //--------------------------------------------------------------------------------------
145 | // Returns back face culling test result (true / false)
146 | //--------------------------------------------------------------------------------------
147 | bool BackFaceCull (
148 | float fEdgeDotProduct0, // Dot product of edge 0 normal with view vector
149 | float fEdgeDotProduct1, // Dot product of edge 1 normal with view vector
150 | float fEdgeDotProduct2, // Dot product of edge 2 normal with view vector
151 | float fBackFaceEpsilon // Epsilon to determine cut off value for what is considered back facing
152 | )
153 | {
154 | float3 f3BackFaceCull;
155 |
156 | f3BackFaceCull.x = ( fEdgeDotProduct0 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
157 | f3BackFaceCull.y = ( fEdgeDotProduct1 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
158 | f3BackFaceCull.z = ( fEdgeDotProduct2 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
159 |
160 | return all( f3BackFaceCull );
161 | }
162 |
163 |
164 | //--------------------------------------------------------------------------------------
165 | // Returns view frustum Culling test result (true / false)
166 | //--------------------------------------------------------------------------------------
167 | bool ViewFrustumCull(
168 | float3 f3EdgePosition0, // World space position of patch control point 0
169 | float3 f3EdgePosition1, // World space position of patch control point 1
170 | float3 f3EdgePosition2, // World space position of patch control point 2
171 | float4 f4ViewFrustumPlanes[4], // 4 plane equations (left, right, top, bottom)
172 | float fCullEpsilon // Epsilon to determine the distance outside the view frustum is still considered inside
173 | )
174 | {
175 | float4 f4PlaneTest;
176 | float fPlaneTest;
177 |
178 | // Left clip plane
179 | f4PlaneTest.x = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
180 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
181 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f );
182 | // Right clip plane
183 | f4PlaneTest.y = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
184 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
185 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f );
186 | // Top clip plane
187 | f4PlaneTest.z = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
188 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
189 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f );
190 | // Bottom clip plane
191 | f4PlaneTest.w = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
192 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
193 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f );
194 |
195 | // Triangle has to pass all 4 plane tests to be visible
196 | return !all( f4PlaneTest );
197 | }
198 |
199 |
200 | //--------------------------------------------------------------------------------------
201 | // EOF
202 | //--------------------------------------------------------------------------------------
203 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DetailTessellation11/AdaptiveTessellation.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: AdaptiveTessellation.hlsl
3 | //
4 | // These utility functions are typically called by the hull shader patch constant function
5 | // in order to apply adaptive levels of tessellation, and cull patches altogether if
6 | // back facing or outside the view frustum
7 | //
8 | // Contributed by the AMD Developer Relations Team
9 | //
10 | // Copyright (c) Microsoft Corporation. All rights reserved.
11 | //--------------------------------------------------------------------------------------
12 |
13 |
14 | //--------------------------------------------------------------------------------------
15 | // Returns the dot product between the viewing vector and the patch edge
16 | //--------------------------------------------------------------------------------------
17 | float GetEdgeDotProduct (
18 | float3 f3EdgeNormal0, // Normalized normal of the first control point of the given patch edge
19 | float3 f3EdgeNormal1, // Normalized normal of the second control point of the given patch edge
20 | float3 f3ViewVector // Normalized viewing vector
21 | )
22 | {
23 | float3 f3EdgeNormal = normalize( ( f3EdgeNormal0 + f3EdgeNormal1 ) * 0.5f );
24 |
25 | float fEdgeDotProduct = dot( f3EdgeNormal, f3ViewVector );
26 |
27 | return fEdgeDotProduct;
28 | }
29 |
30 |
31 | //--------------------------------------------------------------------------------------
32 | // Returns the screen space position from the given world space patch control point
33 | //--------------------------------------------------------------------------------------
34 | float2 GetScreenSpacePosition (
35 | float3 f3Position, // World space position of patch control point
36 | float4x4 f4x4ViewProjection, // View x Projection matrix
37 | float fScreenWidth, // Screen width
38 | float fScreenHeight // Screen height
39 | )
40 | {
41 | float4 f4ProjectedPosition = mul( float4( f3Position, 1.0f ), f4x4ViewProjection );
42 |
43 | float2 f2ScreenPosition = f4ProjectedPosition.xy / f4ProjectedPosition.ww;
44 |
45 | f2ScreenPosition = ( f2ScreenPosition + 1.0f ) * 0.5f * float2( fScreenWidth, -fScreenHeight );
46 |
47 | return f2ScreenPosition;
48 | }
49 |
50 |
51 | //--------------------------------------------------------------------------------------
52 | // Returns the distance of a given point from a given plane
53 | //--------------------------------------------------------------------------------------
54 | float DistanceFromPlane (
55 | float3 f3Position, // World space position of the patch control point
56 | float4 f4PlaneEquation // Plane equation of a frustum plane
57 | )
58 | {
59 | float fDistance = dot( float4( f3Position, 1.0f ), f4PlaneEquation );
60 |
61 | return fDistance;
62 | }
63 |
64 |
65 | //--------------------------------------------------------------------------------------
66 | // Returns a distance adaptive tessellation scale factor (0.0f -> 1.0f)
67 | //--------------------------------------------------------------------------------------
68 | float GetDistanceAdaptiveScaleFactor(
69 | float3 f3Eye, // Position of the camera/eye
70 | float3 f3EdgePosition0, // Position of the first control point of the given patch edge
71 | float3 f3EdgePosition1, // Position of the second control point of the given patch edge
72 | float fMinDistance, // Minimum distance that maximum tessellation factors should be applied at
73 | float fRange // Range beyond the minimum distance where tessellation will scale down to the minimum scaling factor
74 | )
75 | {
76 | float3 f3MidPoint = ( f3EdgePosition0 + f3EdgePosition1 ) * 0.5f;
77 |
78 | float fDistance = distance( f3MidPoint, f3Eye ) - fMinDistance;
79 |
80 | float fScale = 1.0f - saturate( fDistance / fRange );
81 |
82 | return fScale;
83 | }
84 |
85 |
86 | //--------------------------------------------------------------------------------------
87 | // Returns the orientation adaptive tessellation factor (0.0f -> 1.0f)
88 | //--------------------------------------------------------------------------------------
89 | float GetOrientationAdaptiveScaleFactor (
90 | float fEdgeDotProduct, // Dot product of edge normal with view vector
91 | float fSilhouetteEpsilon // Epsilon to determine the range of values considered to be silhoutte
92 | )
93 | {
94 | float fScale = 1.0f - abs( fEdgeDotProduct );
95 |
96 | fScale = saturate( ( fScale - fSilhouetteEpsilon ) / ( 1.0f - fSilhouetteEpsilon ) );
97 |
98 | return fScale;
99 | }
100 |
101 |
102 | //--------------------------------------------------------------------------------------
103 | // Returns the screen resolution adaptive tessellation scale factor (0.0f -> 1.0f)
104 | //--------------------------------------------------------------------------------------
105 | float GetScreenResolutionAdaptiveScaleFactor(
106 | float fCurrentWidth, // Current render window width
107 | float fCurrentHeight, // Current render window height
108 | float fMaxWidth, // Width considered to be max
109 | float fMaxHeight // Height considered to be max
110 | )
111 | {
112 | float fMaxArea = fMaxWidth * fMaxHeight;
113 |
114 | float fCurrentArea = fCurrentWidth * fCurrentHeight;
115 |
116 | float fScale = saturate( fCurrentArea / fMaxArea );
117 |
118 | return fScale;
119 | }
120 |
121 |
122 | //--------------------------------------------------------------------------------------
123 | // Returns the screen space adaptive tessellation scale factor (0.0f -> 1.0f)
124 | //--------------------------------------------------------------------------------------
125 | float GetScreenSpaceAdaptiveScaleFactor (
126 | float2 f2EdgeScreenPosition0, // Screen coordinate of the first patch edge control point
127 | float2 f2EdgeScreenPosition1, // Screen coordinate of the second patch edge control point
128 | float fMaxEdgeTessFactor, // Maximum edge tessellation factor
129 | float fTargetEdgePrimitiveSize // Desired primitive edge size in pixels
130 | )
131 | {
132 | float fEdgeScreenLength = distance( f2EdgeScreenPosition0, f2EdgeScreenPosition1 );
133 |
134 | float fTargetTessFactor = fEdgeScreenLength / fTargetEdgePrimitiveSize;
135 |
136 | fTargetTessFactor /= fMaxEdgeTessFactor;
137 |
138 | float fScale = saturate( fTargetTessFactor );
139 |
140 | return fScale;
141 | }
142 |
143 |
144 | //--------------------------------------------------------------------------------------
145 | // Returns back face culling test result (true / false)
146 | //--------------------------------------------------------------------------------------
147 | bool BackFaceCull (
148 | float fEdgeDotProduct0, // Dot product of edge 0 normal with view vector
149 | float fEdgeDotProduct1, // Dot product of edge 1 normal with view vector
150 | float fEdgeDotProduct2, // Dot product of edge 2 normal with view vector
151 | float fBackFaceEpsilon // Epsilon to determine cut off value for what is considered back facing
152 | )
153 | {
154 | float3 f3BackFaceCull;
155 |
156 | f3BackFaceCull.x = ( fEdgeDotProduct0 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
157 | f3BackFaceCull.y = ( fEdgeDotProduct1 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
158 | f3BackFaceCull.z = ( fEdgeDotProduct2 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
159 |
160 | return all( f3BackFaceCull );
161 | }
162 |
163 |
164 | //--------------------------------------------------------------------------------------
165 | // Returns view frustum Culling test result (true / false)
166 | //--------------------------------------------------------------------------------------
167 | bool ViewFrustumCull(
168 | float3 f3EdgePosition0, // World space position of patch control point 0
169 | float3 f3EdgePosition1, // World space position of patch control point 1
170 | float3 f3EdgePosition2, // World space position of patch control point 2
171 | float4 f4ViewFrustumPlanes[4], // 4 plane equations (left, right, top, bottom)
172 | float fCullEpsilon // Epsilon to determine the distance outside the view frustum is still considered inside
173 | )
174 | {
175 | float4 f4PlaneTest;
176 | float fPlaneTest;
177 |
178 | // Left clip plane
179 | f4PlaneTest.x = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
180 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
181 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f );
182 | // Right clip plane
183 | f4PlaneTest.y = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
184 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
185 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f );
186 | // Top clip plane
187 | f4PlaneTest.z = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
188 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
189 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f );
190 | // Bottom clip plane
191 | f4PlaneTest.w = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
192 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
193 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f );
194 |
195 | // Triangle has to pass all 4 plane tests to be visible
196 | return !all( f4PlaneTest );
197 | }
198 |
199 |
200 | //--------------------------------------------------------------------------------------
201 | // EOF
202 | //--------------------------------------------------------------------------------------
203 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DetailTessellation11/POM.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: POM.hlsl
3 | //
4 | // HLSL file containing shader functions for Parallax Occlusion Mapping.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 | #include "Shader_include.h"
9 |
10 | //--------------------------------------------------------------------------------------
11 | // Structures
12 | //--------------------------------------------------------------------------------------
13 | struct VS_INPUT
14 | {
15 | float3 inPositionOS : POSITION;
16 | float2 inTexCoord : TEXCOORD0;
17 | float3 vInNormalOS : NORMAL;
18 | float3 vInBinormalOS : BINORMAL;
19 | float3 vInTangentOS : TANGENT;
20 | };
21 |
22 | struct VS_OUTPUT
23 | {
24 | float2 texCoord : TEXCOORD0;
25 | float3 vLightTS : TEXCOORD1; // Light vector in tangent space, denormalized
26 | float3 vViewTS : TEXCOORD2; // View vector in tangent space, denormalized
27 | float2 vParallaxOffsetTS : TEXCOORD3; // Parallax offset vector in tangent space
28 | float3 vNormalWS : TEXCOORD4; // Normal vector in world space
29 | float3 vViewWS : TEXCOORD5; // View vector in world space
30 |
31 | float4 position : SV_POSITION; // Output position
32 | };
33 |
34 | struct PS_INPUT
35 | {
36 | float2 texCoord : TEXCOORD0;
37 | float3 vLightTS : TEXCOORD1; // Light vector in tangent space, denormalized
38 | float3 vViewTS : TEXCOORD2; // View vector in tangent space, denormalized
39 | float2 vParallaxOffsetTS : TEXCOORD3; // Parallax offset vector in tangent space
40 | float3 vNormalWS : TEXCOORD4; // Normal vector in world space
41 | float3 vViewWS : TEXCOORD5; // View vector in world space
42 | };
43 |
44 |
45 | //--------------------------------------------------------------------------------------
46 | // Vertex shader for POM setup
47 | //--------------------------------------------------------------------------------------
48 | VS_OUTPUT RenderSceneVS( VS_INPUT i )
49 | {
50 | VS_OUTPUT Out;
51 |
52 | // Transform and output input position
53 | Out.position = mul( float4( i.inPositionOS.xyz, 1.0 ), g_mWorldViewProjection );
54 |
55 | // Propagate texture coordinate through:
56 | Out.texCoord = i.inTexCoord * g_fBaseTextureRepeat.x;
57 |
58 | // Transform the normal, tangent and binormal vectors
59 | // from object space to homogeneous projection space:
60 | float3 vNormalWS = mul( i.vInNormalOS, (float3x3) g_mWorld );
61 | float3 vBinormalWS = mul( i.vInBinormalOS, (float3x3) g_mWorld );
62 | float3 vTangentWS = mul( i.vInTangentOS, (float3x3) g_mWorld );
63 |
64 | // Propagate the world space vertex normal through:
65 | Out.vNormalWS = vNormalWS;
66 |
67 | // Normalize tangent space vectors
68 | vNormalWS = normalize( vNormalWS );
69 | vBinormalWS = normalize( vBinormalWS );
70 | vTangentWS = normalize( vTangentWS );
71 |
72 | // Compute position in world space:
73 | float4 vPositionWS = mul( i.inPositionOS, g_mWorld );
74 |
75 | // Compute and output the world view vector (unnormalized):
76 | float3 vViewWS = g_vEye - vPositionWS;
77 | Out.vViewWS = vViewWS;
78 |
79 | // Compute denormalized light vector in world space:
80 | float3 vLightWS = g_LightPosition.xyz - vPositionWS.xyz;
81 | // Need to invert Z for correct lighting
82 | vLightWS.z = -vLightWS.z;
83 |
84 | // Normalize the light and view vectors and transform it to the tangent space:
85 | float3x3 mWorldToTangent = float3x3( vTangentWS, vBinormalWS, vNormalWS );
86 |
87 | // Propagate the view and the light vectors (in tangent space):
88 | Out.vLightTS = mul( mWorldToTangent, vLightWS );
89 | Out.vViewTS = mul( mWorldToTangent, vViewWS );
90 |
91 | // Compute the ray direction for intersecting the
92 | // height field profile with current view ray
93 |
94 | // Compute initial parallax displacement direction:
95 | float2 vParallaxDirection = normalize( Out.vViewTS.xy );
96 |
97 | // The length of this vector determines the furthest amount of displacement:
98 | float fLength = length( Out.vViewTS );
99 | float fParallaxLength = sqrt( fLength * fLength - Out.vViewTS.z * Out.vViewTS.z ) / Out.vViewTS.z;
100 |
101 | // Compute the actual reverse parallax displacement vector:
102 | Out.vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
103 |
104 | // Need to scale the amount of displacement to account for different height ranges in height maps.
105 | Out.vParallaxOffsetTS *= g_fPOMHeightMapScale.x;
106 |
107 | return Out;
108 | }
109 |
110 | //--------------------------------------------------------------------------------------
111 | // Parallax occlusion mapping pixel shader
112 | //--------------------------------------------------------------------------------------
113 | float4 RenderScenePS( PS_INPUT i ) : SV_TARGET
114 | {
115 | // Normalize the interpolated vectors:
116 | float3 vViewTS = normalize( i.vViewTS );
117 | float3 vViewWS = normalize( i.vViewWS );
118 | float3 vLightTS = normalize( i.vLightTS );
119 | float3 vNormalWS = normalize( i.vNormalWS );
120 |
121 | float4 cResultColor = float4( 0, 0, 0, 1 );
122 |
123 | // Compute all the derivatives:
124 | float2 dx = ddx( i.texCoord );
125 | float2 dy = ddy( i.texCoord );
126 |
127 | //===============================================//
128 | // Parallax occlusion mapping offset computation //
129 | //===============================================//
130 |
131 | // Utilize dynamic flow control to change the number of samples per ray
132 | // depending on the viewing angle for the surface. Oblique angles require
133 | // smaller step sizes to achieve more accurate precision for computing displacement.
134 | // We express the sampling rate as a linear function of the angle between
135 | // the geometric normal and the view direction ray:
136 | int nNumSteps = (int)lerp( g_nMaxSamples, g_nMinSamples, dot( vViewWS, vNormalWS ) );
137 |
138 | // Intersect the view ray with the height field profile along the direction of
139 | // the parallax offset ray (computed in the vertex shader. Note that the code is
140 | // designed specifically to take advantage of the dynamic flow control constructs
141 | // in HLSL and is very sensitive to specific syntax. When converting to other examples,
142 | // if still want to use dynamic flow control in the resulting assembly shader,
143 | // care must be applied.
144 | //
145 | // In the below steps we approximate the height field profile as piecewise linear
146 | // curve. We find the pair of endpoints between which the intersection between the
147 | // height field profile and the view ray is found and then compute line segment
148 | // intersection for the view ray and the line segment formed by the two endpoints.
149 | // This intersection is the displacement offset from the original texture coordinate.
150 |
151 | float fCurrHeight = 0.0;
152 | float fStepSize = 1.0 / (float) nNumSteps;
153 | float fPrevHeight = 1.0;
154 | float fNextHeight = 0.0;
155 |
156 | int nStepIndex = 0;
157 | bool bCondition = true;
158 |
159 | float2 vTexOffsetPerStep = fStepSize * i.vParallaxOffsetTS;
160 | float2 vTexCurrentOffset = i.texCoord;
161 | float fCurrentBound = 1.0;
162 | float fParallaxAmount = 0.0;
163 |
164 | float2 pt1 = 0;
165 | float2 pt2 = 0;
166 |
167 | float2 texOffset2 = 0;
168 |
169 | while ( nStepIndex < nNumSteps )
170 | {
171 | vTexCurrentOffset -= vTexOffsetPerStep;
172 |
173 | // Sample height map which in this case is stored in the alpha channel of the normal map:
174 | fCurrHeight = g_nmhTexture.SampleGrad( g_samLinear, vTexCurrentOffset, dx, dy ).a;
175 |
176 | fCurrentBound -= fStepSize;
177 |
178 | if ( fCurrHeight > fCurrentBound )
179 | {
180 | pt1 = float2( fCurrentBound, fCurrHeight );
181 | pt2 = float2( fCurrentBound + fStepSize, fPrevHeight );
182 |
183 | texOffset2 = vTexCurrentOffset - vTexOffsetPerStep;
184 |
185 | nStepIndex = nNumSteps + 1;
186 | }
187 | else
188 | {
189 | nStepIndex++;
190 | fPrevHeight = fCurrHeight;
191 | }
192 | } // End of while ( nStepIndex < nNumSteps )
193 |
194 | float fDelta2 = pt2.x - pt2.y;
195 | float fDelta1 = pt1.x - pt1.y;
196 | float fDenominator = fDelta2 - fDelta1;
197 |
198 | // SM 3.0 and above requires a check for divide by zero since that operation will generate an 'Inf' number instead of 0
199 | [flatten]if ( fDenominator == 0.0f )
200 | {
201 | fParallaxAmount = 0.0f;
202 | }
203 | else
204 | {
205 | fParallaxAmount = ( pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;
206 | }
207 |
208 | float2 vParallaxOffset = i.vParallaxOffsetTS * ( 1.0 - fParallaxAmount );
209 |
210 | // The computed texture offset for the displaced point on the pseudo-extruded surface:
211 | float2 texSample = i.texCoord - vParallaxOffset;
212 |
213 | // Compute resulting color for the pixel:
214 | cResultColor = ComputeIllumination( texSample, vLightTS, vViewTS );
215 |
216 | return cResultColor;
217 | }
218 |
219 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DetailTessellation11/Particle.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Particle.hlsl
3 | //
4 | // HLSL file containing shader function to render front-facing particles.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 | #include "Shader_include.h"
9 |
10 | //--------------------------------------------------------------------------------------
11 | // Internal defines
12 | //--------------------------------------------------------------------------------------
13 | #define FIXED_VERTEX_RADIUS 5.0
14 |
15 | //--------------------------------------------------------------------------------------
16 | // Structures
17 | //--------------------------------------------------------------------------------------
18 | struct VS_PARTICLE_INPUT
19 | {
20 | float3 WSPos : POSITION;
21 | };
22 |
23 | struct GS_PARTICLE_INPUT
24 | {
25 | float4 WSPos : POSITION;
26 | };
27 |
28 | struct PS_PARTICLE_INPUT
29 | {
30 | float4 Pos : SV_POSITION;
31 | float2 Tex : TEXCOORD0;
32 | };
33 |
34 | //--------------------------------------------------------------------------------------
35 | // Vertex Shader to GS
36 | //--------------------------------------------------------------------------------------
37 | GS_PARTICLE_INPUT VSPassThrough( VS_PARTICLE_INPUT input )
38 | {
39 | GS_PARTICLE_INPUT output = (GS_PARTICLE_INPUT)0;
40 |
41 | // Pass world space position to GS
42 | output.WSPos = float4( input.WSPos, 1.0 );
43 |
44 | return output;
45 | }
46 |
47 | //--------------------------------------------------------------------------------------
48 | // Geometry Shader to render point sprites
49 | //--------------------------------------------------------------------------------------
50 | [maxvertexcount(4)]
51 | void GSPointSprite(point GS_PARTICLE_INPUT input[1], inout TriangleStream SpriteStream)
52 | {
53 | const float3 g_positions[4] =
54 | {
55 | float3( -1.0, 1.0, 0.0 ),
56 | float3( 1.0, 1.0, 0.0 ),
57 | float3( -1.0, -1.0, 0.0 ),
58 | float3( 1.0, -1.0, 0.0 ),
59 | };
60 | const float2 g_texcoords[4] =
61 | {
62 | float2( 0.0, 1.0 ),
63 | float2( 1.0, 1.0 ),
64 | float2( 0.0, 0.0 ),
65 | float2( 1.0, 0.0 ),
66 | };
67 | PS_PARTICLE_INPUT output = (PS_PARTICLE_INPUT)0;
68 |
69 | // Emit two new triangles
70 | [unroll]for( int i=0; i<4; ++i )
71 | {
72 | float3 position = g_positions[i] * FIXED_VERTEX_RADIUS;
73 | position = mul( position, (float3x3)g_mInvView ) + input[0].WSPos;
74 | output.Pos = mul( float4( position, 1.0 ), g_mViewProjection );
75 |
76 | // Pass texture coordinates
77 | output.Tex = g_texcoords[i];
78 |
79 | // Add vertex
80 | SpriteStream.Append( output );
81 | }
82 | SpriteStream.RestartStrip();
83 | }
84 |
85 | //--------------------------------------------------------------------------------------
86 | // Pixel Shader to display constant single color
87 | //--------------------------------------------------------------------------------------
88 | float4 PSConstantColor( PS_PARTICLE_INPUT input ) : SV_TARGET
89 | {
90 | // Sample particle texture
91 | float4 vColor = g_baseTexture.Sample( g_samLinear, input.Tex ).wwww;
92 |
93 | // Clip fully transparent pixels
94 | clip( vColor.a - 1.0/255.0 );
95 |
96 | // Return color
97 | return vColor;
98 | }
99 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DetailTessellation11/shader_include.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: shader_include.hlsl
3 | //
4 | // Include file for common shader definitions and functions.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | //--------------------------------------------------------------------------------------
10 | // Defines
11 | //--------------------------------------------------------------------------------------
12 | #define ADD_SPECULAR 0
13 |
14 | //--------------------------------------------------------------------------------------
15 | // Textures
16 | //--------------------------------------------------------------------------------------
17 | Texture2D g_baseTexture : register( t0 ); // Base color texture
18 | Texture2D g_nmhTexture : register( t1 ); // Normal map and height map texture pair
19 |
20 |
21 | //--------------------------------------------------------------------------------------
22 | // Samplers
23 | //--------------------------------------------------------------------------------------
24 | SamplerState g_samLinear : register( s0 );
25 | SamplerState g_samPoint : register( s1 );
26 |
27 |
28 | //--------------------------------------------------------------------------------------
29 | // Constant Buffers
30 | //--------------------------------------------------------------------------------------
31 | cbuffer cbMain : register( b0 )
32 | {
33 | matrix g_mWorld; // World matrix
34 | matrix g_mView; // View matrix
35 | matrix g_mProjection; // Projection matrix
36 | matrix g_mWorldViewProjection; // WVP matrix
37 | matrix g_mViewProjection; // VP matrix
38 | matrix g_mInvView; // Inverse of view matrix
39 | float4 g_vScreenResolution; // Screen resolution
40 |
41 | float4 g_vMeshColor; // Mesh color
42 | float4 g_vTessellationFactor; // Edge, inside, minimum tessellation factor and 1/desired triangle size
43 | float4 g_vDetailTessellationHeightScale; // Height scale for detail tessellation of grid surface
44 | float4 g_vGridSize; // Grid size
45 |
46 | float4 g_vDebugColorMultiply; // Debug colors
47 | float4 g_vDebugColorAdd; // Debug colors
48 |
49 | float4 g_vFrustumPlaneEquation[4]; // View frustum plane equations
50 | };
51 |
52 | cbuffer cbMaterial : register( b1 )
53 | {
54 | float4 g_materialAmbientColor; // Material's ambient color
55 | float4 g_materialDiffuseColor; // Material's diffuse color
56 | float4 g_materialSpecularColor; // Material's specular color
57 | float4 g_fSpecularExponent; // Material's specular exponent
58 |
59 | float4 g_LightPosition; // Light's position in world space
60 | float4 g_LightDiffuse; // Light's diffuse color
61 | float4 g_LightAmbient; // Light's ambient color
62 |
63 | float4 g_vEye; // Camera's location
64 | float4 g_fBaseTextureRepeat; // The tiling factor for base and normal map textures
65 | float4 g_fPOMHeightMapScale; // Describes the useful range of values for the height field
66 |
67 | float4 g_fShadowSoftening; // Blurring factor for the soft shadows computation
68 |
69 | int g_nMinSamples; // The minimum number of samples for sampling the height field profile
70 | int g_nMaxSamples; // The maximum number of samples for sampling the height field profile
71 | };
72 |
73 | //--------------------------------------------------------------------------------------
74 | // Function: ComputeIllumination
75 | //
76 | // Description: Computes phong illumination for the given pixel using its attribute
77 | // textures and a light vector.
78 | //--------------------------------------------------------------------------------------
79 | float4 ComputeIllumination( float2 texCoord, float3 vLightTS, float3 vViewTS )
80 | {
81 | // Sample the normal from the normal map for the given texture sample:
82 | float3 vNormalTS = normalize( g_nmhTexture.Sample(g_samLinear, texCoord) * 2.0 - 1.0 );
83 |
84 | // Sample base map
85 | float4 cBaseColor = g_baseTexture.Sample( g_samLinear, texCoord );
86 |
87 | // Compute diffuse color component:
88 | float4 cDiffuse = saturate( dot( vNormalTS, vLightTS ) ) * g_materialDiffuseColor;
89 |
90 | // Compute the specular component if desired:
91 | float4 cSpecular = 0;
92 |
93 | #if ADD_SPECULAR==1
94 |
95 | float3 vReflectionTS = normalize( 2 * dot( vViewTS, vNormalTS ) * vNormalTS - vViewTS );
96 | float fRdotL = saturate( dot( vReflectionTS, vLightTS ) );
97 | cSpecular = pow( fRdotL, g_fSpecularExponent.x ) * g_materialSpecularColor;
98 |
99 | #endif
100 |
101 | // Composite the final color:
102 | float4 cFinalColor = ( g_materialAmbientColor + cDiffuse ) * cBaseColor + cSpecular;
103 |
104 | return cFinalColor;
105 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DynamicShaderLinkage11/DynamicShaderLinkage11_LightPSH.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DynamicShaderLinkage11_LightPSH.h
3 | //
4 | // The pixel shader light header file for the DynamicShaderLinkage11 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | //--------------------------------------------------------------------------------------
10 | // Interfaces
11 | //--------------------------------------------------------------------------------------
12 | interface iBaseLight
13 | {
14 | float3 IlluminateAmbient(float3 vNormal);
15 |
16 | float3 IlluminateDiffuse(float3 vNormal);
17 |
18 | float3 IlluminateSpecular(float3 vNormal, int specularPower );
19 |
20 | };
21 |
22 | //--------------------------------------------------------------------------------------
23 | // Classes
24 | //--------------------------------------------------------------------------------------
25 | class cAmbientLight : iBaseLight
26 | {
27 | float3 m_vLightColor;
28 | bool m_bEnable;
29 |
30 | float3 IlluminateAmbient(float3 vNormal);
31 |
32 | float3 IlluminateDiffuse(float3 vNormal)
33 | {
34 | return (float3)0;
35 | }
36 |
37 | float3 IlluminateSpecular(float3 vNormal, int specularPower )
38 | {
39 | return (float3)0;
40 | }
41 | };
42 |
43 | class cHemiAmbientLight : cAmbientLight
44 | {
45 | // inherited float4 m_vLightColor is the SkyColor
46 | float4 m_vGroundColor;
47 | float4 m_vDirUp;
48 |
49 | float3 IlluminateAmbient(float3 vNormal);
50 |
51 | };
52 |
53 | class cDirectionalLight : cAmbientLight
54 | {
55 | // inherited float4 m_vLightColor is the LightColor
56 | float4 m_vLightDir;
57 |
58 | float3 IlluminateDiffuse( float3 vNormal );
59 |
60 | float3 IlluminateSpecular( float3 vNormal, int specularPower );
61 |
62 | };
63 |
64 | class cOmniLight : cAmbientLight
65 | {
66 | float3 m_vLightPosition;
67 | float radius;
68 |
69 | float3 IlluminateDiffuse( float3 vNormal );
70 |
71 | };
72 |
73 | class cSpotLight : cAmbientLight
74 | {
75 | float3 m_vLightPosition;
76 | float3 m_vLightDir;
77 | };
78 |
79 | class cEnvironmentLight : cAmbientLight
80 | {
81 | float3 IlluminateSpecular( float3 vNormal, int specularPower );
82 | };
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DynamicShaderLinkage11/DynamicShaderLinkage11_MaterialPSH.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DynamicShaderLinkage11_MATERIALPSH.h
3 | //
4 | // The pixel shader material header file for the DynamicShaderLinkage11 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | //--------------------------------------------------------------------------------------
10 | // Interfaces
11 | //--------------------------------------------------------------------------------------
12 | interface iBaseMaterial
13 | {
14 | float3 GetAmbientColor(float2 vTexcoord);
15 |
16 | float3 GetDiffuseColor(float2 vTexcoord);
17 |
18 | int GetSpecularPower();
19 |
20 | };
21 |
22 | //--------------------------------------------------------------------------------------
23 | // Classes
24 | //--------------------------------------------------------------------------------------
25 | class cBaseMaterial : iBaseMaterial
26 | {
27 | float3 m_vColor;
28 | int m_iSpecPower;
29 |
30 | float3 GetAmbientColor(float2 vTexcoord)
31 | {
32 | return m_vColor;
33 | }
34 |
35 | float3 GetDiffuseColor(float2 vTexcoord)
36 | {
37 | return (float3)m_vColor;
38 | }
39 |
40 | int GetSpecularPower()
41 | {
42 | return m_iSpecPower;
43 | }
44 |
45 | };
46 |
47 | class cPlasticMaterial : cBaseMaterial
48 | {
49 |
50 | };
51 |
52 | class cPlasticTexturedMaterial : cPlasticMaterial
53 | {
54 | float3 GetAmbientColor(float2 vTexcoord);
55 |
56 | float3 GetDiffuseColor(float2 vTexcoord);
57 |
58 | };
59 |
60 | class cPlasticLightingOnlyMaterial : cBaseMaterial
61 | {
62 | float3 GetAmbientColor(float2 vTexcoord)
63 | {
64 | return (float3)1.0f;
65 | }
66 |
67 | float3 GetDiffuseColor(float2 vTexcoord)
68 | {
69 | return (float3)1.0f;
70 | }
71 |
72 | };
73 |
74 | class cRoughMaterial : cBaseMaterial
75 | {
76 | int GetSpecularPower()
77 | {
78 | return m_iSpecPower;
79 | }
80 | };
81 |
82 | class cRoughTexturedMaterial : cRoughMaterial
83 | {
84 | float3 GetAmbientColor(float2 vTexcoord);
85 |
86 | float3 GetDiffuseColor(float2 vTexcoord);
87 |
88 | };
89 |
90 |
91 | class cRoughLightingOnlyMaterial : cRoughMaterial
92 | {
93 | float3 GetAmbientColor(float2 vTexcoord)
94 | {
95 | return (float3)1.0f;
96 | }
97 |
98 | float3 GetDiffuseColor(float2 vTexcoord)
99 | {
100 | return (float3)1.0f;
101 | }
102 |
103 | };
104 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DynamicShaderLinkage11/DynamicShaderLinkage11_PS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DynamicShaderLinkage11.psh
3 | //
4 | // The pixel shader header file for the DynamicShaderLinkage11 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | //--------------------------------------------------------------------------------------
10 | // Header Includes
11 | //--------------------------------------------------------------------------------------
12 | #include "DynamicShaderLinkage11_PSBuffers.h"
13 |
14 | // Defines for default static permutated setting
15 | #if defined( STATIC_PERMUTE )
16 | #define HEMI_AMBIENT //CONST_AMBIENT //HEMI_AMBIENT
17 | #define TEXTURE_ENABLE
18 | #define SPECULAR_ENABLE
19 | #endif
20 |
21 | //--------------------------------------------------------------------------------------
22 | // Input / Output structures
23 | //--------------------------------------------------------------------------------------
24 | struct PS_INPUT
25 | {
26 | float4 vPosition : SV_POSITION;
27 | float3 vNormal : NORMAL;
28 | float2 vTexcoord : TEXCOORD0;
29 | float4 vMatrix : TEXCOORD1;
30 | };
31 |
32 | //--------------------------------------------------------------------------------------
33 | // Abstract Interface Instances for dyamic linkage / permutation
34 | //--------------------------------------------------------------------------------------
35 | #if !defined( STATIC_PERMUTE )
36 | iBaseLight g_abstractAmbientLighting;
37 | iBaseLight g_abstractDirectLighting;
38 | iBaseLight g_abstractEnvironmentLighting;
39 | iBaseMaterial g_abstractMaterial;
40 | #else
41 | //--------------------------------------------------------------------------------------
42 | // Concrete Instances for STATIC_PERMUTE - static permutation
43 | //--------------------------------------------------------------------------------------
44 | #if defined( HEMI_AMBIENT )
45 | #define g_abstractAmbientLighting g_hemiAmbientLight
46 | #else
47 | // CONST_AMBIENT
48 | #define g_abstractAmbientLighting g_ambientLight
49 | #endif
50 | #define g_abstractDirectLighting g_directionalLight
51 | #define g_abstractEnvironmentLighting g_environmentLight
52 | #if defined( TEXTURE_ENABLE )
53 | #define g_abstractMaterial g_plasticTexturedMaterial
54 | #else
55 | #define g_abstractMaterial g_plasticMaterial
56 | #endif
57 | #endif
58 |
59 | //--------------------------------------------------------------------------------------
60 | // Pixel Shader
61 | //--------------------------------------------------------------------------------------
62 | float4 PSMain( PS_INPUT Input ) : SV_TARGET
63 | {
64 | // Compute the Ambient term
65 | float3 Ambient = (float3)0.0f;
66 | Ambient = g_abstractMaterial.GetAmbientColor( Input.vTexcoord ) * g_abstractAmbientLighting.IlluminateAmbient( Input.vNormal );
67 |
68 | // Accumulate the Diffuse contribution
69 | float3 Diffuse = (float3)0.0f;
70 |
71 | Diffuse += g_abstractMaterial.GetDiffuseColor( Input.vTexcoord ) * g_abstractDirectLighting.IlluminateDiffuse( Input.vNormal );
72 |
73 | // Compute the Specular contribution
74 | float3 Specular = (float3)0.0f;
75 | Specular += g_abstractDirectLighting.IlluminateSpecular( Input.vNormal, g_abstractMaterial.GetSpecularPower() );
76 | Specular += g_abstractEnvironmentLighting.IlluminateSpecular( Input.vNormal, g_abstractMaterial.GetSpecularPower() );
77 |
78 | // Accumulate the lighting with saturation
79 | float3 Lighting = saturate( Ambient + Diffuse + Specular );
80 |
81 | return float4(Lighting,1.0f);
82 | }
83 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DynamicShaderLinkage11/DynamicShaderLinkage11_PSBuffers.h:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DynamicShaderLinkage11_LightPSH.hlsl
3 | //
4 | // The pixel shader light source module file for the DynamicShaderLinkage11 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #include "DynamicShaderLinkage11_LightPSH.h"
10 | #include "DynamicShaderLinkage11_MaterialPSH.h"
11 |
12 | //--------------------------------------------------------------------------------------
13 | // Constant Buffers
14 | //--------------------------------------------------------------------------------------
15 | cbuffer cbPerFrame : register( b0 )
16 | {
17 | cAmbientLight g_ambientLight;
18 | cHemiAmbientLight g_hemiAmbientLight;
19 | cDirectionalLight g_directionalLight;
20 | cEnvironmentLight g_environmentLight;
21 | float4 g_vEyeDir;
22 | };
23 |
24 | cbuffer cbPerPrimitive : register( b1 )
25 | {
26 | cPlasticMaterial g_plasticMaterial;
27 | cPlasticTexturedMaterial g_plasticTexturedMaterial;
28 | cPlasticLightingOnlyMaterial g_plasticLightingOnlyMaterial;
29 | cRoughMaterial g_roughMaterial;
30 | cRoughTexturedMaterial g_roughTexturedMaterial;
31 | cRoughLightingOnlyMaterial g_roughLightingOnlyMaterial;
32 | };
33 |
34 | //--------------------------------------------------------------------------------------
35 | // Textures and Samplers
36 | //--------------------------------------------------------------------------------------
37 | Texture2D g_txDiffuse : register( t0 );
38 | Texture2D g_txNormalMap : register( t1 );
39 | TextureCube g_txEnvironmentMap : register( t2 );
40 |
41 | SamplerState g_samLinear : register( s0 );
42 |
43 | //--------------------------------------------------------------------------------------
44 | // Lighting Class Methods
45 | //--------------------------------------------------------------------------------------
46 | // Ambient Lighting Class Methods
47 | float3 cAmbientLight::IlluminateAmbient(float3 vNormal)
48 | {
49 | return float4( m_vLightColor * m_bEnable, 1.0f);
50 | }
51 |
52 | float3 cHemiAmbientLight::IlluminateAmbient(float3 vNormal)
53 | {
54 | float thetha = (dot( vNormal, m_vDirUp ) + 1.0f) / 2.0f;
55 |
56 | return lerp( m_vGroundColor, m_vLightColor, thetha) * m_bEnable;
57 | }
58 |
59 | // Directional Light class
60 | float3 cDirectionalLight::IlluminateDiffuse( float3 vNormal )
61 | {
62 | float lambert = saturate(dot( vNormal, m_vLightDir ));
63 | return ((float3)lambert * m_vLightColor * m_bEnable);
64 | }
65 |
66 | float3 cDirectionalLight::IlluminateSpecular( float3 vNormal, int specularPower )
67 | {
68 | float3 H = -normalize(g_vEyeDir) + m_vLightDir;
69 | float3 halfAngle = normalize( H );
70 | float specular = pow( max(0,dot( halfAngle, normalize(vNormal) )), specularPower );
71 |
72 | return ((float3)specular * m_vLightColor * m_bEnable);
73 | }
74 |
75 | // Omni Light Class
76 | float3 cOmniLight::IlluminateDiffuse( float3 vNormal )
77 | {
78 | return (float3)0.0f; // TO DO!
79 | }
80 |
81 | // Environment Lighting
82 | float3 cEnvironmentLight::IlluminateSpecular( float3 vNormal, int specularPower )
83 | {
84 | // compute reflection vector taking into account a cheap fresnel falloff;
85 | float3 N = normalize(vNormal);
86 | float3 E = normalize(g_vEyeDir);
87 | float3 R = reflect( E, N );
88 | float fresnel = 1 - dot( -E, N );
89 | fresnel = (fresnel * fresnel * fresnel );
90 |
91 | float3 specular = g_txEnvironmentMap.Sample( g_samLinear, R ) * fresnel;
92 |
93 | return (specular * (float3)m_bEnable);
94 | // return ((float3)fresnel);
95 |
96 | }
97 |
98 | //--------------------------------------------------------------------------------------
99 | // Material Class Methods
100 | //--------------------------------------------------------------------------------------
101 | // Plastic Material Methods
102 | float3 cPlasticTexturedMaterial::GetAmbientColor(float2 vTexcoord)
103 | {
104 | float4 vDiffuse = (float4)1.0f;
105 | vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord );
106 | return m_vColor * vDiffuse;
107 | }
108 |
109 | float3 cPlasticTexturedMaterial::GetDiffuseColor(float2 vTexcoord)
110 | {
111 | float4 vDiffuse = (float4)1.0f;
112 | vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord );
113 | return m_vColor * vDiffuse;
114 | }
115 |
116 | // Rough Material Methods
117 | float3 cRoughTexturedMaterial::GetAmbientColor(float2 vTexcoord)
118 | {
119 | float4 vDiffuse = (float4)1.0f;
120 | vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord );
121 | return m_vColor * vDiffuse;
122 | }
123 |
124 | float3 cRoughTexturedMaterial::GetDiffuseColor(float2 vTexcoord)
125 | {
126 | float4 vDiffuse = (float4)1.0f;
127 | vDiffuse = g_txDiffuse.Sample( g_samLinear, vTexcoord );
128 | return m_vColor * vDiffuse;
129 | }
130 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/DynamicShaderLinkage11/DynamicShaderLinkage11_VS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DynamicShaderLinkage11_VS.hlsl
3 | //
4 | // The vertex shader file for the DynamicShaderLinkage11 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | //--------------------------------------------------------------------------------------
10 | // Globals
11 | //--------------------------------------------------------------------------------------
12 | cbuffer cbPerObject : register( b0 )
13 | {
14 | float4x4 g_mWorldViewProjection : packoffset( c0 );
15 | float4x4 g_mWorld : packoffset( c4 );
16 | };
17 |
18 | //--------------------------------------------------------------------------------------
19 | // Input / Output structures
20 | //--------------------------------------------------------------------------------------
21 | struct VS_INPUT
22 | {
23 | float4 vPosition : POSITION;
24 | float3 vNormal : NORMAL;
25 | float2 vTexcoord : TEXCOORD0;
26 | };
27 |
28 | struct VS_OUTPUT
29 | {
30 | float4 vPosition : SV_POSITION;
31 | float3 vNormal : NORMAL;
32 | float2 vTexcoord0 : TEXCOORD0;
33 | float4 vMatrix : TEXCOORD1; // DEBUG
34 | };
35 |
36 | //--------------------------------------------------------------------------------------
37 | // Vertex Shader
38 | //--------------------------------------------------------------------------------------
39 | // We aliased signed vectors as a unsigned format.
40 | // Need to recover signed values. The values 1.0 and 2.0
41 | // are slightly inaccurate here.
42 | float3 R10G10B10A2_UNORM_TO_R32G32B32_FLOAT( in float3 vVec )
43 | {
44 | vVec *= 2.0f;
45 | return vVec >= 1.0f ? ( vVec - 2.0f ) : vVec;
46 | }
47 |
48 | VS_OUTPUT VSMain( VS_INPUT Input )
49 | {
50 |
51 | VS_OUTPUT Output;
52 | float3 tmpNormal;
53 |
54 | Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
55 |
56 | // Expand compressed vectors
57 | tmpNormal = R10G10B10A2_UNORM_TO_R32G32B32_FLOAT( Input.vNormal );
58 | Output.vNormal = mul( tmpNormal, (float3x3)g_mWorld );
59 |
60 | Output.vTexcoord0 = Input.vTexcoord;
61 |
62 | Output.vMatrix = (float4)g_mWorld[0]; // DEBUG
63 | return Output;
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/FluidCS11/FluidCS11.hlsl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgjones/hlsl-parser-nitra/8b78d4eb24364f5d647e9cbe71f45df036b45c46/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/FluidCS11/FluidCS11.hlsl
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/FluidCS11/FluidRender.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: FluidRender.hlsl
3 | //
4 | // Copyright (c) Microsoft Corporation. All rights reserved.
5 | //--------------------------------------------------------------------------------------
6 |
7 | //--------------------------------------------------------------------------------------
8 | // Particle Rendering
9 | //--------------------------------------------------------------------------------------
10 |
11 | struct Particle {
12 | float2 position;
13 | float2 velocity;
14 | };
15 |
16 | struct ParticleDensity {
17 | float density;
18 | };
19 |
20 | StructuredBuffer ParticlesRO : register( t0 );
21 | StructuredBuffer ParticleDensityRO : register( t1 );
22 |
23 | cbuffer cbRenderConstants : register( b0 )
24 | {
25 | matrix g_mViewProjection;
26 | float g_fParticleSize;
27 | };
28 |
29 | struct VSParticleOut
30 | {
31 | float2 position : POSITION;
32 | float4 color : COLOR;
33 | };
34 |
35 | struct GSParticleOut
36 | {
37 | float4 position : SV_Position;
38 | float4 color : COLOR;
39 | float2 texcoord : TEXCOORD;
40 | };
41 |
42 |
43 | //--------------------------------------------------------------------------------------
44 | // Visualization Helper
45 | //--------------------------------------------------------------------------------------
46 |
47 | static const float4 Rainbow[5] = {
48 | float4(1, 0, 0, 1), // red
49 | float4(1, 1, 0, 1), // orange
50 | float4(0, 1, 0, 1), // green
51 | float4(0, 1, 1, 1), // teal
52 | float4(0, 0, 1, 1), // blue
53 | };
54 |
55 | float4 VisualizeNumber(float n)
56 | {
57 | return lerp( Rainbow[ floor(n * 4.0f) ], Rainbow[ ceil(n * 4.0f) ], frac(n * 4.0f) );
58 | }
59 |
60 | float4 VisualizeNumber(float n, float lower, float upper)
61 | {
62 | return VisualizeNumber( saturate( (n - lower) / (upper - lower) ) );
63 | }
64 |
65 |
66 | //--------------------------------------------------------------------------------------
67 | // Vertex Shader
68 | //--------------------------------------------------------------------------------------
69 |
70 | VSParticleOut ParticleVS(uint ID : SV_VertexID)
71 | {
72 | VSParticleOut Out = (VSParticleOut)0;
73 | Out.position = ParticlesRO[ID].position;
74 | Out.color = VisualizeNumber(ParticleDensityRO[ID].density, 1000.0f, 2000.0f);
75 | return Out;
76 | }
77 |
78 |
79 | //--------------------------------------------------------------------------------------
80 | // Particle Geometry Shader
81 | //--------------------------------------------------------------------------------------
82 |
83 | static const float2 g_positions[4] = { float2(-1, 1), float2(1, 1), float2(-1, -1), float2(1, -1) };
84 | static const float2 g_texcoords[4] = { float2(0, 1), float2(1, 1), float2(0, 0), float2(1, 0) };
85 |
86 | [maxvertexcount(4)]
87 | void ParticleGS(point VSParticleOut In[1], inout TriangleStream SpriteStream)
88 | {
89 | [unroll]
90 | for (int i = 0; i < 4; i++)
91 | {
92 | GSParticleOut Out = (GSParticleOut)0;
93 | float4 position = float4(In[0].position, 0, 1) + g_fParticleSize * float4(g_positions[i], 0, 0);
94 | Out.position = mul(position, g_mViewProjection);
95 | Out.color = In[0].color;
96 | Out.texcoord = g_texcoords[i];
97 | SpriteStream.Append(Out);
98 | }
99 | SpriteStream.RestartStrip();
100 | }
101 |
102 |
103 | //--------------------------------------------------------------------------------------
104 | // Pixel Shader
105 | //--------------------------------------------------------------------------------------
106 |
107 | float4 ParticlePS(GSParticleOut In) : SV_Target
108 | {
109 | return In.color;
110 | }
111 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/BrightPassAndHorizFilterCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: BrightPassAndHorizFilterCS.hlsl
3 | //
4 | // The CS for bright pass and horizontal blur, used in CS path of
5 | // HDRToneMappingCS11 sample
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 | static const float MIDDLE_GRAY = 0.72f;
10 | static const float LUM_WHITE = 1.5f;
11 | static const float BRIGHT_THRESHOLD = 0.5f;
12 |
13 | Texture2D Input : register( t0 );
14 | StructuredBuffer lum : register( t1 );
15 | RWStructuredBuffer Result : register( u0 );
16 |
17 | cbuffer cb0
18 | {
19 | float4 g_avSampleWeights[15];
20 | uint g_outputwidth;
21 | float g_inverse;
22 | int2 g_inputsize;
23 | }
24 |
25 | #define kernelhalf 7
26 | #define groupthreads 128
27 | groupshared float4 temp[groupthreads];
28 |
29 | [numthreads( groupthreads, 1, 1 )]
30 | void CSMain( uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex )
31 | {
32 | int2 coord = int2( GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.x, Gid.y );
33 | coord = coord.xy * 8 + int2(4, 3);
34 | coord = clamp( coord, int2(0, 0), int2(g_inputsize.x-1, g_inputsize.y-1) );
35 | float4 vColor = Input.Load( int3(coord, 0) );
36 |
37 | float fLum = lum[0]*g_inverse;
38 |
39 | // Bright pass and tone mapping
40 | vColor = max( 0.0f, vColor - BRIGHT_THRESHOLD );
41 | vColor *= MIDDLE_GRAY / (fLum + 0.001f);
42 | vColor *= (1.0f + vColor/LUM_WHITE);
43 | vColor /= (1.0f + vColor);
44 |
45 | temp[GI] = vColor;
46 |
47 | GroupMemoryBarrierWithGroupSync();
48 |
49 | // Horizontal blur
50 | if ( GI >= kernelhalf &&
51 | GI < (groupthreads - kernelhalf) &&
52 | ( (Gid.x * (groupthreads - 2 * kernelhalf) + GI - kernelhalf) < g_outputwidth) )
53 | {
54 | float4 vOut = 0;
55 |
56 | [unroll]
57 | for ( int i = -kernelhalf; i <= kernelhalf; ++i )
58 | vOut += temp[GI + i] * g_avSampleWeights[i + kernelhalf];
59 |
60 | Result[GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.x + Gid.y * g_outputwidth] = float4(vOut.rgb, 1.0f);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/DumpToTexture.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: DumpToTexture.hlsl
3 | //
4 | // The PS for converting CS output buffer to a texture, used in CS path of
5 | // HDRToneMappingCS11 sample
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 | StructuredBuffer buffer : register( t0 );
10 |
11 | struct QuadVS_Output
12 | {
13 | float4 Pos : SV_POSITION;
14 | float2 Tex : TEXCOORD0;
15 | };
16 |
17 | cbuffer cbPS : register( b0 )
18 | {
19 | uint4 g_param;
20 | };
21 |
22 | float4 PSDump( QuadVS_Output Input ) : SV_TARGET
23 | {
24 | // To calculate the buffer offset, it is natural to use the screen space coordinates,
25 | // Input.Pos is the screen space coordinates of the pixel being written
26 | return buffer[ (Input.Pos.x - 0.5) + (Input.Pos.y - 0.5) * g_param.x ];
27 | }
28 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/FilterCS.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: FilterCS.hlsl
3 | //
4 | // The CSs for doing vertical and horizontal blur, used in CS path of
5 | // HDRToneMappingCS11 sample
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 | StructuredBuffer InputBuf : register( t0 );
10 | Texture2D InputTex : register( t1 );
11 | RWStructuredBuffer Result : register( u0 );
12 |
13 | cbuffer cb0
14 | {
15 | float4 g_avSampleWeights[15];
16 | int2 g_outputsize;
17 | int2 g_inputsize;
18 | }
19 |
20 | #define kernelhalf 7
21 | #define groupthreads 128
22 | groupshared float4 temp[groupthreads];
23 |
24 | [numthreads( groupthreads, 1, 1 )]
25 | void CSVerticalFilter( uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex )
26 | {
27 | int offsety = GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.y;
28 | offsety = clamp( offsety, 0, g_inputsize.y-1 );
29 | int offset = Gid.x + offsety * g_inputsize.x;
30 | temp[GI] = InputBuf[offset];
31 |
32 | GroupMemoryBarrierWithGroupSync();
33 |
34 | // Vertical blur
35 | if ( GI >= kernelhalf &&
36 | GI < (groupthreads - kernelhalf) &&
37 | ( (GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.y) < g_outputsize.y) )
38 | {
39 | float4 vOut = 0;
40 |
41 | [unroll]
42 | for ( int i = -kernelhalf; i <= kernelhalf; ++i )
43 | vOut += temp[GI + i] * g_avSampleWeights[i + kernelhalf];
44 |
45 | Result[Gid.x + (GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.y) * g_outputsize.x] = float4(vOut.rgb, 1.0f);
46 | }
47 | }
48 |
49 | [numthreads( groupthreads, 1, 1 )]
50 | void CSHorizFilter( uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex )
51 | {
52 | int2 coord = int2( GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.x, Gid.y );
53 | coord = clamp( coord, int2(0, 0), int2(g_inputsize.x-1, g_inputsize.y-1) );
54 | temp[GI] = InputTex.Load( int3(coord, 0) );
55 |
56 | GroupMemoryBarrierWithGroupSync();
57 |
58 | // Horizontal blur
59 | if ( GI >= kernelhalf &&
60 | GI < (groupthreads - kernelhalf) &&
61 | ( (Gid.x * (groupthreads - 2 * kernelhalf) + GI - kernelhalf) < g_outputsize.x) )
62 | {
63 | float4 vOut = 0;
64 |
65 | [unroll]
66 | for ( int i = -kernelhalf; i <= kernelhalf; ++i )
67 | vOut += temp[GI + i] * g_avSampleWeights[i + kernelhalf];
68 |
69 | Result[GI - kernelhalf + (groupthreads - kernelhalf * 2) * Gid.x + Gid.y * g_outputsize.x] = float4(vOut.rgb, 1.0f);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/FinalPass.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: FinalPass.hlsl
3 | //
4 | // The PSs for doing tone-mapping based on the input luminance, used in CS path of
5 | // HDRToneMappingCS11 sample
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 | struct QuadVS_Input
10 | {
11 | float4 Pos : POSITION;
12 | float2 Tex : TEXCOORD0;
13 | };
14 |
15 | struct QuadVS_Output
16 | {
17 | float4 Pos : SV_POSITION;
18 | float2 Tex : TEXCOORD0;
19 | };
20 |
21 | QuadVS_Output QuadVS( QuadVS_Input Input )
22 | {
23 | QuadVS_Output Output;
24 | Output.Pos = Input.Pos;
25 | Output.Tex = Input.Tex;
26 | return Output;
27 | }
28 |
29 | Texture2D tex : register( t0 );
30 | StructuredBuffer lum : register( t1 );
31 | Texture2D bloom : register( t2 );
32 |
33 | SamplerState PointSampler : register (s0);
34 | SamplerState LinearSampler : register (s1);
35 |
36 |
37 | static const float MIDDLE_GRAY = 0.72f;
38 | static const float LUM_WHITE = 1.5f;
39 |
40 | cbuffer cbPS : register( b0 )
41 | {
42 | float4 g_param;
43 | };
44 |
45 | float4 PSFinalPass( QuadVS_Output Input ) : SV_TARGET
46 | {
47 | float4 vColor = tex.Sample( PointSampler, Input.Tex );
48 | float fLum = lum[0]*g_param.x;
49 | float3 vBloom = bloom.Sample( LinearSampler, Input.Tex );
50 |
51 | // Tone mapping
52 | vColor.rgb *= MIDDLE_GRAY / (fLum + 0.001f);
53 | vColor.rgb *= (1.0f + vColor/LUM_WHITE);
54 | vColor.rgb /= (1.0f + vColor);
55 |
56 | vColor.rgb += 0.6f * vBloom;
57 | vColor.a = 1.0f;
58 |
59 | return vColor;
60 | }
61 |
62 | float4 PSFinalPassForCPUReduction( QuadVS_Output Input ) : SV_TARGET
63 | {
64 | float4 vColor = tex.Sample( PointSampler, Input.Tex );
65 | float fLum = g_param.x;
66 | float3 vBloom = bloom.Sample( LinearSampler, Input.Tex );
67 |
68 | // Tone mapping
69 | vColor.rgb *= MIDDLE_GRAY / (fLum + 0.001f);
70 | vColor.rgb *= (1.0f + vColor/LUM_WHITE);
71 | vColor.rgb /= (1.0f + vColor);
72 |
73 | vColor.rgb += 0.6f * vBloom;
74 | vColor.a = 1.0f;
75 |
76 | return vColor;
77 | }
78 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/PSApproach.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: PSApproach.hlsl
3 | //
4 | // The PSs for doing post-processing, used in PS path of
5 | // HDRToneMappingCS11 sample
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 | static const float4 LUM_VECTOR = float4(.299, .587, .114, 0);
10 | static const float MIDDLE_GRAY = 0.72f;
11 | static const float LUM_WHITE = 1.5f;
12 | static const float BRIGHT_THRESHOLD = 0.5f;
13 |
14 | SamplerState PointSampler : register (s0);
15 | SamplerState LinearSampler : register (s1);
16 |
17 | struct QuadVS_Output
18 | {
19 | float4 Pos : SV_POSITION;
20 | float2 Tex : TEXCOORD0;
21 | };
22 |
23 | Texture2D s0 : register(t0);
24 | Texture2D s1 : register(t1);
25 | Texture2D s2 : register(t2);
26 |
27 | float4 DownScale2x2_Lum ( QuadVS_Output Input ) : SV_TARGET
28 | {
29 | float4 vColor = 0.0f;
30 | float fAvg = 0.0f;
31 |
32 | for( int y = -1; y < 1; y++ )
33 | {
34 | for( int x = -1; x < 1; x++ )
35 | {
36 | // Compute the sum of color values
37 | vColor = s0.Sample( PointSampler, Input.Tex, int2(x,y) );
38 |
39 | fAvg += dot( vColor, LUM_VECTOR );
40 | }
41 | }
42 |
43 | fAvg /= 4;
44 |
45 | return float4(fAvg, fAvg, fAvg, 1.0f);
46 | }
47 |
48 | float4 DownScale3x3( QuadVS_Output Input ) : SV_TARGET
49 | {
50 | float fAvg = 0.0f;
51 | float4 vColor;
52 |
53 | for( int y = -1; y <= 1; y++ )
54 | {
55 | for( int x = -1; x <= 1; x++ )
56 | {
57 | // Compute the sum of color values
58 | vColor = s0.Sample( PointSampler, Input.Tex, int2(x,y) );
59 |
60 | fAvg += vColor.r;
61 | }
62 | }
63 |
64 | // Divide the sum to complete the average
65 | fAvg /= 9;
66 |
67 | return float4(fAvg, fAvg, fAvg, 1.0f);
68 | }
69 |
70 | float4 FinalPass( QuadVS_Output Input ) : SV_TARGET
71 | {
72 | //float4 vColor = 0;
73 | float4 vColor = s0.Sample( PointSampler, Input.Tex );
74 | float4 vLum = s1.Sample( PointSampler, float2(0,0) );
75 | float3 vBloom = s2.Sample( LinearSampler, Input.Tex );
76 |
77 | // Tone mapping
78 | vColor.rgb *= MIDDLE_GRAY / (vLum.r + 0.001f);
79 | vColor.rgb *= (1.0f + vColor/LUM_WHITE);
80 | vColor.rgb /= (1.0f + vColor);
81 |
82 | vColor.rgb += 0.6f * vBloom;
83 | vColor.a = 1.0f;
84 |
85 | return vColor;
86 | }
87 |
88 | float4 DownScale3x3_BrightPass( QuadVS_Output Input ) : SV_TARGET
89 | {
90 | float3 vColor = 0.0f;
91 | float4 vLum = s1.Sample( PointSampler, float2(0, 0) );
92 | float fLum = vLum.r;
93 |
94 | vColor = s0.Sample( PointSampler, Input.Tex ).rgb;
95 |
96 | // Bright pass and tone mapping
97 | vColor = max( 0.0f, vColor - BRIGHT_THRESHOLD );
98 | vColor *= MIDDLE_GRAY / (fLum + 0.001f);
99 | vColor *= (1.0f + vColor/LUM_WHITE);
100 | vColor /= (1.0f + vColor);
101 |
102 | return float4(vColor, 1.0f);
103 | }
104 |
105 | cbuffer cb0
106 | {
107 | float2 g_avSampleOffsets[15];
108 | float4 g_avSampleWeights[15];
109 | }
110 |
111 | float4 Bloom( QuadVS_Output Input ) : SV_TARGET
112 | {
113 | float4 vSample = 0.0f;
114 | float4 vColor = 0.0f;
115 | float2 vSamplePosition;
116 |
117 | for( int iSample = 0; iSample < 15; iSample++ )
118 | {
119 | // Sample from adjacent points
120 | vSamplePosition = Input.Tex + g_avSampleOffsets[iSample];
121 | vColor = s0.Sample( PointSampler, vSamplePosition);
122 |
123 | vSample += g_avSampleWeights[iSample]*vColor;
124 | }
125 |
126 | return vSample;
127 | }
128 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/ReduceTo1DCS.hlsl:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // File: ReduceTo1DCS.hlsl
3 | //
4 | // Desc: Reduce an input Texture2D to a buffer
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //-----------------------------------------------------------------------------
8 | Texture2D Input : register( t0 );
9 | RWStructuredBuffer Result : register( u0 );
10 |
11 | cbuffer cbCS : register( b0 )
12 | {
13 | uint4 g_param; // (g_param.x, g_param.y) is the x and y dimensions of the Dispatch call
14 | // (g_param.z, g_param.w) is the size of the above Input Texture2D
15 | };
16 |
17 | //#define CS_FULL_PIXEL_REDUCITON // Defining this or not must be the same as in HDRToneMappingCS11.cpp
18 |
19 | #define blocksize 8
20 | #define blocksizeY 8
21 | #define groupthreads (blocksize*blocksizeY)
22 | groupshared float accum[groupthreads];
23 |
24 | static const float4 LUM_VECTOR = float4(.299, .587, .114, 0);
25 |
26 | [numthreads(blocksize,blocksizeY,1)]
27 | void CSMain( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
28 | {
29 | float4 s =
30 | #ifdef CS_FULL_PIXEL_REDUCITON
31 | Input.Load( uint3(DTid.xy , 0) )+
32 | Input.Load( uint3(DTid.xy + uint2(blocksize*g_param.x, 0), 0) ) +
33 | Input.Load( uint3(DTid.xy + uint2(0, blocksizeY*g_param.y), 0) ) +
34 | Input.Load( uint3(DTid.xy + uint2(blocksize*g_param.x, blocksizeY*g_param.y), 0) );
35 | #else
36 | Input.Load( uint3((float)DTid.x/81.0f*g_param.z, (float)DTid.y/81.0f*g_param.w, 0) );
37 | #endif
38 |
39 | accum[GI] = dot( s, LUM_VECTOR );
40 |
41 | // Parallel reduction algorithm follows
42 | GroupMemoryBarrierWithGroupSync();
43 | if ( GI < 32 )
44 | accum[GI] += accum[32+GI];
45 |
46 | GroupMemoryBarrierWithGroupSync();
47 | if ( GI < 16 )
48 | accum[GI] += accum[16+GI];
49 |
50 | GroupMemoryBarrierWithGroupSync();
51 | if ( GI < 8 )
52 | accum[GI] += accum[8+GI];
53 |
54 | GroupMemoryBarrierWithGroupSync();
55 | if ( GI < 4 )
56 | accum[GI] += accum[4+GI];
57 |
58 | GroupMemoryBarrierWithGroupSync();
59 | if ( GI < 2 )
60 | accum[GI] += accum[2+GI];
61 |
62 | GroupMemoryBarrierWithGroupSync();
63 | if ( GI < 1 )
64 | accum[GI] += accum[1+GI];
65 |
66 | if ( GI == 0 )
67 | {
68 | Result[Gid.y*g_param.x+Gid.x] = accum[0];
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/ReduceToSingleCS.hlsl:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // File: ReduceToSingleCS.hlsl
3 | //
4 | // Desc: Reduce an input buffer by a factor of groupthreads
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //-----------------------------------------------------------------------------
8 |
9 | StructuredBuffer Input : register( t0 );
10 | RWStructuredBuffer Result : register( u0 );
11 |
12 | cbuffer cbCS : register( b0 )
13 | {
14 | uint4 g_param; // g_param.x is the actual elements contained in Input
15 | // g_param.y is the x dimension of the Dispatch call
16 | };
17 |
18 | #define groupthreads 128
19 | groupshared float accum[groupthreads];
20 |
21 | [numthreads(groupthreads,1,1)]
22 | void CSMain( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
23 | {
24 | if ( DTid.x < g_param.x )
25 | accum[GI] = Input[DTid.x];
26 | else
27 | accum[GI] = 0;
28 |
29 | // Parallel reduction algorithm follows
30 | GroupMemoryBarrierWithGroupSync();
31 | if ( GI < 64 )
32 | accum[GI] += accum[64+GI];
33 |
34 | GroupMemoryBarrierWithGroupSync();
35 | if ( GI < 32 )
36 | accum[GI] += accum[32+GI];
37 |
38 | GroupMemoryBarrierWithGroupSync();
39 | if ( GI < 16 )
40 | accum[GI] += accum[16+GI];
41 |
42 | GroupMemoryBarrierWithGroupSync();
43 | if ( GI < 8 )
44 | accum[GI] += accum[8+GI];
45 |
46 | GroupMemoryBarrierWithGroupSync();
47 | if ( GI < 4 )
48 | accum[GI] += accum[4+GI];
49 |
50 | GroupMemoryBarrierWithGroupSync();
51 | if ( GI < 2 )
52 | accum[GI] += accum[2+GI];
53 |
54 | GroupMemoryBarrierWithGroupSync();
55 | if ( GI < 1 )
56 | accum[GI] += accum[1+GI];
57 |
58 | if ( GI == 0 )
59 | {
60 | Result[Gid.x] = accum[0];
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/HDRToneMappingCS11/skybox11.hlsl:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // File: SkyBox11.hlsl
3 | //
4 | // Desc:
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //-----------------------------------------------------------------------------
8 |
9 | cbuffer cbPerObject : register( b0 )
10 | {
11 | row_major matrix g_mWorldViewProjection : packoffset( c0 );
12 | }
13 |
14 | TextureCube g_EnvironmentTexture : register( t0 );
15 | SamplerState g_sam : register( s0 );
16 |
17 | struct SkyboxVS_Input
18 | {
19 | float4 Pos : POSITION;
20 | };
21 |
22 | struct SkyboxVS_Output
23 | {
24 | float4 Pos : SV_POSITION;
25 | float3 Tex : TEXCOORD0;
26 | };
27 |
28 | SkyboxVS_Output SkyboxVS( SkyboxVS_Input Input )
29 | {
30 | SkyboxVS_Output Output;
31 |
32 | Output.Pos = Input.Pos;
33 | Output.Tex = normalize( mul(Input.Pos, g_mWorldViewProjection) );
34 |
35 | return Output;
36 | }
37 |
38 | float4 SkyboxPS( SkyboxVS_Output Input ) : SV_TARGET
39 | {
40 | float4 color = g_EnvironmentTexture.Sample( g_sam, Input.Tex );
41 | return color;
42 | }
43 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/NBodyGravityCS11/NBodyGravityCS11.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: NBodyGravityCS11.hlsl
3 | //
4 | // Demonstrates how to use Compute Shader to do n-body gravity computation
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | static float softeningSquared = 0.0012500000*0.0012500000;
10 | static float g_fG = 6.67300e-11f * 10000.0f;
11 | static float g_fParticleMass = g_fG*10000.0f * 10000.0f;
12 |
13 | #define blocksize 128
14 | groupshared float4 sharedPos[blocksize];
15 |
16 | // Body to body interaction, acceleration of the particle at position bi is updated
17 | void bodyBodyInteraction(inout float3 ai, float4 bj, float4 bi, float mass, int particles )
18 | {
19 | float3 r = bj.xyz - bi.xyz;
20 |
21 | float distSqr = dot(r, r);
22 | distSqr += softeningSquared;
23 |
24 | float invDist = 1.0f / sqrt(distSqr);
25 | float invDistCube = invDist * invDist * invDist;
26 |
27 | float s = mass * invDistCube * particles;
28 |
29 | ai += r * s;
30 | }
31 |
32 | cbuffer cbCS : register( b0 )
33 | {
34 | uint4 g_param; // pcbCS->param[0] = MAX_PARTICLES;
35 | // pcbCS->param[1] = dimx;
36 | float4 g_paramf; // pcbCS->paramf[0] = 0.1f;
37 | // pcbCS->paramf[1] = 1;
38 | };
39 |
40 | struct PosVelo
41 | {
42 | float4 pos;
43 | float4 velo;
44 | };
45 |
46 | StructuredBuffer oldPosVelo;
47 | RWStructuredBuffer newPosVelo;
48 |
49 | [numthreads(blocksize, 1, 1)]
50 | void CSMain( uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint GI : SV_GroupIndex )
51 | {
52 | // Each thread of the CS updates one of the particles
53 |
54 | float4 pos = oldPosVelo[DTid.x].pos;
55 | float4 vel = oldPosVelo[DTid.x].velo;
56 | float3 accel = 0;
57 | float mass = g_fParticleMass;
58 |
59 | // Update current particle using all other particles
60 | [loop]
61 | for (uint tile = 0; tile < g_param.y; tile++)
62 | {
63 | // Cache a tile of particles unto shared memory to increase IO efficiency
64 | sharedPos[GI] = oldPosVelo[tile * blocksize + GI].pos;
65 |
66 | GroupMemoryBarrierWithGroupSync();
67 |
68 | [unroll]
69 | for (uint counter = 0; counter < blocksize; counter+=8 )
70 | {
71 | bodyBodyInteraction(accel, sharedPos[counter], pos, mass, 1);
72 | bodyBodyInteraction(accel, sharedPos[counter+1], pos, mass, 1);
73 | bodyBodyInteraction(accel, sharedPos[counter+2], pos, mass, 1);
74 | bodyBodyInteraction(accel, sharedPos[counter+3], pos, mass, 1);
75 | bodyBodyInteraction(accel, sharedPos[counter+4], pos, mass, 1);
76 | bodyBodyInteraction(accel, sharedPos[counter+5], pos, mass, 1);
77 | bodyBodyInteraction(accel, sharedPos[counter+6], pos, mass, 1);
78 | bodyBodyInteraction(accel, sharedPos[counter+7], pos, mass, 1);
79 | }
80 |
81 | GroupMemoryBarrierWithGroupSync();
82 | }
83 |
84 | // g_param.x is the number of our particles, however this number might not be an exact multiple of the tile size.
85 | // In such cases, out of bound reads occur in the process above, which means there will be
86 | // tooManyParticles "phantom" particles generating false gravity at position (0, 0, 0), so we have to substract them here.
87 | // NOTE, out of bound reads always return 0 in CS
88 | const uint tooManyParticles = g_param.y * blocksize - g_param.x;
89 | bodyBodyInteraction(accel, float4(0, 0, 0, 0), pos, mass, -tooManyParticles);
90 |
91 | // Update the velocity and position of current particle using the acceleration computed above
92 | vel.xyz += accel.xyz * g_paramf.x; //deltaTime;
93 | vel.xyz *= g_paramf.y; //damping;
94 | pos.xyz += vel.xyz * g_paramf.x; //deltaTime;
95 |
96 | if ( DTid.x < g_param.x )
97 | {
98 | newPosVelo[DTid.x].pos = pos;
99 | newPosVelo[DTid.x].velo = float4(vel.xyz, length(accel));
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/NBodyGravityCS11/ParticleDraw.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: ParticleDraw.hlsl
3 | //
4 | // Shaders for rendering the particle as point sprite
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | struct VSParticleIn
10 | {
11 | float4 color : COLOR;
12 | uint id : SV_VERTEXID;
13 | };
14 |
15 | struct VSParticleDrawOut
16 | {
17 | float3 pos : POSITION;
18 | float4 color : COLOR;
19 | };
20 |
21 | struct GSParticleDrawOut
22 | {
23 | float2 tex : TEXCOORD0;
24 | float4 color : COLOR;
25 | float4 pos : SV_POSITION;
26 | };
27 |
28 | struct PSParticleDrawIn
29 | {
30 | float2 tex : TEXCOORD0;
31 | float4 color : COLOR;
32 | };
33 |
34 | struct PosVelo
35 | {
36 | float4 pos;
37 | float4 velo;
38 | };
39 |
40 | Texture2D g_txDiffuse;
41 | StructuredBuffer g_bufPosVelo;
42 |
43 |
44 | SamplerState g_samLinear
45 | {
46 | Filter = MIN_MAG_MIP_LINEAR;
47 | AddressU = Clamp;
48 | AddressV = Clamp;
49 | };
50 |
51 | cbuffer cb0
52 | {
53 | row_major float4x4 g_mWorldViewProj;
54 | row_major float4x4 g_mInvView;
55 | };
56 |
57 | cbuffer cb1
58 | {
59 | static float g_fParticleRad = 10.0f;
60 | };
61 |
62 | cbuffer cbImmutable
63 | {
64 | static float3 g_positions[4] =
65 | {
66 | float3( -1, 1, 0 ),
67 | float3( 1, 1, 0 ),
68 | float3( -1, -1, 0 ),
69 | float3( 1, -1, 0 ),
70 | };
71 |
72 | static float2 g_texcoords[4] =
73 | {
74 | float2(0,0),
75 | float2(1,0),
76 | float2(0,1),
77 | float2(1,1),
78 | };
79 | };
80 |
81 | //
82 | // Vertex shader for drawing the point-sprite particles
83 | //
84 | VSParticleDrawOut VSParticleDraw(VSParticleIn input)
85 | {
86 | VSParticleDrawOut output;
87 |
88 | output.pos = g_bufPosVelo[input.id].pos;
89 |
90 | float mag = g_bufPosVelo[input.id].velo.w/9;
91 | output.color = lerp( float4(1,0.1,0.1,1), input.color, mag );
92 |
93 | return output;
94 | }
95 |
96 | //
97 | // GS for rendering point sprite particles. Takes a point and turns it into 2 tris.
98 | //
99 | [maxvertexcount(4)]
100 | void GSParticleDraw(point VSParticleDrawOut input[1], inout TriangleStream SpriteStream)
101 | {
102 | GSParticleDrawOut output;
103 |
104 | //
105 | // Emit two new triangles
106 | //
107 | for(int i=0; i<4; i++)
108 | {
109 | float3 position = g_positions[i] * g_fParticleRad;
110 | position = mul( position, (float3x3)g_mInvView ) + input[0].pos;
111 | output.pos = mul( float4(position,1.0), g_mWorldViewProj );
112 |
113 | output.color = input[0].color;
114 | output.tex = g_texcoords[i];
115 | SpriteStream.Append(output);
116 | }
117 | SpriteStream.RestartStrip();
118 | }
119 |
120 | //
121 | // PS for drawing particles
122 | //
123 | float4 PSParticleDraw(PSParticleDrawIn input) : SV_Target
124 | {
125 | return g_txDiffuse.Sample( g_samLinear, input.tex ) * input.color;
126 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/PNTriangles11/AdaptiveTessellation.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: AdaptiveTessellation.hlsl
3 | //
4 | // These utility functions are typically called by the hull shader patch constant function
5 | // in order to apply adaptive levels of tessellation, and cull patches altogether if
6 | // back facing or outside the view frustum
7 | //
8 | // Contributed by the AMD Developer Relations Team
9 | //
10 | // Copyright (c) Microsoft Corporation. All rights reserved.
11 | //--------------------------------------------------------------------------------------
12 |
13 |
14 | //--------------------------------------------------------------------------------------
15 | // Returns the dot product between the viewing vector and the patch edge
16 | //--------------------------------------------------------------------------------------
17 | float GetEdgeDotProduct (
18 | float3 f3EdgeNormal0, // Normalized normal of the first control point of the given patch edge
19 | float3 f3EdgeNormal1, // Normalized normal of the second control point of the given patch edge
20 | float3 f3ViewVector // Normalized viewing vector
21 | )
22 | {
23 | float3 f3EdgeNormal = normalize( ( f3EdgeNormal0 + f3EdgeNormal1 ) * 0.5f );
24 |
25 | float fEdgeDotProduct = dot( f3EdgeNormal, f3ViewVector );
26 |
27 | return fEdgeDotProduct;
28 | }
29 |
30 |
31 | //--------------------------------------------------------------------------------------
32 | // Returns the screen space position from the given world space patch control point
33 | //--------------------------------------------------------------------------------------
34 | float2 GetScreenSpacePosition (
35 | float3 f3Position, // World space position of patch control point
36 | float4x4 f4x4ViewProjection, // View x Projection matrix
37 | float fScreenWidth, // Screen width
38 | float fScreenHeight // Screen height
39 | )
40 | {
41 | float4 f4ProjectedPosition = mul( float4( f3Position, 1.0f ), f4x4ViewProjection );
42 |
43 | float2 f2ScreenPosition = f4ProjectedPosition.xy / f4ProjectedPosition.ww;
44 |
45 | f2ScreenPosition = ( f2ScreenPosition + 1.0f ) * 0.5f * float2( fScreenWidth, -fScreenHeight );
46 |
47 | return f2ScreenPosition;
48 | }
49 |
50 |
51 | //--------------------------------------------------------------------------------------
52 | // Returns the distance of a given point from a given plane
53 | //--------------------------------------------------------------------------------------
54 | float DistanceFromPlane (
55 | float3 f3Position, // World space position of the patch control point
56 | float4 f4PlaneEquation // Plane equation of a frustum plane
57 | )
58 | {
59 | float fDistance = dot( float4( f3Position, 1.0f ), f4PlaneEquation );
60 |
61 | return fDistance;
62 | }
63 |
64 |
65 | //--------------------------------------------------------------------------------------
66 | // Returns a distance adaptive tessellation scale factor (0.0f -> 1.0f)
67 | //--------------------------------------------------------------------------------------
68 | float GetDistanceAdaptiveScaleFactor(
69 | float3 f3Eye, // Position of the camera/eye
70 | float3 f3EdgePosition0, // Position of the first control point of the given patch edge
71 | float3 f3EdgePosition1, // Position of the second control point of the given patch edge
72 | float fMinDistance, // Minimum distance that maximum tessellation factors should be applied at
73 | float fRange // Range beyond the minimum distance where tessellation will scale down to the minimum scaling factor
74 | )
75 | {
76 | float3 f3MidPoint = ( f3EdgePosition0 + f3EdgePosition1 ) * 0.5f;
77 |
78 | float fDistance = distance( f3MidPoint, f3Eye ) - fMinDistance;
79 |
80 | float fScale = 1.0f - saturate( fDistance / fRange );
81 |
82 | return fScale;
83 | }
84 |
85 |
86 | //--------------------------------------------------------------------------------------
87 | // Returns the orientation adaptive tessellation factor (0.0f -> 1.0f)
88 | //--------------------------------------------------------------------------------------
89 | float GetOrientationAdaptiveScaleFactor (
90 | float fEdgeDotProduct, // Dot product of edge normal with view vector
91 | float fSilhouetteEpsilon // Epsilon to determine the range of values considered to be silhoutte
92 | )
93 | {
94 | float fScale = 1.0f - abs( fEdgeDotProduct );
95 |
96 | fScale = saturate( ( fScale - fSilhouetteEpsilon ) / ( 1.0f - fSilhouetteEpsilon ) );
97 |
98 | return fScale;
99 | }
100 |
101 |
102 | //--------------------------------------------------------------------------------------
103 | // Returns the screen resolution adaptive tessellation scale factor (0.0f -> 1.0f)
104 | //--------------------------------------------------------------------------------------
105 | float GetScreenResolutionAdaptiveScaleFactor(
106 | float fCurrentWidth, // Current render window width
107 | float fCurrentHeight, // Current render window height
108 | float fMaxWidth, // Width considered to be max
109 | float fMaxHeight // Height considered to be max
110 | )
111 | {
112 | float fMaxArea = fMaxWidth * fMaxHeight;
113 |
114 | float fCurrentArea = fCurrentWidth * fCurrentHeight;
115 |
116 | float fScale = saturate( fCurrentArea / fMaxArea );
117 |
118 | return fScale;
119 | }
120 |
121 |
122 | //--------------------------------------------------------------------------------------
123 | // Returns the screen space adaptive tessellation scale factor (0.0f -> 1.0f)
124 | //--------------------------------------------------------------------------------------
125 | float GetScreenSpaceAdaptiveScaleFactor (
126 | float2 f2EdgeScreenPosition0, // Screen coordinate of the first patch edge control point
127 | float2 f2EdgeScreenPosition1, // Screen coordinate of the second patch edge control point
128 | float fMaxEdgeTessFactor, // Maximum edge tessellation factor
129 | float fTargetEdgePrimitiveSize // Desired primitive edge size in pixels
130 | )
131 | {
132 | float fEdgeScreenLength = distance( f2EdgeScreenPosition0, f2EdgeScreenPosition1 );
133 |
134 | float fTargetTessFactor = fEdgeScreenLength / fTargetEdgePrimitiveSize;
135 |
136 | fTargetTessFactor /= fMaxEdgeTessFactor;
137 |
138 | float fScale = saturate( fTargetTessFactor );
139 |
140 | return fScale;
141 | }
142 |
143 |
144 | //--------------------------------------------------------------------------------------
145 | // Returns back face culling test result (true / false)
146 | //--------------------------------------------------------------------------------------
147 | bool BackFaceCull (
148 | float fEdgeDotProduct0, // Dot product of edge 0 normal with view vector
149 | float fEdgeDotProduct1, // Dot product of edge 1 normal with view vector
150 | float fEdgeDotProduct2, // Dot product of edge 2 normal with view vector
151 | float fBackFaceEpsilon // Epsilon to determine cut off value for what is considered back facing
152 | )
153 | {
154 | float3 f3BackFaceCull;
155 |
156 | f3BackFaceCull.x = ( fEdgeDotProduct0 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
157 | f3BackFaceCull.y = ( fEdgeDotProduct1 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
158 | f3BackFaceCull.z = ( fEdgeDotProduct2 > -fBackFaceEpsilon ) ? ( 0.0f ) : ( 1.0f );
159 |
160 | return all( f3BackFaceCull );
161 | }
162 |
163 |
164 | //--------------------------------------------------------------------------------------
165 | // Returns view frustum Culling test result (true / false)
166 | //--------------------------------------------------------------------------------------
167 | bool ViewFrustumCull(
168 | float3 f3EdgePosition0, // World space position of patch control point 0
169 | float3 f3EdgePosition1, // World space position of patch control point 1
170 | float3 f3EdgePosition2, // World space position of patch control point 2
171 | float4 f4ViewFrustumPlanes[4], // 4 plane equations (left, right, top, bottom)
172 | float fCullEpsilon // Epsilon to determine the distance outside the view frustum is still considered inside
173 | )
174 | {
175 | float4 f4PlaneTest;
176 | float fPlaneTest;
177 |
178 | // Left clip plane
179 | f4PlaneTest.x = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
180 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
181 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[0]) > -fCullEpsilon ) ? 1.0f : 0.0f );
182 | // Right clip plane
183 | f4PlaneTest.y = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
184 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
185 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[1]) > -fCullEpsilon ) ? 1.0f : 0.0f );
186 | // Top clip plane
187 | f4PlaneTest.z = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
188 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
189 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[2]) > -fCullEpsilon ) ? 1.0f : 0.0f );
190 | // Bottom clip plane
191 | f4PlaneTest.w = ( ( DistanceFromPlane( f3EdgePosition0, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
192 | ( ( DistanceFromPlane( f3EdgePosition1, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f ) +
193 | ( ( DistanceFromPlane( f3EdgePosition2, f4ViewFrustumPlanes[3]) > -fCullEpsilon ) ? 1.0f : 0.0f );
194 |
195 | // Triangle has to pass all 4 plane tests to be visible
196 | return !all( f4PlaneTest );
197 | }
198 |
199 |
200 | //--------------------------------------------------------------------------------------
201 | // EOF
202 | //--------------------------------------------------------------------------------------
203 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/SimpleBezier11/SimpleBezier11.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: SimpleBezier11.hlsl
3 | //
4 | // This sample shows an simple implementation of the DirectX 11 Hardware Tessellator
5 | // for rendering a Bezier Patch.
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //--------------------------------------------------------------------------------------
9 |
10 | // This allows us to compile the shader with a #define to choose
11 | // the different partition modes for the hull shader.
12 | // See the hull shader: [partitioning(BEZIER_HS_PARTITION)]
13 | // This sample demonstrates "integer", "fractional_even", and "fractional_odd"
14 | #ifndef BEZIER_HS_PARTITION
15 | #define BEZIER_HS_PARTITION "integer"
16 | #endif // BEZIER_HS_PARTITION
17 |
18 | // The input patch size. In this sample, it is 16 control points.
19 | // This value should match the call to IASetPrimitiveTopology()
20 | #define INPUT_PATCH_SIZE 16
21 |
22 | // The output patch size. In this sample, it is also 16 control points.
23 | #define OUTPUT_PATCH_SIZE 16
24 |
25 | //--------------------------------------------------------------------------------------
26 | // Constant Buffers
27 | //--------------------------------------------------------------------------------------
28 | cbuffer cbPerFrame : register( b0 )
29 | {
30 | matrix g_mViewProjection;
31 | float3 g_vCameraPosWorld;
32 | float g_fTessellationFactor;
33 | };
34 |
35 | //--------------------------------------------------------------------------------------
36 | // Vertex shader section
37 | //--------------------------------------------------------------------------------------
38 | struct VS_CONTROL_POINT_INPUT
39 | {
40 | float3 vPosition : POSITION;
41 | };
42 |
43 | struct VS_CONTROL_POINT_OUTPUT
44 | {
45 | float3 vPosition : POSITION;
46 | };
47 |
48 | // This simple vertex shader passes the control points straight through to the
49 | // hull shader. In a more complex scene, you might transform the control points
50 | // or perform skinning at this step.
51 |
52 | // The input to the vertex shader comes from the vertex buffer.
53 |
54 | // The output from the vertex shader will go into the hull shader.
55 |
56 | VS_CONTROL_POINT_OUTPUT BezierVS( VS_CONTROL_POINT_INPUT Input )
57 | {
58 | VS_CONTROL_POINT_OUTPUT Output;
59 |
60 | Output.vPosition = Input.vPosition;
61 |
62 | return Output;
63 | }
64 |
65 | //--------------------------------------------------------------------------------------
66 | // Constant data function for the BezierHS. This is executed once per patch.
67 | //--------------------------------------------------------------------------------------
68 | struct HS_CONSTANT_DATA_OUTPUT
69 | {
70 | float Edges[4] : SV_TessFactor;
71 | float Inside[2] : SV_InsideTessFactor;
72 | };
73 |
74 | struct HS_OUTPUT
75 | {
76 | float3 vPosition : BEZIERPOS;
77 | };
78 |
79 | // This constant hull shader is executed once per patch. For the simple Mobius strip
80 | // model, it will be executed 4 times. In this sample, we set the tessellation factor
81 | // via SV_TessFactor and SV_InsideTessFactor for each patch. In a more complex scene,
82 | // you might calculate a variable tessellation factor based on the camera's distance.
83 |
84 | HS_CONSTANT_DATA_OUTPUT BezierConstantHS( InputPatch ip,
85 | uint PatchID : SV_PrimitiveID )
86 | {
87 | HS_CONSTANT_DATA_OUTPUT Output;
88 |
89 | float TessAmount = g_fTessellationFactor;
90 |
91 | Output.Edges[0] = Output.Edges[1] = Output.Edges[2] = Output.Edges[3] = TessAmount;
92 | Output.Inside[0] = Output.Inside[1] = TessAmount;
93 |
94 | return Output;
95 | }
96 |
97 | // The hull shader is called once per output control point, which is specified with
98 | // outputcontrolpoints. For this sample, we take the control points from the vertex
99 | // shader and pass them directly off to the domain shader. In a more complex scene,
100 | // you might perform a basis conversion from the input control points into a Bezier
101 | // patch, such as the SubD11 Sample.
102 |
103 | // The input to the hull shader comes from the vertex shader
104 |
105 | // The output from the hull shader will go to the domain shader.
106 | // The tessellation factor, topology, and partition mode will go to the fixed function
107 | // tessellator stage to calculate the UVW and domain points.
108 |
109 | [domain("quad")]
110 | [partitioning(BEZIER_HS_PARTITION)]
111 | [outputtopology("triangle_cw")]
112 | [outputcontrolpoints(OUTPUT_PATCH_SIZE)]
113 | [patchconstantfunc("BezierConstantHS")]
114 | HS_OUTPUT BezierHS( InputPatch p,
115 | uint i : SV_OutputControlPointID,
116 | uint PatchID : SV_PrimitiveID )
117 | {
118 | HS_OUTPUT Output;
119 | Output.vPosition = p[i].vPosition;
120 | return Output;
121 | }
122 |
123 | //--------------------------------------------------------------------------------------
124 | // Bezier evaluation domain shader section
125 | //--------------------------------------------------------------------------------------
126 | struct DS_OUTPUT
127 | {
128 | float4 vPosition : SV_POSITION;
129 | float3 vWorldPos : WORLDPOS;
130 | float3 vNormal : NORMAL;
131 | };
132 |
133 | //--------------------------------------------------------------------------------------
134 | float4 BernsteinBasis(float t)
135 | {
136 | float invT = 1.0f - t;
137 |
138 | return float4( invT * invT * invT,
139 | 3.0f * t * invT * invT,
140 | 3.0f * t * t * invT,
141 | t * t * t );
142 | }
143 |
144 | //--------------------------------------------------------------------------------------
145 | float4 dBernsteinBasis(float t)
146 | {
147 | float invT = 1.0f - t;
148 |
149 | return float4( -3 * invT * invT,
150 | 3 * invT * invT - 6 * t * invT,
151 | 6 * t * invT - 3 * t * t,
152 | 3 * t * t );
153 | }
154 |
155 | //--------------------------------------------------------------------------------------
156 | float3 EvaluateBezier( const OutputPatch bezpatch,
157 | float4 BasisU,
158 | float4 BasisV )
159 | {
160 | float3 Value = float3(0,0,0);
161 | Value = BasisV.x * ( bezpatch[0].vPosition * BasisU.x + bezpatch[1].vPosition * BasisU.y + bezpatch[2].vPosition * BasisU.z + bezpatch[3].vPosition * BasisU.w );
162 | Value += BasisV.y * ( bezpatch[4].vPosition * BasisU.x + bezpatch[5].vPosition * BasisU.y + bezpatch[6].vPosition * BasisU.z + bezpatch[7].vPosition * BasisU.w );
163 | Value += BasisV.z * ( bezpatch[8].vPosition * BasisU.x + bezpatch[9].vPosition * BasisU.y + bezpatch[10].vPosition * BasisU.z + bezpatch[11].vPosition * BasisU.w );
164 | Value += BasisV.w * ( bezpatch[12].vPosition * BasisU.x + bezpatch[13].vPosition * BasisU.y + bezpatch[14].vPosition * BasisU.z + bezpatch[15].vPosition * BasisU.w );
165 |
166 | return Value;
167 | }
168 |
169 | // The domain shader is run once per vertex and calculates the final vertex's position
170 | // and attributes. It receives the UVW from the fixed function tessellator and the
171 | // control point outputs from the hull shader. Since we are using the DirectX 11
172 | // Tessellation pipeline, it is the domain shader's responsibility to calculate the
173 | // final SV_POSITION for each vertex. In this sample, we evaluate the vertex's
174 | // position using a Bernstein polynomial and the normal is calculated as the cross
175 | // product of the U and V derivatives.
176 |
177 | // The input SV_DomainLocation to the domain shader comes from fixed function
178 | // tessellator. And the OutputPatch comes from the hull shader. From these, you
179 | // must calculate the final vertex position, color, texcoords, and other attributes.
180 |
181 | // The output from the domain shader will be a vertex that will go to the video card's
182 | // rasterization pipeline and get drawn to the screen.
183 |
184 | [domain("quad")]
185 | DS_OUTPUT BezierDS( HS_CONSTANT_DATA_OUTPUT input,
186 | float2 UV : SV_DomainLocation,
187 | const OutputPatch bezpatch )
188 | {
189 | float4 BasisU = BernsteinBasis( UV.x );
190 | float4 BasisV = BernsteinBasis( UV.y );
191 | float4 dBasisU = dBernsteinBasis( UV.x );
192 | float4 dBasisV = dBernsteinBasis( UV.y );
193 |
194 | float3 WorldPos = EvaluateBezier( bezpatch, BasisU, BasisV );
195 | float3 Tangent = EvaluateBezier( bezpatch, dBasisU, BasisV );
196 | float3 BiTangent = EvaluateBezier( bezpatch, BasisU, dBasisV );
197 | float3 Norm = normalize( cross( Tangent, BiTangent ) );
198 |
199 | DS_OUTPUT Output;
200 | Output.vPosition = mul( float4(WorldPos,1), g_mViewProjection );
201 | Output.vWorldPos = WorldPos;
202 | Output.vNormal = Norm;
203 |
204 | return Output;
205 | }
206 |
207 | //--------------------------------------------------------------------------------------
208 | // Smooth shading pixel shader section
209 | //--------------------------------------------------------------------------------------
210 |
211 | // The pixel shader works the same as it would in a normal graphics pipeline.
212 | // In this sample, it performs very simple N dot L lighting.
213 |
214 | float4 BezierPS( DS_OUTPUT Input ) : SV_TARGET
215 | {
216 | float3 N = normalize(Input.vNormal);
217 | float3 L = normalize(Input.vWorldPos - g_vCameraPosWorld);
218 | return abs(dot(N, L)) * float4(1, 0, 0, 1);
219 | }
220 |
221 | //--------------------------------------------------------------------------------------
222 | // Solid color shading pixel shader (used for wireframe overlay)
223 | //--------------------------------------------------------------------------------------
224 | float4 SolidColorPS( DS_OUTPUT Input ) : SV_TARGET
225 | {
226 | // Return a solid green color
227 | return float4( 0, 1, 0, 1 );
228 | }
229 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/VarianceShadows11/2DQuadShaders.hlsl:
--------------------------------------------------------------------------------
1 | //--------------------------------------------------------------------------------------
2 | // File: Skinning10.fx
3 | //
4 | // The effect file for the Skinning10 sample.
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //--------------------------------------------------------------------------------------
8 |
9 | #ifndef SEPERABLE_BLUR_KERNEL_SIZE
10 | #define SEPERABLE_BLUR_KERNEL_SIZE 3
11 | #endif
12 |
13 | static const int BLUR_KERNEL_BEGIN = SEPERABLE_BLUR_KERNEL_SIZE / -2;
14 | static const int BLUR_KERNEL_END = SEPERABLE_BLUR_KERNEL_SIZE / 2 + 1;
15 | static const float FLOAT_BLUR_KERNEL_SIZE = (float)SEPERABLE_BLUR_KERNEL_SIZE;
16 |
17 | cbuffer cbblurVS : register( b2)
18 | {
19 | int2 g_iWidthHeight : packoffset( c0 );
20 | int g_iKernelStart : packoffset( c0.z );
21 | int g_iKernelEnd : packoffset( c0.w );
22 | };
23 |
24 | //--------------------------------------------------------------------------------------
25 | // defines
26 | //--------------------------------------------------------------------------------------
27 |
28 | Texture2DArray g_txShadow : register( t5 );
29 | SamplerState g_samShadow : register( s5 );
30 |
31 | //--------------------------------------------------------------------------------------
32 | // Input/Output structures
33 | //--------------------------------------------------------------------------------------
34 |
35 | struct PSIn
36 | {
37 | float4 Pos : SV_Position; //Position
38 | float2 Tex : TEXCOORD; //Texture coordinate
39 | float2 ITex : TEXCOORD2;
40 | };
41 |
42 | struct VSIn
43 | {
44 | uint Pos : SV_VertexID ;
45 | };
46 |
47 |
48 | PSIn VSMain(VSIn inn)
49 | {
50 | PSIn output;
51 |
52 | output.Pos.y = -1.0f + (inn.Pos%2) * 2.0f ;
53 | output.Pos.x = -1.0f + (inn.Pos/2) * 2.0f;
54 | output.Pos.z = .5;
55 | output.Pos.w = 1;
56 | output.Tex.x = inn.Pos/2;
57 | output.Tex.y = 1.0f - inn.Pos%2;
58 | output.ITex.x = (float)(g_iWidthHeight.x * output.Tex.x);
59 | output.ITex.y = (float)(g_iWidthHeight.y * output.Tex.y);
60 | return output;
61 | }
62 |
63 | //float PSDepth
64 |
65 | //------------------------------------------------------------------------------
66 | // Logarithmic filtering
67 | //------------------------------------------------------------------------------
68 |
69 | float log_conv ( float x0, float X, float y0, float Y )
70 | {
71 | return (X + log(x0 + (y0 * exp(Y - X))));
72 | }
73 |
74 |
75 | //--------------------------------------------------------------------------------------
76 | // Pixel shader that performs bump mapping on the final vertex
77 | //--------------------------------------------------------------------------------------
78 | float2 PSBlurX(PSIn input) : SV_Target
79 | {
80 | /*
81 | float2 centerDistance;
82 | if ( input.Tex.x < .5 ) centerDistance.x = (1.0 - input.Tex.x);
83 | else centerDistance.x = input.Tex.x;
84 | if ( input.Tex.y < .5 ) centerDistance.y = (1.0 - input.Tex.y);
85 | else centerDistance.y = input.Tex.y;
86 | if (centerDistance.x < centerDistance.y) centerDistance.x = centerDistance.y;
87 | centerDistance.x -= .2;
88 | centerDistance.x *= (1.0f / .8);
89 |
90 | float store_samples[8];
91 | int ind = 0;
92 | for (int x = g_iKernelStart; x < g_iKernelEnd; ++x) {
93 | store_samples[ind] = g_txShadow.Load( int3(input.ITex.x+(float)x * centerDistance.x , input.ITex.y, 0) ).r;
94 | ind++;
95 | }
96 | const float c = (1.f/5.f);
97 |
98 | float accum;
99 | accum = log_conv( c, store_samples[0], c, store_samples[1] );
100 |
101 | ind = 0;
102 | for (x = g_iKernelStart - 2; x < g_iKernelEnd; ++x) {
103 | ind++;
104 | accum += log_conv( 1.0f, accum, c, store_samples[ind] );
105 | }
106 | float2 rt;
107 | rt.x = accum;
108 | return rt;
109 | */
110 | /*
111 | float2 dep = 0;
112 | float2 centerDistance;
113 | if ( input.Tex.x < .5 ) centerDistance.x = (1.0 - input.Tex.x);
114 | else centerDistance.x = input.Tex.x;
115 | if ( input.Tex.y < .5 ) centerDistance.y = (1.0 - input.Tex.y);
116 | else centerDistance.y = input.Tex.y;
117 | if (centerDistance.x < centerDistance.y) centerDistance.x = centerDistance.y;
118 | centerDistance.x -= .2;
119 | centerDistance.x *= ( 1.0f / 0.8f );
120 |
121 | for (int x = g_iKernelStart; x < g_iKernelEnd; ++x) {
122 | dep += g_txShadow.Load( int3(input.ITex.x+(float)x * centerDistance.x , input.ITex.y, 0) ).rg;
123 | }
124 | dep /= (g_iKernelEnd - g_iKernelStart);
125 | return dep;
126 | */
127 |
128 | float2 dep=0;
129 | [unroll]for ( int x = BLUR_KERNEL_BEGIN; x < BLUR_KERNEL_END; ++x ) {
130 | dep += g_txShadow.Sample( g_samShadow, float3( input.Tex.x, input.Tex.y, 0 ), int2( x,0 ) ).rg;
131 | }
132 | dep /= FLOAT_BLUR_KERNEL_SIZE;
133 | return dep;
134 |
135 | // return g_txShadow.Sample(g_samShadow, float3(input.Tex.x, input.Tex.y, 0) ).rg;
136 |
137 | }
138 |
139 | //--------------------------------------------------------------------------------------
140 | // Pixel shader that performs bump mapping on the final vertex
141 | //--------------------------------------------------------------------------------------
142 | float2 PSBlurY(PSIn input) : SV_Target
143 | {
144 | /*
145 | float2 centerDistance;
146 | if ( input.Tex.x < .5 ) centerDistance.x = (1.0 - input.Tex.x);
147 | else centerDistance.x = input.Tex.x;
148 | if ( input.Tex.y < .5 ) centerDistance.y = (1.0 - input.Tex.y);
149 | else centerDistance.y = input.Tex.y;
150 | if (centerDistance.x < centerDistance.y) centerDistance.x = centerDistance.y;
151 | centerDistance.x -= .2;
152 | centerDistance.x *= (1.0f / .8);
153 |
154 | float store_samples[8];
155 | int ind = 0;
156 | for (int y = g_iKernelStart; y < g_iKernelEnd; ++y) {
157 | store_samples[ind] = g_txShadow.Load( int3(input.ITex.x, input.ITex.y+(float)y * centerDistance.x, 0) ).r;
158 | }
159 | const float c = (1.f/5.f);
160 |
161 | float accum;
162 | accum = log_conv( c, store_samples[0], c, store_samples[1] );
163 |
164 | ind = 0;
165 | for (y = g_iKernelStart; y < g_iKernelEnd; ++y) {
166 | ind++;
167 | accum += log_conv( 1.0f, accum, c, store_samples[ind] );
168 | }
169 | float2 rt;
170 | rt.x = accum;
171 | return rt;
172 | */
173 |
174 |
175 | /*
176 | float2 dep = 0;
177 |
178 | float2 centerDistance;
179 | if ( input.Tex.x < .5 ) centerDistance.x = (1.0 - input.Tex.x);
180 | else centerDistance.x = input.Tex.x;
181 | if ( input.Tex.y < .5 ) centerDistance.y = (1.0 - input.Tex.y);
182 | else centerDistance.y = input.Tex.y;
183 | if (centerDistance.x < centerDistance.y) centerDistance.x = centerDistance.y;
184 | centerDistance.x -= 0;
185 | centerDistance.x *= (1.0f / 1.0f);
186 |
187 | if (centerDistance.x < centerDistance.y) centerDistance.x = centerDistance.y;
188 | for (int y = g_iKernelStart; y < g_iKernelEnd; ++y) {
189 | dep += g_txShadow.Load( int3(input.ITex.x, input.ITex.y+(float)y * centerDistance.x, 0) ).rg;
190 | }
191 |
192 |
193 | dep /= (g_iKernelEnd - g_iKernelStart);
194 | return dep;
195 |
196 | */
197 |
198 |
199 | float2 dep=0;
200 | [unroll]for ( int y = BLUR_KERNEL_BEGIN; y < BLUR_KERNEL_END; ++y ) {
201 | dep += g_txShadow.Sample( g_samShadow, float3( input.Tex.x, input.Tex.y, 0 ), int2( 0,y ) ).rg;
202 | }
203 | dep /= FLOAT_BLUR_KERNEL_SIZE;
204 | return dep;
205 |
206 | //return g_txShadow.Sample(g_samShadow, float3(input.Tex.x, input.Tex.y, 0) ).rg;
207 | }
208 |
209 |
210 |
211 |
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/Direct3D11/VarianceShadows11/RenderVarianceShadow.hlsl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | //--------------------------------------------------------------------------------------
5 | // Globals
6 | //--------------------------------------------------------------------------------------
7 | cbuffer cbPerObject : register( b0 )
8 | {
9 | matrix g_mWorldViewProjection : packoffset( c0 );
10 | };
11 |
12 | //--------------------------------------------------------------------------------------
13 | // Input / Output structures
14 | //--------------------------------------------------------------------------------------
15 | struct VS_INPUT
16 | {
17 | float4 vPosition : POSITION;
18 | };
19 |
20 | struct VS_OUTPUT
21 | {
22 | float4 vPosition : SV_POSITION;
23 | };
24 |
25 | //--------------------------------------------------------------------------------------
26 | // Vertex Shader
27 | //--------------------------------------------------------------------------------------
28 | VS_OUTPUT VSMain( VS_INPUT Input )
29 | {
30 | VS_OUTPUT Output;
31 |
32 |
33 | Output.vPosition = mul( Input.vPosition, g_mWorldViewProjection );
34 |
35 | return Output;
36 | }
37 |
38 |
39 | float2 PSMain (VS_OUTPUT Input) : SV_TARGET
40 | {
41 | float2 rt;
42 | rt.x = Input.vPosition.z;
43 | rt.y = rt.x * rt.x;
44 | return rt;
45 | }
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/DirectX SDK EULA.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgjones/hlsl-parser-nitra/8b78d4eb24364f5d647e9cbe71f45df036b45c46/src/HlslParser.Tests/Shaders/Sdk/DirectX SDK EULA.txt
--------------------------------------------------------------------------------
/src/HlslParser.Tests/Shaders/Sdk/readme.txt:
--------------------------------------------------------------------------------
1 | From DirectX SDK (June 2010) Samples
--------------------------------------------------------------------------------
/src/HlslParser.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/HlslParser.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{EDCC3B85-0BAD-11DB-BC1A-00112FDE8B61}") = "HlslParser", "HlslParser\HlslParser.nproj", "{8E98D01E-2E3F-4503-A338-40CB79CE39C6}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HlslParser.Tests", "HlslParser.Tests\HlslParser.Tests.csproj", "{B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {8E98D01E-2E3F-4503-A338-40CB79CE39C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {8E98D01E-2E3F-4503-A338-40CB79CE39C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {8E98D01E-2E3F-4503-A338-40CB79CE39C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {8E98D01E-2E3F-4503-A338-40CB79CE39C6}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {B77DF2B3-9940-4CE5-BC00-9CE4AEDF909D}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/src/HlslParser/HlslParser.nproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | 8e98d01e-2e3f-4503-a338-40cb79ce39c6
9 | Library
10 | Properties
11 | HlslParser
12 | HlslParser
13 | v4.5
14 | 512
15 | true
16 | Net-4.0
17 | $(ProgramFiles)\Nemerle
18 | $(NemerleBinPathRoot)\$(NemerleVersion)
19 |
20 | HlslParser
21 |
22 |
23 | true
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 |
30 |
31 | false
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 | $(OutputPath)\$(AssemblyName).xml
38 |
39 |
40 |
41 |
42 |
43 | 3.5
44 |
45 |
46 | 3.5
47 |
48 |
49 | 3.5
50 |
51 |
52 |
53 |
54 | False
55 | $(Nemerle)\Nemerle.dll
56 | True
57 |
58 |
59 | False
60 | $(NitraPath)\Nitra.Runtime.dll
61 | True
62 |
63 |
64 | False
65 | $(NitraPath)\Nitra.Core.dll
66 | True
67 |
68 |
69 | $(Nemerle)\Nemerle.Linq.dll
70 |
71 |
72 | $(NitraPath)\Nitra.Compiler.dll
73 |
74 |
75 |
76 |
77 | Code
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
94 |
--------------------------------------------------------------------------------
/src/HlslParser/Properties/AssemblyInfo.n:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: Nemerle.Macro.Resource(@"Properties\Resources.resx")]
6 | [assembly: Nemerle.Macro.Settings(@"Properties\Settings.settings")]
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: AssemblyTitle("HlslParser")]
12 | [assembly: AssemblyDescription("")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("")]
15 | [assembly: AssemblyProduct("HlslParser")]
16 | [assembly: AssemblyCopyright("Copyright © 2014")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 |
20 | // Setting ComVisible to false makes the types in this assembly not visible
21 | // to COM components. If you need to access a type in this assembly from
22 | // COM, set the ComVisible attribute to true on that type.
23 | [assembly: ComVisible(false)]
24 |
25 | // The following GUID is for the ID of the typelib if this project is exposed to COM
26 | [assembly: Guid("8e98d01e-2e3f-4503-a338-40cb79ce39c6")]
27 |
28 | // Version information for an assembly consists of the following four values:
29 | //
30 | // Major Version
31 | // Minor Version
32 | // Build Number
33 | // Revision
34 | //
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------