09-29-2023, 09:50 AM
I am looking for a way to colour a mesh based on height and I saw that the HeightMap has this functionality. Unfortunately, I have a area that is not square and the triangulation is already defined therefore I cannot make use of the heightmap. Also, the heightmap caused RAM to run out very quickly on larger areas.
I also tried using the VertexColorMaterial to achieve the same effect but there is obviously colour blending across a triangle and I want a hard edge where the edge represents a single height value (like a topographical contour).
I was looking at creating a custom shader to allow shading of the mesh based on height with options to customize the height ranges (and possibly colours).
I looked through the API reference and started experimenting with custom shaders. I was able to create a SPV shader using the Vulkan SDK and I was able to load it with the shader manager (see code below). Where I am having issues is the next step. How do I go about applying the shader to a material?
I have only worked with shaders through engines like Unity and Godot where they have a UI for applying shaders to materials, so I have a lack of knowledge on how it happens at a code level.
If you could steer me in the right direction I would appreciate it.
I also tried using the VertexColorMaterial to achieve the same effect but there is obviously colour blending across a triangle and I want a hard edge where the edge represents a single height value (like a topographical contour).
I was looking at creating a custom shader to allow shading of the mesh based on height with options to customize the height ranges (and possibly colours).
I looked through the API reference and started experimenting with custom shaders. I was able to create a SPV shader using the Vulkan SDK and I was able to load it with the shader manager (see code below). Where I am having issues is the next step. How do I go about applying the shader to a material?
I have only worked with shaders through engines like Unity and Godot where they have a UI for applying shaders to materials, so I have a lack of knowledge on how it happens at a code level.
If you could steer me in the right direction I would appreciate it.
Code:
var byteArrayVert = File.ReadAllBytes(@"C:\Users\Kyle\Desktop\shader\vert.spv");
var byteArrayFrag = File.ReadAllBytes(@"C:\Users\Kyle\Desktop\shader\frag.spv");
var sman = view!.GpuDevice!.ShadersManager;
sman.RegisterShaderResource("vs", byteArrayVert);
sman.RegisterShaderResource("fs", byteArrayFrag);
var siv = sman.GetOrCreatePipelineShaderStage("vs", ShaderStageFlags.Vertex, "main");
var sif = sman.GetOrCreatePipelineShaderStage("fs", ShaderStageFlags.Fragment, "main");