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

RFE (Request for Enhancement) Vertex shaders for Spheres #87

Closed
coderextreme opened this issue Jan 6, 2024 · 7 comments
Closed

RFE (Request for Enhancement) Vertex shaders for Spheres #87

coderextreme opened this issue Jan 6, 2024 · 7 comments

Comments

@coderextreme
Copy link

Vertex shaders for spheres are pretty critical for my projects, unless PBR can do this:

https://coderextreme.net/X3DJSONLD/src/main/personal/cgeball.x3d

I'm trying to learn how to compile shaders, etc. I'm not sure if that's necessary.

@coderextreme
Copy link
Author

This is higher priority:

#39

Thanks!

@coderextreme
Copy link
Author

coderextreme commented Jan 6, 2024

Perhaps I just need to learn how to compile shaders. I'm not sure how to read the first error message of https://coderextreme.net/X3DJSONLD/src/main/personal/cgeball.x3d I don't know if Spheres can't have vertex shaders, or the shader can't compile.

The current version I have removed the issue with the version not coming first, but there's additional variable issues (related to version 140). Some idea of what version might work would be welcome. Essentially, I get errors when I put a version, and different ones when I don't

@coderextreme
Copy link
Author

I finally found this, looking at it:

https://castle-engine.io/apidoc/html/CastleGLShaders.html

@coderextreme
Copy link
Author

If you're wondering what's wrong with what's displayed, I'm pretty sure the ball is supposed to be translucent and reflective, not magenta.

@michaliskambi
Copy link
Member

michaliskambi commented Jan 6, 2024

We already support shaders on any X3D geometry, including on Sphere.

You can use ComposedShader and ShaderPart nodes, from the standard, https://castle-engine.io/x3d_implementation_shaders.php .

Or you can use Effect, EffectPart nodes, which are CGE-specific extensions (actually, FreeWRL also implements them but we didn't test for perfect compatibielity) and allow to write shader code to enhance the "core" rendering provided the engine.

Demos of all above are available in e.g. https://github.com/castle-engine/demo-models ,

That said, it doesn't mean we support any GLSL code in our shader. We cannot. Each browser requires a bit different set of uniforms, due to the way its internal shaders are made (e.g. whether you do animation on GPU or not), and the OpenGL(ES) version used is also relevant (dictates what you can support). In effect, it is hard to write GLSL code for ComposedShader and ShaderPart that is compatible across all X3D browsers. Our Effect, EffectPart offer a way to write portable GLSL code, but so far only CGE and FreeWRL implement it.

Opening the referenced model ( https://coderextreme.net/X3DJSONLD/src/main/personal/cgeball.x3d ) -- it uses gl_Xxx uniforms which have been removed in new OpenGL.

@coderextreme
Copy link
Author

coderextreme commented Jan 7, 2024 via email

@coderextreme
Copy link
Author

I had to add:

uniform mat4 castle_ModelViewMatrix;
uniform mat4 castle_ProjectionMatrix;
uniform mat3 castle_NormalMatrix;
attribute vec4 castle_Vertex;
attribute vec3 castle_Normal;

to my castle.vs shader.

So it works, but there are additional warnings, unrelated to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants