How to go about rendering images / decals using 2D raytracing?

Hey everyone, recently, I’ve been working on this prototype of sorts as a way to introduce flexibility amongst optimization and both resolution capabilities, I looked into how engines (such as DooM & Wolfenstein 3D render using raytracing), and through the help of both the DevForum, several of youtube videos and more… I figured out a way to render the engine thus far, and now I’m at a dead-end.

How it looks so far:

My problem specifically is how to go about rendering decals, images, or textures? How would I start on something like that? I’m not the brightest in math, but I really want to improve in it, however, I genuinely have no idea where to start, therefore I’m coming to you all with this question in hand.

7 Likes

I do have some methods on how to go about this, but I’m trying to narrow this down to the easiest possible method.

1.) use HTTP requests to basically get the image and break it down pixel per pixel, then render in a column based on the hit position relative to the center of the brick being hit
2.) reconstruct textures by creating a table of sorts, then index based on the landing position of the raycast
3.) find out how to splice images and then based on the raycasts hitting the wall, construct a view based on the center of the brick itself, then find an offset based on the center and then the hit position itself thus giving me a sort of ‘splice offset’, or an intake on which pixel should be rendered at that specific time(?)

1 Like

I figured out an actual way about going with this. I have to make use of the ImageLabel instance, but I’m still having a bit of trouble. Right now, I’m trying to find the amount of frames rendering said image so that way I can split amongst them, but I still have no idea where to go from here… Any help would be greatly appreciated. :slight_smile:

What I have as of now:

local TotalFrames = 0;

for _,v in pairs(Screen:GetChildren()) do -- A way to gather all frames currently rendering a part with a texture.
  if (v:FindFirstChild("ImageFrame")) and (v.ImageFrame.Image == Texture.Image) then
    TotalFrames += 1;
  end
end
--print(TotalFrames);
local Width,Height = 1024,1005; -- use HTTPService to get these later... I have these set as constants for testing as of now, these are the images dimensions.
local X = Width/Count;
--1024
Frame.ImageFrame.ImageRectSize = Vector2.new(X, Height)
Frame.ImageFrame.ImageRectOffset = Vector2.new(-((Player.Position - ViewRay.Position).Magnitude) * tonumber(Frame.Name), 0);

I’m also aware of the ZIndex bug, but not too interested as of now, I’d much rather focus on finding a viable solution to this, first.

1 Like

I fixed the rendering issue… :sweat_smile:, now it’s more or less just a scaling issue.

Here’s a gif:
96ffb46cffa48fc035899d25a7c1531e

To get to the point, here’s my issues:
1.) How can I keep the size proportionate between the entire size of the ray-casted part and not just the dimensions of the decal itself? I know I could collect the frames that are raycasting onto said part with said textures, but… unfortunately, I don’t know where to plug this in.
2.) How can I keep the position constant, and not based on the player’s camera orientation?

1 Like

I figured it out, ultimately, I had to get all frames rendering the texture at the time, then I had to make use of dividing the width of image by the amount of frames currently rendering that image, now I’m just tweaking to make sure everything looks good. Here’s a gif!

335e2fd5a5e6c14822400685efad905a

1 Like