
Mon, 04/13/2020 - 13:54
Forums:
Hello everyone, when I used Graphic3d_ShaderProgram of occt 7.4.0, I wrote XRay.vs and XRay.fs two coloring fragments. Add the shader to the selected model through the first code below, but in myAISContext-> CurrentViewer ()-> Update (); when the program crashes, but if you remove the three PushVariableFloat places and change the uniform in XRay.fs to a local variable, the program can execute normally and the shader can also function normally. I wonder if you have encountered this problem? Thank you.
Handle(Graphic3d_ShaderProgram) aProgram;
aProgram = new Graphic3d_ShaderProgram();
Handle(Graphic3d_ShaderObject) vertexshader=Graphic3d_ShaderObject::CreateFromFile(Graphic3d_TOS_VERTEX, maSrcVert);
Handle(Graphic3d_ShaderObject) fragmentshader = Graphic3d_ShaderObject::CreateFromFile(Graphic3d_TOS_FRAGMENT, maSrcFrag);
if (vertexshader.IsNull())
{
return;
}
if (fragmentshader.IsNull())
{
return;
}
if (!vertexshader->IsDone())
{
return;
}
if (!fragmentshader->IsDone())
{
return;
}
Standard_Boolean attach1=aProgram->AttachShader(vertexshader);
Standard_Boolean attach2=aProgram->AttachShader(fragmentshader);
if ((!attach1)||(!attach2))
{
return;
}
if (!aProgram->IsDone())
{
return;
}
Standard_Boolean set1=aProgram->PushVariableFloat("edgefalloff", 2.0f);
Standard_Boolean set2=aProgram->PushVariableFloat("intensity", 2.0f);
Standard_Boolean set3 = aProgram->PushVariableFloat("ambient", 0.01f);
if ((!set1)||(!set2)||(!set3))
{
return;
}
Handle(Prs3d_ShadingAspect) aNewAspect = new Prs3d_ShadingAspect();
aNewAspect->Aspect()->SetShaderProgram(aProgram);
//aNewAspect->Aspect()->SetAlphaMode(Graphic3d_AlphaMode::Graphic3d_AlphaMode_Blend);
selobject->Attributes()->SetShadingAspect(aNewAspect);
myAISContext->CurrentViewer()->Update();
// XRay.vs
varying vec3 N;
varying vec3 I;
varying vec4 Cs;
//! Computes the normal in view space
vec3 TransformNormal (in vec3 theNormal)
{
vec4 aResult = occWorldViewMatrixInverseTranspose
* occModelWorldMatrixInverseTranspose
* vec4 (theNormal, 0.0);
return normalize (aResult.xyz);
}
//! Entry point to the Vertex Shader
void main ()
{
N = TransformNormal (occNormal);
vec4 P = occWorldViewMatrix * occModelWorldMatrix * occVertex;
I = P.xyz-vec3 (0);
Cs = occColor;
gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}
// Xray.fs
// vertex to fragment shader io
varying vec3 N;
varying vec3 I;
varying vec4 Cs;
// globals
uniform float edgefalloff;
uniform float intensity;
uniform float ambient;
// entry point
void main ()
{
float opac = dot (normalize (-N), normalize (-I));
opac = abs (opac);
opac = ambient + intensity * (1.0-pow (opac, edgefalloff));
// opac = 1.0-opac;
gl_FragColor = opac * Cs;
gl_FragColor.a = opac;
}
Thu, 04/16/2020 - 23:02
The callstack with the crash (with debug OCCT build) may help to reveal what might be wrong.
Fri, 05/08/2020 - 20:08
Hello. I finally compiled occt 7.4.0 in android studio and can debug normally.
I can finally debug the previously mentioned issue of setting variables for shader programs that will crash.
During the debugging process, I found the situation in Figure 1 2 3 4. The key place is position 2 in Figure 2. During dynamic_cast, the returned value is NULL, causing the program to crash.
I don't know if you can give some suggestions? Also, can you take a look at the question here https://www.opencascade.com/content/brepfilletapimakefillet-crash-occt-740.
The same problem occurs when the conversion result is NULL when the type is converted, causing the program to crash.
Sun, 05/10/2020 - 11:18
The symptoms with dynamic_cast unexpectedly returning NULL look similar to the following Android NDK bug:
https://github.com/android/ndk/issues/1075
https://tracker.dev.opencascade.org/view.php?id=30937
If this is your case (compare symptops and preconditions) - you may try to reanimate existing report to Google or create a new one and try providing more details (as previous one has been closed due to lack of details).
Sun, 05/10/2020 - 13:12
ok!Thanks a lot.
I do some change as the search result from google(search the dynamic_cast NULL).Then it works.
1.build the occt 7.4.0 with cppflags -frtti -fexceptions
2.build my project with cppflags -frtti -fexceptions
3.remove the loadLibVerbos(including the occt library and the gnustl_shared)
You are so friendly.
Also, can you take a look at the question here https://www.opencascade.com/content/color-picture-obtained-dump-different-color-rendered-scene.