Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interpolation option for varying in WGSL #14893

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ export class WebGPUShaderProcessorWGSL extends WebGPUShaderProcessor {
}

public varyingProcessor(varying: string, isFragment: boolean, preProcessors: { [key: string]: string }) {
const varyingRegex = /\s*varying\s+(?:(?:highp)?|(?:lowp)?)\s*(\S+)\s*:\s*(.+)\s*;/gm;
const varyingRegex = /\s*(flat|linear|perspective)?\s*(center|centroid|sample)?\s*varying\s+(?:(?:highp)?|(?:lowp)?)\s*(\S+)\s*:\s*(.+)\s*;/gm;
const match = varyingRegex.exec(varying);
if (match !== null) {
const varyingType = match[2];
const name = match[1];
const interpolationType = match[1] ?? "perspective";
const interpolationSampling = match[2] ?? "center";
const varyingType = match[4];
const name = match[3];
let location: number;
if (isFragment) {
location = this._webgpuProcessingContext.availableVaryings[name];
Expand All @@ -125,7 +127,7 @@ export class WebGPUShaderProcessorWGSL extends WebGPUShaderProcessor {
} else {
location = this._webgpuProcessingContext.getVaryingNextLocation(varyingType, this._getArraySize(name, varyingType, preProcessors)[2]);
this._webgpuProcessingContext.availableVaryings[name] = location;
this._varyingsWGSL.push(` @location(${location}) ${name} : ${varyingType},`);
this._varyingsWGSL.push(` @location(${location}) @interpolate(${interpolationType}, ${interpolationSampling}) ${name} : ${varyingType},`);
this._varyingNamesWGSL.push(name);
}

Expand Down