Bump map or Emboss Vulcan shader .slang

Hi, is there a bump map (sometimes called Emboss) Vulcan shader / .slang available? or can it be done? It would make 3d scenes textures more interesting. It basically makes all the textures “bump”, to appear like they have “depth”.

This is an example for re-shade:

(also pasted here to avoid errors due forum reformatting https://pastebin.com/kavKZbQP)

Sure, here’s a slang version:

#version 450

layout(push_constant) uniform Push
{
	vec4 SourceSize;
	vec4 OriginalSize;
	vec4 OutputSize;
	uint FrameCount;
   float EmbossPower, EmbossOffset, EmbossAngle;
} params;

#pragma parameter EmbossPower "Emboss Power" 1.0 0.01 2.0 0.05
#pragma parameter EmbossOffset "Emboss Offset" 0.5 0.1 5.0 0.1
#pragma parameter EmbossAngle "Emboss Angle" 1.0 1.0 4.0 1.0
int Angle = int(params.EmbossAngle);

layout(std140, set = 0, binding = 0) uniform UBO
{
	mat4 MVP;
} global;

#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;

void main()
{
   gl_Position = global.MVP * Position;
   vTexCoord = TexCoord * 1.0001;
}

#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;

void main()
{
   vec3 color = texture(Source, vTexCoord).rgb;
   float luminance = dot(color, vec3(0.2125, 0.7154, 0.0721));
   vec2 PixelSize = params.SourceSize.zw;

   vec2 angle;
   if(Angle == 1) angle = vec2(-1.,1.);
   else if(Angle == 2) angle = vec2(1.,1.);
   else if(Angle == 3) angle = vec2(1.,-1.);
   else angle = vec2(-1.,-1.);

   vec3 col1 = texture(Source, vTexCoord - PixelSize * params.EmbossOffset * angle).rgb;
   vec3 col2 = color.rgb;
   vec3 col3 = texture(Source, vTexCoord + PixelSize * params.EmbossOffset * angle).rgb;

   vec3 colEmboss = col1 * 2.0 - col2 - col3;

   float colDot = max(0., dot(colEmboss, vec3(0.333))) * params.EmbossPower;

   vec3 colFinal = col2 - colDot;

   color.xyz = mix(colFinal, col2, luminance * luminance).xyz;

   FragColor = vec4(color, 1.0);
}
1 Like

omg, awesome! thanks!

Now I’ll mess around with it to bring to life those rocky textures! Here’s a screenshot of a small playtest with the shader without much tweaking, if anyone in the future is curious

Thanks again!