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

Switching shader causes single frame glitch #319

Closed
bbeaumont opened this issue Jul 2, 2012 · 4 comments
Closed

Switching shader causes single frame glitch #319

bbeaumont opened this issue Jul 2, 2012 · 4 comments
Assignees
Labels

Comments

@bbeaumont
Copy link
Member

This is an issue when changing a shader on a material at runtime with a directional light. The first frame after the switch the object appears black. It's something that @lidev fixed on our fork but I don't think it's made it into the main fork, he can probably advise a bit better on what the problem is, but here is the commit that fixed it.

https://github.com/mindshapes/away3d-core-fp11/commit/37f8603c9c20a425f15e96ae9327e381a2e2824a

not sure if thats going to be visible outside the organisation, so here the patch

From 37f8603c9c20a425f15e96ae9327e381a2e2824a Mon Sep 17 00:00:00 2001
From: Alejandro Santander <palebluedot@gmail.com>
Date: Fri, 18 May 2012 12:12:46 -0300
Subject: [PATCH] fixed the dreaded mouse over/out highlight shader bug    

---
 src/away3d/lights/DirectionalLight.as              |    4 ++++
 src/away3d/materials/methods/BasicAmbientMethod.as |    5 +++--
 src/away3d/materials/passes/DefaultScreenPass.as   |    2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/away3d/lights/DirectionalLight.as b/src/away3d/lights/DirectionalLight.as
index deeac4c..edea32e 100644
--- a/src/away3d/lights/DirectionalLight.as
+++ b/src/away3d/lights/DirectionalLight.as
@@ -1,5 +1,6 @@
 package away3d.lights
 {
+
    import away3d.arcane;
    import away3d.bounds.BoundingVolumeBase;
    import away3d.bounds.NullBounds;
@@ -47,6 +48,9 @@
         */
        public function get sceneDirection() : Vector3D
        {
+           if( _sceneTransformDirty ) {
+               updateSceneTransform();
+           }
        return _sceneDirection;
        }
diff --git a/src/away3d/materials/methods/BasicAmbientMethod.as       b/src/away3d/materials/methods/BasicAmbientMethod.as
index 1a0f4aa..1de9e14 100644
--- a/src/away3d/materials/methods/BasicAmbientMethod.as
+++ b/src/away3d/materials/methods/BasicAmbientMethod.as
@@ -1,11 +1,12 @@
 package away3d.materials.methods
 {
+
    import away3d.arcane;
    import away3d.core.managers.Stage3DProxy;
    import away3d.materials.utils.ShaderRegisterCache;
    import away3d.materials.utils.ShaderRegisterElement;
    import away3d.textures.Texture2DBase;
-   
+
    import flash.display3D.Context3D;
    import flash.display3D.Context3DProgramType;

@@ -165,7 +166,7 @@ package away3d.materials.methods
        /**
         * Updates the ambient color data used by the render state.
         */
-       private function updateAmbient() : void
+       public function updateAmbient() : void
        {
            _ambientData[uint(0)] = _ambientR = ((_ambientColor >> 16) & 0xff) / 0xff * _ambient * _lightAmbientR;
            _ambientData[uint(1)] = _ambientG = ((_ambientColor >> 8) & 0xff) / 0xff * _ambient * _lightAmbientG;
diff --git a/src/away3d/materials/passes/DefaultScreenPass.as b/src/away3d/materials/passes/DefaultScreenPass.as
index f1769fd..071cbcb 100644
--- a/src/away3d/materials/passes/DefaultScreenPass.as
+++ b/src/away3d/materials/passes/DefaultScreenPass.as
@@ -1,5 +1,6 @@
 package away3d.materials.passes
 {
+
    import away3d.arcane;
    import away3d.cameras.Camera3D;
    import away3d.core.base.IRenderable;
@@ -552,6 +553,7 @@ package away3d.materials.passes
            _ambientMethod._lightAmbientR = _ambientLightR;
            _ambientMethod._lightAmbientG = _ambientLightG;
            _ambientMethod._lightAmbientB = _ambientLightB;
+           _ambientMethod.activate( stage3DProxy );
            if (_shadowMethod) _shadowMethod.setRenderState(renderable, stage3DProxy, camera);
            _diffuseMethod.setRenderState(renderable, stage3DProxy, camera);
            if (_usingSpecularMethod) _specularMethod.setRenderState(renderable, stage3DProxy, camera);
-- 
1.7.3.2
@ghost ghost assigned DerSchmale Jul 2, 2012
@richardolsson
Copy link
Member

Thanks for reporting. I took the liberty of formatting the patch a little as you are indeed right that it's not visible outside your organization.

@lidev Maybe you can explain the fix? To me it looks a little bit weird that updateAmbient() would need to be public. Did you make any further changes in client code required for this fix to work?

@DerSchmale What do you think?

@ghost ghost assigned eternauta1337 Jul 2, 2012
@eternauta1337
Copy link
Contributor

I've re-run the experiment on the latest release branch and was unable to reproduce shader glitches when adding/removing a method from a material. Considering it fixed then.

@bbeaumont
Copy link
Member Author

I've just been in the process of upgrading to the Gold release, and I'm still seeing this issue occuring. However, reimplementing the above fix does still work.

@ontheronix
Copy link

@lidev can you explain the fix? Is it a fix or a bypass?

@ghost ghost assigned DerSchmale Apr 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants