mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Shader #include + Remved unused Dx11Effect
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include "ShaderFunctions.hlsl"
|
||||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
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
|
||||
* cnrm: The x- and y-components of a normalized normal vector
|
||||
*/
|
||||
float3 DecompressNormal(float2 cnrm)
|
||||
{
|
||||
return float3(cnrm, sqrt(1.0 - cnrm.x * cnrm.x - cnrm.y * cnrm.y));
|
||||
}
|
||||
//float3 DecompressNormal(float2 cnrm)
|
||||
//{
|
||||
// return float3(cnrm, sqrt(1.0 - cnrm.x * cnrm.x - cnrm.y * cnrm.y));
|
||||
//}
|
||||
|
||||
float4 PS(PS_IN input) : SV_TARGET
|
||||
{
|
||||
|
||||
@@ -116,8 +116,7 @@ namespace GlitchyEditor
|
||||
|
||||
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 normal = new Texture2D("Textures/TestMat/rustediron2_normal.png"))
|
||||
using (Texture2D rough = new Texture2D("Textures/TestMat/rustediron2_roughness.png"))
|
||||
@@ -127,31 +126,34 @@ namespace GlitchyEditor
|
||||
normal.SamplerState = SamplerStateManager.AnisotropicClamp;
|
||||
rough.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();
|
||||
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());
|
||||
|
||||
clips = scope .();
|
||||
|
||||
ModelLoader.LoadModel("content/Models/sphere.glb", myEffect, mat, _scene.[Friend]_ecsWorld, clips);
|
||||
|
||||
List<AnimationClip> clips = scope .();
|
||||
|
||||
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, 0, 1, 1));
|
||||
//mat.SetVariable("LightDir", Vector3(1, 1, 0).Normalized());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
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!();
|
||||
|
||||
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");
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace GlitchyEngine.Renderer
|
||||
.OptimizationLevel3;
|
||||
#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!();
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace GlitchyEngine.Renderer
|
||||
ID3DBlob* errorBlob = 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)
|
||||
{
|
||||
StringView str = StringView((char8*)errorBlob.GetBufferPointer(), (int)errorBlob.GetBufferSize());
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
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!();
|
||||
|
||||
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");
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
ProcessFile(filename, fileContent, vsName, psName);
|
||||
|
||||
Compile(fileContent, vsName, psName);
|
||||
Compile(fileContent, filename, vsName, psName);
|
||||
|
||||
MergeResources();
|
||||
|
||||
@@ -268,15 +268,15 @@ namespace GlitchyEngine.Renderer
|
||||
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!();
|
||||
|
||||
// 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;
|
||||
vs.ReleaseRef();
|
||||
let ps = new PixelShader(fileContent, psEntry);
|
||||
let ps = new PixelShader(fileContent, (StringView)fileName, psEntry);
|
||||
PixelShader = ps;
|
||||
ps.ReleaseRef();
|
||||
}
|
||||
@@ -349,7 +349,7 @@ namespace GlitchyEngine.Renderer
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace GlitchyEngine.Renderer
|
||||
public class PixelShader : Shader
|
||||
{
|
||||
[AllowAppend]
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(source, entryPoint, macros) { }
|
||||
public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(code, fileName, entryPoint, macros) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace GlitchyEngine.Renderer
|
||||
public ShaderTextureCollection Textures => _textures;
|
||||
|
||||
[AllowAppend]
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace GlitchyEngine.Renderer
|
||||
_buffers = new BufferCollection();
|
||||
_textures = new ShaderTextureCollection();
|
||||
|
||||
CompileFromSource(source, entryPoint);
|
||||
CompileFromSource(code, fileName, entryPoint);
|
||||
}
|
||||
|
||||
public ~this()
|
||||
@@ -52,15 +52,14 @@ namespace GlitchyEngine.Renderer
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
String fileContent = new String();
|
||||
|
||||
File.ReadAllText(fileName, fileContent, true);
|
||||
T shader = new T(fileContent, entryPoint, macros);
|
||||
T shader = new T(fileContent, (StringView)fileName, entryPoint, macros);
|
||||
|
||||
delete fileContent;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace GlitchyEngine.Renderer
|
||||
public class VertexShader : Shader
|
||||
{
|
||||
[AllowAppend]
|
||||
public this(String source, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(source, entryPoint, macros) { }
|
||||
public this(StringView code, StringView? fileName, String entryPoint, ShaderDefine[] macros = null)
|
||||
: base(code, fileName, entryPoint, macros) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user