Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Shader
#1
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.

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");
  


Messages In This Thread
Custom Shader - by Kyle - 09-29-2023, 09:50 AM
RE: Custom Shader - by abenedik - 09-29-2023, 01:21 PM
RE: Custom Shader - by Kyle - 10-02-2023, 08:38 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)