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

[shader-ast] texture2D call in vertexShader causes error. #278

Merged
merged 3 commits into from
Feb 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions packages/shader-ast/src/builtin/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
import type { IVec, Prim, Sampler, Vec } from "../api/types";
import { isVec } from "../ast/checks";
import { builtinCall } from "../ast/function";
import { FLOAT0, INT0 } from "../ast/lit";

const texRetType = (sampler: Term<Sampler>) => {
const t = sampler.type[0];
Expand All @@ -47,13 +46,9 @@ const $call = (
uv: Term<Vec>,
bias?: FloatTerm
) => {
const f = builtinCall(
name,
texRetType(sampler),
sampler,
uv,
bias || FLOAT0
);
const f = bias
? builtinCall(name, texRetType(sampler), sampler, uv, bias)
: builtinCall(name, texRetType(sampler), sampler, uv);
!isVec(f) && (f.info = "n");
return f;
};
Expand Down Expand Up @@ -165,13 +160,19 @@ export function textureOffset(sampler: USampler3DTerm, uvw: Vec3Term, off: IVec3
export function textureOffset(sampler: Term<"sampler2DShadow">, uvw: Vec3Term, off: IVec2Term, bias?: FloatTerm): FnCall<"float">;
// prettier-ignore
export function textureOffset(sampler: Term<Sampler>, uv: Term<Vec>, off: Term<IVec>, bias?: FloatTerm): FnCall<any> {
const f = builtinCall(
const f = bias ? builtinCall(
"textureOffset",
texRetType(sampler),
sampler,
uv,
off,
bias || FLOAT0
bias
) : builtinCall(
"textureOffset",
texRetType(sampler),
sampler,
uv,
off
);
!isVec(f) && (f.info = "n");
return f;
Expand All @@ -191,12 +192,17 @@ export function texelFetch(sampler: USampler2DTerm, uv: IVec2Term, lod?: IntTerm
export function texelFetch(sampler: USampler3DTerm, uvw: IVec3Term, lod?: IntTerm): FnCall<"uvec4">;
// prettier-ignore
export function texelFetch(sampler: Term<Sampler>, uv: Term<IVec>, lod?: IntTerm): FnCall<any> {
return builtinCall(
return lod ? builtinCall(
"texelFetch",
texRetType(sampler),
sampler,
uv,
lod || INT0
lod
) : builtinCall(
"texelFetch",
texRetType(sampler),
sampler,
uv
);
}

Expand Down