소스 검색

Fixy Fixy

Sebastien Vandenberghe 6 년 전
부모
커밋
fe09cdc0a4

+ 1 - 1
Playground/js/indexWebGPU.js

@@ -575,7 +575,7 @@ function showError(errorMessage, errorEvent) {
                         await engine.initAsync(window.shadercOptions);
 
                         //create scene
-                        eval("scene = " + createSceneFunction + "()");
+                        eval("scene = " + createSceneFunction + "(engine, canvas)");
 
                         if (!scene) {
                             showError(createSceneFunction + " function must return a scene.", null);

+ 10 - 1
src/Engines/WebGPU/webgpuShaderProcessors.ts

@@ -88,7 +88,10 @@ export class WebGPUShaderProcessor implements IShaderProcessor {
             if (uniformType.indexOf("texture") === 0 || uniformType.indexOf("sampler") === 0) {
                 let samplerInfo = _knownSamplers[name];
                 if (!samplerInfo) {
-                    samplerInfo = webgpuProcessingContext.getNextFreeTextureBinding();
+                    samplerInfo = webgpuProcessingContext.availableSamplers[name];
+                    if (!samplerInfo) {
+                        samplerInfo = webgpuProcessingContext.getNextFreeTextureBinding();
+                    }
                 }
 
                 const setIndex = samplerInfo.setIndex;
@@ -122,6 +125,12 @@ export class WebGPUShaderProcessor implements IShaderProcessor {
                     name = name.substr(0, startArray);
                 }
 
+                for (let i = 0; i < webgpuProcessingContext.leftOverUniforms.length; i++) {
+                    if (webgpuProcessingContext.leftOverUniforms[i].name === name) {
+                        return "";
+                    }
+                }
+
                 webgpuProcessingContext.leftOverUniforms.push({
                     name,
                     type: uniformType,

+ 8 - 4
src/Engines/webgpuEngine.ts

@@ -504,6 +504,10 @@ export class WebGPUEngine extends Engine {
     }
 
     public clear(color: Color4, backBuffer: boolean, depth: boolean, stencil: boolean = false): void {
+        // Some PGs are using color3...
+        if (color.a === undefined) {
+            color.a = 1;
+        }
         this._mainColorAttachments[0].loadValue = backBuffer ? color : WebGPUConstants.GPULoadOp_load;
 
         this._mainDepthAttachment.depthLoadValue = depth ? this._clearDepthValue : WebGPUConstants.GPULoadOp_load;
@@ -1199,7 +1203,7 @@ export class WebGPUEngine extends Engine {
             texture._sphericalPolynomial = webglEngineTexture._sphericalPolynomial;
 
             let mipMaps = Scalar.Log2(Math.max(width, height));
-            mipMaps = Math.round(mipMaps);
+            mipMaps = Math.floor(mipMaps);
 
             const textureExtent = {
                 width,
@@ -2063,16 +2067,16 @@ export class WebGPUEngine extends Engine {
                     continue;
                 }
 
-                // TODO WEBGPU. Authorize shared samplers and Vertex Textures.
+                // TODO WEBGPU. Optimize shared samplers visibility for vertex/framgent.
                 if (bindingDefinition.isSampler) {
                     bindings.push({
                         binding: j,
-                        visibility: WebGPUConstants.GPUShaderStageBit_FRAGMENT,
+                        visibility: WebGPUConstants.GPUShaderStageBit_VERTEX | WebGPUConstants.GPUShaderStageBit_FRAGMENT,
                         type: WebGPUConstants.GPUBindingType_sampledTexture,
                     }, {
                         // TODO WEBGPU. No Magic + 1.
                         binding: j + 1,
-                        visibility: WebGPUConstants.GPUShaderStageBit_FRAGMENT,
+                        visibility: WebGPUConstants.GPUShaderStageBit_VERTEX | WebGPUConstants.GPUShaderStageBit_FRAGMENT,
                         type: WebGPUConstants.GPUBindingType_sampler
                     });
                 }

+ 1 - 1
src/Shaders/ShadersInclude/lightFragment.fx

@@ -120,7 +120,7 @@
         #endif
 
         #ifdef PROJECTEDLIGHTTEXTURE{X}
-            info.diffuse *= computeProjectionTextureDiffuseLighting(projectionLightSampler{X}, textureProjectionMatrix{X});
+            info.diffuse *= texture2D(projectionLightSampler{X}, computeProjectionTextureDiffuseLightingUV(textureProjectionMatrix{X})).rgb;
         #endif
     #endif
 

+ 2 - 3
src/Shaders/ShadersInclude/lightsFragmentFunctions.fx

@@ -109,9 +109,8 @@ lightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4
 		return result;
 }
 
-vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler, mat4 textureProjectionMatrix){
+vec2 computeProjectionTextureDiffuseLightingUV(mat4 textureProjectionMatrix){
 	vec4 strq = textureProjectionMatrix * vec4(vPositionW, 1.0);
 	strq /= strq.w;
-	vec3 textureColor = texture2D(projectionLightSampler, strq.xy).rgb;
-	return textureColor;
+	return strq.xy;
 }

+ 4 - 5
src/Shaders/ShadersInclude/pbrDirectLightingFunctions.fx

@@ -39,11 +39,10 @@ vec3 computeDiffuseLighting(preLightingInfo info, vec3 lightColor) {
     return diffuseTerm * info.attenuation * info.NdotL * lightColor;
 }
 
-vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler, mat4 textureProjectionMatrix){
-    vec4 strq = textureProjectionMatrix * vec4(vPositionW, 1.0);
-    strq /= strq.w;
-    vec3 textureColor = texture2D(projectionLightSampler, strq.xy).rgb;
-    return toLinearSpace(textureColor);
+vec2 computeProjectionTextureDiffuseLightingUV(mat4 textureProjectionMatrix){
+	vec4 strq = textureProjectionMatrix * vec4(vPositionW, 1.0);
+	strq /= strq.w;
+	return strq.xy;
 }
 
 #ifdef SS_TRANSLUCENCY