DigvijaysinhGohil / Godot-Shader-Lib

Visual shader node library for Godot engine.
MIT License
129 stars 6 forks source link

Can I use it for creating a Skybox shader on a sphere? #3

Closed Eisenspalter closed 5 months ago

Eisenspalter commented 7 months ago

I want to create a Skybox on a sphere based on a panorama sky texture. In Godot I can only use the shader type SKY for the default skybox. I cannot use for a custom sphere, so I have to write me own shader. I do a lot of research but I can't get any further. Can I use your Shader-Lib do create such a shader? I'm very desperate because I haven't made any progress for months.

DigvijaysinhGohil commented 7 months ago

Hi @Eisenspalter, To create a sphere skybox you need to use shader type spatial because our sphere is a 3D object, then you can simply apply panaromic texture just make sure to set cull mode to front You don't necessarily have to use the add-on as well.

Eisenspalter commented 6 months ago

That is not so easy. That only works, if you stand in the middle of the sphere and you don't move. If you want to use it like a real SkyBox you need a shader with an Equirectangular Projection.

DigvijaysinhGohil commented 6 months ago

Hi @Eisenspalter, I have a question, why create a skybox on sphere? Any specific reasons?

Eisenspalter commented 6 months ago

For a SciFi game: Each sphere is a world and you move/fly from one to another then you shrink down and play the level. I also will use this it for an art exhibition where each artist has his own sphere and you walk from one to another to watch the paintings. Both are VR projects. In Unity I have the shader to do this. I tried to port it to Godot but something doesn't work. vec3 viewDirection = CAMERA_DIRECTION_WORLD; vec2 equiUV = (vec2( (atan( viewDirection.x , viewDirection.z ) / TAU ), (1.0 + ( ( asin( viewDirection.y ) / ( HALF_PI ) ) - -1.0) * (0.0 - 1.0) / (1.0 - -1.0)) )); ALBEDO = texture(skyBoxi, equiUV).xyz; This is the shader I created in Godot. But It doesn't work

Eisenspalter commented 6 months ago

This is the Unity (Amplify) Shader that works and I tried to recreate image

DigvijaysinhGohil commented 6 months ago

I don't know much about Amplify but could you tell me what would be in "viewDirectionRotated"? Just a View direction of a fragment in world space? By knowing that I think I could solve this.

Eisenspalter commented 6 months ago

These are optional animation parameters to rotate the skybox. But I have now used VIEW instead of CAMERA_DIRECTION_WORLD. Now things look much better. Now the only thing that seems to be missing is the rotation of the HEAD/Camera/View. In addition, VIEW is only available in the fragment shader (worse performance).

Eisenspalter commented 6 months ago

image Better image. This image looks better, and I hide some test items

Eisenspalter commented 6 months ago

I forget to say. The optional rotation was multiplied with the View Direction in World Space. That the reason I use the VIEW know in my viewDirection variable