- Edited
Megalomaniak
Unfortunately mesh is the entire world (this is a minecraft clone), duplicating the mesh would be really hard on performance I think? Im open to harder solutions though
Megalomaniak
Unfortunately mesh is the entire world (this is a minecraft clone), duplicating the mesh would be really hard on performance I think? Im open to harder solutions though
I use a shader to toggle on and off the roof of a house.
if (is_roof_pixel) {
ALPHA = 0.0;
}
The problem is this lets sunlight in.
Is there a way to hide the roof without letting in directional light?
Maybe there's some way to hide the mesh after it draws its shadow?
I also tried discard
as well but no luck.
Blender has a visibility option that allows you to hide meshes for specific cameras, maybe theres a similar feature in godot?
I have to boxes. In the editor the top box casts a shadow on the lower one.
In game the shadow does not appear:
The light is coming from a DirectionalLight3D
This is the material Im using for the boxes:
Any idea how I can get shadows in game?
If you cant read the text on the image please right click the image and open it in a new tab.
Thanks!
Megalomaniak
Thank you for the response! I solved my problem by simply enabling smooth shading in blender and then those changes translated to Godot on export.
I made the false assumption that shading was separate from the mesh. I guess shading is a property of the mesh?
Can anyone explain what that property is? and how it works?
Thanks!
Blender has something called "smooth shading", or "mesh smoothing." As you can see the two meshes on the left are flat shaded and their smooth shaded versions are on the right:
Smooth shading gives low poly cubes the impression that they are rounded.
Is there a way to do this in Godot?
I tried playing with diffuse modes but they all had a hard edge to them.
Megalomaniak
Thank you so much! It was a normal issue
Heres my mesh in blender:
Here it is looking good in the editor:
But in the game the shadows look chunky:
Whats going on? and how can I make the game look like the editor?
Im not sure a normal map will be enough. Heres an exaggerated example of the problem:
In this picture you can see the silhouette of a billboard in the foreground. Ideally Id like it to not even be a silhouette.
I think I may have to write my own shader, but Im not really sure how. Basically Id like to simulate light hitting a flat surface when in reality its hitting a scaled surface.
If I try actually make the surface of the mesh an actual cube it solves the above problem but presents a new one. Lets say I want to simulate a half block it works fine when my light source is in front of the half-block like so :
However if I move the light behind the cube then the shadow betrays the illusion, revealing that it is infact a whole cube not a half cube:
because the shadow does not respect the normal map and the "top" of the half cube appears shaded because the side of the full cube mesh is being shaded.
Im playing with the Godot voxel engine. I have a fixed isometric camera.
Each voxel is a billboard like this:
When I put them all together into a 3D mesh they look like this (which Im happy with):
But I would like to have a torch effect in game so when I move the torch around it lights up near by voxels. Unfortunately the lighting ruins the 2.5 D effect by revealing that each voxel is a billboard because you can see that the floor is not flat. (I am using normal maps)
I tried changing all the voxles to actual cubes but then when I add lighting
it betrays that my voxles are actually perfect cubes and not intricately shaped blocks of dirt. (As you can see by the dark perfectly square shadows)
Can you guys think of anyway I can do lighting without revealing the underlying geometry of each voxel?
Megalomaniak
yup youre right I found it in the code. thank you!
My game is based of zylanns voxel demo.
Id like to shrink the size of his main avatar to be half the height.
But I cant figure out how to do that.
In the scene above you can see he has a MeshInatance. Could the mesh instance have a collision box?
I dont see anything that looks like one. I tried lowering its size from 1 to .5 but that didnt work. I tried hiding it too by clicking the eye icon in the scene, but no luck.
I also added an animatedsprite3d to the scene but I dont think that has any collision stuff on it.
Im just not sure what Im looking for...
Thanks for any help!
Ive gota fragment shader.
Ideally Id like to have a function like this:
void draw_normal_pixel() {
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo,base_uv);
albedo_tex *= COLOR;
ALBEDO = albedo.rgb * albedo_tex.rgb;
SPECULAR = specular;
ALPHA = albedo.a * albedo_tex.a;
ALPHA_SCISSOR_THRESHOLD = .3;
}
because I have a ton of if else statements and they all call the above code.
Without the function I have a lot of code duplication.
But outside of the fragment function UV doesnt mean anything. So if I write that function I get
"unknown identifier in expression: "UV"
Im also worried that the function may add extra overhead and slow the shader down.
What is the most optimal way to eliminate the code duplication?
I have a shader material. Its properties are pictured above. Id like to instantiate its "Slice Sprite UV Offset Y" property on start up.
I tried this:
var _solids_material = load("res://blocks/solids_materal.tres")
func _init():
_solids_material.set_shader_uniform("slice_sprite_uv_offset_y", slice_sprite_uv_offset_y)
ResourceSaver.save(_solids_material, "res://blocks/_solids_material.tres")
But the property didnt change?
Any idea what im doing wrong?
Thanks!
I have a shader material that Id like to add a normal map to. It doesnt have a slot for the normal map, and I assume I need to add it programmatically.
Can anyone link to an example project? Im using Godot 4.
Thanks!
How can I create a mesh from a .obj file? Not a MeshInstance, but a Mesh? I can do it in the editor GUI, but how could it be done in code? Mesh doesnt seem to have a load() function like MeshInstance...
Thank you!
I'd like to be able to move my UVs over a bit in the shader. I tried doing this in the fragment shader: UV.x += 0.0161333333333; UV.y += 0.0226472; But Godot tells me constants cant be modified. I'm trying to create an effect that if a player pushes a button then the texture of an object changes, but I dont want to load a whole new texture so I figured I'd just move the UVs over a bit.
I've gota voxel game with a fixed camera. Every voxel is a billboard. But the billboards are larger than the cells so they clip into lower cells (although from the fixed camera perspective they appear to fit into the cells). So every cell has a mix of voxels that are above or below it and when I hide the ones above it I need to go into the lower cell and hide the parts that clip down into it. So for every billboard I calculate its normal and a point on the billboard then use the dot product to figure out if a the current pixel being drawn falls on the same plane that the billboard inhabits. Then I hide every pixel that falls on those planes. Unfortunately this code is rather slow and it seems I will likely have to rewrite this feature in the voxel engine itself rather than the shader...
edit actually it runs fast enough. It was something else that was lagging me. But I do wonder if there is a more optimal way to write it.
I did notice that if I replace discard; with ALPHA = 0.0; it does seem to run a bit faster.
I'm not sure what the correct way to write this is:
vec3 plane_a_point_1 = vec3(0.791629, 0.901993, 0.380778);
vec3 plane_a_normal = vec3(0.3298,0.81282,-0.48016);
vec3 vector_from_plane_a_point_1_to_p = p - plane_a_point_1;
float plane_a_result = dot(vector_from_plane_a_point_1_to_p, plane_a_normal);
vec3 plane_b_point_1 = vec3(0.827042, 0.776654, 0.506066);
vec3 plane_b_normal = vec3(0.3298,0.81281,-0.48017);
vec3 vector_from_plane_b_point_1_to_p = p - plane_b_point_1;
float plane_b_result = dot(vector_from_plane_b_point_1_to_p, plane_b_normal);
vec3 plane_c_point_1 = vec3(0.130028, 0.61924, 0.447717);
vec3 plane_c_normal = vec3(0.32981,0.81281,-0.48018);
vec3 vector_from_plane_c_point_1_to_p = p - plane_c_point_1;
float plane_c_result = dot(vector_from_plane_c_point_1_to_p, plane_c_normal);
if (overlap_plane_a_result > -0.001 && overlap_plane_a_result < 0.001) {
discard;
}
else if (overlap_plane_b_result > -0.001 && overlap_plane_b_result < 0.001) {
discard;
}
else if (overlap_plane_c_result > -0.001 && overlap_plane_c_result < 0.001) {
discard;
}
I actually tons of these planes that I'm hiding. I'm just wondering if there is a way to optimize this code? Maybe I shouldn't use if else?