Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1412064 Posts in 69447 Topics- by 58483 Members - Latest Member: Exye

June 24, 2024, 08:24:30 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 67 68 [69]
Print
Author Topic: General thread for quick questions  (Read 138295 times)
a-k-
Level 2
**


View Profile
« Reply #1360 on: February 02, 2023, 07:23:19 PM »

For the general case:
1. y = ax+b
2. (x%1 - 0.5)² + (y%1 - 0.5)² < 0.1

Translate the line to get rid of the two 0.5's.
"Inflate" it so that it has a thickness of 2*sqrt(0.1).
Let y1 and y2 be the upper and lower outlines of the thick line.

For any integer x0:
- For any integer y0 in the open interval (y1, y2):
- - (x0, y0) is the origin of a circle intersecting the translated line
- - Calculate its 2 intersections with the translated line
- - Translate back to the original coordinates system

Edit: more details
« Last Edit: February 02, 2023, 08:03:11 PM by a-k- » Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1361 on: February 03, 2023, 08:03:02 AM »

Thanks, there is some interesting ideas.

I forgot to specify I was trying to get rid of for loop because shader... I guess this is no longer a quick question and I should open a thread ... I'm looking for a result in form of kf(x), in which k give the kth hit, as a generalization of ddx algorithm, but on "concave" primitive instead of line or plane.
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1362 on: March 24, 2023, 11:21:32 AM »

I made a thread: probably not solvable ?
https://forums.tigsource.com/index.php?topic=74410.0

I solved first hit before applying my wrapping trick, but once the ray wrapped vertically (using minor axis symmetry to select the vertical), finding other hit for n wrap in fixed step (no loop aka no raymarch) seems like a tall order.
Logged

Abashi76
Level 0
*


I need rpg maker partner.


View Profile WWW
« Reply #1363 on: January 14, 2024, 04:47:48 PM »

How do you add or change your avatar on this forum?
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1364 on: April 15, 2024, 05:16:44 PM »

I need help on a godot shader Sad
I can't find help in internet anymore!
where are all the help going today?

It's not the first time I make a cylinder intersection code, but somehow I messed this one And can't figure out:

Code:
shader_type spatial;

uniform sampler2D text;

void fragment()
{
mat3 TBN = mat3(TANGENT, BINORMAL, NORMAL);
vec3 viewDirTangentSpace = TBN * VIEW;

const float mydepth = 1.0;
vec3 raydir = viewDirTangentSpace;///.5; // ray direction/depth

const vec2 centers = vec2(-0.0,.5);//x and depth
const float radius = 0.3;
const float r2 = radius * radius;

const vec2 UVsurfacePos = vec2(UV.x,0);

//vector: 2d origine to circles center in 2d along vertical depth plane
const vec2 L = centers.xy-UVsurfacePos.xy; const vec2 L2 = L*L;

//dot projection: 2d centers to 2d ray line
vec2 raydir2d = normalize(raydir.xz);
float tca = dot(L,raydir2d);

//2d distances to projected
float distances = abs( (L2.x + L2.y) - (tca) );
float d = sqrt( distances );float d2 = d * d;
//float d2 = distances * distances;

//2d intersections points
float thcdiff = r2 - d2; float thc = sqrt (thcdiff);
vec2 t = vec2(tca +thc, tca -thc);

//get extrusion in y
//vec3 p11 = vec3(UV,0) + raydir * t.x; //first impact column 1
//vec3 p12 = vec3(UV,0) + raydir * t.y; //second impact column 1
vec3 p11 = raydir * t.x; //first impact column 1
vec3 p12 = raydir * t.y; //second impact column 1

//get normal
vec3 N11 = normalize( vec3(  (UV+p11.xz - centers),0) );
vec3 N12 = normalize( vec3( -(UV+p12.xz - centers),0) );

//get twist
float twist11 = atan(N11.x, N11.y);
float twist12 = atan(-N12.x, -N12.y);//reverse the N

vec3 result = vec3(0.0); // black color if not intersecting

if( t.x > 0.0 && t.y > 0.0 )
{
result = vec3(1.0, 0.0, 0.0); // red color if intersecting cylinder1
//result = N11; // red color if intersecting cylinder1
}

float ptmin = min(t.x,t.y);
vec2 UVoffset = UV+raydir.xy * ptmin;

ALBEDO = result;
NORMAL = N11.xzy;
ALBEDO = vec3(UVoffset,0);
ALBEDO = texture(text, UVoffset).xyz;
//ALBEDO = vec3(L.x+0.5,0.0,0.0);
//ALBEDO = vec3(twist11+0.05);
//ALBEDO = N12.xzy;
//ALPHA = 0.0;
//NORMAL

}

Technically I use scratch pixel version. BUT I intercept a 2d circles that I'm trying to extrude along X to get axis aligned cylinder.

Then I supposed to find the angle (twist) of the hit to compute the distance to the spiral.

BUT all I get is a blobby mess and nothing usable, which mean the code partially works but don't output correct result, that suggest something is screwy somewhere!
Logged

Pages: 1 ... 67 68 [69]
Print
Jump to:  

Theme orange-lt created by panic