# Creating a Base Material > **Notice:** The sections below cover advanced manual material development: material definitions, inheritance, and rendering integration. **The recommended way to create materials is through the visual, node-based [Material Editor](../../../content/materials/index.md), which provides an approachable workflow without writing material and shader code by hand.** A source-authored base material connects exposed settings to shader calculations and the passes used by rendering. A practical starting point is an opaque mesh material that changes the surface's albedo and roughness while reusing the Engine's geometry processing and lighting integration. The example below draws alternating colors along a mesh's first UV coordinate. It uses the standard [Mesh](../../../code/materials_shaders/abstract_materials/mesh.md) abstract material and adds two colors, a stripe count, roughness, and an optional albedo texture. The description is written in [ULON](../../../code/formats/materials_formats/ulon_base_material_format.md), with embedded [UUSL](../../../code/uusl/index.md) shader code. ## Creating the Base in the Editor Create the base material from the Editor's opaque mesh template: 1. In the *Asset Browser*, open or create the `materials/striped_surface` folder inside your project's `data` directory. 2. Right-click an empty area and choose *Create Code → Base Material → Mesh → Opaque*. 3. Enter *striped_surface* in the *Material Name* field. The Editor creates `striped_surface.basemat` from the template based on *Unigine::mesh* and imports it. Open the created `*.basemat` file in a text editor, replace its contents with the complete example below, and save it. ```glsl BaseMaterial { Group "Striped Surface" { Color base_color = [0.7 0.7 0.7 1] Color stripe_color = [0.05 0.1 0.2 1] Slider stripe_count = 8.0 Slider roughness = 0.5 State use_texture = false Texture2D albedo = "core/textures/common/white.texture" if[use_texture] } Shader vertex_struct = #{ INIT_BASE_DATA #} Shader fragment = #{ float stripe = step(0.5f, frac(DATA_UV.x * var_stripe_count)); float3 color = lerp(var_base_color.rgb, var_stripe_color.rgb, stripe); #ifdef STATE_USE_TEXTURE color *= TEXTURE(tex_albedo, DATA_UV.xy).rgb; #endif OUT_FRAG_ALBEDO = color; OUT_FRAG_ROUGHNESS = var_roughness; #} } ``` The base's manual name is *Samples::striped_surface*: the file name supplies *striped_surface*, and the root argument supplies the namespace. The abstract parent is selected independently by *parent=Unigine::mesh*. See [Material Inheritance](../../../code/materials_shaders/inheritance/index.md) for the difference between incorporating an abstract description and creating a derived material. ## Declaring the Inputs The group organizes settings in the Editor. The declarations inside it also establish names and types that the shader code uses. The Mesh abstract description supplies the *var* parameter prefix and *tex* texture prefix. | Declaration | Shader name | Purpose | |---|---|---| | Color base_color | var_base_color | The color used for the first half of each stripe period. | | Color stripe_color | var_stripe_color | The color used for the second half of each period. | | Slider stripe_count | var_stripe_count | A float controlling the number of periods across a UV interval of one. | | Slider roughness | var_roughness | A float used as the surface roughness. | | State use_texture | STATE_USE_TEXTURE | A shader definition present when the toggle is enabled. | | Texture2D albedo | tex_albedo | The optional texture sampled by the fragment code. | The Engine generates the shader declarations for these parameters and the texture. There is no need to declare matching uniforms or texture slots manually in this example. Only the RGB components of the color parameters and texture are used; opacity remains at the abstract material's default. The texture's *if[use_texture]* condition controls its availability, while *#ifdef STATE_USE_TEXTURE* controls the code that samples it. Both use the same state, so the shader does not refer to the texture when the feature is disabled. The initial white texture leaves the stripe colors unchanged; choose an imported albedo texture to see the modulation. See the [Parameters](../../../code/formats/materials_formats/ulon_materials/parameters.md), [States](../../../code/formats/materials_formats/ulon_materials/states.md), and [Textures](../../../code/formats/materials_formats/ulon_materials/textures.md) references for other input types and their arguments. ## Providing the Shader Calculations The named shader blocks are extension points used by the abstract description. They are code fragments incorporated into complete shader programs; neither block needs its own entry point. The *vertex_struct* fragment expands *INIT_BASE_DATA*, which provides the standard data used by the Mesh implementation, including interpolated UV coordinates. The inherited vertex processing transforms the mesh and passes this data to the fragment stage. The example reads the first UV set as *DATA_UV.xy*. The *fragment* block uses *frac()* to repeat a UV interval and *step()* to split it into two bands. It selects a color, optionally multiplies it by the texture, and assigns the result to *OUT_FRAG_ALBEDO*. Roughness is assigned separately to *OUT_FRAG_ROUGHNESS*. These outputs describe surface properties. They are not a final display color: the inherited code writes the required buffers, and the Engine performs lighting afterward. The apparent brightness and reflections therefore depend on the scene's lighting and environment. ## Using the Inherited Passes The new base does not declare its own pass because Mesh already supplies the relevant programs. Its main surface pass is the following inherited declaration, shown here for explanation: ```glsl Pass deferred if[gbuffer] { Vertex = mesh_shader Control = mesh_shader Evaluate = mesh_shader Fragment = mesh_shader } ``` The named source *mesh_shader* contains the stage-specific implementation and incorporates the extension fragments supplied by the base. Tessellation is disabled by default, so its control and evaluation stages are cleared during shader preprocessing. The ordinary surface path uses vertex and fragment processing. Do not add a second copy of this declaration to the example. Repeating a pass name adds another variant rather than replacing the inherited pass. Mesh also supplies passes for shadows and other rendering tasks, so the complete material is not limited to one pass. See [Passes](../../../code/formats/materials_formats/ulon_materials/passes.md) for variant selection and stage definitions. ## Creating and Testing a Material in the Editor Use a static mesh with UV coordinates in a lit scene. For a simple test, open a world and add a plane through *[Create → Primitive → Plane](../../../editor2/create_import_nodes/index.md#plane)*. If the scene has no light, add one through *[Create → Lights → World](../../../objects/lights/world/index.md#add)* and rotate it to illuminate the plane. View the plane from above. 1. After saving the source, let UnigineEditor reload the base. Open *Windows → Material Hierarchy* and locate *Samples::striped_surface*, the name formed from the namespace and file name. 2. Right-click this base and choose *[Create Child](../../../editor2/materials_settings/organizing_materials/index.md#inherit_material)*. The Editor creates a material asset. Rename it in the Asset Browser to `striped_surface_demo.mat`. 3. Assign the child to the target mesh surface. See [Assigning a Material](../../../editor2/materials_settings/organizing_materials/index.md#assign_material) for the Editor operations. 4. In the child's settings, change *Base Color*, *Stripe Color*, and *Stripe Count*. The surface should show repeating bands along its U coordinate. 5. To test texturing, [import](../../../editor2/assets_workflow/assets_create_import.md#import) a visibly patterned image into the Asset Browser. Enable *Use Albedo Texture* and assign the imported texture to *Albedo*. It should multiply both stripe colors. The initial white texture leaves them unchanged. 6. Change *Roughness* and observe the highlights from different viewing angles. The change is visible where the lighting produces a reflection. Adjust the child when choosing values for this surface. Edit the `*.basemat` source when changing declarations or calculations. For example, replacing *DATA_UV.x* with *DATA_UV.y* changes the stripe direction for every material using this base. After saving source changes, check the Editor's reload messages and shader compilation errors. If a loaded base needs an explicit reload, run *materials_reload* in the [console](../../../code/console/index.md). This command reloads all loaded base materials, not just the example. A child's own overrides continue to take precedence over changed defaults. ## Checking the Result | Unexpected result | Check | |---|---| | The base is missing or cannot be used. | Check import and material loading errors, the root syntax, and whether another manual material already has the same namespace and file name. | | The mesh has a uniform color. | Check that its first UV set varies across the surface. The stripe pattern depends on UVs, not object size or world position. | | The Albedo texture setting is unavailable. | Enable Use Albedo Texture. The input is conditional. | | A change to a default value is not visible. | Check whether the child overrides that value. Reset the override to inherit the new default. | | A source edit has no visible effect. | Check reload and compilation messages and confirm that the assigned child uses Samples::striped_surface. | This starting point changes surface properties while retaining Mesh's rendering behavior. Vertex deformation, transparency, custom lighting, and additional rendering operations need further changes to the appropriate declarations and shader extension points. The [Abstract Materials](../../../code/materials_shaders/abstract_materials/index.md) guide describes how shared descriptions expose those extension points.