@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
120 lines • 7.43 kB
JavaScript
// Do not edit.
import { ShaderStore } from "../Engines/shaderStore.js";
import { clipPlaneVertexDeclarationWGSL } from "./ShadersInclude/clipPlaneVertexDeclaration.js";
import { fogVertexDeclarationWGSL } from "./ShadersInclude/fogVertexDeclaration.js";
import { logDepthDeclarationWGSL } from "./ShadersInclude/logDepthDeclaration.js";
import { clipPlaneVertexWGSL } from "./ShadersInclude/clipPlaneVertex.js";
import { fogVertexWGSL } from "./ShadersInclude/fogVertex.js";
import { logDepthVertexWGSL } from "./ShadersInclude/logDepthVertex.js";
const name = "gpuRenderParticlesVertexShader";
const shader = `uniform view: mat4x4f;uniform projection: mat4x4f;uniform translationPivot: vec2f;uniform worldOffset: vec3f;
uniform emitterWM: mat4x4f;
attribute position: vec3f;attribute age: f32;attribute life: f32;attribute size: vec3f;
attribute initialDirection: vec3f;
attribute direction: vec3f;
attribute angle: f32;
attribute cellIndex: f32;
attribute offset: vec2f;attribute uv: vec2f;varying vUV: vec2f;varying vColor: vec4f;varying vPositionW: vec3f;
uniform invView: mat4x4f;
var colorGradientSamplerSampler: sampler;var colorGradientSampler: texture_2d<f32>;
attribute seed: vec4f;
uniform colorDead: vec4f;attribute color: vec4f;
uniform sheetInfos: vec3f;
uniform eyePosition: vec3f;
fn particleBasePosition()->vec3f {
return (uniforms.emitterWM*vec4f(vertexInputs.position,1.0)).xyz+uniforms.worldOffset;
return vertexInputs.position+uniforms.worldOffset;
}
fn rotate(yaxis: vec3f,rotatedCorner: vec3f)->vec3f {let xaxis: vec3f=normalize(cross(vec3f(0.0,1.0,0.0),yaxis));let zaxis: vec3f=normalize(cross(yaxis,xaxis));let rotMatrix: mat3x3f=mat3x3f(xaxis,yaxis,zaxis);return particleBasePosition()+rotMatrix*rotatedCorner;}
fn rotateAlign(toCamera: vec3f,rotatedCorner: vec3f)->vec3f {let normalizedToCamera: vec3f=normalize(toCamera);
let normalizedCrossDirToCamera: vec3f=normalize(cross(normalize(vertexInputs.initialDirection),normalizedToCamera));let row1: vec3f=normalize(vertexInputs.initialDirection);
let normalizedCrossDirToCamera: vec3f=normalize(cross(normalize(vertexInputs.direction),normalizedToCamera));let row1: vec3f=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));
let rotMatrix: mat3x3f=mat3x3f(normalizedCrossDirToCamera,row1,normalizedToCamera);return particleBasePosition()+rotMatrix*rotatedCorner;}
@vertex
fn main(input: VertexInputs)->FragmentInputs {
let shouldCullParticle: bool=vertexInputs.life>0.0 && vertexInputs.age>=vertexInputs.life;
let rowOffset: f32=floor(vertexInputs.cellIndex/uniforms.sheetInfos.z);let columnOffset: f32=vertexInputs.cellIndex-rowOffset*uniforms.sheetInfos.z;let uvScale: vec2f=uniforms.sheetInfos.xy;let uvOffset: vec2f=vec2f(vertexInputs.uv.x,1.0-vertexInputs.uv.y);vertexOutputs.vUV=(uvOffset+vec2f(columnOffset,rowOffset))*uvScale;
vertexOutputs.vUV=vertexInputs.uv;
let ratio: f32=min(1.0,vertexInputs.age/vertexInputs.life);
let vColor1: vec4f=textureSampleLevel(colorGradientSampler,colorGradientSamplerSampler,vec2f(ratio,0.25),0.0);let vColor2: vec4f=textureSampleLevel(colorGradientSampler,colorGradientSamplerSampler,vec2f(ratio,0.75),0.0);vertexOutputs.vColor=mix(vColor1,vColor2,vertexInputs.seed.x);
vertexOutputs.vColor=textureSampleLevel(colorGradientSampler,colorGradientSamplerSampler,vec2f(ratio,0.0),0.0);
vertexOutputs.vColor=vertexInputs.color*vec4f(1.0-ratio)+uniforms.colorDead*vec4f(ratio);
let cornerPos: vec2f=(vertexInputs.offset-uniforms.translationPivot)*vertexInputs.size.yz*vertexInputs.size.x;
var rotatedCorner: vec4f;rotatedCorner.w=0.0;
rotatedCorner.x=cornerPos.x*cos(vertexInputs.angle)-cornerPos.y*sin(vertexInputs.angle);rotatedCorner.z=cornerPos.x*sin(vertexInputs.angle)+cornerPos.y*cos(vertexInputs.angle);rotatedCorner.y=0.0;rotatedCorner.x+=uniforms.translationPivot.x;rotatedCorner.z+=uniforms.translationPivot.y;var yaxis: vec3f=vertexInputs.position+uniforms.worldOffset-uniforms.eyePosition;yaxis.y=0.0;vertexOutputs.vPositionW=rotate(normalize(yaxis),rotatedCorner.xyz);let viewPosition: vec4f=uniforms.view*vec4f(vertexOutputs.vPositionW,1.0);
rotatedCorner.x=cornerPos.x*cos(vertexInputs.angle)-cornerPos.y*sin(vertexInputs.angle);rotatedCorner.y=cornerPos.x*sin(vertexInputs.angle)+cornerPos.y*cos(vertexInputs.angle);rotatedCorner.z=0.0;rotatedCorner.x+=uniforms.translationPivot.x;rotatedCorner.y+=uniforms.translationPivot.y;let toCamera: vec3f=vertexInputs.position+uniforms.worldOffset-uniforms.eyePosition;vertexOutputs.vPositionW=rotateAlign(toCamera,rotatedCorner.xyz);let viewPosition: vec4f=uniforms.view*vec4f(vertexOutputs.vPositionW,1.0);
rotatedCorner.x=cornerPos.x*cos(vertexInputs.angle)-cornerPos.y*sin(vertexInputs.angle);rotatedCorner.y=cornerPos.x*sin(vertexInputs.angle)+cornerPos.y*cos(vertexInputs.angle);rotatedCorner.z=0.0;rotatedCorner.x+=uniforms.translationPivot.x;rotatedCorner.y+=uniforms.translationPivot.y;let viewPosition: vec4f=uniforms.view*vec4f(particleBasePosition(),1.0)+rotatedCorner;vertexOutputs.vPositionW=(uniforms.invView*viewPosition).xyz;
var rotatedCorner: vec3f;rotatedCorner.x=cornerPos.x*cos(vertexInputs.angle)-cornerPos.y*sin(vertexInputs.angle);rotatedCorner.y=0.0;rotatedCorner.z=cornerPos.x*sin(vertexInputs.angle)+cornerPos.y*cos(vertexInputs.angle);rotatedCorner.x+=uniforms.translationPivot.x;rotatedCorner.z+=uniforms.translationPivot.y;let yaxis: vec3f=normalize(vertexInputs.initialDirection);vertexOutputs.vPositionW=rotate(yaxis,rotatedCorner);let viewPosition: vec4f=uniforms.view*vec4f(vertexOutputs.vPositionW,1.0);
vertexOutputs.position=uniforms.projection*viewPosition;
let worldPos: vec4f=vec4f(vertexOutputs.vPositionW,1.0);
if (shouldCullParticle) {vertexOutputs.position=vec4f(0.0,0.0,2.0,1.0);vertexOutputs.vColor=vec4f(0.0);vertexOutputs.vUV=vec2f(0.0);vertexOutputs.vPositionW=vec3f(0.0);}
}
`;
// Sideeffect
if (!ShaderStore.ShadersStoreWGSL[name]) {
ShaderStore.ShadersStoreWGSL[name] = shader;
}
const includes = [clipPlaneVertexDeclarationWGSL, fogVertexDeclarationWGSL, logDepthDeclarationWGSL, clipPlaneVertexWGSL, fogVertexWGSL, logDepthVertexWGSL];
for (const inc of includes) {
if (!ShaderStore.IncludesShadersStoreWGSL[inc.name]) {
ShaderStore.IncludesShadersStoreWGSL[inc.name] = inc.shader;
}
}
/** @internal */
export const gpuRenderParticlesVertexShaderWGSL = { name, shader };
//# sourceMappingURL=gpuRenderParticles.vertex.js.map