private void CreateRenderTargets(int width, int height) { Colors?.Dispose(); Albedo?.Dispose(); Normals?.Dispose(); Depth?.Dispose(); #if OPENGL Colors = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8); Albedo = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8); Normals = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8); Depth = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Vector2, DepthFormat.Depth24Stencil8); #else Colors = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8); Albedo = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8); Normals = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8); Depth = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Vector2, DepthFormat.Depth24Stencil8); #endif _bufferTextureSize = new Vector2(width, height); _gBufferTargets = new[] { new RenderTargetBinding(Colors), new RenderTargetBinding(Normals), new RenderTargetBinding(Depth), new RenderTargetBinding(Albedo) }; _lightMap?.Dispose(); _lightMap = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); }
public void Dispose() { Albedo?.Dispose(); NormalMap?.Dispose(); HeightMap?.Dispose(); Occlusion?.Dispose(); }
public static Task <byte[]> GenerateAsync( ShaderStage stage, Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Specular_Mask specular_mask, Material_Model material_model, Environment_Mapping environment_mapping, Self_Illumination self_illumination, Blend_Mode blend_mode, Parallax parallax, Misc misc, Distortion distortion, Soft_fade soft_fade ) { return(Task.Run(() => GenerateShader( stage, albedo, bump_mapping, alpha_test, specular_mask, material_model, environment_mapping, self_illumination, blend_mode, parallax, misc, distortion, soft_fade ))); }
internal Material(ColorF diffuseColor, Albedo albedo, float specularExponent, float refractiveIndex) { DiffuseColor = diffuseColor; Albedo = albedo; SpecularExponent = specularExponent; RefractiveIndex = refractiveIndex; }
public virtual void Scatter(Ray ray, Vector3 normal, Vector2 uv, Vector3 pos, out Vector3 vec, out Vector3 albedo) { float dot = VMath.Dot(normal, ray.vec); albedo = Albedo.GetColor(uv) * Math.Abs(dot); vec = CreateReflectedVector(ray, normal, pos); }
public FoliageGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.alpha_test = (Alpha_Test)options[1]; this.material_model = (Material_Model)options[2]; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public LightVolumeGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.blend_mode = (Blend_Mode)options[1]; this.fog = (Fog)options[2]; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public LightVolumeGenerator(Albedo albedo, Blend_Mode blend_mode, Fog fog, bool applyFixes = false) { this.albedo = albedo; this.blend_mode = blend_mode; this.fog = fog; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public FoliageGenerator(Albedo albedo, Alpha_Test alpha_test, Material_Model material_model, bool applyFixes = false) { this.albedo = albedo; this.alpha_test = alpha_test; this.material_model = material_model; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public BeamGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.blend_mode = (Blend_Mode)options[1]; this.black_point = (Black_Point)options[2]; this.fog = (Fog)options[3]; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public BeamGenerator(Albedo albedo, Blend_Mode blend_mode, Black_Point black_point, Fog fog, bool applyFixes = false) { this.albedo = albedo; this.blend_mode = blend_mode; this.black_point = black_point; this.fog = fog; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public DecalGenerator(Albedo albedo, Blend_Mode blend_mode, Render_Pass render_pass, Specular specular, Bump_Mapping bump_mapping, Tinting tinting, bool applyFixes = false) { this.albedo = albedo; this.blend_mode = blend_mode; this.render_pass = render_pass; this.specular = specular; this.bump_mapping = bump_mapping; this.tinting = tinting; ApplyFixes = applyFixes; DecalIsSimple = this.render_pass == Render_Pass.Pre_Lighting && this.bump_mapping == Bump_Mapping.Leave; TemplateGenerationValid = true; }
public DecalGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.blend_mode = (Blend_Mode)options[1]; this.render_pass = (Render_Pass)options[2]; this.specular = (Specular)options[3]; this.bump_mapping = (Bump_Mapping)options[4]; this.tinting = (Tinting)options[5]; ApplyFixes = applyFixes; DecalIsSimple = this.render_pass == Render_Pass.Pre_Lighting && this.bump_mapping == Bump_Mapping.Leave; TemplateGenerationValid = true; }
public static ShaderGeneratorResult GenerateShader( ShaderStage stage, Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Specular_Mask specular_mask, Material_Model material_model, Environment_Mapping environment_mapping, Self_Illumination self_illumination, Blend_Mode blend_mode, Parallax parallax, Misc misc, Distortion distortion, Soft_fade soft_fade ) { if (!HaloShaderGeneratorPrivate.IsBaseDLLLoaded) { return(null); } Type shadergeneratortype = HaloShaderGeneratorPrivate.HaloShaderGeneratorAssembly.ExportedTypes.Where(t => t.Name == "ShaderGenerator").FirstOrDefault(); if (shadergeneratortype == null) { return(null); } var result = (byte[])shadergeneratortype.GetMethod("GenerateShader").Invoke(null, new object[] { stage, albedo, bump_mapping, alpha_test, specular_mask, material_model, environment_mapping, self_illumination, blend_mode, parallax, misc, distortion, soft_fade }); if (result == null) { return(null); } return(new ShaderGeneratorResult(result)); }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public CustomGenerator(Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Specular_Mask specular_mask, Material_Model material_model, Environment_Mapping environment_mapping, Self_Illumination self_illumination, Blend_Mode blend_mode, Parallax parallax, Misc misc) { this.albedo = albedo; this.bump_mapping = bump_mapping; this.alpha_test = alpha_test; this.specular_mask = specular_mask; this.material_model = material_model; this.environment_mapping = environment_mapping; this.self_illumination = self_illumination; this.blend_mode = blend_mode; this.parallax = parallax; this.misc = misc; TemplateGenerationValid = true; }
public CortanaGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.bump_mapping = (Bump_Mapping)options[1]; this.alpha_test = (Alpha_Test)options[2]; this.material_model = (Material_Model)options[3]; this.environment_mapping = (Environment_Mapping)options[4]; this.warp = (Warp)options[5]; this.lighting = (Lighting)options[6]; this.scanlines = (Scanlines)options[7]; this.transparency = (Transparency)options[8]; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public CustomGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.bump_mapping = (Bump_Mapping)options[1]; this.alpha_test = (Alpha_Test)options[2]; this.specular_mask = (Specular_Mask)options[3]; this.material_model = (Material_Model)options[4]; this.environment_mapping = (Environment_Mapping)options[5]; this.self_illumination = (Self_Illumination)options[6]; this.blend_mode = (Blend_Mode)options[7]; this.parallax = (Parallax)options[8]; this.misc = (Misc)options[9]; //ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public CortanaGenerator(Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Material_Model material_model, Environment_Mapping environment_mapping, Warp warp, Lighting lighting, Scanlines scanlines, Transparency transparency, bool applyFixes = false) { this.albedo = albedo; this.bump_mapping = bump_mapping; this.alpha_test = alpha_test; this.material_model = material_model; this.environment_mapping = environment_mapping; this.warp = warp; this.lighting = lighting; this.scanlines = scanlines; this.transparency = transparency; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public ParticleGenerator(byte[] options, bool applyFixes = false) { this.albedo = (Albedo)options[0]; this.blend_mode = (Blend_Mode)options[1]; this.specialized_rendering = (Specialized_Rendering)options[2]; this.lighting = (Lighting)options[3]; this.render_targets = (Render_Targets)options[4]; this.depth_fade = (Depth_Fade)options[5]; this.black_point = (Black_Point)options[6]; this.fog = (Fog)options[7]; this.frame_blend = (Frame_Blend)options[8]; this.self_illumination = (Self_Illumination)options[9]; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
/// <summary> /// Generator instantiation for method specific shaders. /// </summary> public ParticleGenerator(Albedo albedo, Blend_Mode blend_mode, Specialized_Rendering specialized_rendering, Lighting lighting, Render_Targets render_targets, Depth_Fade depth_fade, Black_Point black_point, Fog fog, Frame_Blend frame_blend, Self_Illumination self_illumination, bool applyFixes = false) { this.albedo = albedo; this.blend_mode = blend_mode; this.specialized_rendering = specialized_rendering; this.lighting = lighting; this.render_targets = render_targets; this.depth_fade = depth_fade; this.black_point = black_point; this.fog = fog; this.frame_blend = frame_blend; this.self_illumination = self_illumination; ApplyFixes = applyFixes; TemplateGenerationValid = true; }
public virtual void Release() { if (Albedo != null) { Albedo.Release(); Albedo = null; } if (Height != null) { Height.Release(); Height = null; } if (Normal != null) { Normal.Release(); Normal = null; } if (Metallic != null) { Metallic.Release(); Metallic = null; } if (Roughness != null) { Roughness.Release(); Roughness = null; } if (Occlusion != null) { Occlusion.Release(); Occlusion = null; } if (Thickness != null) { Thickness.Release(); Thickness = null; } if (Emission != null) { Emission.Release(); Emission = null; } }
public static byte[] GenerateShader( ShaderStage stage, Albedo albedo, Bump_Mapping bump_mapping, Alpha_Test alpha_test, Specular_Mask specular_mask, Material_Model material_model, Environment_Mapping environment_mapping, Self_Illumination self_illumination, Blend_Mode blend_mode, Parallax parallax, Misc misc, Distortion distortion, Soft_fade soft_fade ) { string template = $"shader.hlsl"; List <D3D.SHADER_MACRO> macros = new List <D3D.SHADER_MACRO>(); switch (stage) { //case ShaderStage.Default: case ShaderStage.Albedo: //case ShaderStage.Static_Per_Pixel: //case ShaderStage.Static_Per_Vertex: //case ShaderStage.Static_Sh: case ShaderStage.Static_Prt_Ambient: case ShaderStage.Static_Prt_Linear: case ShaderStage.Static_Prt_Quadratic: //case ShaderStage.Dynamic_Light: //case ShaderStage.Shadow_Generate: case ShaderStage.Active_Camo: //case ShaderStage.Lightmap_Debug_Mode: //case ShaderStage.Static_Per_Vertex_Color: //case ShaderStage.Dynamic_Light_Cinematic: //case ShaderStage.Sfx_Distort: break; default: return(null); } // prevent the definition helper from being included macros.Add(new D3D.SHADER_MACRO { Name = "_DEFINITION_HELPER_HLSLI", Definition = "1" }); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderStage>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <ShaderType>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Albedo>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Bump_Mapping>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Alpha_Test>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Specular_Mask>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Material_Model>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Environment_Mapping>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Self_Illumination>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Blend_Mode>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Parallax>()); macros.AddRange(ShaderGeneratorBase.CreateMethodEnumDefinitions <Misc>()); macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_ps", albedo, "calc_albedo_", "_ps")); if (albedo == Albedo.Constant_Color) { macros.Add(ShaderGeneratorBase.CreateMacro("calc_albedo_vs", albedo, "calc_albedo_", "_vs")); } macros.Add(ShaderGeneratorBase.CreateMacro("calc_bumpmap_ps", bump_mapping, "calc_bumpmap_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_bumpmap_vs", bump_mapping, "calc_bumpmap_", "_vs")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_alpha_test_ps", alpha_test, "calc_alpha_test_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_specular_mask_ps", specular_mask, "calc_specular_mask_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_self_illumination_ps", self_illumination, "calc_self_illumination_", "_ps")); macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_ps", parallax, "calc_parallax_", "_ps")); switch (parallax) { case Parallax.Simple_Detail: macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_vs", Parallax.Simple, "calc_parallax_", "_vs")); break; default: macros.Add(ShaderGeneratorBase.CreateMacro("calc_parallax_vs", parallax, "calc_parallax_", "_vs")); break; } macros.Add(ShaderGeneratorBase.CreateMacro("material_type", material_model, "material_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type", environment_mapping, "envmap_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("blend_type", blend_mode, "blend_type_")); macros.Add(ShaderGeneratorBase.CreateMacro("shaderstage", stage, "shaderstage_")); macros.Add(ShaderGeneratorBase.CreateMacro("shadertype", stage, "shadertype_")); macros.Add(ShaderGeneratorBase.CreateMacro("albedo_arg", albedo, "k_albedo_")); macros.Add(ShaderGeneratorBase.CreateMacro("self_illumination_arg", self_illumination, "k_self_illumination_")); macros.Add(ShaderGeneratorBase.CreateMacro("material_type_arg", material_model, "k_material_model_")); macros.Add(ShaderGeneratorBase.CreateMacro("envmap_type_arg", environment_mapping, "k_environment_mapping_")); macros.Add(ShaderGeneratorBase.CreateMacro("blend_type_arg", blend_mode, "k_blend_mode_")); var shader_bytecode = ShaderGeneratorBase.GenerateSource(template, macros, "entry_" + stage.ToString().ToLower(), "ps_3_0"); return(shader_bytecode); }
public virtual void Release() { if (UI3DPreview.Instance != null) { var prev = UI3DPreview.Instance; if (Albedo != null && Albedo != prev.defaultBlack && Albedo != prev.defaultDarkGray && Albedo != prev.defaultGray && Albedo != prev.defaultWhite) { Albedo.Release(); Albedo = null; } if (Height != null && Height != prev.defaultBlack && Height != prev.defaultDarkGray && Height != prev.defaultGray && Height != prev.defaultWhite) { Height.Release(); Height = null; } if (Normal != null && Normal != prev.defaultBlack && Normal != prev.defaultDarkGray && Normal != prev.defaultGray && Normal != prev.defaultWhite) { Normal.Release(); Normal = null; } if (Metallic != null && Metallic != prev.defaultBlack && Metallic != prev.defaultDarkGray && Metallic != prev.defaultGray && Metallic != prev.defaultWhite) { Metallic.Release(); Metallic = null; } if (Roughness != null && Roughness != prev.defaultBlack && Roughness != prev.defaultDarkGray && Roughness != prev.defaultGray && Roughness != prev.defaultWhite) { Roughness.Release(); Roughness = null; } if (Occlusion != null && Occlusion != prev.defaultBlack && Occlusion != prev.defaultDarkGray && Occlusion != prev.defaultGray && Occlusion != prev.defaultWhite) { Occlusion.Release(); Occlusion = null; } } else { if (Albedo != null) { Albedo.Release(); Albedo = null; } if (Height != null) { Height.Release(); Height = null; } if (Normal != null) { Normal.Release(); Normal = null; } if (Metallic != null) { Metallic.Release(); Metallic = null; } if (Roughness != null) { Roughness.Release(); Roughness = null; } if (Occlusion != null) { Occlusion.Release(); Occlusion = null; } } }
public override string Serialize() => Invariant($"{ScatterFactor}}}{Albedo.Serialize()}}}{Emission.Serialize()}}}");
public void Use(Shader shader, float part) { Albedo.Use(shader, 2, part); shader.SetFloat("disturbance", Disturbance); }
public override string Serialize() => Invariant($"{Refraction}}}{Albedo.Serialize()}}}{Emission.Serialize()}}}");
bool RegenerateShader( RenderMethodTemplate rmt2, PixelShader pixl, int[] shader_args, ShaderType type, ShaderStage shaderstage, RenderMethodTemplate.ShaderModeBitmask bit, RenderMethodTemplate.ShaderMode mode ) { MethodInfo method = null; switch (type) { case ShaderType.Shader: method = typeof(HaloShaderGenerator.HaloShaderGenerator).GetMethod("GenerateShader"); break; case ShaderType.Cortana: method = typeof(HaloShaderGenerator.HaloShaderGenerator).GetMethod("GenerateShaderCortana"); break; default: return(false); } if (method == null) { return(false); } //TODO: Rewrite this crazyness if ((rmt2.DrawModeBitmask | bit) != 0) { if (HaloShaderGenerator.HaloShaderGenerator.IsShaderSuppored(type, shaderstage)) { var GenerateShaderArgs = CreateArguments(method, shaderstage, shader_args); //TODO: Remove this switch (shaderstage) { case ShaderStage.Albedo: Albedo albedo = GenerateShaderArgs.Where(x => x.GetType() == typeof(Albedo)).Cast <Albedo>().FirstOrDefault(); if (albedo > Albedo.Two_Detail_Black_Point) { return(false); // saber territory } Bump_Mapping bumpmapping = GenerateShaderArgs.Where(x => x.GetType() == typeof(Bump_Mapping)).Cast <Bump_Mapping>().FirstOrDefault(); if (bumpmapping > Bump_Mapping.Detail) { return(false); // saber territory } break; } var shaderGeneratorResult = method.Invoke(null, GenerateShaderArgs) as HaloShaderGenerator.ShaderGeneratorResult; if (shaderGeneratorResult?.Bytecode == null) { return(false); } var offset = pixl.DrawModes[(int)mode].Offset; var count = pixl.DrawModes[(int)mode].Count; var pixelShaderBlock = Porting.PortTagCommand.GeneratePixelShaderBlock(CacheContext, shaderGeneratorResult); pixl.Shaders[offset] = pixelShaderBlock; rmt2.DrawModeBitmask |= bit; return(true); } // todo, disable it. but for now, we'll just keep the other shaders here } return(false); }
public bool Equals(Metal other) => Albedo.Equals(other.Albedo) && Fuzziness.Equals(other.Fuzziness);