Shader #include + Remved unused Dx11Effect

This commit is contained in:
Simon Lübeß
2022-05-09 18:19:24 +02:00
parent dc235399c8
commit 3c2c37b270
10 changed files with 53 additions and 81 deletions
@@ -1,3 +1,5 @@
#include "ShaderFunctions.hlsl"
#define PI 3.14159265358979323846f #define PI 3.14159265358979323846f
SamplerState Sampler : register(s0); SamplerState Sampler : register(s0);
@@ -109,10 +111,10 @@ float3 FresnelSchlick(float cosTheta, float3 F0)
* Reconstructs the z-component of a normalized normal vector from a two-component value * Reconstructs the z-component of a normalized normal vector from a two-component value
* cnrm: The x- and y-components of a normalized normal vector * cnrm: The x- and y-components of a normalized normal vector
*/ */
float3 DecompressNormal(float2 cnrm) //float3 DecompressNormal(float2 cnrm)
{ //{
return float3(cnrm, sqrt(1.0 - cnrm.x * cnrm.x - cnrm.y * cnrm.y)); // return float3(cnrm, sqrt(1.0 - cnrm.x * cnrm.x - cnrm.y * cnrm.y));
} //}
float4 PS(PS_IN input) : SV_TARGET float4 PS(PS_IN input) : SV_TARGET
{ {
+28 -26
View File
@@ -116,8 +116,7 @@ namespace GlitchyEditor
private void TestEntitiesWithModels() private void TestEntitiesWithModels()
{ {
Effect myEffect = new Effect("content/Shaders/myEffect.hlsl")..ReleaseRefNoDelete(); using (Effect myEffect = new Effect("content/Shaders/myEffect.hlsl"))
using (Texture2D albedo = new Texture2D("Textures/TestMat/rustediron2_albedo.png", true)) using (Texture2D albedo = new Texture2D("Textures/TestMat/rustediron2_albedo.png", true))
using (Texture2D normal = new Texture2D("Textures/TestMat/rustediron2_normal.png")) using (Texture2D normal = new Texture2D("Textures/TestMat/rustediron2_normal.png"))
using (Texture2D rough = new Texture2D("Textures/TestMat/rustediron2_roughness.png")) using (Texture2D rough = new Texture2D("Textures/TestMat/rustediron2_roughness.png"))
@@ -127,31 +126,34 @@ namespace GlitchyEditor
normal.SamplerState = SamplerStateManager.AnisotropicClamp; normal.SamplerState = SamplerStateManager.AnisotropicClamp;
rough.SamplerState = SamplerStateManager.AnisotropicClamp; rough.SamplerState = SamplerStateManager.AnisotropicClamp;
metal.SamplerState = SamplerStateManager.AnisotropicClamp; metal.SamplerState = SamplerStateManager.AnisotropicClamp;
Material mat = new Material(myEffect)..ReleaseRefNoDelete();
mat.SetTexture("AlbedoTexture", albedo);
mat.SetTexture("NormalTexture", normal);
mat.SetTexture("MetallicTexture", metal);
mat.SetTexture("RoughnessTexture", rough);
//mat.SetVariable("BaseColor", Vector4(1, 0, 1, 1));
//mat.SetVariable("LightDir", Vector3(1, 1, 0).Normalized());
List<AnimationClip> clips = scope .();
ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips);
mat = new Material(myEffect)..ReleaseRefNoDelete(); List<AnimationClip> clips = scope .();
mat.SetTexture("AlbedoTexture", albedo);
mat.SetTexture("NormalTexture", normal); using (Material mat = new .(myEffect))
mat.SetTexture("MetallicTexture", metal); {
mat.SetTexture("RoughnessTexture", rough); mat.SetTexture("AlbedoTexture", albedo);
//mat.SetVariable("BaseColor", Vector4(1, 1, 0, 1)); mat.SetTexture("NormalTexture", normal);
//mat.SetVariable("LightDir", Vector3(0, 1, 0).Normalized()); mat.SetTexture("MetallicTexture", metal);
mat.SetTexture("RoughnessTexture", rough);
clips = scope .(); //mat.SetVariable("BaseColor", Vector4(1, 0, 1, 1));
//mat.SetVariable("LightDir", Vector3(1, 1, 0).Normalized());
ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips);
ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips);
}
using (Material mat = new .(myEffect))
{
mat.SetTexture("AlbedoTexture", albedo);
mat.SetTexture("NormalTexture", normal);
mat.SetTexture("MetallicTexture", metal);
mat.SetTexture("RoughnessTexture", rough);
//mat.SetVariable("BaseColor", Vector4(1, 1, 0, 1));
//mat.SetVariable("LightDir", Vector3(0, 1, 0).Normalized());
ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips);
}
ClearAndReleaseItems!(clips); ClearAndReleaseItems!(clips);
} }
} }
@@ -1,31 +0,0 @@
#if GE_GRAPHICS_DX11
using System;
using DirectX;
using DirectX.D3D11;
using internal GlitchyEngine.Renderer;
namespace GlitchyEngine.Renderer
{
extension Effect
{
protected override void Compile(String vsPath, String vsEntry, String psPath, String psEntry)
{
Debug.Profiler.ProfileResourceFunction!();
// Todo: macros
VertexShader = new VertexShader(vsPath, vsEntry);
PixelShader = new PixelShader(psPath, psEntry);
Reflect();
}
private void Reflect()
{
}
}
}
#endif
@@ -14,11 +14,11 @@ namespace GlitchyEngine.Renderer
{ {
internal ID3D11PixelShader* nativeShader ~ _?.Release(); internal ID3D11PixelShader* nativeShader ~ _?.Release();
public override void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null) public override void CompileFromSource(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
{ {
Debug.Profiler.ProfileRendererFunction!(); Debug.Profiler.ProfileRendererFunction!();
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "ps_5_0", DefaultCompileFlags, out nativeCode); Shader.PlattformCompileShaderFromSource(code, fileName, macros, entryPoint, "ps_5_0", DefaultCompileFlags, out nativeCode);
{ {
Debug.Profiler.ProfileResourceScope!("CreateNativePixelShader"); Debug.Profiler.ProfileResourceScope!("CreateNativePixelShader");
@@ -25,7 +25,7 @@ namespace GlitchyEngine.Renderer
.OptimizationLevel3; .OptimizationLevel3;
#endif #endif
internal static void PlattformCompileShaderFromSource(String code, ShaderDefine[] macros, String entryPoint, String target, ShaderCompileFlags compileFlags, out ID3DBlob* shaderBlob) internal static void PlattformCompileShaderFromSource(StringView code, StringView? fileName, ShaderDefine[] macros, String entryPoint, String target, ShaderCompileFlags compileFlags, out ID3DBlob* shaderBlob)
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
@@ -43,7 +43,7 @@ namespace GlitchyEngine.Renderer
ID3DBlob* errorBlob = null; ID3DBlob* errorBlob = null;
shaderBlob = null; shaderBlob = null;
var result = D3DCompiler.D3DCompile(code.CStr(), (.)code.Length, null, nativeMacros, null, entryPoint, target, compileFlags, .None, &shaderBlob, &errorBlob); var result = D3DCompiler.D3DCompile(code.Ptr, (.)code.Length, fileName?.ToScopeCStr!(), nativeMacros, ID3DInclude.StandardInclude, entryPoint, target, compileFlags, .None, &shaderBlob, &errorBlob);
if(result.Failed) if(result.Failed)
{ {
StringView str = StringView((char8*)errorBlob.GetBufferPointer(), (int)errorBlob.GetBufferSize()); StringView str = StringView((char8*)errorBlob.GetBufferPointer(), (int)errorBlob.GetBufferSize());
@@ -15,11 +15,11 @@ namespace GlitchyEngine.Renderer
{ {
internal ID3D11VertexShader* nativeShader ~ _?.Release(); internal ID3D11VertexShader* nativeShader ~ _?.Release();
public override void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null) public override void CompileFromSource(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
Shader.PlattformCompileShaderFromSource(code, macros, entryPoint, "vs_5_0", DefaultCompileFlags, out nativeCode); Shader.PlattformCompileShaderFromSource(code, fileName, macros, entryPoint, "vs_5_0", DefaultCompileFlags, out nativeCode);
{ {
Debug.Profiler.ProfileResourceScope!("CreateNativeVertexShader"); Debug.Profiler.ProfileResourceScope!("CreateNativeVertexShader");
+5 -5
View File
@@ -169,7 +169,7 @@ namespace GlitchyEngine.Renderer
ProcessFile(filename, fileContent, vsName, psName); ProcessFile(filename, fileContent, vsName, psName);
Compile(fileContent, vsName, psName); Compile(fileContent, filename, vsName, psName);
MergeResources(); MergeResources();
@@ -268,15 +268,15 @@ namespace GlitchyEngine.Renderer
ps.ReleaseRef(); ps.ReleaseRef();
} }
private void Compile(String fileContent, String vsEntry, String psEntry) private void Compile(String fileContent, String fileName, String vsEntry, String psEntry)
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
// TODO: vsEntry and psEntry could be empty (which is a valid case.) // TODO: vsEntry and psEntry could be empty (which is a valid case.)
let vs = new VertexShader(fileContent, vsEntry); let vs = new VertexShader(fileContent, (StringView)fileName, vsEntry);
VertexShader = vs; VertexShader = vs;
vs.ReleaseRef(); vs.ReleaseRef();
let ps = new PixelShader(fileContent, psEntry); let ps = new PixelShader(fileContent, (StringView)fileName, psEntry);
PixelShader = ps; PixelShader = ps;
ps.ReleaseRef(); ps.ReleaseRef();
} }
@@ -349,7 +349,7 @@ namespace GlitchyEngine.Renderer
fileContent.Remove(effectIndex, lineEndIndex - effectIndex); fileContent.Remove(effectIndex, lineEndIndex - effectIndex);
} }
protected extern void Compile(String vsPath, String vsEntry, String psPath, String psEntry); //protected extern void Compile(String code, String fileName, String vsEntry, String psEntry);
private void MergeResources() private void MergeResources()
{ {
+2 -2
View File
@@ -5,7 +5,7 @@ namespace GlitchyEngine.Renderer
public class PixelShader : Shader public class PixelShader : Shader
{ {
[AllowAppend] [AllowAppend]
public this(String source, String entryPoint, ShaderDefine[] macros = null) public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
: base(source, entryPoint, macros) { } : base(code, fileName, entryPoint, macros) { }
} }
} }
+4 -5
View File
@@ -30,7 +30,7 @@ namespace GlitchyEngine.Renderer
public ShaderTextureCollection Textures => _textures; public ShaderTextureCollection Textures => _textures;
[AllowAppend] [AllowAppend]
public this(String source, String entryPoint, ShaderDefine[] macros = null) public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
@@ -39,7 +39,7 @@ namespace GlitchyEngine.Renderer
_buffers = new BufferCollection(); _buffers = new BufferCollection();
_textures = new ShaderTextureCollection(); _textures = new ShaderTextureCollection();
CompileFromSource(source, entryPoint); CompileFromSource(code, fileName, entryPoint);
} }
public ~this() public ~this()
@@ -52,15 +52,14 @@ namespace GlitchyEngine.Renderer
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
String fileContent = new String(); String fileContent = new String();
File.ReadAllText(fileName, fileContent, true); File.ReadAllText(fileName, fileContent, true);
T shader = new T(fileContent, entryPoint, macros); T shader = new T(fileContent, (StringView)fileName, entryPoint, macros);
delete fileContent; delete fileContent;
shader shader
} }
public abstract void CompileFromSource(String code, String entryPoint, ShaderDefine[] macros = null); public abstract void CompileFromSource(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null);
} }
} }
+2 -2
View File
@@ -5,7 +5,7 @@ namespace GlitchyEngine.Renderer
public class VertexShader : Shader public class VertexShader : Shader
{ {
[AllowAppend] [AllowAppend]
public this(String source, String entryPoint, ShaderDefine[] macros = null) public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
: base(source, entryPoint, macros) { } : base(code, fileName, entryPoint, macros) { }
} }
} }