I am trying to use a post process effect with a custom fragment shader. When I run my app and look at the console, I am hit with a ton of invalid shader warnings for both the fragment and vertex. It should be using the built-in ShadersWGSL/postprocess.vertex.fx shader.
The first warning I always get is: Invalid fragment shader: The varying named “vUV” is not declared in the vertex shader! This declaration will be ignored.
Which is implying that the vertex shader is not exporting the vUV varying. I did a debug shader code on the engine to see and the vertex shader was in fact missing the varying in the fragmentInputs struct. The result of that dump is here:
//#define SHADER_NAME vertex:postprocess
diagnostic(off, chromium.unreachable_code);
struct VertexInputs {
@builtin(vertex_index) vertexIndex : u32,
@builtin(instance_index) instanceIndex : u32,
@location(0) position : vec3f,
};
var vertexInputs : VertexInputs;
struct FragmentInputs {
@builtin(position) position : vec4,
};
var vertexOutputs : FragmentInputs;
struct LeftOver {
world : mat4x4,
viewProjection : mat4x4f,
color : vec4f,
aspectRatio : f32,
h_color: vec3,
};
@group(1) @binding(1) var uniforms : LeftOver;
const IS_NDC_HALF_ZRANGE = true;
struct Internals {
yFactor_: f32,
textureOutputHeight_: f32,
};
@group(1) @binding(0) var internals : Internals;
const madd=vec2(0.5,0.5);
//#define CUSTOM_VERTEX_DEFINITIONS
@vertex
fn main(input : VertexInputs)->FragmentInputs {
vertexInputs = input;
//#define CUSTOM_VERTEX_MAIN_BEGIN
vertexOutputs.vUV=(vertexInputs.position*madd+madd)*uniforms.scale;
vertexOutputs.position=vec4(vertexInputs.position,0.0,1.0);
//#define CUSTOM_VERTEX_MAIN_END
vertexOutputs.position.y = vertexOutputs.position.y * internals.yFactor_;
return vertexOutputs;
}
I create my post process like this
this._highlightEffect = new PostProcess('Highlight Effect', shadersPath + '/highlightEffect', {
shaderLanguage: ShaderLanguage.WGSL,
samplers: ['renderTargetTexture'],
uniforms: ['aspectRatio', 'h_color'],
camera: camera
});
And my shader has the correct variables at the top for a post process shader
uniform aspectRatio : f32;
uniform h_color: vec3<f32>;
// Varying
varying vUV : vec2<f32>;
var textureSamplerSampler : sampler;
var textureSampler: texture_2d<f32>;
var renderTargetTextureSampler : sampler;
var renderTargetTexture: texture_2d<f32>;
I tested this in the playground with a custom fragment shader and it worked.
I am using Babylon 8.36.1 on Windows, building into an angular app with webpack.
Any help is appreciated.
Thanks