├── .gitignore ├── BuildNuGet.sh ├── Dependencies ├── Axiom.Platforms.OpenTK.dll ├── Axiom.Plugins.SystemDrawingCodecs.dll ├── Axiom.RenderSystems.DirectX9.dll ├── Axiom.RenderSystems.OpenGL.OpenTK.dll ├── Axiom.dll ├── Axiom.xml ├── ICSharpCode.Decompiler.dll ├── ICSharpCode.Decompiler.xml ├── ICSharpCode.NRefactory.dll ├── ICSharpCode.NRefactory.xml ├── Mogre.dll ├── Mogre.xml ├── Mono.Cecil.dll ├── NuGet.exe ├── OgreMain.dll ├── OpenTK.Compatibility.dll ├── OpenTK.GLControl.dll ├── OpenTK.dll ├── OpenTK.xml ├── RenderSystem_Direct3D9.dll ├── RenderSystem_GL.dll ├── SlimDX.dll └── nunit.framework.dll ├── IIS.SLSharp.Bindings.Axiom ├── Bindings.cs └── IIS.SLSharp.Bindings.Axiom.csproj ├── IIS.SLSharp.Bindings.Mogre ├── Bindings.cs └── IIS.SLSharp.Bindings.Mogre.csproj ├── IIS.SLSharp.Bindings.OpenTK ├── Bindings.cs ├── GpuStopwatch.cs ├── IIS.SLSharp.Bindings.OpenTK.csproj ├── Program.cs ├── Quad.cs ├── Textures │ ├── Externals │ │ ├── LoaderDDS.cs │ │ └── LoaderStatics.cs │ ├── FramebufferObject.cs │ ├── ITexture.cs │ ├── RenderToTexture.cs │ ├── RenderbufferObject.cs │ ├── Texture1D.cs │ ├── Texture2D.cs │ ├── TextureBase.cs │ └── TextureCube.cs └── Utilities.cs ├── IIS.SLSharp.Bindings.SlimDX └── IIS.SLSharp.Bindings.SlimDX.csproj ├── IIS.SLSharp.Bindings.Xna ├── Bindings.cs └── IIS.SLSharp.Bindings.Xna.csproj ├── IIS.SLSharp.Examples.Axiom.GeoClipmap ├── App.config ├── DemoWindow.cs ├── GeoClipmap │ ├── Clipmap.cs │ ├── ClipmapLevel.cs │ ├── IntFloat.cs │ ├── IntFloatVector2.cs │ ├── Patch.cs │ ├── PatchLocation.cs │ ├── PatchLocations.cs │ └── PatchRenderable.cs ├── IIS.SLSharp.Examples.Axiom.GeoClipmap.csproj ├── Program.cs └── Shaders │ └── ClipmapShader.cs ├── IIS.SLSharp.Examples.Axiom ├── App.config ├── DemoWindow.cs ├── IIS.SLSharp.Examples.Axiom.csproj ├── Program.cs ├── Shaders │ ├── SimpleShader.cs │ └── WangShader.cs └── Textures │ └── WangMap.cs ├── IIS.SLSharp.Examples.Complex ├── DemoWindow.cs ├── IIS.SLSharp.Examples.Complex.csproj ├── Program.cs ├── Resources.Designer.cs ├── Resources.resx ├── Shaders │ ├── BackdropShader.cs │ ├── Cube.cs │ ├── CubeShader.cs │ ├── SimplexNoiseShader.cs │ └── WangShader.cs └── Textures │ └── WangMap.cs ├── IIS.SLSharp.Examples.GeoClipmap ├── Clipmap │ ├── Clipmap.cs │ ├── ClipmapLevel.cs │ ├── Patch.cs │ ├── PatchLocation.cs │ └── PatchLocations.cs ├── DemoWindow.cs ├── IIS.SLSharp.Examples.GeoClipmap.csproj ├── IntFloat.cs ├── IntFloatVector2.cs ├── Program.cs ├── Shaders │ ├── ClipmapShader.cs │ └── DebugShader.cs └── Utilities.cs ├── IIS.SLSharp.Examples.Mogre.GeoClipmap ├── App.config ├── DemoWindow.cs ├── GeoClipmap │ ├── Clipmap.cs │ ├── ClipmapLevel.cs │ ├── IntFloat.cs │ ├── IntFloatVector2.cs │ ├── Patch.cs │ ├── PatchLocation.cs │ ├── PatchLocations.cs │ └── PatchRenderable.cs ├── IIS.SLSharp.Examples.Mogre.GeoClipmap.csproj ├── Program.cs └── Shaders │ └── ClipmapShader.cs ├── IIS.SLSharp.Examples.Mogre ├── App.config ├── DemoWindow.cs ├── IIS.SLSharp.Examples.Mogre.csproj ├── Program.cs ├── Shaders │ ├── SimpleShader.cs │ └── WangShader.cs └── Textures │ └── WangMap.cs ├── IIS.SLSharp.Examples.Simple ├── DemoWindow.cs ├── IIS.SLSharp.Examples.Simple.csproj ├── Program.cs └── Shaders │ ├── InvertShader.cs │ └── MyShader.cs ├── IIS.SLSharp.Examples.Xna ├── DemoWindow.cs ├── IIS.SLSharp.Examples.Xna.csproj ├── Program.cs └── Shaders │ └── SimpleShader.cs ├── IIS.SLSharp.NuGet └── SLSharp.nuspec ├── IIS.SLSharp.Tests ├── ExponentialTests.cs ├── GeometricTests.cs ├── IIS.SLSharp.Tests.csproj ├── ITestRuntime.cs ├── OpenTKTestRuntime │ └── OpenTKTestRuntime.cs ├── ShaderBuilder.cs ├── ShaderTest.cs └── TestState.cs ├── IIS.SLSharp ├── Annotations │ ├── FragmentOutAttribute.cs │ ├── FragmentShaderAttribute.cs │ ├── IShaderAttribute.cs │ ├── ShaderVariableAttribute.cs │ ├── UndefinedBehaviorAttribute.cs │ ├── UniformAttribute.cs │ ├── VaryingAttribute.cs │ ├── VertexInAttribute.cs │ ├── VertexShaderAttribute.cs │ └── WarningAttribute.cs ├── Bindings │ ├── Binding.cs │ ├── IProgram.cs │ └── ISLSharpBinding.cs ├── Descriptions │ ├── FunctionDescription.cs │ ├── SourceDescription.cs │ └── VariableDescription.cs ├── Extensions.cs ├── IIS.SLSharp.csproj ├── Reflection │ ├── ReflectionMarkerAttribute.cs │ └── ReflectionToken.cs ├── Runtime │ └── ResourceManager.cs ├── SLSharpException.cs ├── ShaderType.cs ├── Shaders │ ├── AttributeHelper.cs │ ├── Shader.Context.cs │ ├── Shader.cs │ ├── ShaderDefinition.BooleanVector.cs │ ├── ShaderDefinition.Cecil.cs │ ├── ShaderDefinition.Common.cs │ ├── ShaderDefinition.Derivative.cs │ ├── ShaderDefinition.DoubleMatrix.cs │ ├── ShaderDefinition.DoubleVector.cs │ ├── ShaderDefinition.Exponential.cs │ ├── ShaderDefinition.Geometric.cs │ ├── ShaderDefinition.Int32Vector.cs │ ├── ShaderDefinition.Integer.cs │ ├── ShaderDefinition.Interpolation.cs │ ├── ShaderDefinition.Matrix.cs │ ├── ShaderDefinition.MatrixFunctions.cs │ ├── ShaderDefinition.Noise.cs │ ├── ShaderDefinition.Packing.cs │ ├── ShaderDefinition.Sampler.cs │ ├── ShaderDefinition.SingleVector.cs │ ├── ShaderDefinition.Special.cs │ ├── ShaderDefinition.Texture.cs │ ├── ShaderDefinition.Trigonometry.cs │ ├── ShaderDefinition.UInt32Vector.cs │ └── ShaderDefinition.cs └── Translation │ ├── GLSL │ ├── GlslSourceBuilder.cs │ ├── GlslTransform.cs │ ├── GlslVisitor.ShaderDef.cs │ ├── GlslVisitor.Unimplemented.cs │ ├── GlslVisitor.cs │ └── Workarounds │ │ ├── Exponential.cs │ │ └── Trigonometric.cs │ ├── HLSL │ ├── HlslSourceBuilder.cs │ ├── HlslTransform.cs │ ├── HlslVisitor.ShaderDef.cs │ ├── HlslVisitor.Unimplemented.cs │ ├── HlslVisitor.cs │ └── Workarounds │ │ ├── Exponential.cs │ │ └── Trigonometric.cs │ ├── ITransform.cs │ ├── RenameLocals.cs │ ├── Utility.cs │ ├── VisitorBase.Abstract.cs │ ├── VisitorBase.Illegal.cs │ ├── VisitorBase.ShaderDef.cs │ ├── VisitorBase.Unsupported.cs │ └── VisitorBase.cs ├── LICENSE ├── Local.testsettings ├── README.md ├── Resources ├── box.mesh ├── height.jpg ├── tiles.png └── xwing.xnb ├── SLSharp.Mono.sln ├── SLSharp.sln ├── SLSharp.vsmdi └── SolutionInfo.cs /.gitignore: -------------------------------------------------------------------------------- 1 | *.opensdf 2 | *.sdf 3 | *.suo 4 | *.user 5 | *.userprefs 6 | *.pdb 7 | *.pidb 8 | *.vsp 9 | *.orig 10 | 11 | *_ReSharper*/* 12 | bin/* 13 | */obj/* 14 | IIS.SLSharp.NuGet/*/* 15 | TestResults/* 16 | -------------------------------------------------------------------------------- /BuildNuGet.sh: -------------------------------------------------------------------------------- 1 | rm -rf IIS.SLSharp.NuGet/App_Readme 2 | mkdir IIS.SLSharp.NuGet/App_Readme 3 | 4 | rm -rf IIS.SLSharp.NuGet/lib 5 | mkdir IIS.SLSharp.NuGet/lib 6 | 7 | cp bin/Release/IIS.SLSharp.dll IIS.SLSharp.NuGet/lib 8 | cp bin/Release/IIS.SLSharp.xml IIS.SLSharp.NuGet/lib 9 | 10 | cp bin/Release/IIS.SLSharp.Bindings.*.dll IIS.SLSharp.NuGet/lib 11 | cp bin/Release/IIS.SLSharp.Bindings.*.xml IIS.SLSharp.NuGet/lib 12 | 13 | cp Dependencies/*.dll IIS.SLSharp.NuGet/lib 14 | cp Dependencies/*.xml IIS.SLSharp.NuGet/lib 15 | 16 | cp README.md IIS.SLSharp.NuGet/App_Readme/SLSharp.readme.txt 17 | 18 | Dependencies/NuGet.exe pack "IIS.SLSharp.NuGet/SLSharp.nuspec" -outputDirectory bin/Release 19 | -------------------------------------------------------------------------------- /Dependencies/Axiom.Platforms.OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Axiom.Platforms.OpenTK.dll -------------------------------------------------------------------------------- /Dependencies/Axiom.Plugins.SystemDrawingCodecs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Axiom.Plugins.SystemDrawingCodecs.dll -------------------------------------------------------------------------------- /Dependencies/Axiom.RenderSystems.DirectX9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Axiom.RenderSystems.DirectX9.dll -------------------------------------------------------------------------------- /Dependencies/Axiom.RenderSystems.OpenGL.OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Axiom.RenderSystems.OpenGL.OpenTK.dll -------------------------------------------------------------------------------- /Dependencies/Axiom.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Axiom.dll -------------------------------------------------------------------------------- /Dependencies/ICSharpCode.Decompiler.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/ICSharpCode.Decompiler.dll -------------------------------------------------------------------------------- /Dependencies/ICSharpCode.NRefactory.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/ICSharpCode.NRefactory.dll -------------------------------------------------------------------------------- /Dependencies/Mogre.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Mogre.dll -------------------------------------------------------------------------------- /Dependencies/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/Mono.Cecil.dll -------------------------------------------------------------------------------- /Dependencies/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/NuGet.exe -------------------------------------------------------------------------------- /Dependencies/OgreMain.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/OgreMain.dll -------------------------------------------------------------------------------- /Dependencies/OpenTK.Compatibility.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/OpenTK.Compatibility.dll -------------------------------------------------------------------------------- /Dependencies/OpenTK.GLControl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/OpenTK.GLControl.dll -------------------------------------------------------------------------------- /Dependencies/OpenTK.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/OpenTK.dll -------------------------------------------------------------------------------- /Dependencies/RenderSystem_Direct3D9.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/RenderSystem_Direct3D9.dll -------------------------------------------------------------------------------- /Dependencies/RenderSystem_GL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/RenderSystem_GL.dll -------------------------------------------------------------------------------- /Dependencies/SlimDX.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/SlimDX.dll -------------------------------------------------------------------------------- /Dependencies/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Dependencies/nunit.framework.dll -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.Axiom/IIS.SLSharp.Bindings.Axiom.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {176019E3-AF31-4BA2-AADD-62036ACA9C74} 9 | Library 10 | Properties 11 | IIS.SLSharp.Bindings.Axiom 12 | IIS.SLSharp.Bindings.Axiom 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | ..\bin\Debug\IIS.SLSharp.Bindings.Axiom.xml 26 | 1591 27 | true 28 | x86 29 | 30 | 31 | pdbonly 32 | true 33 | ..\bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | ..\bin\Release\IIS.SLSharp.Bindings.Axiom.xml 38 | 1591 39 | true 40 | x86 41 | 42 | 43 | 44 | False 45 | ..\Dependencies\Axiom.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Properties\SolutionInfo.cs 57 | 58 | 59 | 60 | 61 | 62 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 63 | IIS.SLSharp 64 | 65 | 66 | 67 | 74 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.Mogre/IIS.SLSharp.Bindings.Mogre.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {08922A61-B3E4-4A4D-8476-59F1937254A2} 9 | Library 10 | Properties 11 | IIS.SLSharp.Bindings.Mogre 12 | IIS.SLSharp.Bindings.Mogre 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | ..\bin\Debug\IIS.SLSharp.Bindings.Mogre.xml 26 | 1591 27 | true 28 | x86 29 | 30 | 31 | pdbonly 32 | true 33 | ..\bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 1591 38 | ..\bin\Release\IIS.SLSharp.Bindings.Mogre.xml 39 | true 40 | x86 41 | 42 | 43 | 44 | ..\Dependencies\Mogre.dll 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Properties\SolutionInfo.cs 57 | 58 | 59 | 60 | 61 | 62 | 63 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 64 | IIS.SLSharp 65 | 66 | 67 | 68 | 75 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/GpuStopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | using OpenTK.Graphics.OpenGL; 5 | 6 | namespace IIS.SLSharp.Bindings.OpenTK 7 | { 8 | public sealed class GpuStopwatch : IDisposable 9 | { 10 | private readonly bool _hasArbTimer; 11 | 12 | private readonly Stopwatch _simpleWatch; 13 | 14 | private uint _query; 15 | 16 | public GpuStopwatch() 17 | { 18 | _hasArbTimer = GL.GetString(StringName.Extensions).Contains("ARB_timer_query"); 19 | 20 | if (_hasArbTimer) 21 | GL.GenQueries(1, out _query); 22 | else 23 | _simpleWatch = new Stopwatch(); 24 | } 25 | 26 | public void Restart() 27 | { 28 | if (!_hasArbTimer) 29 | _simpleWatch.Restart(); 30 | else 31 | GL.BeginQuery((QueryTarget)(0x88BF), _query); 32 | } 33 | 34 | public void Stop() 35 | { 36 | if (!_hasArbTimer) 37 | _simpleWatch.Stop(); 38 | else 39 | GL.EndQuery((QueryTarget)(0x88BF)); 40 | } 41 | 42 | public void StopAndFinish() 43 | { 44 | if (_hasArbTimer) 45 | { 46 | Stop(); 47 | GL.Finish(); 48 | } 49 | else 50 | { 51 | GL.Finish(); 52 | Stop(); 53 | } 54 | } 55 | 56 | public bool IsGpuWatch 57 | { 58 | get { return _hasArbTimer; } 59 | } 60 | 61 | public bool Available 62 | { 63 | get 64 | { 65 | if (!_hasArbTimer) 66 | return true; 67 | 68 | int available; 69 | GL.GetQueryObject(_query, GetQueryObjectParam.QueryResultAvailable, out available); 70 | return available != 0; 71 | } 72 | } 73 | 74 | public void WaitForResult() 75 | { 76 | while (!Available) 77 | Thread.Yield(); 78 | } 79 | 80 | public long ElapsedTicks 81 | { 82 | get 83 | { 84 | if (!_hasArbTimer) 85 | return _simpleWatch.ElapsedTicks; 86 | 87 | WaitForResult(); 88 | uint time; 89 | GL.GetQueryObject(_query, GetQueryObjectParam.QueryResult, out time); 90 | return time; 91 | } 92 | } 93 | 94 | public void Dispose() 95 | { 96 | if (_query == 0) 97 | return; 98 | 99 | GL.DeleteQueries(1, ref _query); 100 | _query = 0; 101 | 102 | GC.SuppressFinalize(this); 103 | } 104 | 105 | ~GpuStopwatch() 106 | { 107 | Dispose(); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/IIS.SLSharp.Bindings.OpenTK.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {8A901280-C858-4018-AD66-45255EFEC519} 9 | Library 10 | Properties 11 | IIS.SLSharp.Bindings.OpenTK 12 | IIS.SLSharp.Bindings.OpenTK 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | ..\bin\Debug\IIS.SLSharp.Bindings.OpenTK.xml 26 | true 27 | 1591 28 | 29 | 30 | pdbonly 31 | true 32 | ..\bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | true 37 | ..\bin\Release\IIS.SLSharp.Bindings.OpenTK.xml 38 | 1591 39 | 40 | 41 | 42 | Properties\SolutionInfo.cs 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | False 60 | ..\Dependencies\OpenTK.dll 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 77 | IIS.SLSharp 78 | 79 | 80 | 81 | 82 | 83 | 84 | 91 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using IIS.SLSharp.Descriptions; 5 | using IIS.SLSharp.Shaders; 6 | using OpenTK.Graphics.OpenGL; 7 | using System.Linq; 8 | 9 | namespace IIS.SLSharp.Bindings.OpenTK 10 | { 11 | sealed class Program: IProgram 12 | { 13 | public int Name { get; private set; } 14 | 15 | public List VertexIns { get; private set; } 16 | 17 | private void Validate() 18 | { 19 | int linkStatus, validStatus; 20 | var logCompile = GL.GetProgramInfoLog(Name); 21 | GL.ValidateProgram(Name); 22 | var logValidate = GL.GetProgramInfoLog(Name); 23 | 24 | GL.GetProgram(Name, ProgramParameter.LinkStatus, out linkStatus); 25 | GL.GetProgram(Name, ProgramParameter.ValidateStatus, out validStatus); 26 | 27 | var log = "=== Compilation log ===" + Environment.NewLine + 28 | logCompile + Environment.NewLine + 29 | "=== Validation log ===" + Environment.NewLine + logValidate; 30 | 31 | if (linkStatus != 1) 32 | throw new SLSharpException("Program linkage failed: " + Environment.NewLine + log); 33 | 34 | if (validStatus != 1) 35 | { 36 | Debug.WriteLine("Program validation failed: " + Environment.NewLine + log); 37 | return; 38 | } 39 | 40 | if (!String.IsNullOrEmpty(logCompile) || !String.IsNullOrEmpty(logValidate)) 41 | Debug.WriteLine("Link info: " + log); 42 | } 43 | 44 | public Program(IEnumerable> units) 45 | { 46 | Name = GL.CreateProgram(); 47 | 48 | var merged = SourceDescription.Empty; 49 | foreach (var unit in units) 50 | { 51 | GL.AttachShader(Name, unit.Item1); 52 | merged = merged.Merge(unit.Item2); 53 | } 54 | VertexIns = merged.VertexIns; 55 | 56 | GL.LinkProgram(Name); 57 | Validate(); 58 | Utilities.CheckGL(); 59 | } 60 | 61 | public void Dispose() 62 | { 63 | if (Name != 0) 64 | GL.DeleteProgram(Name); 65 | Name = 0; 66 | } 67 | 68 | public void Activate() 69 | { 70 | GL.UseProgram(Name); 71 | Utilities.CheckGL(); 72 | } 73 | 74 | public void Finish() 75 | { 76 | GL.UseProgram(0); 77 | } 78 | 79 | public int GetUniformIndex(string name) 80 | { 81 | var result = GL.GetUniformLocation(Name, name); 82 | Utilities.CheckGL(); 83 | return result; 84 | } 85 | 86 | public int GetAttributeIndex(string name) 87 | { 88 | var result = GL.GetAttribLocation(Name, name); 89 | Utilities.CheckGL(); 90 | return result; 91 | } 92 | 93 | public Tuple GetBinary() 94 | { 95 | int length; 96 | GL.GetProgram(Name, ProgramParameter.ProgramBinaryLength, out length); 97 | 98 | var bin = new byte[length]; 99 | BinaryFormat format; 100 | int numRead; 101 | GL.GetProgramBinary(Name, length, out numRead, out format, bin); 102 | if (numRead < length) 103 | bin = bin.Take(length).ToArray(); 104 | 105 | return new Tuple(bin, format); 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Quad.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using OpenTK; 7 | using OpenTK.Graphics.OpenGL; 8 | 9 | namespace IIS.SLSharp.Bindings.OpenTK 10 | { 11 | class Quad: IDisposable 12 | { 13 | private int _vbo; 14 | 15 | public Quad() 16 | { 17 | var data = new[] 18 | { 19 | new Vector2(-1.0f, -1.0f), 20 | new Vector2(1.0f, -1.0f), 21 | new Vector2(1.0f, 1.0f), 22 | new Vector2(-1.0f, 1.0f), 23 | new Vector2(0.0f, 0.0f), 24 | new Vector2(1.0f, 0.0f), 25 | new Vector2(1.0f, 1.0f), 26 | new Vector2(0.0f, 1.0f), 27 | }; 28 | 29 | GL.GenBuffers(1, out _vbo); 30 | GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); 31 | GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Marshal.SizeOf(typeof(Vector2)) * data.Length), 32 | data, BufferUsageHint.StaticDraw); 33 | GL.BindBuffer(BufferTarget.ArrayBuffer, 0); 34 | } 35 | 36 | public void Dispose() 37 | { 38 | if (_vbo != 0) 39 | { 40 | GL.DeleteBuffers(1, ref _vbo); 41 | _vbo = 0; 42 | } 43 | } 44 | 45 | public void Render(int posLocation, bool positive) 46 | { 47 | GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); 48 | GL.VertexAttribPointer(posLocation, 2, VertexAttribPointerType.Float, false, 0, 0); 49 | GL.EnableVertexAttribArray(posLocation); 50 | GL.DrawArrays(BeginMode.Quads, positive ? 4 : 0, 4); 51 | GL.DisableVertexAttribArray(posLocation); 52 | GL.BindBuffer(BufferTarget.ArrayBuffer, 0); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/Externals/LoaderStatics.cs: -------------------------------------------------------------------------------- 1 | #region --- License --- 2 | /* Licensed under the MIT/X11 license. 3 | * Copyright (c) 2006-2008 the OpenTK Team. 4 | * This notice may not be removed from any source distribution. 5 | * See license.txt for licensing details. 6 | */ 7 | #endregion 8 | 9 | using OpenTK.Graphics.OpenGL; 10 | 11 | namespace IIS.SLSharp.Bindings.OpenTK.Textures.Externals 12 | { 13 | 14 | /// The parameters in this class have only effect on the following Texture loads. 15 | static class TextureLoaderParameters 16 | { 17 | /// (Debug Aid, should be set to false) If set to false only Errors will be printed. If set to true, debug information (Warnings and Queries) will be printed in addition to Errors. 18 | public static bool Verbose = false; 19 | 20 | /// Always-valid fallback parameter for GL.BindTexture (Default: 0). This number will be returned if loading the Texture failed. You can set this to a checkerboard texture or similar, which you have already loaded. 21 | public static uint OpenGLDefaultTexture = 0; 22 | 23 | /// Compressed formats must have a border of 0, so this is constant. 24 | public const int Border = 0; 25 | 26 | /// false==DirectX TexCoords, true==OpenGL TexCoords (Default: true) 27 | public static bool FlipImages = false; 28 | 29 | /// When enabled, will use Glu to create MipMaps for images loaded with GDI+ (Default: false) 30 | public static bool BuildMipmapsForUncompressed = false; 31 | 32 | /// Selects the Magnification filter for following Textures to be loaded. (Default: Nearest) 33 | public static TextureMagFilter MagnificationFilter = TextureMagFilter.Nearest; 34 | 35 | /// Selects the Minification filter for following Textures to be loaded. (Default: Nearest) 36 | public static TextureMinFilter MinificationFilter = TextureMinFilter.Nearest; 37 | 38 | /// Selects the S Wrapping for following Textures to be loaded. (Default: Repeat) 39 | public static TextureWrapMode WrapModeS = TextureWrapMode.Repeat; 40 | 41 | /// Selects the T Wrapping for following Textures to be loaded. (Default: Repeat) 42 | public static TextureWrapMode WrapModeT = TextureWrapMode.Repeat; 43 | 44 | /// Selects the Texture Environment Mode for the following Textures to be loaded. Default: Modulate) 45 | public static TextureEnvMode EnvMode = TextureEnvMode.Modulate; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/FramebufferObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace IIS.SLSharp.Bindings.OpenTK.Textures 5 | { 6 | /// 7 | /// Manages an OpenGl framebuffer object 8 | /// This is normally only used internally by the RenderToTexture class 9 | /// 10 | public sealed class FramebufferObject : IDisposable 11 | { 12 | private int _fbo; 13 | 14 | public FramebufferObject() 15 | { 16 | GL.GenFramebuffers(1, out _fbo); 17 | 18 | Utilities.CheckGL(); 19 | } 20 | 21 | public void Dispose() 22 | { 23 | if (_fbo == 0) 24 | return; 25 | 26 | GL.DeleteFramebuffers(1, ref _fbo); 27 | 28 | Utilities.CheckGL(); 29 | 30 | _fbo = 0; 31 | 32 | GC.SuppressFinalize(this); 33 | } 34 | 35 | /// 36 | /// Activates the framebuffer object. 37 | /// All fragment output that follows will be captured by it. 38 | /// 39 | public void Activate() 40 | { 41 | GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fbo); 42 | } 43 | 44 | /// 45 | /// Removes any current framebuffer object. 46 | /// 47 | public void Finish() 48 | { 49 | GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); 50 | } 51 | 52 | /// 53 | /// Associates a Texture with the framebuffer object 54 | /// 55 | /// The texture to associate 56 | /// The channel to asscociate 57 | public void SetTexture(Texture2D texture, int index = 0) 58 | { 59 | if (texture == null) 60 | throw new ArgumentNullException("texture"); 61 | 62 | Activate(); 63 | 64 | GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, 65 | FramebufferAttachment.ColorAttachment0 + index, 66 | texture.Target, texture.Name, 0); 67 | 68 | Finish(); 69 | } 70 | 71 | /// 72 | /// Validates readyness of the framebuffer object 73 | /// 74 | public void Check() 75 | { 76 | Activate(); 77 | var code = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); 78 | Finish(); 79 | 80 | if (code == FramebufferErrorCode.FramebufferComplete) 81 | return; 82 | 83 | Utilities.ThrowGLError(GL.GetError()); 84 | } 85 | 86 | ~FramebufferObject() 87 | { 88 | Dispose(); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/ITexture.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.OpenGL; 2 | 3 | namespace IIS.SLSharp.Bindings.OpenTK.Textures 4 | { 5 | public interface ITexture 6 | { 7 | /// 8 | /// OpenGL texture target 9 | /// 10 | TextureTarget Target { get; } 11 | 12 | /// 13 | /// Binds the texture 14 | /// 15 | void Activate(); 16 | 17 | /// 18 | /// Unbinds any current texture 19 | /// 20 | void Finish(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/RenderbufferObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace IIS.SLSharp.Bindings.OpenTK.Textures 5 | { 6 | /// 7 | /// Manages an OpenGL renderbuffer object 8 | /// This is similar to a FramebufferObject but the resources wont be 9 | /// accessable. As the FramebufferObject this is normally used only 10 | /// internally by RenderToTexture 11 | /// 12 | public sealed class RenderbufferObject : IDisposable 13 | { 14 | private int _rbo; 15 | 16 | public RenderbufferObject() 17 | { 18 | GL.GenRenderbuffers(1, out _rbo); 19 | } 20 | 21 | public void Dispose() 22 | { 23 | if (_rbo == 0) 24 | return; 25 | 26 | GL.DeleteRenderbuffers(1, ref _rbo); 27 | _rbo = 0; 28 | 29 | GC.SuppressFinalize(this); 30 | } 31 | 32 | /// 33 | /// Makes this renderbuffer active 34 | /// 35 | public void Activate() 36 | { 37 | GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _rbo); 38 | } 39 | 40 | /// 41 | /// Removes any currently active renderbuffer 42 | /// 43 | public void Finish() 44 | { 45 | GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); 46 | } 47 | 48 | /// 49 | /// Sets the size of the renderbuffer 50 | /// 51 | /// The width in pixels of the renderbuffer 52 | /// The height in pixels of the renderbuffer 53 | public void SetSize(int width, int height) 54 | { 55 | Activate(); 56 | 57 | GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent24, width, height); 58 | GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, 59 | RenderbufferTarget.Renderbuffer, _rbo); 60 | 61 | Finish(); 62 | } 63 | 64 | ~RenderbufferObject() 65 | { 66 | Dispose(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/Texture1D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace IIS.SLSharp.Bindings.OpenTK.Textures 5 | { 6 | /// 7 | /// Specialization of BaseTexture for 1D Textures. 8 | /// 9 | public class Texture1D : TextureBase 10 | { 11 | public int Width { get; private set; } 12 | 13 | /// 14 | /// Creates a new managed 1D Texture 15 | /// 16 | /// The width in Pixels of the Texture 17 | /// The number of components. Must be 1 2 3 or 4. 18 | /// The data type to use (Default is 16bit Half) 19 | public Texture1D(int width, int components = 4, Type type = null) 20 | : base(TextureTarget.Texture1D) 21 | { 22 | Width = width; 23 | 24 | Activate(); 25 | GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); // GL_REPEAT 26 | GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); 27 | GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); 28 | 29 | PixelInternalFormat internalformat; 30 | PixelFormat format; 31 | GetFormat(components, type ?? typeof(byte), out internalformat, out format); 32 | 33 | GL.TexImage1D(TextureTarget.Texture1D, 0, internalformat, Width, 0, format, PixelType.UnsignedByte, IntPtr.Zero); 34 | 35 | Utilities.CheckGL(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Textures/TextureCube.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using OpenTK.Graphics.OpenGL; 3 | 4 | namespace IIS.SLSharp.Bindings.OpenTK.Textures 5 | { 6 | /// 7 | /// Specialization of BaseTexture for Cube maps. 8 | /// 9 | public class TextureCube : Bindings.OpenTK.Textures.TextureBase 10 | { 11 | public int Width { get; private set; } 12 | 13 | public int Height { get; private set; } 14 | 15 | /// 16 | /// Creates a new managed 2D Texture 17 | /// 18 | /// The width in Pixels of the Texture 19 | /// The height in Pixels of the Texture 20 | /// The number of components. Must be 1 2 3 or 4. 21 | /// The data type to use (Default is 16bit Half) 22 | public TextureCube(int width, int height, int components, Type type = null) 23 | : base(TextureTarget.TextureCubeMap) 24 | { 25 | Width = width; 26 | Height = height; 27 | 28 | Activate(); 29 | GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); // GL_REPEAT 30 | GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); // GL_REPEAT 31 | GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge); // GL_REPEAT 32 | GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); 33 | GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); 34 | 35 | PixelInternalFormat internalformat; 36 | PixelFormat format; 37 | GetFormat(components, type ?? typeof(byte), out internalformat, out format); 38 | 39 | for (var i = 0; i < 6; i++) 40 | GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, internalformat, Width, Height, 0, format, 41 | PixelType.UnsignedByte, IntPtr.Zero); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.OpenTK/Utilities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using OpenTK.Graphics.OpenGL; 4 | 5 | namespace IIS.SLSharp 6 | { 7 | public static class Utilities 8 | { 9 | public static bool IsVersion(int major, int minor = 0) 10 | { 11 | var s = GL.GetString(StringName.Version); 12 | 13 | var idx = s.IndexOf(' '); 14 | if (idx != -1) 15 | s = s.Substring(0, idx); 16 | 17 | var v = s.Split('.').Select(x => int.Parse(x)).ToArray(); 18 | 19 | if (v[0] > major) 20 | return true; 21 | 22 | if (v[0] < major) 23 | return false; 24 | 25 | return v[1] >= minor; 26 | } 27 | 28 | public static bool HasExtension(string name) 29 | { 30 | if (name == null) 31 | throw new ArgumentNullException("name"); 32 | 33 | if (IsVersion(3, 1)) 34 | { 35 | int numExt; 36 | GL.GetInteger(GetPName.NumExtensions, out numExt); 37 | 38 | for (var i = 0; i < numExt; i++) 39 | if (GL.GetString(StringName.Extensions, 1) == name) 40 | return true; 41 | 42 | return false; 43 | } 44 | 45 | return GL.GetString(StringName.Extensions).Contains(name); 46 | } 47 | 48 | internal static void ThrowGLError(ErrorCode error) 49 | { 50 | var lastError = string.Format("{0} [{1}]", error.ToString("f"), (int)error); 51 | throw new SLSharpException("GL Error: " + lastError); 52 | } 53 | 54 | public static void CheckGL() 55 | { 56 | var err = GL.GetError(); 57 | if (err == ErrorCode.NoError) 58 | return; 59 | 60 | ThrowGLError(err); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.SlimDX/IIS.SLSharp.Bindings.SlimDX.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {63CF8750-EBA9-40A7-9556-2F4EBF9EF922} 9 | Library 10 | Properties 11 | IIS.SLSharp.Bindings.SlimDX 12 | IIS.SLSharp.Bindings.SlimDX 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | ..\bin\Debug\IIS.SLSharp.Bindings.SlimDX.xml 26 | 1591 27 | x86 28 | true 29 | 30 | 31 | pdbonly 32 | true 33 | ..\bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 1591 38 | ..\bin\Release\IIS.SLSharp.Bindings.SlimDX.xml 39 | x86 40 | true 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Properties\SolutionInfo.cs 55 | 56 | 57 | 58 | 65 | -------------------------------------------------------------------------------- /IIS.SLSharp.Bindings.Xna/IIS.SLSharp.Bindings.Xna.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {31C6D7EC-615F-4A19-8079-967B10A8FA3E} 9 | Library 10 | Properties 11 | IIS.SLSharp.Bindings.Xna 12 | IIS.SLSharp.Bindings.Xna 13 | v4.0 14 | 512 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | ..\bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | ..\bin\Debug\IIS.SLSharp.Bindings.Xna.xml 27 | 1591 28 | x86 29 | true 30 | 31 | 32 | pdbonly 33 | true 34 | ..\bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | 1591 39 | ..\bin\Release\IIS.SLSharp.Bindings.Xna.xml 40 | x86 41 | true 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | Properties\SolutionInfo.cs 59 | 60 | 61 | 62 | 63 | 64 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 65 | IIS.SLSharp 66 | 67 | 68 | 69 | 76 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Axiom.Core; 4 | using Axiom.Graphics; 5 | using Axiom.Math; 6 | using IIS.SLSharp.Bindings.Axiom; 7 | using IIS.SLSharp.Examples.Axiom.GeoClipmap.GeoClipmap; 8 | using IIS.SLSharp.Examples.Axiom.GeoClipmap.Shaders; 9 | using IIS.SLSharp.Shaders; 10 | using Math = System.Math; 11 | 12 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap 13 | { 14 | public sealed class DemoWindow 15 | { 16 | private readonly Root _root; 17 | private SceneManager _scene; 18 | private Camera _camera; 19 | private readonly RenderWindow _window; 20 | private Clipmap _clipmap; 21 | private float _z; 22 | 23 | public DemoWindow(Root root, RenderWindow renderWindow) 24 | { 25 | _root = root; 26 | _window = renderWindow; 27 | } 28 | 29 | private float Lerp(float a, float b, float w) 30 | { 31 | return w * b + (1 - w) * a; 32 | } 33 | 34 | private void RecalcHeight() 35 | { 36 | _z = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 - 1), -(_clipmap.Position.Y.Integer * 2 - 1)); 37 | var zx = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 + 1), -(_clipmap.Position.Y.Integer * 2 - 1)); 38 | var zy = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 - 1), -(_clipmap.Position.Y.Integer * 2 + 1)); 39 | var zxy = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 + 1), -(_clipmap.Position.Y.Integer * 2 + 1)); 40 | 41 | var v1 = Lerp(_z, zx, _clipmap.Position.X.Fraction); 42 | var v2 = Lerp(zy, zxy, _clipmap.Position.X.Fraction); 43 | _z = Lerp(v1, v2, _clipmap.Position.Y.Fraction); 44 | } 45 | 46 | public void OnLoad() 47 | { 48 | var dir = Directory.GetCurrentDirectory(); 49 | ResourceGroupManager.Instance.AddResourceLocation(dir, "Folder"); 50 | //MaterialManager.Instance.Initialize(); 51 | 52 | _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance"); 53 | _scene.ClearScene(); 54 | 55 | Bindings.Axiom.SLSharp.Init(); 56 | Shader.DebugMode = true; 57 | 58 | //Shader.DebugMode = true; 59 | 60 | _clipmap = new Clipmap(_scene); 61 | RecalcHeight(); 62 | 63 | _camera = _scene.CreateCamera("MainCamera"); 64 | _camera.Position = new Vector3(0, 0, 5); 65 | _camera.LookAt(Vector3.Zero); 66 | _camera.Near = 0.001f; 67 | _camera.Far = 20.0f; 68 | _camera.AutoAspectRatio = true; 69 | 70 | var vp = _window.AddViewport(_camera); 71 | vp.BackgroundColor = ColorEx.CornflowerBlue; 72 | } 73 | 74 | public void OnUnload() 75 | { 76 | _clipmap.Dispose(); 77 | } 78 | 79 | public void OnRenderFrame(object s, FrameEventArgs e) 80 | { 81 | _clipmap.MoveBy(0.0f, 0.4f); 82 | RecalcHeight(); 83 | 84 | var angle = Utility.DegreesToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6); 85 | 86 | angle *= 4; 87 | var z = 1.0f + (float)Math.Sin(angle); 88 | if (z < _z) 89 | z = _z; 90 | 91 | var cam = new Vector3(0.0f, 0.0f, z); 92 | var look = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0.1f); 93 | var up = new Vector3(0.0f, 0.0f, 1.0f); 94 | 95 | _camera.Position = cam; 96 | _camera.LookAt(look); 97 | _camera.FixedYawAxis = up; 98 | 99 | e.StopRendering = _window.IsClosed; 100 | } 101 | 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/GeoClipmap/IntFloat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap.GeoClipmap 5 | { 6 | /// 7 | /// Utility struct to encode high precision map locations 8 | /// Data is stored as lossless integral part and lossy (due to rounding precision) 9 | /// fractional part. 10 | /// The fractional part is always kept in range [0..1) 11 | /// This implies that rounding realted logic is always towards +inf 12 | /// -0.4 for example will be encoded as -1 + 0.6 rather than 0 + -0.4 13 | /// Also notice that there is no way to encode -0 as you can do with floats. 14 | /// 15 | public struct IntFloat: IEquatable 16 | { 17 | private const float Epsilon = 5.96e-08f; 18 | 19 | /// 20 | /// 32bit Integral part of the IntFloat 21 | /// 22 | public readonly int Integer; 23 | 24 | /// 25 | /// Fractional part [0..1) of the IntFloat 26 | /// 27 | public readonly float Fraction; 28 | 29 | public IntFloat(float f) 30 | { 31 | var integral = (float)Math.Floor(f); 32 | Fraction = f - integral; 33 | Integer = (int)integral; 34 | } 35 | 36 | public IntFloat(int i) 37 | { 38 | Integer = i; 39 | Fraction = 0.0f; 40 | } 41 | 42 | public IntFloat(int i, float f) : this(f) 43 | { 44 | Integer += i; 45 | } 46 | 47 | 48 | public static IntFloat operator +(IntFloat lhs, IntFloat rhs) 49 | { 50 | return new IntFloat(lhs.Integer + rhs.Integer, lhs.Fraction + rhs.Fraction); 51 | } 52 | 53 | public static IntFloat operator +(IntFloat lhs, int rhs) 54 | { 55 | return new IntFloat(lhs.Integer + rhs, lhs.Fraction); 56 | } 57 | 58 | 59 | public static IntFloat operator -(IntFloat lhs, IntFloat rhs) 60 | { 61 | return new IntFloat(lhs.Integer - rhs.Integer, lhs.Fraction - rhs.Fraction); 62 | } 63 | 64 | public static IntFloat operator -(IntFloat lhs, int rhs) 65 | { 66 | return new IntFloat(lhs.Integer - rhs, lhs.Fraction); 67 | } 68 | 69 | public static bool operator ==(IntFloat lhs, IntFloat rhs) 70 | { 71 | return (lhs.Integer == rhs.Integer) && (Math.Abs(lhs.Fraction - rhs.Fraction) < Epsilon); 72 | } 73 | 74 | public static bool operator !=(IntFloat lhs, IntFloat rhs) 75 | { 76 | return (lhs.Integer != rhs.Integer) || (Math.Abs(lhs.Fraction - rhs.Fraction) > Epsilon); 77 | } 78 | 79 | /// 80 | /// Shorthand version for x = y+y 81 | /// 82 | [Pure] 83 | public IntFloat Mul2() 84 | { 85 | return this + this; 86 | } 87 | 88 | /// 89 | /// Calculates 0.5 * this 90 | /// 91 | [Pure] 92 | public IntFloat Div2() 93 | { 94 | // sign extended carry (+1 or -1 iff lowest bit is set, 0 otherwise) 95 | var carry = Math.Sign(Integer) * (Integer & 1); 96 | 97 | 98 | var integral = Integer / 2; 99 | var fraction = (Fraction + carry) * 0.5f; 100 | 101 | // use the safe ctor here in order to avoid 2 compares 102 | return new IntFloat(integral, fraction); 103 | } 104 | 105 | public bool Equals(IntFloat other) 106 | { 107 | return other.Integer == Integer && other.Fraction.Equals(Fraction); 108 | } 109 | 110 | public override bool Equals(object obj) 111 | { 112 | if (ReferenceEquals(null, obj)) 113 | return false; 114 | return obj is IntFloat && Equals((IntFloat)obj); 115 | } 116 | 117 | public override int GetHashCode() 118 | { 119 | unchecked 120 | { 121 | return (Integer * 397) ^ Fraction.GetHashCode(); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/GeoClipmap/IntFloatVector2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap.GeoClipmap 5 | { 6 | public struct IntFloatVector2 : IEquatable 7 | { 8 | public readonly IntFloat X; 9 | 10 | public readonly IntFloat Y; 11 | 12 | public IntFloatVector2(IntFloat x, IntFloat y) 13 | { 14 | X = x; 15 | Y = y; 16 | } 17 | 18 | public static bool operator ==(IntFloatVector2 lhs, IntFloatVector2 rhs) 19 | { 20 | return (lhs.X == rhs.X) && (lhs.Y == rhs.Y); 21 | } 22 | 23 | public static bool operator !=(IntFloatVector2 lhs, IntFloatVector2 rhs) 24 | { 25 | return (lhs.X != rhs.X) || (lhs.Y != rhs.Y); 26 | } 27 | 28 | [Pure] 29 | public IntFloatVector2 MoveBy(int dx, int dy) 30 | { 31 | return new IntFloatVector2(X + dx, Y + dy); 32 | } 33 | 34 | [Pure] 35 | public IntFloatVector2 MoveBy(float dx, float dy) 36 | { 37 | return MoveBy(new IntFloat(dx), new IntFloat(dy)); 38 | } 39 | 40 | [Pure] 41 | public IntFloatVector2 MoveBy(IntFloat dx, IntFloat dy) 42 | { 43 | return new IntFloatVector2(X + dx, Y + dy); 44 | } 45 | 46 | [Pure] 47 | public IntFloatVector2 Div2() 48 | { 49 | return new IntFloatVector2(X.Div2(), Y.Div2()); 50 | } 51 | 52 | [Pure] 53 | public IntFloatVector2 Mul2() 54 | { 55 | return new IntFloatVector2(X.Mul2(), Y.Mul2()); 56 | } 57 | 58 | public bool Equals(IntFloatVector2 other) 59 | { 60 | return other.X.Equals(X) && other.Y.Equals(Y); 61 | } 62 | 63 | public override bool Equals(object obj) 64 | { 65 | if (ReferenceEquals(null, obj)) 66 | return false; 67 | return obj is IntFloatVector2 && Equals((IntFloatVector2)obj); 68 | } 69 | 70 | public override int GetHashCode() 71 | { 72 | unchecked 73 | { 74 | return (X.GetHashCode() * 419) ^ Y.GetHashCode(); 75 | } 76 | } 77 | 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/GeoClipmap/PatchLocation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap.GeoClipmap 5 | { 6 | public struct PatchLocation 7 | { 8 | public readonly int X; 9 | 10 | public readonly int Y; 11 | 12 | public readonly int Index; 13 | 14 | public readonly Patch Patch; 15 | 16 | public PatchLocation(int x, int y, int index, Patch patch) 17 | { 18 | X = x; 19 | Y = y; 20 | Index = index; 21 | Patch = patch; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/GeoClipmap/PatchRenderable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Axiom.Core; 6 | using Axiom.Core.Collections; 7 | using Axiom.Graphics; 8 | using Axiom.Math; 9 | using IIS.SLSharp.Bindings.Axiom; 10 | using IIS.SLSharp.Examples.Axiom.GeoClipmap.Shaders; 11 | using IIS.SLSharp.Shaders; 12 | 13 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap.GeoClipmap 14 | { 15 | internal class PatchRenderable: IRenderable 16 | { 17 | private readonly ClipmapShader _shader; 18 | 19 | private readonly Patch _patch; 20 | 21 | private static readonly LightList _nullLights = new LightList(); 22 | 23 | public Vector4 ScaleFactor; 24 | 25 | public Vector4 FineBlockOrigin; 26 | 27 | private readonly string _scaleFactorName; 28 | 29 | private readonly string _fineBlockOriginName; 30 | 31 | public ClipmapLevel Level; 32 | 33 | public PatchRenderable(Patch patch, ClipmapShader shader) 34 | { 35 | _patch = patch; 36 | _shader = shader; 37 | 38 | _scaleFactorName = Shader.UniformName(() => _shader.ScaleFactor); 39 | _fineBlockOriginName = Shader.UniformName(() => _shader.FineBlockOrigin); 40 | } 41 | 42 | public bool NormalizeNormals 43 | { 44 | get { return false; } 45 | } 46 | 47 | public ushort NumWorldTransforms 48 | { 49 | get { return 1; } 50 | } 51 | 52 | public bool UseIdentityProjection 53 | { 54 | get { return false; } 55 | } 56 | 57 | public bool UseIdentityView 58 | { 59 | get { return false; } 60 | } 61 | 62 | public bool PolygonModeOverrideable 63 | { 64 | get { return true; } 65 | } 66 | 67 | public Quaternion WorldOrientation 68 | { 69 | get { throw new NotImplementedException(); } 70 | } 71 | 72 | public Vector3 WorldPosition 73 | { 74 | get { throw new NotImplementedException(); } 75 | } 76 | 77 | public void GetWorldTransforms(Matrix4[] matrices) 78 | { 79 | matrices[0] = Matrix4.Identity; 80 | } 81 | 82 | public float GetSquaredViewDepth(Camera cam) 83 | { 84 | return 0.0f; 85 | } 86 | 87 | public Vector4 GetCustomParameter(int index) 88 | { 89 | throw new NotImplementedException(); 90 | } 91 | 92 | public void SetCustomParameter(int index, Vector4 val) 93 | { 94 | throw new NotImplementedException(); 95 | } 96 | 97 | public void UpdateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry constant, GpuProgramParameters parameters) 98 | { 99 | parameters.SetNamedConstant(_scaleFactorName, ScaleFactor); 100 | parameters.SetNamedConstant(_fineBlockOriginName, FineBlockOrigin); 101 | } 102 | 103 | public bool CastsShadows 104 | { 105 | get { throw new NotImplementedException(); } 106 | } 107 | 108 | public Material Material 109 | { 110 | get { return Level.Material; } 111 | } 112 | 113 | public Technique Technique 114 | { 115 | get { return Level.Material.GetTechnique(0); } 116 | } 117 | 118 | public RenderOperation RenderOperation 119 | { 120 | get 121 | { 122 | var op = new RenderOperation(); 123 | op.useIndices = true; 124 | op.operationType = OperationType.TriangleList; 125 | op.vertexData = _patch.VertexData; 126 | op.indexData = _patch.IndexData; 127 | return op; 128 | } 129 | } 130 | 131 | public LightList Lights 132 | { 133 | get { return _nullLights; } 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Axiom.Core; 3 | 4 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap 5 | { 6 | internal static class Program 7 | { 8 | private static void Main() 9 | { 10 | using (var r = new Root()) 11 | { 12 | if (r.RenderSystems.Count == 0) 13 | throw new Exception("No Rendersystem found"); 14 | 15 | Console.WriteLine("Select a Rendersystem"); 16 | for (var i = 0; i < r.RenderSystems.Count; i++) 17 | Console.WriteLine("{0}: {1}", i + 1, r.RenderSystems[i].Name); 18 | 19 | while (true) 20 | { 21 | int index; 22 | if (!int.TryParse(Console.ReadKey(true).KeyChar.ToString(), out index)) 23 | continue; 24 | 25 | if (index < 1) 26 | continue; 27 | index--; 28 | 29 | if (index >= r.RenderSystems.Count) 30 | continue; 31 | 32 | r.RenderSystem = r.RenderSystems[index]; 33 | break; 34 | } 35 | 36 | 37 | using (r.Initialize(true)) 38 | { 39 | var win = new DemoWindow(r, r.AutoWindow); 40 | win.OnLoad(); 41 | r.FrameRenderingQueued += win.OnRenderFrame; 42 | r.StartRendering(); 43 | win.OnUnload(); 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom.GeoClipmap/Shaders/ClipmapShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.Axiom.GeoClipmap.Shaders 5 | { 6 | public abstract class ClipmapShader : Shader 7 | { 8 | [Uniform] 9 | public abstract vec4 Color { set; get; } 10 | 11 | [Uniform] 12 | public abstract mat4 ModelViewProjectionMatrix { set; get; } 13 | 14 | [Uniform] 15 | public abstract mat4 NormalMatrix { set; get; } 16 | 17 | [Uniform] 18 | public abstract vec4 ScaleFactor { set; get; } 19 | 20 | [Uniform] 21 | public abstract vec4 FineBlockOrigin { set; get; } 22 | 23 | [Uniform] 24 | public abstract vec2 ViewerPosition { set; get; } 25 | 26 | [Uniform] 27 | public abstract vec2 AlphaOffset { set; get; } 28 | 29 | [Uniform] 30 | public abstract vec2 OneOverWidth { set; get; } 31 | 32 | [Uniform] 33 | public abstract float ZTexScaleFactor { set; get; } 34 | 35 | [Uniform] 36 | public abstract float DebugValue { set; get; } 37 | 38 | [Uniform] 39 | public abstract float alpha { set; get; } 40 | 41 | [Uniform] 42 | public abstract sampler2D Heightmap { set; get; } 43 | 44 | [Varying] 45 | public vec2 _uv; 46 | 47 | [Varying(UsageSemantic.Position0)] 48 | private vec4 _position; 49 | 50 | [Varying] 51 | public float _z; 52 | 53 | [Varying] 54 | public vec4 _finalPos; 55 | 56 | [Varying] 57 | public vec3 Normal; 58 | 59 | [VertexIn(UsageSemantic.Position0)] 60 | public vec4 Vertex; 61 | 62 | [FragmentOut(UsageSemantic.Color0)] 63 | public vec4 FragColor; 64 | 65 | [VertexShader(true)] 66 | public void ClipmapVertexMain() 67 | { 68 | var worldPos = (Vertex.xy + ScaleFactor.xy) * ScaleFactor.zw; 69 | _uv = (Vertex.xy + FineBlockOrigin.xy) * FineBlockOrigin.zw; 70 | 71 | 72 | var texel = new vec3(TextureLod(Heightmap, _uv, 1.0f).r); 73 | 74 | var zfZd = texel.x * 512.0f; 75 | var zf = Floor(zfZd) * 0.001953125f; 76 | var zd = Fraction(zfZd) * 2.0f - 1.0f; 77 | 78 | //var alpha = Clamp((Abs(worldPos - ViewerPosition) - AlphaOffset) * OneOverWidth, 0.0f, 1.0f); 79 | //alpha.x = Max(alpha.x, alpha.y); 80 | 81 | 82 | _z = zf + /* alpha * */ zd; 83 | 84 | //_z = zfZd; // alpha blend not implemented, yet 85 | 86 | // planar map 87 | var worldPosFinal = new vec4(worldPos, _z * 0.3f, 1.0f); 88 | 89 | _finalPos = ModelViewProjectionMatrix * worldPosFinal; 90 | _position = _finalPos; 91 | 92 | 93 | // just for testing, derive normal using interpolation over heights 94 | var dfdx = (TextureLod(Heightmap, _uv + new vec2(FineBlockOrigin.z, 0.0f), 1.0f).r - texel.r); 95 | var dfdy = (TextureLod(Heightmap, _uv + new vec2(0.0f, FineBlockOrigin.w), 1.0f).r - texel.r); 96 | var dz = 2.0f * ScaleFactor.z - dfdx * dfdx - dfdy * dfdy; 97 | Normal = new vec3(dfdx, dfdy, dz); 98 | 99 | //normal = normalize(vec3(texel.yz, 1.0)); 100 | } 101 | 102 | [FragmentShader(true)] 103 | public void ClipmapFragmentMain() 104 | { 105 | var light = Normalize(new vec3(0.0f, 1.0f, 0.6f)); 106 | var n = Normalize(Normal); 107 | 108 | /* 109 | var n2 = Normalize(Cross(dFdx(_finalPos.xyz),dFdy(_finalPos.xyz))); 110 | n2.xy = -n2.xy; 111 | var light2 = new mat3(NormalMatrix) * (light); 112 | */ 113 | var i = Max(Dot(light, n), 0.0f) * 0.8f + 0.2f; // Dot(light2, n2); 114 | 115 | 116 | FragColor = /*Color **/ new vec4(i); 117 | } 118 | 119 | protected ClipmapShader() 120 | { 121 | Link(); 122 | } 123 | 124 | 125 | public override void Dispose() 126 | { 127 | base.Dispose(); 128 | } 129 | 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using Axiom.Core; 5 | using Axiom.Graphics; 6 | using Axiom.Math; 7 | using IIS.SLSharp.Bindings.Axiom; 8 | using IIS.SLSharp.Examples.Axiom.Shaders; 9 | using IIS.SLSharp.Shaders; 10 | 11 | namespace IIS.SLSharp.Examples.Axiom 12 | { 13 | public sealed class DemoWindow 14 | { 15 | private SimpleShader _shader; 16 | private readonly Root _root; 17 | private SceneManager _scene; 18 | private Entity _patchEntity; 19 | private Camera _camera; 20 | 21 | public DemoWindow(Root root) 22 | { 23 | _root = root; 24 | } 25 | 26 | public void OnLoad() 27 | { 28 | var dir = Directory.GetCurrentDirectory(); 29 | ResourceGroupManager.Instance.AddResourceLocation(dir, "Folder"); 30 | //MaterialManager.Instance.Initialize(); 31 | 32 | _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance"); 33 | _scene.ClearScene(); 34 | 35 | Bindings.Axiom.SLSharp.Init(); 36 | Shader.DebugMode = true; 37 | 38 | //Shader.DebugMode = true; 39 | 40 | _shader = Shader.CreateSharedShader(); 41 | 42 | _patchEntity = _scene.CreateEntity("Box", "box.mesh"); 43 | _scene.RootSceneNode.AttachObject(_patchEntity); 44 | 45 | var mat = _shader.ToMaterial(); 46 | var pass = mat.GetTechnique(0).GetPass(0); 47 | pass.SetAlphaRejectSettings(CompareFunction.GreaterEqual, 128); 48 | pass.CullingMode = CullingMode.None; 49 | 50 | // SL# on OGRE: bind auto semantic to a uniform! 51 | // (we might automate this via semantic attributes within the SL# shaders in future!) 52 | _shader.SetAuto(() => _shader.ModelviewProjection, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix); 53 | 54 | _shader.Begin(); 55 | 56 | _patchEntity.MaterialName = mat.Name; 57 | //_patchEntity.Material = mat; 58 | 59 | 60 | _camera = _scene.CreateCamera("MainCamera"); 61 | _camera.Position = new Vector3(0, 0, 5); 62 | _camera.LookAt(Vector3.Zero); 63 | _camera.Near = 0.00001f; 64 | _camera.Far = 4.0f; 65 | _camera.AutoAspectRatio = true; 66 | 67 | var vp = _root.AutoWindow.AddViewport(_camera); 68 | vp.BackgroundColor = ColorEx.CornflowerBlue; 69 | 70 | } 71 | 72 | public void OnUnload() 73 | { 74 | _shader.Dispose(); 75 | } 76 | 77 | public void OnRenderFrame(object s, FrameEventArgs e) 78 | { 79 | var angle = Utility.DegreesToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6 * 4); 80 | var cam = new Vector3((float)Math.Sin(angle), 0.5f, (float)Math.Cos(angle)) * ((float)Math.Sin(angle * 4) + 1.7f); 81 | var look = Vector3.Zero; 82 | 83 | _camera.Position = cam + look; 84 | _camera.LookAt(look); 85 | 86 | // Axiom Bug: cant set in GL mode properly atm 87 | // SL# allows direct manipulation of uniforms like this! 88 | //_shader.Blue = (float)Math.Sin(angle * 8.0f); 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Axiom.Core; 4 | 5 | namespace IIS.SLSharp.Examples.Axiom 6 | { 7 | internal static class Program 8 | { 9 | private static void Main() 10 | { 11 | using (var r = new Root()) 12 | { 13 | if (r.RenderSystems.Count == 0) 14 | throw new Exception("No Rendersystem found"); 15 | 16 | Console.WriteLine("Select a Rendersystem"); 17 | for (var i = 0; i < r.RenderSystems.Count; i++) 18 | Console.WriteLine("{0}: {1}", i + 1, r.RenderSystems[i].Name); 19 | 20 | while (true) 21 | { 22 | int index; 23 | if (!int.TryParse(Console.ReadKey(true).KeyChar.ToString(), out index)) 24 | continue; 25 | 26 | if (index < 1) 27 | continue; 28 | index--; 29 | 30 | if (index >= r.RenderSystems.Count) 31 | continue; 32 | 33 | r.RenderSystem = r.RenderSystems[index]; 34 | break; 35 | } 36 | 37 | 38 | using (r.Initialize(true)) 39 | { 40 | var win = new DemoWindow(r); 41 | win.OnLoad(); 42 | r.FrameRenderingQueued += win.OnRenderFrame; 43 | r.StartRendering(); 44 | win.OnUnload(); 45 | } 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom/Shaders/SimpleShader.cs: -------------------------------------------------------------------------------- 1 | using Axiom.Core; 2 | using IIS.SLSharp.Annotations; 3 | using IIS.SLSharp.Examples.Axiom.Textures; 4 | using IIS.SLSharp.Shaders; 5 | using IIS.SLSharp.Bindings.Axiom; 6 | 7 | namespace IIS.SLSharp.Examples.Axiom.Shaders 8 | { 9 | public abstract class SimpleShader : Shader 10 | { 11 | // demonstrate using a shared library 12 | public WangShader Wang { get; private set; } 13 | 14 | // expose a simple uniform (this can be directly accessed from client code) 15 | [Uniform] 16 | public abstract float Blue { set; get; } 17 | 18 | [Uniform] 19 | public abstract mat4 ModelviewProjection { set; get; } 20 | 21 | [Varying] 22 | private vec2 _uv; 23 | 24 | [Varying(UsageSemantic.Position0)] 25 | private vec4 _position; 26 | 27 | [VertexIn(UsageSemantic.Position0)] 28 | public vec4 Vertex; 29 | 30 | [VertexIn(UsageSemantic.Texcoord0)] 31 | public vec2 Texcoord; 32 | 33 | [FragmentOut(UsageSemantic.Color0)] 34 | public vec4 Color; 35 | 36 | [FragmentShader(true)] 37 | protected void FragmentMain() 38 | { 39 | var c = Wang.WangAt(_uv); 40 | Color = new vec4(c.rg, Blue, c.a); 41 | } 42 | 43 | [VertexShader(true)] 44 | public void VertexMain() 45 | { 46 | _uv = Texcoord; 47 | _position = ModelviewProjection * Vertex; 48 | } 49 | 50 | // resource setup code 51 | protected SimpleShader() 52 | { 53 | Wang = CreateSharedShader(); 54 | 55 | 56 | var tiles = TextureManager.Instance.Load("tiles.png", ResourceGroupManager.DefaultResourceGroupName); 57 | tiles.MipmapCount = 5; 58 | 59 | Wang.WangTable = new WangMap(64, 64).AsTexture; 60 | Wang.Tiles = tiles; 61 | 62 | Link(new[] { Wang }); 63 | } 64 | 65 | 66 | public override void Dispose() 67 | { 68 | Wang.WangTable.Dispose(); 69 | Wang.Tiles.Dispose(); 70 | Wang.Dispose(); 71 | base.Dispose(); 72 | } 73 | 74 | public override void Begin() 75 | { 76 | Wang.BeginLibrary(this); 77 | base.Begin(); 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Axiom/Shaders/WangShader.cs: -------------------------------------------------------------------------------- 1 | using Axiom.Core; 2 | using Axiom.Graphics; 3 | using IIS.SLSharp.Annotations; 4 | using IIS.SLSharp.Shaders; 5 | using IIS.SLSharp.Bindings.Axiom; 6 | 7 | namespace IIS.SLSharp.Examples.Axiom.Shaders 8 | { 9 | public abstract class WangShader : Shader 10 | { 11 | public Texture Tiles { get; set; } 12 | 13 | public Texture WangTable { get; set; } 14 | 15 | [Uniform] 16 | public abstract sampler2D WangTiles { set; get; } 17 | 18 | [Uniform] 19 | public abstract sampler2D WangMap { set; get; } 20 | 21 | [FragmentShader] 22 | public vec4 WangAt(vec2 tex) 23 | { 24 | 25 | var address = tex - tex % (1.0f / 256.0f); 26 | var subPos = Fraction(tex * 256.0f) / 4.0f; 27 | var offset = Texture(WangMap, Fraction(address)).xw; 28 | var tc = offset + subPos; 29 | var tileScaledTex = tex * new vec2(32.0f / 1.0f); 30 | 31 | return TextureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex)); 32 | } 33 | 34 | public override void Begin() 35 | { 36 | base.Begin(); 37 | var smp = this.Sampler(() => WangTiles); 38 | smp.SetTextureName(Tiles.Name); 39 | smp.SetTextureFiltering(FilterOptions.Linear, FilterOptions.Linear, FilterOptions.Linear); 40 | 41 | smp = this.Sampler(() => WangMap); 42 | smp.SetTextureName(WangTable.Name); 43 | smp.SetTextureFiltering(FilterOptions.Point, FilterOptions.Point, FilterOptions.None); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using IIS.SLSharp.Bindings.OpenTK; 4 | using IIS.SLSharp.Examples.Complex.Shaders; 5 | using IIS.SLSharp.Shaders; 6 | using OpenTK; 7 | using OpenTK.Graphics.OpenGL; 8 | 9 | namespace IIS.SLSharp.Examples.Complex 10 | { 11 | public sealed class DemoWindow : GameWindow 12 | { 13 | private CubeShader _cubeShader; 14 | 15 | private BackdropShader _backdropShader; 16 | 17 | private Cube _cube; 18 | 19 | private readonly Stopwatch _timer = new Stopwatch(); 20 | 21 | private float _time; 22 | 23 | private float _aspect; 24 | 25 | protected override void OnLoad(EventArgs e) 26 | { 27 | Bindings.OpenTK.SLSharp.Init(); 28 | _backdropShader = Shader.CreateSharedShader(); 29 | _cubeShader = Shader.CreateSharedShader(); 30 | _cube = new Cube(); 31 | _timer.Start(); 32 | } 33 | 34 | protected override void OnUnload(EventArgs e) 35 | { 36 | _backdropShader.Dispose(); 37 | _cubeShader.Dispose(); 38 | _cube.Dispose(); 39 | } 40 | 41 | protected override void OnResize(EventArgs e) 42 | { 43 | GL.Viewport(ClientRectangle); 44 | } 45 | 46 | private Matrix4 SetupCamera() 47 | { 48 | const float r = 4.0f; 49 | var eyeX = (float)System.Math.Cos(_time * MathHelper.TwoPi) * r; 50 | var eyeZ = (float)System.Math.Sin(_time * MathHelper.TwoPi) * r; 51 | var eyeY = (float)System.Math.Sin(_time * MathHelper.TwoPi * 3) * 1.5f; 52 | 53 | var lookAt = Matrix4.LookAt(eyeX, eyeY, eyeZ, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); 54 | var projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), _aspect, 0.01f, 6.0f); 55 | 56 | return lookAt * projection; 57 | } 58 | 59 | protected override void OnRenderFrame(FrameEventArgs e) 60 | { 61 | _time = (_timer.ElapsedMilliseconds % 4000) / 4000.0f; 62 | _aspect = (float)Width / Height; 63 | 64 | GL.ClearColor(0.3f, 0.3f, 1.0f, 1.0f); 65 | GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 66 | GL.Enable(EnableCap.CullFace); 67 | 68 | SetupCamera(); 69 | 70 | _backdropShader.Begin(); 71 | _backdropShader.Render(_time, _aspect); 72 | _backdropShader.End(); 73 | 74 | _cubeShader.Begin(); 75 | _cubeShader.ModelViewProjectionMatrix = SetupCamera().ToMatrix4F(); 76 | _cube.Render(Shader.AttributeLocation(_cubeShader, () => _cubeShader.Vertex)); 77 | _cubeShader.End(); 78 | 79 | SwapBuffers(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Program.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Examples.Complex 2 | { 3 | internal static class Program 4 | { 5 | private static void Main() 6 | { 7 | using (var win = new DemoWindow { Title = "GeoClip Shader Demo" }) 8 | win.Run(0.0d); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.225 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace IIS.SLSharp.Examples.Complex { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("IIS.SLSharp.Examples.Complex.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | internal static System.Drawing.Bitmap tiles { 64 | get { 65 | object obj = ResourceManager.GetObject("tiles", resourceCulture); 66 | return ((System.Drawing.Bitmap)(obj)); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Shaders/BackdropShader.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.Reflection; 3 | using System.Resources; 4 | using IIS.SLSharp.Annotations; 5 | using IIS.SLSharp.Bindings.OpenTK; 6 | using IIS.SLSharp.Bindings.OpenTK.Textures; 7 | using IIS.SLSharp.Examples.Complex.Textures; 8 | using IIS.SLSharp.Shaders; 9 | using OpenTK; 10 | 11 | namespace IIS.SLSharp.Examples.Complex.Shaders 12 | { 13 | public abstract class BackdropShader : Shader 14 | { 15 | [Uniform] 16 | public abstract float MaxScale { get; set; } 17 | 18 | [Uniform] 19 | public abstract vec2 Scale { get; set; } 20 | 21 | [Varying] 22 | private vec2 _uv; 23 | 24 | [Varying(UsageSemantic.Position0)] 25 | private vec4 _position; 26 | 27 | [FragmentOut(UsageSemantic.Color0)] 28 | protected vec4 Color; 29 | 30 | [VertexIn(UsageSemantic.Position0)] 31 | public vec4 GlVertex; 32 | 33 | // demonstrate using a shared library 34 | public WangShader Wang { get; private set; } 35 | 36 | [FragmentShader(true)] 37 | protected void FragmentMain() 38 | { 39 | Color = Wang.WangAt(_uv); 40 | } 41 | 42 | [VertexShader(true)] 43 | public void VertexMain() 44 | { 45 | _uv = GlVertex.xy * 0.5f * Scale * MaxScale; 46 | _position = GlVertex; 47 | } 48 | 49 | // resource setup code 50 | protected BackdropShader() 51 | { 52 | Wang = CreateSharedShader(); 53 | var wang = new WangMap(64, 64); 54 | Wang.WangTable = wang; 55 | var asm = Assembly.GetExecutingAssembly(); 56 | var resourceManager = new ResourceManager(asm.EntryPoint.DeclaringType.Namespace + ".Resources", asm); 57 | var bmp = (Bitmap)resourceManager.GetObject("tiles"); 58 | Wang.Tiles = Texture2D.FromBitmap(bmp); 59 | Wang.Tiles.GenerateMipMaps(5); 60 | Link(new[] { Wang }); 61 | } 62 | 63 | public override void Dispose() 64 | { 65 | Wang.WangTable.Dispose(); 66 | Wang.Tiles.Dispose(); 67 | Wang.Dispose(); 68 | base.Dispose(); 69 | } 70 | 71 | public override void Begin() 72 | { 73 | Wang.BeginLibrary(this); 74 | base.Begin(); 75 | } 76 | 77 | public void Render(float time, float aspect) 78 | { 79 | MaxScale = 2.0f; 80 | var s = (float)(System.Math.Cos(time * MathHelper.TwoPi) + 1.0f) * 0.5f + 0.05f; 81 | Scale = (new Vector2(s * aspect, s).ToVector2F()); 82 | RenderQuad(this, () => GlVertex); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Shaders/Cube.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using OpenTK; 4 | using OpenTK.Graphics.OpenGL; 5 | 6 | namespace IIS.SLSharp.Examples.Complex.Shaders 7 | { 8 | public sealed class Cube : IDisposable 9 | { 10 | private int _vbo; 11 | 12 | private int _ibo; 13 | 14 | private readonly int _numIndices; 15 | 16 | public Cube() 17 | { 18 | GL.GenBuffers(1, out _vbo); 19 | GL.GenBuffers(1, out _ibo); 20 | 21 | var vertices = new[] 22 | { 23 | new Vector3(-1.0f, -1.0f, -1.0f), 24 | new Vector3(1.0f, -1.0f, -1.0f), 25 | new Vector3(-1.0f, 1.0f, -1.0f), 26 | new Vector3(1.0f, 1.0f, -1.0f), 27 | new Vector3(-1.0f, -1.0f, 1.0f), 28 | new Vector3(1.0f, -1.0f, 1.0f), 29 | new Vector3(-1.0f, 1.0f, 1.0f), 30 | new Vector3(1.0f, 1.0f, 1.0f), 31 | }; 32 | 33 | var indices = new short[] 34 | { 35 | 2, 3, 1, 0, // back 36 | 4, 6, 2, 0, // left 37 | 1, 3, 7, 5, // right 38 | 4, 5, 7, 6, // front 39 | 0, 1, 5, 4, // bottom 40 | 6, 7, 3, 2, // top 41 | }; 42 | 43 | GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); 44 | GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Marshal.SizeOf(typeof(Vector3)) * vertices.Length), 45 | vertices, BufferUsageHint.StaticDraw); 46 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ibo); 47 | GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(short) * indices.Length), 48 | indices, BufferUsageHint.StaticDraw); 49 | _numIndices = indices.Length; 50 | } 51 | 52 | public void Dispose() 53 | { 54 | GL.DeleteBuffers(1, ref _vbo); 55 | GL.DeleteBuffers(1, ref _ibo); 56 | } 57 | 58 | public void Render(int vertexLocation) 59 | { 60 | GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); 61 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ibo); 62 | GL.EnableVertexAttribArray(vertexLocation); 63 | GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, 0, 0); 64 | GL.DrawElements(BeginMode.Quads, _numIndices, DrawElementsType.UnsignedShort, 0); 65 | GL.DisableVertexAttribArray(vertexLocation); 66 | GL.BindBuffer(BufferTarget.ArrayBuffer, 0); 67 | GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Shaders/CubeShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.Complex.Shaders 5 | { 6 | public abstract class CubeShader : Shader 7 | { 8 | [Varying] 9 | private vec3 _uvw; 10 | 11 | [Varying(UsageSemantic.Position0)] 12 | private vec4 _position; 13 | 14 | [VertexIn(UsageSemantic.Position0)] 15 | public vec4 Vertex; 16 | 17 | [FragmentOut(UsageSemantic.Color0)] 18 | public vec4 Color; 19 | 20 | [Uniform] 21 | public abstract mat4 ModelViewProjectionMatrix { get; set; } 22 | 23 | // demonstrate using a shared library 24 | public SimplexNoiseShader Noise { get; private set; } 25 | 26 | [FragmentShader(true)] 27 | protected void FragmentMain() 28 | { 29 | var n = Noise.FBm(_uvw * 4.0f, 6, 1.6f, 0.7f); 30 | Color = new vec4(n); 31 | } 32 | 33 | [VertexShader(true)] 34 | public void VertexMain() 35 | { 36 | _uvw = (Vertex.xyz + new vec3(1.0f)) * 0.5f; 37 | _position = ModelViewProjectionMatrix * Vertex; 38 | } 39 | 40 | // resource setup code 41 | protected CubeShader() 42 | { 43 | Noise = CreateSharedShader(); 44 | Link(new[] { Noise }); 45 | } 46 | 47 | public override void Dispose() 48 | { 49 | Noise.Dispose(); 50 | base.Dispose(); 51 | } 52 | 53 | public override void Begin() 54 | { 55 | Noise.BeginLibrary(this); 56 | base.Begin(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Complex/Shaders/WangShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Bindings.OpenTK; 3 | using IIS.SLSharp.Bindings.OpenTK.Textures; 4 | using IIS.SLSharp.Shaders; 5 | 6 | namespace IIS.SLSharp.Examples.Complex.Shaders 7 | { 8 | public abstract class WangShader : Shader 9 | { 10 | [Uniform] 11 | public abstract sampler2D WangTiles { set; get; } 12 | 13 | [Uniform] 14 | public abstract sampler2D WangMap { set; get; } 15 | 16 | public Texture2D Tiles { get; set; } 17 | 18 | public Texture2D WangTable { get; set; } 19 | 20 | [FragmentShader] 21 | public vec4 WangAt(vec2 tex) 22 | { 23 | var address = tex - tex % (1.0f / 256.0f); 24 | var subPos = Fraction(tex * 256.0f) / 4.0f; 25 | var offset = Texture(WangMap, Fraction(address)).xw; 26 | var tc = offset + subPos; 27 | var tileScaledTex = tex * new vec2(32.0f / 1.0f); 28 | 29 | return TextureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex)); 30 | } 31 | 32 | public override void Begin() 33 | { 34 | base.Begin(); 35 | WangTiles = BindTexture(Tiles).ToSampler(); 36 | WangMap = BindTexture(WangTable).ToSampler(); ; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/Clipmap/PatchLocation.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Examples.GeoClipmap.Clipmap 2 | { 3 | public struct PatchLocation 4 | { 5 | public readonly int X; 6 | 7 | public readonly int Y; 8 | 9 | public readonly int Index; 10 | 11 | public readonly Patch Patch; 12 | 13 | public PatchLocation(int x, int y, int index, Patch patch) 14 | { 15 | X = x; 16 | Y = y; 17 | Index = index; 18 | Patch = patch; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/IntFloat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace IIS.SLSharp.Examples.GeoClipmap 8 | { 9 | /// 10 | /// Utility struct to encode high precision map locations 11 | /// Data is stored as lossless integral part and lossy (due to rounding precision) 12 | /// fractional part. 13 | /// The fractional part is always kept in range [0..1) 14 | /// This implies that rounding realted logic is always towards +inf 15 | /// -0.4 for example will be encoded as -1 + 0.6 rather than 0 + -0.4 16 | /// Also notice that there is no way to encode -0 as you can do with floats. 17 | /// 18 | public struct IntFloat: IEquatable 19 | { 20 | private const float Epsilon = 5.96e-08f; 21 | 22 | /// 23 | /// 32bit Integral part of the IntFloat 24 | /// 25 | public readonly int Integer; 26 | 27 | /// 28 | /// Fractional part [0..1) of the IntFloat 29 | /// 30 | public readonly float Fraction; 31 | 32 | public IntFloat(float f) 33 | { 34 | var integral = (float)Math.Floor(f); 35 | Fraction = f - integral; 36 | Integer = (int)integral; 37 | } 38 | 39 | public IntFloat(int i) 40 | { 41 | Integer = i; 42 | Fraction = 0.0f; 43 | } 44 | 45 | public IntFloat(int i, float f) : this(f) 46 | { 47 | Integer += i; 48 | } 49 | 50 | 51 | public static IntFloat operator +(IntFloat lhs, IntFloat rhs) 52 | { 53 | return new IntFloat(lhs.Integer + rhs.Integer, lhs.Fraction + rhs.Fraction); 54 | } 55 | 56 | public static IntFloat operator +(IntFloat lhs, int rhs) 57 | { 58 | return new IntFloat(lhs.Integer + rhs, lhs.Fraction); 59 | } 60 | 61 | 62 | public static IntFloat operator -(IntFloat lhs, IntFloat rhs) 63 | { 64 | return new IntFloat(lhs.Integer - rhs.Integer, lhs.Fraction - rhs.Fraction); 65 | } 66 | 67 | public static IntFloat operator -(IntFloat lhs, int rhs) 68 | { 69 | return new IntFloat(lhs.Integer - rhs, lhs.Fraction); 70 | } 71 | 72 | public static bool operator ==(IntFloat lhs, IntFloat rhs) 73 | { 74 | return (lhs.Integer == rhs.Integer) && (Math.Abs(lhs.Fraction - rhs.Fraction) < Epsilon); 75 | } 76 | 77 | public static bool operator !=(IntFloat lhs, IntFloat rhs) 78 | { 79 | return (lhs.Integer != rhs.Integer) || (Math.Abs(lhs.Fraction - rhs.Fraction) > Epsilon); 80 | } 81 | 82 | /// 83 | /// Shorthand version for x = y+y 84 | /// 85 | [Pure] 86 | public IntFloat Mul2() 87 | { 88 | return this + this; 89 | } 90 | 91 | /// 92 | /// Calculates 0.5 * this 93 | /// 94 | [Pure] 95 | public IntFloat Div2() 96 | { 97 | // sign extended carry (+1 or -1 iff lowest bit is set, 0 otherwise) 98 | var carry = Math.Sign(Integer) * (Integer & 1); 99 | 100 | 101 | var integral = Integer / 2; 102 | var fraction = (Fraction + carry) * 0.5f; 103 | 104 | // use the safe ctor here in order to avoid 2 compares 105 | return new IntFloat(integral, fraction); 106 | } 107 | 108 | public bool Equals(IntFloat other) 109 | { 110 | return other.Integer == Integer && other.Fraction.Equals(Fraction); 111 | } 112 | 113 | public override bool Equals(object obj) 114 | { 115 | if (ReferenceEquals(null, obj)) 116 | return false; 117 | return obj is IntFloat && Equals((IntFloat)obj); 118 | } 119 | 120 | public override int GetHashCode() 121 | { 122 | unchecked 123 | { 124 | return (Integer * 397) ^ Fraction.GetHashCode(); 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/IntFloatVector2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace IIS.SLSharp.Examples.GeoClipmap 8 | { 9 | public struct IntFloatVector2 : IEquatable 10 | { 11 | public readonly IntFloat X; 12 | 13 | public readonly IntFloat Y; 14 | 15 | public IntFloatVector2(IntFloat x, IntFloat y) 16 | { 17 | X = x; 18 | Y = y; 19 | } 20 | 21 | public static bool operator ==(IntFloatVector2 lhs, IntFloatVector2 rhs) 22 | { 23 | return (lhs.X == rhs.X) && (lhs.Y == rhs.Y); 24 | } 25 | 26 | public static bool operator !=(IntFloatVector2 lhs, IntFloatVector2 rhs) 27 | { 28 | return (lhs.X != rhs.X) || (lhs.Y != rhs.Y); 29 | } 30 | 31 | [Pure] 32 | public IntFloatVector2 MoveBy(int dx, int dy) 33 | { 34 | return new IntFloatVector2(X + dx, Y + dy); 35 | } 36 | 37 | [Pure] 38 | public IntFloatVector2 MoveBy(float dx, float dy) 39 | { 40 | return MoveBy(new IntFloat(dx), new IntFloat(dy)); 41 | } 42 | 43 | [Pure] 44 | public IntFloatVector2 MoveBy(IntFloat dx, IntFloat dy) 45 | { 46 | return new IntFloatVector2(X + dx, Y + dy); 47 | } 48 | 49 | [Pure] 50 | public IntFloatVector2 Div2() 51 | { 52 | return new IntFloatVector2(X.Div2(), Y.Div2()); 53 | } 54 | 55 | [Pure] 56 | public IntFloatVector2 Mul2() 57 | { 58 | return new IntFloatVector2(X.Mul2(), Y.Mul2()); 59 | } 60 | 61 | public bool Equals(IntFloatVector2 other) 62 | { 63 | return other.X.Equals(X) && other.Y.Equals(Y); 64 | } 65 | 66 | public override bool Equals(object obj) 67 | { 68 | if (ReferenceEquals(null, obj)) 69 | return false; 70 | return obj is IntFloatVector2 && Equals((IntFloatVector2)obj); 71 | } 72 | 73 | public override int GetHashCode() 74 | { 75 | unchecked 76 | { 77 | return (X.GetHashCode() * 419) ^ Y.GetHashCode(); 78 | } 79 | } 80 | 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/Program.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Examples.GeoClipmap 2 | { 3 | internal static class Program 4 | { 5 | private static void Main() 6 | { 7 | using (var win = new DemoWindow { Title = "GeoClip Shader Demo" }) 8 | win.Run(0.0d); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/Shaders/DebugShader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IIS.SLSharp.Annotations; 6 | using IIS.SLSharp.Bindings.OpenTK; 7 | using IIS.SLSharp.Bindings.OpenTK.Textures; 8 | using IIS.SLSharp.Shaders; 9 | 10 | namespace IIS.SLSharp.Examples.GeoClipmap.Shaders 11 | { 12 | public abstract class DebugShader: Shader 13 | { 14 | private readonly Texture2D _debugTex; 15 | 16 | private int _heightmap; 17 | 18 | public Texture2D HeightmapTex 19 | { 20 | set { BindTexture(value, _heightmap); } 21 | } 22 | 23 | [Uniform] 24 | public abstract sampler2D DebugTex { set; get; } 25 | 26 | [Uniform] 27 | public abstract sampler2D Heightmap { set; get; } 28 | 29 | [Uniform] 30 | public abstract vec4 HeightSize { set; get; } 31 | 32 | [VertexIn(UsageSemantic.Position0)] 33 | public vec4 Vertex; 34 | 35 | [FragmentOut(UsageSemantic.Color0)] 36 | public vec4 FragColor; 37 | 38 | [Varying] 39 | public vec2 _uv; 40 | 41 | [Varying(UsageSemantic.Position0)] 42 | private vec4 _position; 43 | 44 | [FragmentShader(true)] 45 | public void DebugFragmentMain() 46 | { 47 | var uvs = _uv * HeightSize.xy; 48 | var subUv = Fraction(uvs); 49 | var val = (uvs - subUv + new vec2(0.5f)) / HeightSize.xy; 50 | var height = Texture(Heightmap, val); 51 | //var height = new vec4(1.0f); 52 | 53 | var idx = height.r * 255.0f; 54 | idx -= Fraction(idx); // idx = [0..255] now 55 | idx /= 16.0f; 56 | var xidx = Fraction(idx); 57 | idx -= xidx; 58 | var yidx = idx / 16.0f; 59 | 60 | var tileUv = new vec2(subUv.x/16.0f + xidx, (1.0f-subUv.y)/16.0f + yidx); 61 | 62 | FragColor = Texture(DebugTex, tileUv); 63 | 64 | 65 | //FragColor = height; 66 | 67 | //FragColor = texture(Heightmap, _uv); //new vec4(_uv, 0.0f, 1.0f); 68 | } 69 | 70 | [VertexShader(true)] 71 | public void FragmentMain() 72 | { 73 | _position = Vertex; 74 | _uv = Vertex.xy * 0.5f + new vec2(0.5f); 75 | } 76 | 77 | protected DebugShader() 78 | { 79 | _debugTex = Texture2D.FromFile(@"E:\SLSharp\IIS.SLSharp.Examples.GeoClipmap\debug.png"); 80 | Link(); 81 | } 82 | 83 | public override void Begin() 84 | { 85 | base.Begin(); 86 | _heightmap = AllocateSamplerSlot(); 87 | Heightmap = _heightmap.ToSampler(); 88 | DebugTex = BindTexture(_debugTex).ToSampler(); 89 | } 90 | 91 | public override void Dispose() 92 | { 93 | _debugTex.Dispose(); 94 | base.Dispose(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.GeoClipmap/Utilities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IIS.SLSharp.Examples.GeoClipmap 7 | { 8 | public static class Utilities 9 | { 10 | public static float Fract(float f) 11 | { 12 | var fout = (float)Math.Floor(f); 13 | return f - fout; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using IIS.SLSharp.Bindings.MOGRE; 4 | using IIS.SLSharp.Examples.MOGRE.GeoClipmap.GeoClipmap; 5 | using IIS.SLSharp.Examples.MOGRE.GeoClipmap.Shaders; 6 | using IIS.SLSharp.Shaders; 7 | using Mogre; 8 | using Math = System.Math; 9 | 10 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap 11 | { 12 | public sealed class DemoWindow 13 | { 14 | private readonly Root _root; 15 | private SceneManager _scene; 16 | private Camera _camera; 17 | private readonly RenderWindow _window; 18 | private Clipmap _clipmap; 19 | private float _z; 20 | 21 | public DemoWindow(Root root, RenderWindow renderWindow) 22 | { 23 | _root = root; 24 | _window = renderWindow; 25 | } 26 | 27 | private float Lerp(float a, float b, float w) 28 | { 29 | return w * b + (1 - w) * a; 30 | } 31 | 32 | private void RecalcHeight() 33 | { 34 | _z = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 - 1), -(_clipmap.Position.Y.Integer * 2 - 1)); 35 | var zx = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 + 1), -(_clipmap.Position.Y.Integer * 2 - 1)); 36 | var zy = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 - 1), -(_clipmap.Position.Y.Integer * 2 + 1)); 37 | var zxy = _clipmap.GeneratePixelAt(-(_clipmap.Position.X.Integer * 2 + 1), -(_clipmap.Position.Y.Integer * 2 + 1)); 38 | 39 | var v1 = Lerp(_z, zx, _clipmap.Position.X.Fraction); 40 | var v2 = Lerp(zy, zxy, _clipmap.Position.X.Fraction); 41 | _z = Lerp(v1, v2, _clipmap.Position.Y.Fraction); 42 | } 43 | 44 | public void OnLoad() 45 | { 46 | var dir = Directory.GetCurrentDirectory(); 47 | ResourceGroupManager.Singleton.AddResourceLocation(dir, "FileSystem"); 48 | MaterialManager.Singleton.Initialise(); 49 | 50 | _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance"); 51 | _scene.ClearScene(); 52 | 53 | Bindings.MOGRE.SLSharp.Init(); 54 | Shader.DebugMode = true; 55 | 56 | //Shader.DebugMode = true; 57 | 58 | _clipmap = new Clipmap(_scene); 59 | RecalcHeight(); 60 | 61 | _camera = _scene.CreateCamera("MainCamera"); 62 | _camera.Position = new Vector3(0, 0, 5); 63 | _camera.LookAt(Vector3.ZERO); 64 | _camera.NearClipDistance = 0.001f; 65 | _camera.FarClipDistance = 20.0f; 66 | _camera.AutoAspectRatio = true; 67 | 68 | var vp = _window.AddViewport(_camera); 69 | vp.BackgroundColour = ColourValue.Blue; 70 | } 71 | 72 | public void OnUnload() 73 | { 74 | _clipmap.Dispose(); 75 | } 76 | 77 | public bool OnRenderFrame(FrameEvent evt) 78 | { 79 | _clipmap.MoveBy(0.0f, 0.4f); 80 | RecalcHeight(); 81 | 82 | var angle = Mogre.Math.DegreesToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6); 83 | 84 | angle *= 4; 85 | var z = 1.0f + (float)Math.Sin(angle); 86 | if (z < _z) 87 | z = _z; 88 | 89 | var cam = new Vector3(0.0f, 0.0f, z); 90 | var look = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0.1f); 91 | var up = new Vector3(0.0f, 0.0f, 1.0f); 92 | 93 | _camera.Position = cam; 94 | _camera.LookAt(look); 95 | _camera.SetFixedYawAxis(true, up); 96 | 97 | return !_window.IsClosed; 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/GeoClipmap/IntFloat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap.GeoClipmap 5 | { 6 | /// 7 | /// Utility struct to encode high precision map locations 8 | /// Data is stored as lossless integral part and lossy (due to rounding precision) 9 | /// fractional part. 10 | /// The fractional part is always kept in range [0..1) 11 | /// This implies that rounding realted logic is always towards +inf 12 | /// -0.4 for example will be encoded as -1 + 0.6 rather than 0 + -0.4 13 | /// Also notice that there is no way to encode -0 as you can do with floats. 14 | /// 15 | public struct IntFloat: IEquatable 16 | { 17 | private const float Epsilon = 5.96e-08f; 18 | 19 | /// 20 | /// 32bit Integral part of the IntFloat 21 | /// 22 | public readonly int Integer; 23 | 24 | /// 25 | /// Fractional part [0..1) of the IntFloat 26 | /// 27 | public readonly float Fraction; 28 | 29 | public IntFloat(float f) 30 | { 31 | var integral = (float)Math.Floor(f); 32 | Fraction = f - integral; 33 | Integer = (int)integral; 34 | } 35 | 36 | public IntFloat(int i) 37 | { 38 | Integer = i; 39 | Fraction = 0.0f; 40 | } 41 | 42 | public IntFloat(int i, float f) : this(f) 43 | { 44 | Integer += i; 45 | } 46 | 47 | 48 | public static IntFloat operator +(IntFloat lhs, IntFloat rhs) 49 | { 50 | return new IntFloat(lhs.Integer + rhs.Integer, lhs.Fraction + rhs.Fraction); 51 | } 52 | 53 | public static IntFloat operator +(IntFloat lhs, int rhs) 54 | { 55 | return new IntFloat(lhs.Integer + rhs, lhs.Fraction); 56 | } 57 | 58 | 59 | public static IntFloat operator -(IntFloat lhs, IntFloat rhs) 60 | { 61 | return new IntFloat(lhs.Integer - rhs.Integer, lhs.Fraction - rhs.Fraction); 62 | } 63 | 64 | public static IntFloat operator -(IntFloat lhs, int rhs) 65 | { 66 | return new IntFloat(lhs.Integer - rhs, lhs.Fraction); 67 | } 68 | 69 | public static bool operator ==(IntFloat lhs, IntFloat rhs) 70 | { 71 | return (lhs.Integer == rhs.Integer) && (Math.Abs(lhs.Fraction - rhs.Fraction) < Epsilon); 72 | } 73 | 74 | public static bool operator !=(IntFloat lhs, IntFloat rhs) 75 | { 76 | return (lhs.Integer != rhs.Integer) || (Math.Abs(lhs.Fraction - rhs.Fraction) > Epsilon); 77 | } 78 | 79 | /// 80 | /// Shorthand version for x = y+y 81 | /// 82 | [Pure] 83 | public IntFloat Mul2() 84 | { 85 | return this + this; 86 | } 87 | 88 | /// 89 | /// Calculates 0.5 * this 90 | /// 91 | [Pure] 92 | public IntFloat Div2() 93 | { 94 | // sign extended carry (+1 or -1 iff lowest bit is set, 0 otherwise) 95 | var carry = Math.Sign(Integer) * (Integer & 1); 96 | 97 | 98 | var integral = Integer / 2; 99 | var fraction = (Fraction + carry) * 0.5f; 100 | 101 | // use the safe ctor here in order to avoid 2 compares 102 | return new IntFloat(integral, fraction); 103 | } 104 | 105 | public bool Equals(IntFloat other) 106 | { 107 | return other.Integer == Integer && other.Fraction.Equals(Fraction); 108 | } 109 | 110 | public override bool Equals(object obj) 111 | { 112 | if (ReferenceEquals(null, obj)) 113 | return false; 114 | return obj is IntFloat && Equals((IntFloat)obj); 115 | } 116 | 117 | public override int GetHashCode() 118 | { 119 | unchecked 120 | { 121 | return (Integer * 397) ^ Fraction.GetHashCode(); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/GeoClipmap/IntFloatVector2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | 4 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap.GeoClipmap 5 | { 6 | public struct IntFloatVector2 : IEquatable 7 | { 8 | public readonly IntFloat X; 9 | 10 | public readonly IntFloat Y; 11 | 12 | public IntFloatVector2(IntFloat x, IntFloat y) 13 | { 14 | X = x; 15 | Y = y; 16 | } 17 | 18 | public static bool operator ==(IntFloatVector2 lhs, IntFloatVector2 rhs) 19 | { 20 | return (lhs.X == rhs.X) && (lhs.Y == rhs.Y); 21 | } 22 | 23 | public static bool operator !=(IntFloatVector2 lhs, IntFloatVector2 rhs) 24 | { 25 | return (lhs.X != rhs.X) || (lhs.Y != rhs.Y); 26 | } 27 | 28 | [Pure] 29 | public IntFloatVector2 MoveBy(int dx, int dy) 30 | { 31 | return new IntFloatVector2(X + dx, Y + dy); 32 | } 33 | 34 | [Pure] 35 | public IntFloatVector2 MoveBy(float dx, float dy) 36 | { 37 | return MoveBy(new IntFloat(dx), new IntFloat(dy)); 38 | } 39 | 40 | [Pure] 41 | public IntFloatVector2 MoveBy(IntFloat dx, IntFloat dy) 42 | { 43 | return new IntFloatVector2(X + dx, Y + dy); 44 | } 45 | 46 | [Pure] 47 | public IntFloatVector2 Div2() 48 | { 49 | return new IntFloatVector2(X.Div2(), Y.Div2()); 50 | } 51 | 52 | [Pure] 53 | public IntFloatVector2 Mul2() 54 | { 55 | return new IntFloatVector2(X.Mul2(), Y.Mul2()); 56 | } 57 | 58 | public bool Equals(IntFloatVector2 other) 59 | { 60 | return other.X.Equals(X) && other.Y.Equals(Y); 61 | } 62 | 63 | public override bool Equals(object obj) 64 | { 65 | if (ReferenceEquals(null, obj)) 66 | return false; 67 | return obj is IntFloatVector2 && Equals((IntFloatVector2)obj); 68 | } 69 | 70 | public override int GetHashCode() 71 | { 72 | unchecked 73 | { 74 | return (X.GetHashCode() * 419) ^ Y.GetHashCode(); 75 | } 76 | } 77 | 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/GeoClipmap/PatchLocation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using IIS.SLSharp.Examples.MOGRE.GeoClipmap.Shaders; 3 | using IIS.SLSharp.Shaders; 4 | 5 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap.GeoClipmap 6 | { 7 | public struct PatchLocation 8 | { 9 | public readonly int X; 10 | 11 | public readonly int Y; 12 | 13 | public readonly int Index; 14 | 15 | public readonly Patch Patch; 16 | 17 | public PatchLocation(int x, int y, int index, Patch patch) 18 | { 19 | X = x; 20 | Y = y; 21 | Index = index; 22 | Patch = patch; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/GeoClipmap/PatchRenderable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IIS.SLSharp.Bindings.MOGRE; 6 | using IIS.SLSharp.Examples.MOGRE.GeoClipmap.Shaders; 7 | using IIS.SLSharp.Shaders; 8 | using Mogre; 9 | 10 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap.GeoClipmap 11 | { 12 | internal class PatchRenderable: Renderable 13 | { 14 | private readonly ClipmapShader _shader; 15 | 16 | private readonly Patch _patch; 17 | 18 | private static readonly LightList _nullLights = new LightList(); 19 | 20 | public Vector4 ScaleFactor; 21 | 22 | public Vector4 FineBlockOrigin; 23 | 24 | private readonly string _scaleFactorName; 25 | 26 | private readonly string _fineBlockOriginName; 27 | 28 | public ClipmapLevel Level; 29 | 30 | public PatchRenderable(Patch patch, ClipmapShader shader) 31 | { 32 | _patch = patch; 33 | _shader = shader; 34 | 35 | _scaleFactorName = Shader.UniformName(() => _shader.ScaleFactor); 36 | _fineBlockOriginName = Shader.UniformName(() => _shader.FineBlockOrigin); 37 | } 38 | 39 | public override MaterialPtr GetMaterial() 40 | { 41 | return Level.Material; 42 | } 43 | 44 | public override ushort NumWorldTransforms 45 | { 46 | get 47 | { 48 | return 1; 49 | } 50 | } 51 | 52 | public override void GetRenderOperation(RenderOperation op) 53 | { 54 | op.useIndexes = true; 55 | op.operationType = RenderOperation.OperationTypes.OT_TRIANGLE_LIST; 56 | op.vertexData = _patch.VertexData; 57 | op.indexData = _patch.IndexData; 58 | } 59 | 60 | public override void _updateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry_NativePtr constantEntry, GpuProgramParameters @params) 61 | { 62 | base._updateCustomGpuParameter(constantEntry, @params); 63 | @params.SetNamedConstant(_scaleFactorName, ScaleFactor); 64 | @params.SetNamedConstant(_fineBlockOriginName, FineBlockOrigin); 65 | } 66 | 67 | public override unsafe void GetWorldTransforms(Matrix4.NativeValue* xform) 68 | { 69 | *xform = Matrix4.IDENTITY.value; 70 | } 71 | 72 | public override float GetSquaredViewDepth(Camera cam) 73 | { 74 | return 0.0f; 75 | } 76 | 77 | public override Const_LightList GetLights() 78 | { 79 | return _nullLights; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Mogre; 3 | 4 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap 5 | { 6 | class Program 7 | { 8 | private static void Main() 9 | { 10 | using (var r = new Root()) 11 | { 12 | 13 | Console.WriteLine(); 14 | Console.WriteLine(); 15 | Console.WriteLine("Select Render system:"); 16 | Console.WriteLine("1.) OpenGL"); 17 | Console.WriteLine("2.) Direct3D9"); 18 | while (true) 19 | { 20 | var k = Console.ReadKey(true); 21 | int v; 22 | if (!int.TryParse(k.KeyChar.ToString(), out v)) 23 | continue; 24 | if (v > 2 || v == 0) 25 | continue; 26 | 27 | if (v == 1) 28 | { 29 | r.LoadPlugin("RenderSystem_GL"); 30 | r.RenderSystem = r.GetRenderSystemByName("OpenGL Rendering Subsystem"); 31 | } 32 | else 33 | { 34 | r.LoadPlugin("RenderSystem_Direct3D9"); 35 | r.RenderSystem = r.GetRenderSystemByName("Direct3D9 Rendering Subsystem"); 36 | } 37 | break; 38 | } 39 | 40 | using (r.Initialise(false)) 41 | { 42 | using (var w = r.RenderSystem._createRenderWindow("SL# Demo", 640, 480, false)) 43 | { 44 | var win = new DemoWindow(r, w); 45 | win.OnLoad(); 46 | r.FrameRenderingQueued += win.OnRenderFrame; 47 | r.StartRendering(); 48 | win.OnUnload(); 49 | } 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre.GeoClipmap/Shaders/ClipmapShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Bindings.MOGRE; 3 | using IIS.SLSharp.Shaders; 4 | 5 | namespace IIS.SLSharp.Examples.MOGRE.GeoClipmap.Shaders 6 | { 7 | public abstract class ClipmapShader : Shader 8 | { 9 | [Uniform] 10 | public abstract vec4 Color { set; get; } 11 | 12 | [Uniform] 13 | public abstract mat4 ModelViewProjectionMatrix { set; get; } 14 | 15 | [Uniform] 16 | public abstract mat4 NormalMatrix { set; get; } 17 | 18 | [Uniform] 19 | public abstract vec4 ScaleFactor { set; get; } 20 | 21 | [Uniform] 22 | public abstract vec4 FineBlockOrigin { set; get; } 23 | 24 | [Uniform] 25 | public abstract vec2 ViewerPosition { set; get; } 26 | 27 | [Uniform] 28 | public abstract vec2 AlphaOffset { set; get; } 29 | 30 | [Uniform] 31 | public abstract vec2 OneOverWidth { set; get; } 32 | 33 | [Uniform] 34 | public abstract float ZTexScaleFactor { set; get; } 35 | 36 | [Uniform] 37 | public abstract float DebugValue { set; get; } 38 | 39 | [Uniform] 40 | public abstract float alpha { set; get; } 41 | 42 | [Uniform] 43 | public abstract sampler2D Heightmap { set; get; } 44 | 45 | [Varying] 46 | public vec2 _uv; 47 | 48 | [Varying(UsageSemantic.Position0)] 49 | private vec4 _position; 50 | 51 | [Varying] 52 | public float _z; 53 | 54 | [Varying] 55 | public vec4 _finalPos; 56 | 57 | [Varying] 58 | public vec3 Normal; 59 | 60 | [VertexIn(UsageSemantic.Position0)] 61 | public vec4 Vertex; 62 | 63 | [FragmentOut(UsageSemantic.Color0)] 64 | public vec4 FragColor; 65 | 66 | [VertexShader(true)] 67 | public void ClipmapVertexMain() 68 | { 69 | var worldPos = (Vertex.xy + ScaleFactor.xy) * ScaleFactor.zw; 70 | _uv = (Vertex.xy + FineBlockOrigin.xy) * FineBlockOrigin.zw; 71 | 72 | 73 | var texel = new vec3(TextureLod(Heightmap, _uv, 1.0f).r); 74 | 75 | var zfZd = texel.x * 512.0f; 76 | var zf = Floor(zfZd) * 0.001953125f; 77 | var zd = Fraction(zfZd) * 2.0f - 1.0f; 78 | 79 | //var alpha = Clamp((Abs(worldPos - ViewerPosition) - AlphaOffset) * OneOverWidth, 0.0f, 1.0f); 80 | //alpha.x = Max(alpha.x, alpha.y); 81 | 82 | 83 | _z = zf + /* alpha * */ zd; 84 | 85 | //_z = zfZd; // alpha blend not implemented, yet 86 | 87 | // planar map 88 | var worldPosFinal = new vec4(worldPos, _z * 0.3f, 1.0f); 89 | 90 | _finalPos = ModelViewProjectionMatrix * worldPosFinal; 91 | _position = _finalPos; 92 | 93 | 94 | // just for testing, derive normal using interpolation over heights 95 | var dfdx = (TextureLod(Heightmap, _uv + new vec2(FineBlockOrigin.z, 0.0f), 1.0f).r - texel.r); 96 | var dfdy = (TextureLod(Heightmap, _uv + new vec2(0.0f, FineBlockOrigin.w), 1.0f).r - texel.r); 97 | var dz = 2.0f * ScaleFactor.z - dfdx * dfdx - dfdy * dfdy; 98 | Normal = new vec3(dfdx, dfdy, dz); 99 | 100 | //normal = normalize(vec3(texel.yz, 1.0)); 101 | } 102 | 103 | [FragmentShader(true)] 104 | public void ClipmapFragmentMain() 105 | { 106 | var light = Normalize(new vec3(0.0f, 1.0f, 0.6f)); 107 | var n = Normalize(Normal); 108 | 109 | /* 110 | var n2 = Normalize(Cross(dFdx(_finalPos.xyz),dFdy(_finalPos.xyz))); 111 | n2.xy = -n2.xy; 112 | var light2 = new mat3(NormalMatrix) * (light); 113 | */ 114 | var i = Max(Dot(light, n), 0.0f) * 0.8f + 0.2f; // Dot(light2, n2); 115 | 116 | 117 | FragColor = /*Color **/ new vec4(i); 118 | } 119 | 120 | protected ClipmapShader() 121 | { 122 | Link(); 123 | } 124 | 125 | public override void Dispose() 126 | { 127 | base.Dispose(); 128 | } 129 | 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using IIS.SLSharp.Bindings.MOGRE; 4 | using IIS.SLSharp.Examples.MOGRE.Shaders; 5 | using IIS.SLSharp.Examples.MOGRE.Textures; 6 | using IIS.SLSharp.Shaders; 7 | using Mogre; 8 | using Math = System.Math; 9 | 10 | namespace IIS.SLSharp.Examples.MOGRE 11 | { 12 | public sealed class DemoWindow 13 | { 14 | private SimpleShader _shader; 15 | private readonly Root _root; 16 | private SceneManager _scene; 17 | private Entity _patchEntity; 18 | private Camera _camera; 19 | private readonly RenderWindow _window; 20 | 21 | public DemoWindow(Root root, RenderWindow renderWindow) 22 | { 23 | _root = root; 24 | _window = renderWindow; 25 | } 26 | 27 | public void OnLoad() 28 | { 29 | var dir = Directory.GetCurrentDirectory(); 30 | ResourceGroupManager.Singleton.AddResourceLocation(dir, "FileSystem"); 31 | MaterialManager.Singleton.Initialise(); 32 | 33 | _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance"); 34 | _scene.ClearScene(); 35 | 36 | Bindings.MOGRE.SLSharp.Init(); 37 | Shader.DebugMode = true; 38 | 39 | //Shader.DebugMode = true; 40 | 41 | _shader = Shader.CreateSharedShader(); 42 | 43 | _patchEntity = _scene.CreateEntity("Box", "box.mesh"); 44 | _scene.RootSceneNode.AttachObject(_patchEntity); 45 | 46 | var mat = _shader.ToMaterial(); 47 | var pass = mat.GetTechnique(0).GetPass(0); 48 | pass.SetAlphaRejectSettings(CompareFunction.CMPF_GREATER_EQUAL, 128); 49 | pass.CullingMode = CullingMode.CULL_NONE; 50 | 51 | // SL# on OGRE: bind auto semantic to a uniform! 52 | // (we might automate this via semantic attributes within the SL# shaders in future!) 53 | _shader.SetAuto(() => _shader.ModelviewProjection, GpuProgramParameters.AutoConstantType.ACT_WORLDVIEWPROJ_MATRIX); 54 | 55 | _shader.Begin(); 56 | 57 | // Set a texture 58 | /* 59 | var smp = _shader.Sampler(() => _shader.Texture); 60 | smp.SetTextureName(TextureManager.Singleton.Load("test.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).Name); 61 | smp.SetTextureName(_wang.AsTexture.Name); 62 | smp.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_POINT); 63 | */ 64 | 65 | _patchEntity.SetMaterial(mat); 66 | 67 | _camera = _scene.CreateCamera("MainCamera"); 68 | _camera.Position = new Vector3(0, 0, 5); 69 | _camera.LookAt(Vector3.ZERO); 70 | _camera.NearClipDistance = 0.0001f; 71 | _camera.FarClipDistance = 4.0f; 72 | _camera.AutoAspectRatio = true; 73 | 74 | var vp = _window.AddViewport(_camera); 75 | vp.BackgroundColour = ColourValue.Blue; 76 | } 77 | 78 | public void OnUnload() 79 | { 80 | _shader.Dispose(); 81 | } 82 | 83 | public bool OnRenderFrame(FrameEvent evt) 84 | { 85 | var angle = Mogre.Math.DegreesToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6 * 4); 86 | var cam = new Vector3((float)Math.Sin(angle), 0.5f, (float)Math.Cos(angle)) * ((float)Math.Sin(angle*4) + 1.7f); 87 | var look = Vector3.ZERO; 88 | 89 | _camera.Position = cam + look; 90 | _camera.LookAt(look); 91 | 92 | 93 | // SL# allows direct manipulation of uniforms like this! 94 | _shader.Blue = (float)Math.Sin(angle * 8.0f); 95 | 96 | 97 | return !_window.IsClosed; 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Mogre; 6 | 7 | namespace IIS.SLSharp.Examples.MOGRE 8 | { 9 | class Program 10 | { 11 | private static void Main() 12 | { 13 | using (var r = new Root()) 14 | { 15 | 16 | Console.WriteLine(); 17 | Console.WriteLine(); 18 | Console.WriteLine("Select Render system:"); 19 | Console.WriteLine("1.) OpenGL"); 20 | Console.WriteLine("2.) Direct3D9"); 21 | while (true) 22 | { 23 | var k = Console.ReadKey(true); 24 | int v; 25 | if (!int.TryParse(k.KeyChar.ToString(), out v)) 26 | continue; 27 | if (v > 2 || v == 0) 28 | continue; 29 | 30 | if (v == 1) 31 | { 32 | r.LoadPlugin("RenderSystem_GL"); 33 | r.RenderSystem = r.GetRenderSystemByName("OpenGL Rendering Subsystem"); 34 | } 35 | else 36 | { 37 | r.LoadPlugin("RenderSystem_Direct3D9"); 38 | r.RenderSystem = r.GetRenderSystemByName("Direct3D9 Rendering Subsystem"); 39 | } 40 | break; 41 | } 42 | 43 | using (r.Initialise(false)) 44 | { 45 | using (var w = r.RenderSystem._createRenderWindow("SL# Demo", 640, 480, false)) 46 | { 47 | var win = new DemoWindow(r, w); 48 | win.OnLoad(); 49 | r.FrameRenderingQueued += win.OnRenderFrame; 50 | r.StartRendering(); 51 | win.OnUnload(); 52 | } 53 | } 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre/Shaders/SimpleShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Examples.MOGRE.Textures; 3 | using IIS.SLSharp.Shaders; 4 | using IIS.SLSharp.Bindings.MOGRE; 5 | using Mogre; 6 | 7 | namespace IIS.SLSharp.Examples.MOGRE.Shaders 8 | { 9 | public abstract class SimpleShader : Shader 10 | { 11 | // demonstrate using a shared library 12 | public WangShader Wang { get; private set; } 13 | 14 | // expose a simple uniform (this can be directly accessed from client code) 15 | [Uniform] 16 | public abstract float Blue { set; get; } 17 | 18 | [Uniform] 19 | public abstract mat4 ModelviewProjection { set; get; } 20 | 21 | [Varying] 22 | private vec2 _uv; 23 | 24 | [Varying(UsageSemantic.Position0)] 25 | private vec4 _position; 26 | 27 | [VertexIn(UsageSemantic.Position0)] 28 | public vec4 Vertex; 29 | 30 | [VertexIn(UsageSemantic.Texcoord0)] 31 | public vec2 Texcoord; 32 | 33 | [FragmentOut(UsageSemantic.Color0)] 34 | public vec4 Color; 35 | 36 | [FragmentShader(true)] 37 | protected void FragmentMain() 38 | { 39 | var c = Wang.WangAt(_uv); 40 | Color = new vec4(c.rg, Blue, c.a); 41 | } 42 | 43 | [VertexShader(true)] 44 | public void VertexMain() 45 | { 46 | _uv = Texcoord; 47 | _position = ModelviewProjection * Vertex; 48 | } 49 | 50 | // resource setup code 51 | protected SimpleShader() 52 | { 53 | Wang = CreateSharedShader(); 54 | 55 | 56 | var tiles = TextureManager.Singleton.Load("tiles.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); 57 | tiles.Target.NumMipmaps = 5; 58 | 59 | Wang.WangTable = new WangMap(64, 64).AsTexture; 60 | Wang.Tiles = tiles; 61 | 62 | Link(new[] { Wang }); 63 | } 64 | 65 | 66 | public override void Dispose() 67 | { 68 | Wang.WangTable.Dispose(); 69 | Wang.Tiles.Dispose(); 70 | Wang.Dispose(); 71 | base.Dispose(); 72 | } 73 | 74 | public override void Begin() 75 | { 76 | Wang.BeginLibrary(this); 77 | base.Begin(); 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Mogre/Shaders/WangShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | using Mogre; 4 | using IIS.SLSharp.Bindings.MOGRE; 5 | 6 | namespace IIS.SLSharp.Examples.MOGRE.Shaders 7 | { 8 | public abstract class WangShader : Shader 9 | { 10 | public Texture Tiles { get; set; } 11 | 12 | public Texture WangTable { get; set; } 13 | 14 | [Uniform] 15 | public abstract sampler2D WangTiles { set; get; } 16 | 17 | [Uniform] 18 | public abstract sampler2D WangMap { set; get; } 19 | 20 | [FragmentShader] 21 | public vec4 WangAt(vec2 tex) 22 | { 23 | var address = tex - tex % (1.0f / 256.0f); 24 | var subPos = Fraction(tex * 256.0f) / 4.0f; 25 | var offset = Texture(WangMap, Fraction(address)).xw; 26 | var tc = offset + subPos; 27 | var tileScaledTex = tex * new vec2(32.0f / 1.0f); 28 | 29 | return TextureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex)); 30 | } 31 | 32 | public override void Begin() 33 | { 34 | base.Begin(); 35 | var smp = this.Sampler(() => WangTiles); 36 | smp.SetTextureName(Tiles.Name); 37 | 38 | smp = this.Sampler(() => WangMap); 39 | smp.SetTextureName(WangTable.Name); 40 | smp.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_POINT); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Simple/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using IIS.SLSharp.Bindings.OpenTK; 4 | using IIS.SLSharp.Examples.Simple.Shaders; 5 | using IIS.SLSharp.Shaders; 6 | using OpenTK; 7 | using OpenTK.Graphics.OpenGL; 8 | 9 | namespace IIS.SLSharp.Examples.Simple 10 | { 11 | public sealed class DemoWindow : GameWindow 12 | { 13 | private MyShader _myShader; 14 | 15 | protected override void OnLoad(EventArgs e) 16 | { 17 | Bindings.OpenTK.SLSharp.Init(); 18 | _myShader = Shader.CreateSharedShader(); 19 | } 20 | 21 | protected override void OnUnload(EventArgs e) 22 | { 23 | _myShader.Dispose(); 24 | } 25 | 26 | protected override void OnResize(EventArgs e) 27 | { 28 | GL.Viewport(ClientRectangle); 29 | } 30 | 31 | protected override void OnRenderFrame(FrameEventArgs e) 32 | { 33 | GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 34 | GL.Disable(EnableCap.CullFace); 35 | 36 | _myShader.Begin(); 37 | _myShader.Blue = 0.5f; 38 | _myShader.Invert.Channels = (new Vector4(0.0f, 1.0f, 0.0f, 0.0f)).ToVector4F(); 39 | _myShader.RenderQuad(); 40 | _myShader.End(); 41 | 42 | SwapBuffers(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Simple/Program.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Examples.Simple 2 | { 3 | internal static class Program 4 | { 5 | private static void Main() 6 | { 7 | using (var win = new DemoWindow { Title = "GeoClip Shader Demo" }) 8 | win.Run(0.0d); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Simple/Shaders/InvertShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.Simple.Shaders 5 | { 6 | public abstract class InvertShader : Shader 7 | { 8 | [Uniform] 9 | public abstract vec4 Channels { get; set; } 10 | 11 | [VertexShader] 12 | [FragmentShader] 13 | // this library function is callable from both fragment and vertex shaders 14 | // if inverts the colors which are set to 1.0 in the Channels uniform 15 | // and leaves the colors which are set to 0.0 in the Channels uniform 16 | public vec4 Invert(vec4 v) 17 | { 18 | return Channels - Channels * v + (new vec4(1.0f) - Channels) * v; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Simple/Shaders/MyShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.Simple.Shaders 5 | { 6 | public abstract class MyShader : Shader 7 | { 8 | // expose a simple uniform (this can be directly accessed from client code) 9 | [Uniform] 10 | public abstract float Blue { set; get; } 11 | 12 | [Varying] 13 | private vec2 _uv; 14 | 15 | [VertexIn(UsageSemantic.Position0)] 16 | public vec4 Vertex; 17 | 18 | [FragmentOut(UsageSemantic.Color0)] 19 | public vec4 Color; 20 | 21 | [Varying(UsageSemantic.Position0)] 22 | public vec4 Position; 23 | 24 | // demonstrate using a shared library 25 | public InvertShader Invert { get; private set; } 26 | 27 | [FragmentShader(true)] 28 | protected void FragmentMain() 29 | { 30 | //Invert.Channels = new vec4(1.0f); // invalid testcode 31 | Color = Invert.Invert(new vec4(_uv, Blue, 1.0f)); 32 | } 33 | 34 | [VertexShader(true)] 35 | public void VertexMain() 36 | { 37 | _uv = (Vertex.xy + new vec2(1.0f)) * 0.5f; 38 | Position = Vertex; 39 | } 40 | 41 | // resource setup code 42 | protected MyShader() 43 | { 44 | Invert = CreateSharedShader(); 45 | Link(new[] { Invert }); 46 | } 47 | 48 | public override void Dispose() 49 | { 50 | Invert.Dispose(); 51 | base.Dispose(); 52 | } 53 | 54 | public override void Begin() 55 | { 56 | Invert.BeginLibrary(this); 57 | base.Begin(); 58 | } 59 | 60 | public void RenderQuad() 61 | { 62 | RenderQuad(this, () => Vertex); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Xna/DemoWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using IIS.SLSharp.Bindings.XNA; 3 | using IIS.SLSharp.Examples.XNA.Shaders; 4 | using IIS.SLSharp.Shaders; 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace IIS.SLSharp.Examples.XNA 9 | { 10 | class DemoWindow: Game 11 | { 12 | private readonly GraphicsDeviceManager _gdm; 13 | private SimpleShader _shader; 14 | private Model _model; 15 | 16 | public DemoWindow() 17 | { 18 | _gdm = new GraphicsDeviceManager(this); 19 | IsMouseVisible = true; 20 | Window.AllowUserResizing = true; 21 | } 22 | 23 | protected override void LoadContent() 24 | { 25 | Bindings.XNA.SLSharp.Init(GraphicsDevice); 26 | Shader.DebugMode = true; 27 | _shader = Shader.CreateSharedShader(); 28 | _model = Content.Load("xwing"); 29 | } 30 | 31 | protected override void UnloadContent() 32 | { 33 | _shader.Dispose(); 34 | } 35 | 36 | protected override void Draw(GameTime gameTime) 37 | { 38 | GraphicsDevice.Clear(Color.CornflowerBlue); 39 | 40 | var angle = MathHelper.ToRadians((DateTime.Now.Millisecond / 1000.0f + DateTime.Now.Second) * 6 * 4); 41 | var cam = new Vector3((float) Math.Sin(angle), 0.0f, (float) Math.Cos(angle)); 42 | var aspect = ((float) Window.ClientBounds.Width)/Window.ClientBounds.Height; 43 | var world = Matrix.CreateScale(0.005f); 44 | var view = Matrix.CreateLookAt(cam,Vector3.Zero, Vector3.UnitY); 45 | var proj = Matrix.CreatePerspectiveFieldOfView( 46 | MathHelper.ToRadians(45.0f), aspect, 0.1f, 10.0f); 47 | 48 | 49 | 50 | _shader.Begin(); 51 | foreach (var mesh in _model.Meshes) 52 | { 53 | var modelview = world * view * mesh.ParentBone.Transform; 54 | var mvp = Matrix.Transpose(modelview*proj); 55 | 56 | _shader.Blue = (float)Math.Sin(angle * 8.0f); 57 | _shader.ModelviewProjection = mvp.ToMatrix4F(); 58 | foreach (var part in mesh.MeshParts) 59 | { 60 | GraphicsDevice.SetVertexBuffer(part.VertexBuffer, part.VertexOffset); 61 | GraphicsDevice.Indices = part.IndexBuffer; 62 | GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 63 | 0, part.VertexOffset, part.NumVertices, part.StartIndex, part.PrimitiveCount); 64 | } 65 | } 66 | _shader.End(); 67 | 68 | //_model.Draw(model, view, proj); 69 | 70 | base.Draw(gameTime); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Xna/IIS.SLSharp.Examples.Xna.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {83127CAD-D3FB-473C-A798-3599AD5BD459} 9 | Exe 10 | Properties 11 | IIS.SLSharp.Examples.Xna 12 | IIS.SLSharp.Examples.Xna 13 | v4.0 14 | 15 | 16 | 512 17 | 18 | 19 | x86 20 | true 21 | full 22 | false 23 | ..\bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | 1591 30 | true 31 | 32 | 33 | x86 34 | pdbonly 35 | true 36 | ..\bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | 41 | 42 | 1591 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Properties\SolutionInfo.cs 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | {31C6D7EC-615F-4A19-8079-967B10A8FA3E} 74 | IIS.SLSharp.Bindings.Xna 75 | 76 | 77 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 78 | IIS.SLSharp 79 | 80 | 81 | 82 | 83 | xwing.xnb 84 | PreserveNewest 85 | 86 | 87 | 88 | 95 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Xna/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace IIS.SLSharp.Examples.XNA 4 | { 5 | internal static class Program 6 | { 7 | private static void Main() 8 | { 9 | using (var win = new DemoWindow()) 10 | { 11 | win.Run(); 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IIS.SLSharp.Examples.Xna/Shaders/SimpleShader.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Examples.XNA.Shaders 5 | { 6 | public abstract class SimpleShader : Shader 7 | { 8 | // expose a simple uniform (this can be directly accessed from client code) 9 | [Uniform] 10 | public abstract float Blue { set; get; } 11 | 12 | [Uniform] 13 | public abstract mat4 ModelviewProjection { set; get; } 14 | 15 | [Varying] 16 | private vec2 _fragNormal; 17 | 18 | [Varying(UsageSemantic.Position0)] 19 | private vec4 _position; 20 | 21 | [VertexIn(UsageSemantic.Position0)] 22 | public vec4 Vertex; 23 | 24 | [VertexIn(UsageSemantic.Normal0)] 25 | public vec2 Normal; 26 | 27 | [FragmentOut(UsageSemantic.Color0)] 28 | public vec4 Color; 29 | 30 | [FragmentShader(true)] 31 | protected void FragmentMain() 32 | { 33 | Color = new vec4(_fragNormal.xy, Blue, 1.0f); 34 | } 35 | 36 | [VertexShader(true)] 37 | public void VertexMain() 38 | { 39 | _fragNormal = Normal; 40 | _position = ModelviewProjection * Vertex; 41 | } 42 | 43 | // resource setup code 44 | protected SimpleShader() 45 | { 46 | Link(); 47 | } 48 | 49 | public void RenderQuad() 50 | { 51 | RenderQuad(this, () => Vertex); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /IIS.SLSharp.NuGet/SLSharp.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SLSharp 5 | 2.0 6 | Ignite Interactive Studio 7 | Runtime IL-to-shader translator, allowing developers to write GLSL/HLSL shaders in pure C#. 8 | en-US 9 | https://github.com/IgniteInteractiveStudio/SLSharp/blob/master/LICENSE 10 | https://github.com/IgniteInteractiveStudio/SLSharp 11 | il glsl hlsl c# runtime shader shaders opengl directx dx ogl gl graphics graphic opentk otk game games axiom ogre mogre xna 12 | 13 | 14 | -------------------------------------------------------------------------------- /IIS.SLSharp.Tests/IIS.SLSharp.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {0BA0BA6E-87FD-44B2-81AD-9939F19EB63C} 9 | Library 10 | Properties 11 | IIS.SLSharp.Tests 12 | IIS.SLSharp.Tests 13 | v4.0 14 | 512 15 | Client 16 | 17 | 18 | true 19 | full 20 | false 21 | ..\bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | true 26 | 27 | 28 | pdbonly 29 | true 30 | ..\bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | true 35 | 36 | 37 | 38 | False 39 | ..\Dependencies\nunit.framework.dll 40 | 41 | 42 | ..\Dependencies\OpenTK.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Properties\SolutionInfo.cs 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | {8A901280-C858-4018-AD66-45255EFEC519} 67 | IIS.SLSharp.Bindings.OpenTK 68 | 69 | 70 | {ECF58025-4591-4708-8EC9-4B95A5673DDA} 71 | IIS.SLSharp 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /IIS.SLSharp.Tests/ITestRuntime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IIS.SLSharp.Shaders; 6 | 7 | namespace IIS.SLSharp.Examples.Tests 8 | { 9 | public interface ITestRuntime 10 | { 11 | void Initialize(); 12 | void Cleanup(); 13 | Vector4 ProcessFragment(); 14 | 15 | ShaderDefinition.vec2 Convert(Vector2 v); 16 | ShaderDefinition.vec3 Convert(Vector3 v); 17 | ShaderDefinition.vec4 Convert(Vector4 v); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /IIS.SLSharp.Tests/OpenTKTestRuntime/OpenTKTestRuntime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using IIS.SLSharp.Bindings.OpenTK; 7 | using IIS.SLSharp.Bindings.OpenTK.Textures; 8 | using IIS.SLSharp.Shaders; 9 | using OpenTK; 10 | using OpenTK.Graphics; 11 | using OpenTK.Graphics.OpenGL; 12 | 13 | namespace IIS.SLSharp.Examples.Tests.OpenTKTestRuntime 14 | { 15 | internal sealed class OpenTKTestRuntime: ITestRuntime 16 | { 17 | private INativeWindow _window; // OpenTK forces us to create one ... (great design eh?) 18 | 19 | private IGraphicsContext _context; 20 | 21 | private RenderToTexture _rtt; 22 | 23 | public void Initialize() 24 | { 25 | // 26 | // OpenTK has a great fuckup in its design here. It's absolutly nohm it possible to create 27 | // a render context for offscreen rendering without creating an OpenTK window. 28 | // before. 29 | // Passing Utilities.CreateDummyWindowInfo() or anything else will cause an invalid cast exception 30 | // Using Utilities.CreateWindowsWindowInfo(IntPtr.Zero) binds the code to windows only 31 | // Really great, why do i need to have a window in order to render to memory? -_- 32 | // 33 | 34 | _window = new NativeWindow { Visible = false }; 35 | _context = new GraphicsContext(GraphicsMode.Default, _window.WindowInfo, 2, 0, GraphicsContextFlags.Default); 36 | _context.MakeCurrent(_window.WindowInfo); 37 | _context.LoadAll(); 38 | 39 | // create offscreen rendertarget with high precision 40 | _rtt = new RenderToTexture(1, 1, false, 4, typeof(float)); 41 | 42 | int precision; 43 | int range; 44 | GL.GetShaderPrecisionFormat(OpenTK.Graphics.OpenGL.ShaderType.FragmentShader, ShaderPrecisionType.HighFloat, out range, out precision); 45 | Debug.WriteLine("Precision: {0}, Range {1}", precision, range); 46 | 47 | // init SL# 48 | Bindings.OpenTK.SLSharp.Init(); 49 | } 50 | 51 | public void Cleanup() 52 | { 53 | _rtt.Dispose(); 54 | _context.Dispose(); 55 | _window.Dispose(); 56 | } 57 | 58 | public Vector4 ProcessFragment() 59 | { 60 | var pixel = new float[4]; 61 | _rtt.Activate(); 62 | GL.Viewport(0, 0, 1, 1); 63 | GL.ClearColor(0.1f, 0.3f, 0.6f, 0.9f); 64 | GL.Clear(ClearBufferMask.ColorBufferBit); 65 | //GL.Arb.ClampColor(ArbColorBufferFloat.ClampFragmentColorArb, ArbColorBufferFloat.RgbaFloatModeArb); 66 | //GL.Arb.ClampColor(ArbColorBufferFloat.ClampVertexColorArb, ArbColorBufferFloat.RgbaFloatModeArb); 67 | //GL.Arb.ClampColor(ArbColorBufferFloat.ClampReadColorArb, ArbColorBufferFloat.RgbaFloatModeArb); 68 | //GL.ClampColor(ClampColorTarget.ClampVertexColor, ClampColorMode.False); 69 | //GL.ClampColor(ClampColorTarget.ClampFragmentColor, ClampColorMode.False); 70 | //GL.ClampColor(ClampColorTarget.ClampReadColor, ClampColorMode.False); 71 | 72 | GL.Begin(BeginMode.Points); 73 | GL.Vertex3(0, 0, 0); 74 | GL.End(); 75 | GL.Flush(); 76 | GL.ReadPixels(0, 0, 1, 1, PixelFormat.Rgba, PixelType.Float, pixel); 77 | _rtt.Finish(); 78 | Utilities.CheckGL(); 79 | 80 | //_context.SwapBuffers(); 81 | 82 | return new Vector4(pixel[0], pixel[1], pixel[2], pixel[3]); 83 | } 84 | 85 | public ShaderDefinition.vec2 Convert(Vector2 v) 86 | { 87 | var v2 = new OpenTK.Vector2(v.X, v.Y); 88 | return v2.ToVector2F(); 89 | } 90 | 91 | public ShaderDefinition.vec3 Convert(Vector3 v) 92 | { 93 | var v3 = new OpenTK.Vector3(v.X, v.Y, v.Z); 94 | return v3.ToVector3F(); 95 | } 96 | 97 | public ShaderDefinition.vec4 Convert(Vector4 v) 98 | { 99 | var v4 = new OpenTK.Vector4(v.X, v.Y, v.Z, v.W); 100 | return v4.ToVector4F(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /IIS.SLSharp.Tests/TestState.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace IIS.SLSharp.Examples.Tests 4 | { 5 | [SetUpFixture] 6 | public sealed class TestState 7 | { 8 | public static readonly ITestRuntime Runtime = new OpenTKTestRuntime.OpenTKTestRuntime(); 9 | 10 | private static bool _initialized; 11 | 12 | public static void Initialize() 13 | { 14 | if (_initialized) 15 | return; 16 | Runtime.Initialize(); 17 | _initialized = true; 18 | } 19 | 20 | public static void Cleanup() 21 | { 22 | if (!_initialized) 23 | return; 24 | Runtime.Cleanup(); 25 | _initialized = false; 26 | } 27 | 28 | [SetUp] 29 | public static void AssemblyInit() 30 | { 31 | Initialize(); // first init 32 | } 33 | 34 | [TearDown] 35 | public static void AssemblyCleanup() 36 | { 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/FragmentOutAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] 6 | public sealed class FragmentOutAttribute : ShaderVariableAttribute 7 | { 8 | public FragmentOutAttribute(UsageSemantic hint) 9 | {} 10 | } 11 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/FragmentShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | /// 6 | /// Attribute to flag Fragment-shader routines 7 | /// 8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 9 | public sealed class FragmentShaderAttribute : Attribute, IShaderAttribute 10 | { 11 | public bool EntryPoint { get; private set; } 12 | 13 | /// 14 | /// Flags a method to be compiled as fragment routine. 15 | /// 16 | /// Set to true for the function that serves as fragment entrypoint (main) 17 | public FragmentShaderAttribute(bool entryPoint = false) 18 | { 19 | EntryPoint = entryPoint; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/IShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Annotations 2 | { 3 | internal interface IShaderAttribute 4 | { 5 | bool EntryPoint { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/ShaderVariableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | /// 6 | /// Attribute to flag Varying shader variables. 7 | /// 8 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] 9 | public abstract class ShaderVariableAttribute : Attribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/UndefinedBehaviorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IIS.SLSharp.Annotations 7 | { 8 | class UndefinedBehaviorAttribute: Attribute 9 | { 10 | public UndefinedBehaviorAttribute(string condition) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/UniformAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | /// 6 | /// Attribute to flag Uniform shader variables. 7 | /// 8 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] 9 | public sealed class UniformAttribute : ShaderVariableAttribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/VaryingAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] 6 | public sealed class VaryingAttribute : ShaderVariableAttribute 7 | { 8 | public VaryingAttribute() 9 | { 10 | } 11 | 12 | public VaryingAttribute(UsageSemantic hint) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/VertexInAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | public enum UsageSemantic 6 | { 7 | /* 8 | Binormal, 9 | Blendindices, 10 | Blendweight, 11 | Color, 12 | Normal, 13 | Position, 14 | PositionT, 15 | PSize, 16 | Tangent, 17 | Texcoord, 18 | Fog, 19 | TessFactor, 20 | VFace, 21 | VPos, 22 | Depth*/ 23 | Unknown, 24 | 25 | Depth, 26 | 27 | PositionX, 28 | Position0, 29 | Position1, 30 | Position2, 31 | Position3, 32 | Position4, 33 | Position5, 34 | Position6, 35 | Position7, 36 | Position8, 37 | Position9, 38 | Position10, 39 | Position11, 40 | Position12, 41 | Position13, 42 | Position14, 43 | Position15, 44 | 45 | ColorX, 46 | Color0, 47 | Color1, 48 | Color2, 49 | Color3, 50 | Color4, 51 | Color5, 52 | Color6, 53 | Color7, 54 | Color8, 55 | Color9, 56 | Color10, 57 | Color11, 58 | Color12, 59 | Color13, 60 | Color14, 61 | Color15, 62 | 63 | TexcoordX, 64 | Texcoord0, 65 | Texcoord1, 66 | Texcoord2, 67 | Texcoord3, 68 | Texcoord4, 69 | Texcoord5, 70 | Texcoord6, 71 | Texcoord7, 72 | Texcoord8, 73 | Texcoord9, 74 | Texcoord10, 75 | Texcoord11, 76 | Texcoord12, 77 | Texcoord13, 78 | Texcoord14, 79 | Texcoord15, 80 | 81 | NormalX, 82 | Normal0, 83 | Normal1, 84 | Normal2, 85 | Normal3, 86 | Normal4, 87 | Normal5, 88 | Normal6, 89 | Normal7, 90 | Normal8, 91 | Normal9, 92 | Normal10, 93 | Normal11, 94 | Normal12, 95 | Normal13, 96 | Normal14, 97 | Normal15, 98 | }; 99 | 100 | 101 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] 102 | public sealed class VertexInAttribute : ShaderVariableAttribute 103 | { 104 | public VertexInAttribute(UsageSemantic hint) { } 105 | } 106 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/VertexShaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Annotations 4 | { 5 | /// 6 | /// Attribute to flag Vertex-shader routines 7 | /// 8 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 9 | public sealed class VertexShaderAttribute : Attribute, IShaderAttribute 10 | { 11 | public bool EntryPoint { get; private set; } 12 | 13 | /// 14 | /// Flags a method to be compiled as vertex routine. 15 | /// 16 | /// Set to true for the function that serves as vertex entrypoint (main) 17 | public VertexShaderAttribute(bool entryPoint = false) 18 | { 19 | EntryPoint = entryPoint; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IIS.SLSharp/Annotations/WarningAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IIS.SLSharp.Annotations 7 | { 8 | internal class WarningAttribute: Attribute 9 | { 10 | public WarningAttribute(string warning) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IIS.SLSharp/Bindings/Binding.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using IIS.SLSharp.Reflection; 4 | 5 | namespace IIS.SLSharp.Bindings 6 | { 7 | public sealed class Binding 8 | { 9 | private static Dictionary Methods 10 | { 11 | get 12 | { 13 | if (_handlers == null) 14 | throw new SLSharpException("SLSharp has not been initialized"); 15 | return _handlers; 16 | } 17 | } 18 | 19 | private static Dictionary _handlers; 20 | 21 | public static void Register(ISLSharpBinding binding) 22 | { 23 | _handlers = binding.PassiveMethods; 24 | Active = binding; 25 | } 26 | 27 | public static MethodInfo Resolve(ReflectionToken token) 28 | { 29 | MethodInfo result; 30 | if (!Methods.TryGetValue(token, out result)) 31 | throw new SLSharpException("Binding does not support " + token); 32 | return result; 33 | } 34 | 35 | public static ISLSharpBinding Active; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /IIS.SLSharp/Bindings/IProgram.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Bindings 4 | { 5 | public interface IProgram: IDisposable 6 | { 7 | void Activate(); 8 | void Finish(); 9 | int GetUniformIndex(string name); 10 | int GetAttributeIndex(string name); 11 | } 12 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Bindings/ISLSharpBinding.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using IIS.SLSharp.Descriptions; 4 | using IIS.SLSharp.Reflection; 5 | using IIS.SLSharp.Shaders; 6 | using IIS.SLSharp.Translation; 7 | 8 | namespace IIS.SLSharp.Bindings 9 | { 10 | public interface ISLSharpBinding 11 | { 12 | Dictionary PassiveMethods { get; } 13 | ITransform Transform { get; } 14 | 15 | void TexActivate(int textureUnit, object tex); 16 | void TexFinish(int textureUnit, object tex); 17 | void TexReset(); 18 | 19 | object Compile(Shader shader, ShaderType typ, SourceDescription source); 20 | IProgram Link(Shader shader, IEnumerable units); 21 | 22 | /// 23 | /// Called back as resources are needed. 24 | /// This happens when the first shader gets created 25 | /// 26 | void Initialize(); 27 | 28 | /// 29 | /// Signals that resources are not needed anymore 30 | /// This happens when the last shader got disposed 31 | /// Note: another Initialize() may follow at any time after Cleanup call 32 | /// 33 | void Cleanup(); 34 | 35 | void FullscreenQuad(int vertexLocation, bool positive); 36 | } 37 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Descriptions/FunctionDescription.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp.Descriptions 2 | { 3 | public class FunctionDescription 4 | { 5 | public readonly string Name; 6 | public readonly string Body; 7 | public readonly bool EntryPoint; 8 | public readonly ShaderType Type; 9 | 10 | public FunctionDescription(string name, string body, bool entryPoint, ShaderType type) 11 | { 12 | Name = name; 13 | EntryPoint = entryPoint; 14 | Body = body; 15 | Type = type; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /IIS.SLSharp/Descriptions/VariableDescription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using IIS.SLSharp.Annotations; 4 | using IIS.SLSharp.Shaders; 5 | 6 | namespace IIS.SLSharp.Descriptions 7 | { 8 | public class VariableDescription 9 | { 10 | public readonly Type Type; 11 | public readonly string Name; 12 | public readonly UsageSemantic Semantic; 13 | public readonly string Comment; 14 | public int? DefaultRegister { get; set; } 15 | 16 | public VariableDescription(Type type, string name, UsageSemantic semantic = UsageSemantic.Unknown, string comment = "") 17 | { 18 | Type = type; 19 | Comment = comment; 20 | Semantic = semantic; 21 | Name = name; 22 | } 23 | 24 | public bool IsSampler() 25 | { 26 | return Type.BaseType == typeof(ShaderDefinition.Sampler); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /IIS.SLSharp/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace IIS.SLSharp 5 | { 6 | public static class Extensions 7 | { 8 | public static TSource Max(this IEnumerable source, Func selector) 9 | where TSelect : IComparable 10 | { 11 | if (source == null) 12 | throw new ArgumentNullException("source"); 13 | 14 | if (selector == null) 15 | throw new ArgumentNullException("selector"); 16 | 17 | var enumer = source.GetEnumerator(); 18 | 19 | enumer.MoveNext(); 20 | var maxItem = enumer.Current; 21 | var maxValue = selector(maxItem); 22 | 23 | while (enumer.MoveNext()) 24 | { 25 | var currentItem = enumer.Current; 26 | var currentValue = selector(currentItem); 27 | 28 | if (currentValue.CompareTo(maxValue) <= 0) 29 | continue; 30 | 31 | maxItem = currentItem; 32 | maxValue = currentValue; 33 | } 34 | 35 | return maxItem; 36 | } 37 | 38 | public static TSource Min(this IEnumerable source, Func selector) 39 | where TSelect : IComparable 40 | { 41 | if (source == null) 42 | throw new ArgumentNullException("source"); 43 | 44 | if (selector == null) 45 | throw new ArgumentNullException("selector"); 46 | 47 | var enumer = source.GetEnumerator(); 48 | 49 | enumer.MoveNext(); 50 | var minItem = enumer.Current; 51 | var minValue = selector(minItem); 52 | 53 | while (enumer.MoveNext()) 54 | { 55 | var currentItem = enumer.Current; 56 | var currentValue = selector(currentItem); 57 | 58 | if (currentValue.CompareTo(minValue) >= 0) 59 | continue; 60 | 61 | minItem = currentItem; 62 | minValue = currentValue; 63 | } 64 | 65 | return minItem; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /IIS.SLSharp/Reflection/ReflectionMarkerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | namespace IIS.SLSharp.Reflection 6 | { 7 | public sealed class ReflectionMarkerAttribute : Attribute 8 | { 9 | public ReflectionToken Token { get; private set; } 10 | 11 | public ReflectionMarkerAttribute(ReflectionToken token) 12 | { 13 | Token = token; 14 | } 15 | 16 | public static PropertyInfo FindProperty(Type t, ReflectionToken token) 17 | { 18 | if (t == null) 19 | throw new ArgumentNullException("t"); 20 | 21 | return (from p in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) 22 | let attr = p.GetCustomAttributes(typeof(ReflectionMarkerAttribute), false) 23 | where attr.Length != 0 24 | let att = (ReflectionMarkerAttribute)attr[0] 25 | where att.Token == token 26 | select p).Single(); 27 | } 28 | 29 | public static MethodInfo FindMethod(Type t, ReflectionToken token) 30 | { 31 | if (t == null) 32 | throw new ArgumentNullException("t"); 33 | 34 | return (from m in t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) 35 | let attr = m.GetCustomAttributes(typeof(ReflectionMarkerAttribute), false) 36 | where attr.Length != 0 37 | let att = (ReflectionMarkerAttribute)attr[0] 38 | where att.Token == token 39 | select m).Single(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /IIS.SLSharp/Reflection/ReflectionToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Reflection 4 | { 5 | [Serializable] 6 | public enum ReflectionToken 7 | { 8 | NullToken, 9 | ShaderName, 10 | ShaderActivate, 11 | ShaderVec1Helper, 12 | ShaderVec2Helper, 13 | ShaderVec3Helper, 14 | ShaderVec4Helper, 15 | ShaderUniformMatrix2X2Helper, 16 | ShaderUniformMatrix2X3Helper, 17 | ShaderUniformMatrix2X4Helper, 18 | ShaderUniformMatrix3X2Helper, 19 | ShaderUniformMatrix3X3Helper, 20 | ShaderUniformMatrix3X4Helper, 21 | ShaderUniformMatrix4X2Helper, 22 | ShaderUniformMatrix4X3Helper, 23 | ShaderUniformMatrix4X4Helper, 24 | ShaderBegin, 25 | ResourceHelperRelease, 26 | ShaderSamplerHelper, 27 | ShaderIvec1Helper, 28 | ShaderIvec2Helper, 29 | ShaderIvec3Helper, 30 | ShaderIvec4Helper, 31 | ShaderUvec1Helper, 32 | ShaderUvec2Helper, 33 | ShaderUvec3Helper, 34 | ShaderUvec4Helper, 35 | ShaderDvec1Helper, 36 | ShaderDvec2Helper, 37 | ShaderDvec3Helper, 38 | ShaderDvec4Helper, 39 | ShaderUniformDMatrix2X2Helper, 40 | ShaderUniformDMatrix2X3Helper, 41 | ShaderUniformDMatrix2X4Helper, 42 | ShaderUniformDMatrix3X2Helper, 43 | ShaderUniformDMatrix3X3Helper, 44 | ShaderUniformDMatrix3X4Helper, 45 | ShaderUniformDMatrix4X2Helper, 46 | ShaderUniformDMatrix4X3Helper, 47 | ShaderUniformDMatrix4X4Helper, 48 | ShaderBvec1Helper, 49 | ShaderBvec2Helper, 50 | ShaderBvec3Helper, 51 | ShaderBvec4Helper, 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /IIS.SLSharp/SLSharpException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace IIS.SLSharp 5 | { 6 | /// 7 | /// Exception thrown by the SL# library when an error occurs. 8 | /// 9 | [Serializable] 10 | public class SLSharpException : Exception 11 | { 12 | public SLSharpException() 13 | { 14 | } 15 | 16 | public SLSharpException(string message) 17 | : base(message) 18 | { 19 | } 20 | 21 | public SLSharpException(string message, Exception inner) 22 | : base(message, inner) 23 | { 24 | } 25 | 26 | protected SLSharpException(SerializationInfo info, StreamingContext context) 27 | : base(info, context) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /IIS.SLSharp/ShaderType.cs: -------------------------------------------------------------------------------- 1 | namespace IIS.SLSharp 2 | { 3 | public enum ShaderType 4 | { 5 | FragmentShader, 6 | VertexShader 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/AttributeHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using IIS.SLSharp.Annotations; 3 | using Mono.Cecil; 4 | 5 | namespace IIS.SLSharp.Shaders 6 | { 7 | internal static class AttributeHelper 8 | { 9 | private static readonly int _uniformToken = typeof(UniformAttribute).MetadataToken; 10 | 11 | private static readonly int[] _attribToken = new[] 12 | { 13 | typeof(VaryingAttribute).MetadataToken, 14 | typeof(VertexInAttribute).MetadataToken, 15 | typeof(FragmentOutAttribute).MetadataToken, 16 | }; 17 | 18 | public static bool IsUniform(this TypeReference t) 19 | { 20 | return t.Resolve().MetadataToken.ToInt32() == _uniformToken; 21 | } 22 | 23 | public static bool IsVarying(this TypeReference t) 24 | { 25 | return t.Resolve().MetadataToken.ToInt32() == _attribToken[0]; 26 | } 27 | 28 | public static bool IsVertexIn(this TypeReference t) 29 | { 30 | return t.Resolve().MetadataToken.ToInt32() == _attribToken[1]; 31 | } 32 | 33 | public static bool IsFragmentOut(this TypeReference t) 34 | { 35 | return t.Resolve().MetadataToken.ToInt32() == _attribToken[2]; 36 | } 37 | 38 | public static bool IsAttribute(this TypeReference t) 39 | { 40 | return _attribToken.Contains(t.Resolve().MetadataToken.ToInt32()); 41 | } 42 | 43 | public static bool Is(this TypeReference t) 44 | { 45 | return t.Resolve().MetadataToken.ToInt32() == typeof (T).MetadataToken; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.Cecil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using Mono.Cecil; 7 | 8 | namespace IIS.SLSharp.Shaders 9 | { 10 | partial class ShaderDefinition 11 | { 12 | private static readonly Dictionary _types = new Dictionary(); 13 | 14 | private static readonly Dictionary _methods = new Dictionary(); 15 | 16 | static ShaderDefinition() 17 | { 18 | InitCecil(); 19 | } 20 | 21 | private static void InitCecil() 22 | { 23 | var typ = typeof(ShaderDefinition); 24 | var asm = AssemblyDefinition.ReadAssembly(typ.Assembly.Location); 25 | var mod = asm.Modules.Single(x => x.MetadataToken.ToInt32() == typ.Module.MetadataToken); 26 | foreach (var t in mod.Types) 27 | InitCecilType(t); 28 | } 29 | 30 | private static void InitCecilType(TypeDefinition typeDef) 31 | { 32 | _types.Add(typeDef.MetadataToken.ToInt32(), typeDef); 33 | 34 | foreach (var nested in typeDef.NestedTypes) 35 | InitCecilType(nested); 36 | foreach (var method in typeDef.Methods) 37 | _methods.Add(method.MetadataToken.ToInt32(), method); 38 | } 39 | 40 | internal static TypeDefinition ToCecil(Type t) 41 | { 42 | return _types[t.MetadataToken]; 43 | } 44 | 45 | internal static MethodDefinition ToCecil(MethodInfo method) 46 | { 47 | return _methods[method.MetadataToken]; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.Derivative.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | 3 | namespace IIS.SLSharp.Shaders 4 | { 5 | public abstract partial class ShaderDefinition 6 | { 7 | // Derivatives may be computationally expensive and/or numerically unstable. Therefore, an OpenGL 8 | // implementation may approximate the true derivatives by using a fast but not entirely accurate derivative 9 | // computation. Derivatives are undefined within non-uniform control flow. 10 | 11 | #region genType DeriveTowardsX(genType p) 12 | 13 | /// Returns the derivative in x using local differencing for the input argument p. 14 | protected internal static float DeriveTowardsX(float p) { throw _invalidAccess; } 15 | 16 | /// Returns the derivative in x using local differencing for the input argument p. 17 | protected internal static vec2 DeriveTowardsX(vec2 p) { throw _invalidAccess; } 18 | 19 | /// Returns the derivative in x using local differencing for the input argument p. 20 | protected internal static vec3 DeriveTowardsX(vec3 p) { throw _invalidAccess; } 21 | 22 | /// Returns the derivative in x using local differencing for the input argument p. 23 | protected internal static vec4 DeriveTowardsX(vec4 p) { throw _invalidAccess; } 24 | 25 | #endregion 26 | 27 | #region genType DeriveTowardsY(genType p) 28 | 29 | /// Returns the derivative in y using local differencing for the input argument p. 30 | protected internal static float DeriveTowardsY(float p) { throw _invalidAccess; } 31 | 32 | /// Returns the derivative in y using local differencing for the input argument p. 33 | protected internal static vec2 DeriveTowardsY(vec2 p) { throw _invalidAccess; } 34 | 35 | /// Returns the derivative in y using local differencing for the input argument p. 36 | protected internal static vec3 DeriveTowardsY(vec3 p) { throw _invalidAccess; } 37 | 38 | /// Returns the derivative in y using local differencing for the input argument p. 39 | protected internal static vec4 DeriveTowardsY(vec4 p) { throw _invalidAccess; } 40 | 41 | #endregion 42 | 43 | #region genType fwidth(genType p) 44 | 45 | /// Returns the sum of the absolute derivative in x and y using local 46 | /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p)); 47 | protected static float fwidth(float p) { throw _invalidAccess; } 48 | 49 | /// Returns the sum of the absolute derivative in x and y using local 50 | /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p)); 51 | protected static vec2 fwidth(vec2 p) { throw _invalidAccess; } 52 | 53 | /// Returns the sum of the absolute derivative in x and y using local 54 | /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p)); 55 | protected static vec3 fwidth(vec3 p) { throw _invalidAccess; } 56 | 57 | /// Returns the sum of the absolute derivative in x and y using local 58 | /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p)); 59 | protected static vec4 fwidth(vec4 p) { throw _invalidAccess; } 60 | 61 | #endregion 62 | } 63 | } 64 | 65 | // ReSharper restore InconsistentNaming 66 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.Noise.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | 3 | namespace IIS.SLSharp.Shaders 4 | { 5 | public abstract partial class ShaderDefinition 6 | { 7 | // Noise functions are available to fragment, geometry, and vertex shaders. They are stochastic functions that 8 | // can be used to increase visual complexity. Values returned by the following noise functions give the 9 | // appearance of randomness, but are not truly random. 10 | 11 | #region float Noise1(genType x) 12 | 13 | /// Returns a 1D noise value based on the input value x. 14 | protected internal static float Noise1(float x) { throw _invalidAccess; } 15 | 16 | /// Returns a 1D noise value based on the input value x. 17 | protected internal static float Noise1(vec2 x) { throw _invalidAccess; } 18 | 19 | /// Returns a 1D noise value based on the input value x. 20 | protected internal static float Noise1(vec3 x) { throw _invalidAccess; } 21 | 22 | /// Returns a 1D noise value based on the input value x. 23 | protected internal static float Noise1(vec4 x) { throw _invalidAccess; } 24 | 25 | #endregion 26 | 27 | #region vec2 Noise2(genType x) 28 | 29 | /// Returns a 2D noise value based on the input value x. 30 | protected internal static vec2 Noise2(float x) { throw _invalidAccess; } 31 | 32 | /// Returns a 2D noise value based on the input value x. 33 | protected internal static vec2 Noise2(vec2 x) { throw _invalidAccess; } 34 | 35 | /// Returns a 2D noise value based on the input value x. 36 | protected internal static vec2 Noise2(vec3 x) { throw _invalidAccess; } 37 | 38 | /// Returns a 2D noise value based on the input value x. 39 | protected internal static vec2 Noise2(vec4 x) { throw _invalidAccess; } 40 | 41 | #endregion 42 | 43 | #region vec3 Noise3(genType x) 44 | 45 | /// Returns a 3D noise value based on the input value x. 46 | protected internal static vec3 Noise3(float x) { throw _invalidAccess; } 47 | 48 | /// Returns a 3D noise value based on the input value x. 49 | protected internal static vec3 Noise3(vec2 x) { throw _invalidAccess; } 50 | 51 | /// Returns a 3D noise value based on the input value x. 52 | protected internal static vec3 Noise3(vec3 x) { throw _invalidAccess; } 53 | 54 | /// Returns a 3D noise value based on the input value x. 55 | protected internal static vec3 Noise3(vec4 x) { throw _invalidAccess; } 56 | 57 | #endregion 58 | 59 | #region vec4 Noise4(genType x) 60 | 61 | /// Returns a 4D noise value based on the input value x. 62 | protected internal static vec4 Noise4(float x) { throw _invalidAccess; } 63 | 64 | /// Returns a 4D noise value based on the input value x. 65 | protected internal static vec4 Noise4(vec2 x) { throw _invalidAccess; } 66 | 67 | /// Returns a 4D noise value based on the input value x. 68 | protected internal static vec4 Noise4(vec3 x) { throw _invalidAccess; } 69 | 70 | /// Returns a 4D noise value based on the input value x. 71 | protected internal static vec4 Noise4(vec4 x) { throw _invalidAccess; } 72 | 73 | #endregion 74 | } 75 | } 76 | 77 | // ReSharper restore InconsistentNaming 78 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.Sampler.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable InconsistentNaming 2 | 3 | namespace IIS.SLSharp.Shaders 4 | { 5 | public abstract partial class ShaderDefinition 6 | { 7 | public class Sampler 8 | { 9 | } 10 | 11 | public class SamplerTmp 12 | { 13 | } 14 | 15 | public sealed class sampler1D : Sampler 16 | { 17 | public static implicit operator sampler1D(SamplerTmp s) { return null; } 18 | } 19 | 20 | public sealed class sampler2D : Sampler 21 | { 22 | public static implicit operator sampler2D(SamplerTmp s) { return null; } 23 | } 24 | 25 | public sealed class sampler3D : Sampler 26 | { 27 | public static implicit operator sampler3D(SamplerTmp s) { return null; } 28 | } 29 | 30 | public sealed class samplerCube : Sampler 31 | { 32 | public static implicit operator samplerCube(SamplerTmp s) { return null; } 33 | } 34 | 35 | public sealed class sampler1DShadow : Sampler 36 | { 37 | public static implicit operator sampler1DShadow(SamplerTmp s) { return null; } 38 | } 39 | 40 | public sealed class sampler2DShadow : Sampler 41 | { 42 | public static implicit operator sampler2DShadow(SamplerTmp s) { return null; } 43 | } 44 | 45 | public sealed class samplerCubeShadow : Sampler 46 | { 47 | public static implicit operator samplerCubeShadow(SamplerTmp s) { return null; } 48 | } 49 | 50 | public sealed class isampler1D : Sampler 51 | { 52 | public static implicit operator isampler1D(SamplerTmp s) { return null; } 53 | } 54 | 55 | public sealed class isampler2D : Sampler 56 | { 57 | public static implicit operator isampler2D(SamplerTmp s) { return null; } 58 | } 59 | 60 | public sealed class isampler3D : Sampler 61 | { 62 | public static implicit operator isampler3D(SamplerTmp s) { return null; } 63 | } 64 | 65 | public sealed class isamplerCube : Sampler 66 | { 67 | public static implicit operator isamplerCube(SamplerTmp s) { return null; } 68 | } 69 | 70 | public sealed class usampler1D : Sampler 71 | { 72 | public static implicit operator usampler1D(SamplerTmp s) { return null; } 73 | } 74 | 75 | public sealed class usampler2D : Sampler 76 | { 77 | public static implicit operator usampler2D(SamplerTmp s) { return null; } 78 | } 79 | 80 | public sealed class usampler3D : Sampler 81 | { 82 | public static implicit operator usampler3D(SamplerTmp s) { return null; } 83 | } 84 | 85 | public sealed class usamplerCube : Sampler 86 | { 87 | public static implicit operator usamplerCube(SamplerTmp s) { return null; } 88 | } 89 | 90 | public sealed class sampler2DRect : Sampler 91 | { 92 | public static implicit operator sampler2DRect(SamplerTmp s) { return null; } 93 | } 94 | 95 | public sealed class sampler2DRectShadow : Sampler 96 | { 97 | public static implicit operator sampler2DRectShadow(SamplerTmp s) { return null; } 98 | } 99 | 100 | public sealed class isampler2DRect : Sampler 101 | { 102 | public static implicit operator isampler2DRect(SamplerTmp s) { return null; } 103 | } 104 | 105 | public sealed class usampler2DRect : Sampler 106 | { 107 | public static implicit operator usampler2DRect(SamplerTmp s) { return null; } 108 | } 109 | } 110 | } 111 | 112 | // ReSharper restore InconsistentNaming 113 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.Special.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace IIS.SLSharp.Shaders 7 | { 8 | public abstract partial class ShaderDefinition 9 | { 10 | /// 11 | /// Discards the current fragment. 12 | /// 13 | protected internal static void Discard() { throw _invalidAccess; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IIS.SLSharp/Shaders/ShaderDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IIS.SLSharp.Shaders 4 | { 5 | /// 6 | /// Contains definitions to allow GLSL syntax within Shaders 7 | /// 8 | public abstract partial class ShaderDefinition 9 | { 10 | private static readonly Exception _invalidAccess = new InvalidOperationException("Invalid usage"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/GLSL/GlslTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | using ICSharpCode.Decompiler; 6 | using ICSharpCode.Decompiler.Ast; 7 | using IIS.SLSharp.Descriptions; 8 | using IIS.SLSharp.Shaders; 9 | using Mono.Cecil; 10 | 11 | namespace IIS.SLSharp.Translation.GLSL 12 | { 13 | public sealed class GlslTransform: ITransform 14 | { 15 | private readonly HashSet> _functions = new HashSet>(); 16 | 17 | private readonly HashSet _dependencies = new HashSet(); 18 | 19 | public void ResetState() 20 | { 21 | _functions.Clear(); 22 | _dependencies.Clear(); 23 | } 24 | 25 | /// 26 | /// Public translation interface. 27 | /// Translates the given method to GLSL 28 | /// 29 | /// Shader type definition. 30 | /// A method representing a shader to translate. 31 | /// The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute 32 | /// The shader type as ShaderType 33 | /// The translated GLSL shader source 34 | public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr, 35 | ShaderType type) 36 | { 37 | if (s == null) 38 | throw new ArgumentNullException("s"); 39 | 40 | if (m == null) 41 | throw new ArgumentNullException("m"); 42 | 43 | if (attr == null) 44 | throw new ArgumentNullException("attr"); 45 | 46 | var ctx = new DecompilerContext(s.Module) 47 | { 48 | CurrentType = s, 49 | CurrentMethod = m, 50 | CancellationToken = CancellationToken.None 51 | }; 52 | 53 | var d = AstMethodBodyBuilder.CreateMethodBody(m, ctx); 54 | 55 | var glsl = new GlslVisitor(d, attr, ctx); 56 | 57 | _functions.UnionWith(glsl.Functions); 58 | 59 | var sig = GlslVisitor.GetSignature(m); 60 | var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value; 61 | var code = glsl.Result; 62 | var desc = new FunctionDescription(Shader.GetMethodName(m), sig + code, entry, type); 63 | 64 | _dependencies.UnionWith(glsl.Dependencies); 65 | 66 | return desc; 67 | } 68 | 69 | public List ForwardDeclare(bool debugInfo) 70 | { 71 | return _functions.Select(f => f.Item1 + ";" + (debugInfo ? " // " + f.Item2 : string.Empty)).ToList(); 72 | } 73 | 74 | private Shader[] _workaroundDependencies; 75 | 76 | public IEnumerable WorkaroundDependencies 77 | { 78 | get 79 | { 80 | return _workaroundDependencies ?? (_workaroundDependencies = new Shader[] 81 | { 82 | Shader.CreateInstance(), 83 | Shader.CreateInstance() 84 | }); 85 | } 86 | } 87 | 88 | public IEnumerable Dependencies 89 | { 90 | get { return _dependencies; } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/GLSL/GlslVisitor.Unimplemented.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using ICSharpCode.NRefactory.CSharp; 4 | using ICSharpCode.NRefactory.PatternMatching; 5 | 6 | namespace IIS.SLSharp.Translation.GLSL 7 | { 8 | internal sealed partial class GlslVisitor 9 | { 10 | public override StringBuilder VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, int data) 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override StringBuilder VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, int data) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override StringBuilder VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, int data) 21 | { 22 | return null; 23 | } 24 | 25 | public override StringBuilder VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, int data) 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | 30 | public override StringBuilder VisitIndexerExpression(IndexerExpression indexerExpression, int data) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | 35 | public override StringBuilder VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, int data) 36 | { 37 | throw new NotImplementedException(); 38 | } 39 | 40 | public override StringBuilder VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, int data) 41 | { 42 | return null; 43 | } 44 | 45 | public override StringBuilder VisitUncheckedExpression(UncheckedExpression uncheckedExpression, int data) 46 | { 47 | return new StringBuilder(); 48 | } 49 | 50 | public override StringBuilder VisitEmptyExpression(EmptyExpression emptyExpression, int data) 51 | { 52 | throw new NotImplementedException(); 53 | } 54 | 55 | public override StringBuilder VisitEmptyStatement(EmptyStatement emptyStatement, int data) 56 | { 57 | return new StringBuilder(); 58 | } 59 | 60 | public override StringBuilder VisitForeachStatement(ForeachStatement foreachStatement, int data) 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | public override StringBuilder VisitUncheckedStatement(UncheckedStatement uncheckedStatement, int data) 66 | { 67 | return new StringBuilder(); 68 | } 69 | 70 | public override StringBuilder VisitComposedType(ComposedType composedType, int data) 71 | { 72 | throw new NotImplementedException(); 73 | } 74 | 75 | public override StringBuilder VisitArraySpecifier(ArraySpecifier arraySpecifier, int data) 76 | { 77 | throw new NotImplementedException(); 78 | } 79 | 80 | public override StringBuilder VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, int data) 81 | { 82 | throw new NotImplementedException(); 83 | } 84 | 85 | public override StringBuilder VisitIdentifier(Identifier identifier, int data) 86 | { 87 | throw new NotImplementedException(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/GLSL/Workarounds/Exponential.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IIS.SLSharp.Annotations; 6 | using IIS.SLSharp.Shaders; 7 | 8 | namespace IIS.SLSharp.Translation.GLSL.Workarounds 9 | { 10 | public class Exponential: Shader 11 | { 12 | // 1/Log(10) 13 | const float InverseLog10 = 0.4342944819032518276511289189166f; 14 | 15 | #region genType Log10(genType x) 16 | 17 | [FragmentShader] 18 | [VertexShader] 19 | internal new float Log10(float x) 20 | { 21 | return Log(x) * InverseLog10; 22 | } 23 | 24 | [FragmentShader] 25 | [VertexShader] 26 | internal new vec2 Log10(vec2 x) 27 | { 28 | return Log(x) * InverseLog10; 29 | } 30 | 31 | [FragmentShader] 32 | [VertexShader] 33 | internal new vec3 Log10(vec3 x) 34 | { 35 | return Log(x) * InverseLog10; 36 | } 37 | 38 | [FragmentShader] 39 | [VertexShader] 40 | internal new vec4 Log10(vec4 x) 41 | { 42 | return Log(x) * InverseLog10; 43 | } 44 | 45 | #endregion 46 | 47 | #region genType Exp10(genType x) 48 | 49 | [FragmentShader] 50 | [VertexShader] 51 | internal new float Exp10(float x) 52 | { 53 | return Pow(10.0f, x); 54 | } 55 | 56 | [FragmentShader] 57 | [VertexShader] 58 | internal new vec2 Exp10(vec2 x) 59 | { 60 | return Pow(new vec2(10.0f), x); 61 | } 62 | 63 | [FragmentShader] 64 | [VertexShader] 65 | internal new vec3 Exp10(vec3 x) 66 | { 67 | return Pow(new vec3(10.0f), x); 68 | } 69 | 70 | [FragmentShader] 71 | [VertexShader] 72 | internal new vec4 Exp10(vec4 x) 73 | { 74 | return Pow(new vec4(10.0f), x); 75 | } 76 | 77 | #endregion 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/GLSL/Workarounds/Trigonometric.cs: -------------------------------------------------------------------------------- 1 | using IIS.SLSharp.Annotations; 2 | using IIS.SLSharp.Shaders; 3 | 4 | namespace IIS.SLSharp.Translation.GLSL.Workarounds 5 | { 6 | public class Trigonometric: Shader 7 | { 8 | [FragmentShader] 9 | [VertexShader] 10 | internal new void SinCos(float angle, out float s, out float c) 11 | { 12 | s = Sin(angle); 13 | c = Cos(angle); 14 | } 15 | 16 | [FragmentShader] 17 | [VertexShader] 18 | internal new void SinCos(vec2 angle, out vec2 s, out vec2 c) 19 | { 20 | s = Sin(angle); 21 | c = Cos(angle); 22 | } 23 | 24 | [FragmentShader] 25 | [VertexShader] 26 | internal new void SinCos(vec3 angle, out vec3 s, out vec3 c) 27 | { 28 | s = Sin(angle); 29 | c = Cos(angle); 30 | } 31 | 32 | [FragmentShader] 33 | [VertexShader] 34 | internal new void SinCos(vec4 angle, out vec4 s, out vec4 c) 35 | { 36 | s = Sin(angle); 37 | c = Cos(angle); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/HLSL/HlslVisitor.Unimplemented.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using ICSharpCode.NRefactory.CSharp; 4 | using ICSharpCode.NRefactory.PatternMatching; 5 | 6 | namespace IIS.SLSharp.Translation.HLSL 7 | { 8 | internal sealed partial class HlslVisitor 9 | { 10 | public override StringBuilder VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, int data) 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override StringBuilder VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, int data) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override StringBuilder VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, int data) 21 | { 22 | return null; 23 | } 24 | 25 | public override StringBuilder VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, int data) 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | 30 | public override StringBuilder VisitIndexerExpression(IndexerExpression indexerExpression, int data) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | 35 | public override StringBuilder VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, int data) 36 | { 37 | throw new NotImplementedException(); 38 | } 39 | 40 | public override StringBuilder VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, int data) 41 | { 42 | return null; 43 | } 44 | 45 | public override StringBuilder VisitUncheckedExpression(UncheckedExpression uncheckedExpression, int data) 46 | { 47 | return new StringBuilder(); 48 | } 49 | 50 | public override StringBuilder VisitEmptyExpression(EmptyExpression emptyExpression, int data) 51 | { 52 | throw new NotImplementedException(); 53 | } 54 | 55 | public override StringBuilder VisitEmptyStatement(EmptyStatement emptyStatement, int data) 56 | { 57 | return new StringBuilder(); 58 | } 59 | 60 | public override StringBuilder VisitForeachStatement(ForeachStatement foreachStatement, int data) 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | public override StringBuilder VisitUncheckedStatement(UncheckedStatement uncheckedStatement, int data) 66 | { 67 | return new StringBuilder(); 68 | } 69 | 70 | public override StringBuilder VisitComposedType(ComposedType composedType, int data) 71 | { 72 | throw new NotImplementedException(); 73 | } 74 | 75 | public override StringBuilder VisitArraySpecifier(ArraySpecifier arraySpecifier, int data) 76 | { 77 | throw new NotImplementedException(); 78 | } 79 | 80 | public override StringBuilder VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, int data) 81 | { 82 | throw new NotImplementedException(); 83 | } 84 | 85 | public override StringBuilder VisitIdentifier(Identifier identifier, int data) 86 | { 87 | throw new NotImplementedException(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/HLSL/Workarounds/Exponential.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using IIS.SLSharp.Annotations; 6 | using IIS.SLSharp.Shaders; 7 | 8 | namespace IIS.SLSharp.Translation.HLSL.Workarounds 9 | { 10 | public class Exponential: Shader 11 | { 12 | #region genType Exp10(genType x) 13 | 14 | [FragmentShader] 15 | [VertexShader] 16 | internal new float Exp10(float x) 17 | { 18 | return Pow(10.0f, x); 19 | } 20 | 21 | [FragmentShader] 22 | [VertexShader] 23 | internal new vec2 Exp10(vec2 x) 24 | { 25 | return Pow(new vec2(10.0f), x); 26 | } 27 | 28 | [FragmentShader] 29 | [VertexShader] 30 | internal new vec3 Exp10(vec3 x) 31 | { 32 | return Pow(new vec3(10.0f), x); 33 | } 34 | 35 | [FragmentShader] 36 | [VertexShader] 37 | internal new vec4 Exp10(vec4 x) 38 | { 39 | return Pow(new vec4(10.0f), x); 40 | } 41 | 42 | #endregion 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/ITransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using IIS.SLSharp.Descriptions; 5 | using IIS.SLSharp.Shaders; 6 | using Mono.Cecil; 7 | 8 | namespace IIS.SLSharp.Translation 9 | { 10 | public interface ITransform 11 | { 12 | /// 13 | /// Resets the internal state for reuse 14 | /// 15 | void ResetState(); 16 | 17 | /// 18 | /// Translates a single shader method 19 | /// 20 | /// The shader defining the method 21 | /// The method to translate 22 | /// The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute 23 | /// The shader type as ShaderType 24 | /// The source for the translated function 25 | FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr, ShaderType type); 26 | 27 | /// 28 | /// Generates a string that forward declarates all functions used within a shader. 29 | /// 30 | /// Include descriptive elements 31 | /// 32 | List ForwardDeclare(bool debugInfo); 33 | 34 | /// 35 | /// Returns a list of possible workaround libraries 36 | /// TODO: this shall become obsolete when auto determining depdendencies 37 | /// 38 | IEnumerable WorkaroundDependencies { get; } 39 | 40 | IEnumerable Dependencies { get; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/RenameLocals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using ICSharpCode.Decompiler.Ast.Transforms; 4 | using ICSharpCode.NRefactory.CSharp; 5 | 6 | namespace IIS.SLSharp.Translation 7 | { 8 | internal sealed class RenameLocals : IAstTransform 9 | { 10 | private int _ctr; 11 | 12 | private readonly Dictionary _locals = new Dictionary(); 13 | 14 | public void Run(AstNode node) 15 | { 16 | if (node == null) 17 | throw new ArgumentNullException("node"); 18 | 19 | var initializer = node as VariableInitializer; 20 | if (initializer != null) 21 | { 22 | var newName = "_loc" + _ctr++; 23 | _locals[initializer.Name] = newName; 24 | initializer.ReplaceWith(new VariableInitializer(newName, initializer.Initializer)); 25 | } 26 | else 27 | { 28 | var identifier = node as IdentifierExpression; 29 | if (identifier != null) 30 | { 31 | string newName; 32 | if (_locals.TryGetValue(identifier.Identifier, out newName)) 33 | identifier.ReplaceWith(new IdentifierExpression(newName)); 34 | } 35 | } 36 | 37 | foreach (var c in node.Children) 38 | Run(c); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ICSharpCode.NRefactory.CSharp; 6 | 7 | namespace IIS.SLSharp.Translation 8 | { 9 | static class Utility 10 | { 11 | public static StringBuilder ArgsToString(this ICollection args, IAstVisitor visitor) 12 | { 13 | var result = new StringBuilder(); 14 | if (args.Count <= 0) 15 | return result; 16 | 17 | foreach (var v in args.Take(args.Count - 1)) 18 | { 19 | result.Append(v.AcceptVisitor(visitor, 0)); 20 | result.Append(", "); 21 | } 22 | 23 | result.Append(args.Last().AcceptVisitor(visitor, 0)); 24 | return result; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /IIS.SLSharp/Translation/VisitorBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using ICSharpCode.NRefactory.CSharp; 8 | using ICSharpCode.NRefactory.PatternMatching; 9 | using Mono.Cecil; 10 | using Attribute = ICSharpCode.NRefactory.CSharp.Attribute; 11 | 12 | namespace IIS.SLSharp.Translation 13 | { 14 | internal abstract partial class VisitorBase : IAstVisitor 15 | { 16 | public readonly HashSet Dependencies = new HashSet(); 17 | 18 | protected void Warn(string message, params object[] args) 19 | { 20 | var msg = String.Format(message, args); 21 | Debug.WriteLine("Warning: " + msg); 22 | } 23 | 24 | protected void Error(string message, params object[] args) 25 | { 26 | var msg = String.Format(message, args); 27 | Debug.WriteLine("Error: " + msg); 28 | } 29 | 30 | private int _tempCounter; 31 | 32 | protected VariableDeclarationStatement ToTemp(Expression e) 33 | { 34 | return new VariableDeclarationStatement(null, "__tmp" + _tempCounter++, e.Clone()); 35 | } 36 | 37 | protected StringBuilder ArgsToString(ICollection args) 38 | { 39 | var result = new StringBuilder(); 40 | if (args.Count <= 0) 41 | return result; 42 | 43 | foreach (var v in args.Take(args.Count - 1)) 44 | { 45 | result.Append(v.AcceptVisitor(this, 0)); 46 | result.Append(", "); 47 | } 48 | 49 | result.Append(args.Last().AcceptVisitor(this, 0)); 50 | return result; 51 | } 52 | 53 | protected static StringBuilder Indent(AstNode node, StringBuilder b) 54 | { 55 | if (node is BlockStatement) 56 | return b; 57 | 58 | var res = new StringBuilder(); 59 | 60 | res.Append("\t"); 61 | res.Append(b.Replace(Environment.NewLine, Environment.NewLine + "\t")); 62 | 63 | return res; 64 | } 65 | 66 | private static Type GetType(TypeDefinition td) 67 | { 68 | var qualifiedName = Assembly.CreateQualifiedName(td.Module.Assembly.FullName, td.FullName); 69 | return Type.GetType(qualifiedName, true); 70 | } 71 | 72 | protected void AddDependency(MethodDefinition m) 73 | { 74 | var dependency = m.DeclaringType.Resolve(); 75 | Dependencies.Add(GetType(dependency)); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011 Ignite Interactive Studio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Local.testsettings: -------------------------------------------------------------------------------- 1 |  2 | 3 | These are default test settings for a local test run. 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SL#: Runtime IL -> Shader Translator 2 | ==================================== 3 | 4 | Introduction 5 | ------------ 6 | 7 | SL# is a runtime IL-to-GLSL/HLSL translation engine, written in pure C#. It 8 | takes the compiled IL of a shader definition written in a managed language 9 | (usually C#), and generates GLSL or HLSL shader code from it. The shader code 10 | is automatically uploaded to the GPU, and you can use the shader object as any 11 | other object in .NET. Shaders can have properties that map directly to uniform 12 | and varying variables in the GLSL/HLSL code, allowing you to easily interact 13 | with your GPU code from the CPU. 14 | 15 | Please note that SL# is currently a very experimental library. The syntax and 16 | usage may be subject to change at any time, as we further research what design 17 | is the most sane for the project. 18 | 19 | Rationale 20 | --------- 21 | 22 | There are quite a few advantages to this approach: 23 | 24 | * Developers can use existing development tools (Visual Studio, MonoDevelop, 25 | SharpDevelop, etc.) to develop shaders. This means code completion, syntax 26 | checking, and so on. 27 | * Shaders are validated at compile time. Any syntactical or semantical errors 28 | are caught by the C# compiler, rather than at runtime when interacting with 29 | the GPU. 30 | * No more storing shaders as huge strings in source code, or storing them as 31 | resources. They're compiled directly to IL. 32 | 33 | Dependencies 34 | ------------ 35 | 36 | SL# currently depends on Mono.Cecil, ICSharpCode.NRefactory, 37 | ICSharpCode.Decompiler, as well as additional dependencies for the bindings. 38 | 39 | Issues 40 | ------ 41 | 42 | Please report any issues on the GitHub issue tracker. 43 | 44 | Known problems: 45 | 46 | * Geometry shaders are currently not supported. 47 | * Support for other .NET languages (such as F#) is currently up in the air. We 48 | haven't had time to test SL# with F# yet, but we would definitely like to add 49 | support for it in the future (perhaps using quotations). 50 | * HLSL support is currently at a bare minimum. 51 | * Resource management is not very flexible; it relies heavily on static state. 52 | This currently limits how well SL# can use multiple rendering contexts. We will 53 | definitely fix this in the future. 54 | -------------------------------------------------------------------------------- /Resources/box.mesh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Resources/box.mesh -------------------------------------------------------------------------------- /Resources/height.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Resources/height.jpg -------------------------------------------------------------------------------- /Resources/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Resources/tiles.png -------------------------------------------------------------------------------- /Resources/xwing.xnb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/Resources/xwing.xnb -------------------------------------------------------------------------------- /SLSharp.vsmdi: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SolutionInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgniteInteractiveStudio/SLSharp/74b532dbb2ccc11ce4bfdc386f2f24e10bbe3c93/SolutionInfo.cs --------------------------------------------------------------------------------