private ShaderCodeData ReadShaderCode(BfshaFileLoader loader, ShaderFormat format) { ShaderCodeData codeData = null; if (CompressionType == 1) { codeData = loader.Load <ShaderCodeDataCompressed>(); } else if (format == ShaderFormat.Source) { codeData = loader.Load <ShaderCodeDataSource>(); } else { codeData = loader.Load <ShaderCodeDataBinary>(); } return(codeData); }
static Byte[] GetUnlit_VertPosTexCol(ShaderFormat shaderFormat) { String source = ""; if (shaderFormat == ShaderFormat.HLSL) { throw new NotImplementedException (); } if (shaderFormat == ShaderFormat.GLSL) { source = @"Vertex Position, Texture Coordinate & Colour =VSH= attribute vec4 a_vertPosition; attribute vec2 a_vertTexcoord; attribute vec4 a_vertColour; uniform mat4 u_world; uniform mat4 u_view; uniform mat4 u_proj; uniform vec4 u_colour; varying vec2 v_texCoord; varying vec4 v_tint; void main() { gl_Position = u_proj * u_view * u_world * a_vertPosition; v_texCoord = a_vertTexcoord; v_tint = a_vertColour * u_colour; } =FSH= uniform sampler2D s_tex0; varying vec2 v_texCoord; varying vec4 v_tint; void main() { gl_FragColor = v_tint * texture2D(s_tex0, v_texCoord); } "; } if (shaderFormat == ShaderFormat.GLSL_ES) { source = @"Vertex Position, Texture Coordinate & Colour =VSH= attribute mediump vec4 a_vertPosition; attribute mediump vec2 a_vertTexcoord; attribute mediump vec4 a_vertColour; uniform mediump mat4 u_world; uniform mediump mat4 u_view; uniform mediump mat4 u_proj; uniform mediump vec4 u_colour; varying mediump vec2 v_texCoord; varying mediump vec4 v_tint; void main() { gl_Position = u_proj * u_view * u_world * a_vertPosition; v_texCoord = a_vertTexcoord; v_tint = a_vertColour * u_colour; } =FSH= uniform mediump sampler2D s_tex0; varying mediump vec2 v_texCoord; varying mediump vec4 v_tint; void main() { gl_FragColor = v_tint * texture2D(s_tex0, v_texCoord); } "; } return Encoding.UTF8.GetBytes (source); }
static Byte[] GetUnlit_VertPos(ShaderFormat shaderFormat) { String source = ""; if (shaderFormat == ShaderFormat.HLSL) { throw new NotImplementedException (); } if (shaderFormat == ShaderFormat.GLSL) { source = @"Vertex Position =VSH= attribute vec4 a_vertPosition; uniform mat4 u_world; uniform mat4 u_view; uniform mat4 u_proj; uniform vec4 u_colour; varying vec4 v_tint; void main() { gl_Position = u_proj * u_view * u_world * a_vertPosition; v_tint = u_colour; } =FSH= varying vec4 v_tint; void main() { gl_FragColor = v_tint; } "; } if (shaderFormat == ShaderFormat.GLSL_ES) { source = @"Vertex Position =VSH= attribute mediump vec4 a_vertPosition; uniform mediump mat4 u_world; uniform mediump mat4 u_view; uniform mediump mat4 u_proj; uniform mediump vec4 u_colour; varying mediump vec4 v_tint; void main() { gl_Position = u_proj * u_view * u_world * a_vertPosition; v_tint = u_colour; } =FSH= varying mediump vec4 v_tint; void main() { gl_FragColor = v_tint; } "; } return Encoding.UTF8.GetBytes (source); }
static Byte[] GetUnlitShaderSource(ShaderFormat shaderFormat) { var encodedVariants = new [] { GetUnlit_VertPos (shaderFormat), GetUnlit_VertPosTex (shaderFormat), GetUnlit_VertPosCol (shaderFormat), GetUnlit_VertPosTexCol (shaderFormat) }; using (var mem = new MemoryStream ()) { using (var bin = new BinaryWriter (mem)) { bin.Write ((Byte) encodedVariants.Length); foreach (var variant in encodedVariants) { bin.Write (variant.Length); bin.Write (variant); } } return mem.GetBuffer (); } }
public bool IsShaderFormatSupported(ShaderFormat format) => format == ShaderFormat.GLSL;
public abstract Shader CreateShader(ShaderFormat format, string vertex, string fragment, string geometry = null);
public abstract Shader CreateShader(ShaderFormat format, ReadOnlySpan <byte> vertex, ReadOnlySpan <byte> fragment, ReadOnlySpan <byte> geometry = default);
public abstract Shader CreateShader(ShaderFormat format, Stream vertex, Stream fragment, Stream geometry = null);
public abstract bool IsShaderFormatSupported(ShaderFormat format);