SpotLight Node Turns Everything Pitch Black - godot

I am a beginner in Godot and I am making a 3D scene. However, when I added a SpotLight node to the scene, all the other objects turned dark. The OmniLight and the DirectionalLight works fine. When I hide the SpotLight, the scene returns to normal. If the SpotLight isn't facing the objects, they remain how it is supposed to be. Any ideas on how to solve this?
Here is what it looks like.
When I make it not visible:
Oh, and these objects are CSG objects, just so you know.
Here is the link to the minimal repro project.

Related

Prevent modulating color of specific child sprites in godot

Updated: I had a hacky way to fix this in the answers below, but #Theraots answer is the proper way to go about it.
I am creating a game with fish.
In order to modularize my project, I decided to make a base Fish scene and use an instance of it for my FishPlayer and School scenes. This way I can simply use a base Fish in other areas in my game.
In my FishPlayer scene, I would like to add color to my fish which I do by using the modulate property in CanvasItem. However, the only problem with this is that it changes the color of the CPUParticles2D of my base Fish scene. The same thing happens as well in the FishSchool scene.
So, the end goal here is to keep the original particles color of the base Fish scene while in a new scene allowing color modulation of the rest of the base fish.
I've been messing with the shaders of the CPUParticles in hopes that it would prevent the parent instance from changing it but does not work in my case. Any ideas of what I'm missing here?
Here's a fix that I read about, but didn't work in my case: link
From the context menu of the scene tree on the scene where you instance the fish… Select Editable children. Then you will have access to the child nodes of the fish (while it is still an instance of that scene), so you can use modulate only on the nodes you want, instead of having to use modulate on the root of that scene.
The fix I ended up implementing isn't pretty, but the easiest is to grab the individual sprite nodes and modulate them

Can you hide a node when not directly above a parent in Godot?

So I have an instanced scene that is supposed to be the child of a colour rect in my tree. I want to randomly generate the nodes, but I also want parts of the view to be cut off if the texture no longer is above the main section. I know you can render nodes below their parents, but I don't know if stopping part of them from rendering is physically possible.
In this image I want the bottom circle to remain the same, but the top circle to not show anything above the dark purple box
This is the node tree in the editor
Is there any way to do this directly, or am I gonna have to use a viewport of some variety?
I believe what you want is to set rect_clip_content to true on the ColorRect (or whatever Control). Making invisible any part of its children outside of it.
From Godot's documentation:
bool rect_clip_content
Enables whether rendering of CanvasItem based children should be clipped to this control's rectangle. If true, parts of a child which would be visibly outside of this control's rectangle will not be rendered.
If what you want is the opposite, perhaps you can use z_index to have something render on top, occluding the parts you don't want visible.
There is also a trick you can use with lights (including 2D lights):
Make a light that matches the area you want things to be visible.
Set a custom material that will be transparent by default, but visible on the light pass. The simpler way to do this is to set the light_mode of the material to "Light Only". You could also do it with a custom shader instead.
Making something disappear with light, in 2D, is impossible. In 3D, you can use flags_use_shadow_to_opacity. That is how you make a shadow catcher.
But, there is one more trick: you can use a mask. This should give you full control of when to show or hide things. So, if none of the above solutions works for you, use a mask. I have an explanation in a different answer. See also: How to crop sprite in a non-rectangular form?.
Mighty Mochi Games recently (2022-03-30) made a compilation of the different approaches in video form: Mask Methods Collection - Godot 3.x - 2D
.

Can't add child sprite on scaled object

Ok, guys, here's the deal.
aboutBackground = Sprite::create("fadeBack.png");
aboutBackground->setScale(winSize.width, winSize.height);
aboutBackground->setPosition(winSize.width*0.5, winSize.height*0.5);
this->addChild(aboutBackground);
Sprite *sprAboutPanel = Sprite::create("aboutPanel.png");
sprAboutPanel->setPosition(aboutBackground->getBoundingBox().size.width*0.5, aboutBackground->getBoundingBox().size.height*0.5);
aboutBackground->addChild(sprAboutPanel);
Before scaling aboutBackground sprite it works perfectly. But because aboutBackground is just a fading background, I decided to go with 1px picture and scale it to full screen. But right now sprAboutPanel doesn't appear on the screen. I really wonder why? Thx for your responses!
One trick you can use in this instance is to not add the about panel as a child of the background, but rather the scene instead. Scaling a parent makes for tricky positioning of children since positions are scaled. You would probably find that in your code if you set the position of aboutPanel to (0.5,0.5) it would probably work as expected.
I would instead change:
aboutBackground->addChild(sprAboutPanel);
to this:
this->addChild(sprAboutPanel);

Rotating a circle image shifts it's position

I am trying to rotate a circle image using jquery rotate plugin. But, I observe that the circle image appears to be oscillating about it's center while rotating. Something like a linear movement.
In IE7, it's pretty much observable. In Chrome/Firefox, if you zoom a bit, this wobbling issue can be observed.
I tried to rotate the image using Raphael library too. But still, the circle was wobbling.
Then I rotated the image with a c# program to see if the problem is with the browsers' graphic engine. But even here this issue is observed. I even took various images to see if the circle was imperfect. But, all the images show this behavior.
Can this be happening because of anti aliasing? Or, is it just an optical illusion?
If not, then what else can be the reason?
I am using jqueryrotate plugin rotate method to do this. $('#circleimg').rotate(Position);
Check this jsFiddle. Btw, this is the kind of source code you can include yourself in your question to make answering it easier for others.
http://jsfiddle.net/KyJzQ/
I used this rotate plugin since you did not specify which one you used.
HTML
<img id="circleimg" src="http://i.imgur.com/KgUDClr.png">
<img id="circleimg2" src="http://i.imgur.com/sK4qP6z.png">
JAVASCRIPT
var rot = 0;
window.setInterval(function() {
$('#circleimg').rotate(rot);
$('#circleimg2').rotate(rot);
rot += 1;
},
5
);
I think the circle you've provided is not actually a perfect circle, hence the tiny "oscillations" you see.
I added another circle that I rendered myself. If you zoom in closely enough you will see jagged pixels moving around the edge of my circle, but I don't see any way around this since the jQuery plugin is not actually re-rendering the image. I don't see any of the "oscillating" you mention in my circle.
This issue is more about vector art than it is about programming. Get a nice vector graphics program and render the nicest circle you can. Even the one I made is not really that good. Or use HTML5 and canvas to draw dynamically, rather than moving a static image around.

Not able to get stencil to work

Was trying to get Stencil to work in my app. I use Sprites to render content on to the Device. Content could be movies, pictures or text.
Can I set the stencil buffer using these Sprites, which can be used in later passes to stencil out other Sprites being rendered?
I'm even not able to stencil out any of the Sprites by setting StencilFunction = Compare.Never! Anything wrong that I might be doing?
I've already spent almost an entire day checking out posts related to Stencils in MDX, but just couldn't get it to work.
Bit more searching got me to a technique wherein we draw silhouette of the shapes to be added to the stencil buffer. Is this really required in my case? I just want to use the Sprites, and add them to stencil buffer to stencil out other Sprites.
EDIT: OK.. So I figured out how to get it done. Referred to this post - http://www.gamedev.net/community/forums/viewreply.asp?ID=1999276
But now the sprite is ignoring alpha values and rendering sprites opaque. Similar to the effect we get when alpha blending is set to false. Any ideas?
So, I finally figured it out. It's all related to Sprites and its Begin() method.
Sprite.Begin() will modify the RenderState and disable stencil. We can prevent it by setting SpriteFlags.DoNotModifyRenderState flag, but then the alpha blending is not supported when sprites are drawn.
What I did now was simply call Sprite.Begin() without SpriteFlags.DoNotModifyRenderState flag set. And before the call to Sprite.Draw(), enabled stencil on the device.

Resources