# mr_malee

Members

59

185 Neutral

• Rank
Member
1. ## Help finding inverse XP function

I got it working. Thanks again for the help int GetLevelForXP(int xp) { float baseXP = 100; float a = baseXP / 2f; float b = Mathf.Sqrt(a * a + 4 * a * xp) / a; float c = b / 2f; int level = Mathf.CeilToInt(c); //because of rounding issues the level returned might be higher. So check and reduce if necessary //the XP at the level returned should always be <= to the input level while (GetXPForLevel(level) > xp) { level--; } return level; }
2. ## Help finding inverse XP function

Really appreciate the help, I must be stupid, but how did you get 15 out of that equation? I get 750 float a = 50; float b = Mathf.Sqrt(50 * 50 + 4 * 50 * 10500); //1450 float c = (a + b) / 2; //750
3. ## Help finding inverse XP function

Hi, so I've got a function that gives me a XP for a given level. I'm looking at finding the inverse: (Level from XP) e.g: int GetXPForLevel(int level) { float baseXP = 100; float xp = (Mathf.Pow(level, 2) + level) / 2 * baseXP - (level * baseXP); return Mathf.FloorToInt(xp); } int GetLevelForXP(int xp) { //need the inverse of the above function return 0; } My Math skills are not great :(, not sure where to even begin
4. ## Project Camera View onto plane through Matrix

Hi, I'm trying to project a 3D camera's view onto a plane. I currently have this working by:   1. Find normalized viewport position (-1 to 1) 2. Project this coordinate into 3d using the inverse of the cameras View and Projection matrices 3. Find the direction of this coordinate relative to the camera view 4. Find intersection of this direction onto plane.   I'm doing this inside a shader but wondering if I could simplify it by constructing some sort of matrix that finds the plane intersection for a normalized viewpoint. Not sure if that's even possible. Here's a picture that might better explain:     What I currently have: float4 unproject(float x, float y, float z) { // unproject the point // _ProjMatrix is the inverse of a cameras view and projection matrices // _ProjMatrix = inverse(cam.projectionMatrix * cam.viewMatrix) float4 pos = mul(_ProjMatrix, float4(x, y, z, 1)); return pos * (1.0 / pos.w); } v2f vert (appdata v) { v2f o; //convert the mesh vertex into local viewport space float4 vp = v.vertex; float x = vp.x / _Size; float y = vp.z / _Size; //unproject into the near and far clipping planes of the camera float4 p1 = unproject(x, y, -1); float4 p2 = unproject(x, y, 1); //find the direction of this viewport point float4 dir = normalize(p2 - p1); //project this viewport direction onto the world plane float distanceOfVertex = mul(_WorldMatrix, p1.xyz).y; float lengthOfLightDirectionInY = mul(_WorldMatrix, dir.xyz).y; dir = dir * (distanceOfVertex / -lengthOfLightDirectionInY); //output vertex o.vertex = mul(UNITY_MATRIX_VP, p1 + dir); } As you can see there's lots of multiplication here. First I have to find the near and far projections, find the normal between them, find the projection of that normal on the plane. Wondering if this could be simplified if I could just take that viewport position and multiply by the camera projection and view + some plane intersection matrix.
5. ## Find parabola velocity needed to reach a point with air resistance

Ok thanks. I have no idea what a polynomial is, but I'm going to do some reading.   so let's say   t = 3, start position = 0,0, end position = 10,5 gravity: -9.81 drag: 0.5
6. ## Find parabola velocity needed to reach a point with air resistance

Hi, I'm having a very difficult time figuring out how to find the velocity needed to reach a point for a projectile (shot from a cannon) to reach a point with air resistance.   time step is constant: 0.02 air resistance is constant: 1 / (1 + 0.02 * drag), where drag is a constant: 2 gravity is constant: -9.81 initial velocity is: 7, 20 mass is constant: 1   integration is like so:   velocity += gravity * 0.02 velocity *= airResistance position += velocity * 0.02   I'm not much of a math guy, any help would be greatly appreciated :)
7. ## Direct Compute, extracting bounds of pixels

Thanks :) yeah this shader is for a specific sized texture
8. ## Direct Compute, extracting bounds of pixels

You are a life saver. I finally got it working. I didn't realize that making a reference to bounds[0] was copying it to a new variable!   If I use bounds[0] in the InterlockedMin function, it saves my data :D   final working code: #pragma kernel CSMain struct Bound { uint minX; uint minY; uint maxX; uint maxY; }; Texture2D<float4> tex; RWStructuredBuffer<Bound> bounds : register(u0); [numthreads(8, 8, 1)] void CSMain (uint2 pos : SV_DispatchThreadID) { float4 color = tex[pos]; if (color.r == 0 && color.g == 0 && color.b == 0) { InterlockedMin(bounds[0].minX, pos.x); InterlockedMax(bounds[0].maxX, pos.x); InterlockedMin(bounds[0].minY, pos.y); InterlockedMax(bounds[0].maxY, pos.y); } } Thanks again
9. ## Direct Compute, extracting bounds of pixels

Ok thanks. So what's happening is multiple threads are accessing the bounds[0] and modifying that value in random order?   You mentioned atomic computations. I've tried implementing the InterlockedMin on a groupshared object without success: groupshared Bound boundary[1]; [numthreads(8, 8, 1)] void CSMain (uint2 pos : SV_DispatchThreadID) { Bound b = boundary[0]; InterlockedMin(b.minX, (float)pos.x); } But I just get this error:   "interlocked targets must be groupshared or UAV"   How do you define a group shared object?
10. ## Direct Compute, extracting bounds of pixels

This works, but is really really really slow. 5fps [numthreads(1, 1, 1)] void CSMain (uint2 id : SV_DispatchThreadID) { uint w, h; tex.GetDimensions(w, h); uint2 pos; Bound b = bounds[0]; for (pos.x = 0; pos.x < w; pos.x++) { for (pos.y = 0; pos.y < h; pos.y++) { float4 color = tex[pos]; if (color.r == 0 && color.g == 0 && color.b == 0) { b.minX = min(b.minX, pos.x); b.minY = min(b.minY, pos.y); b.maxX = max(b.maxX, pos.x); b.maxY = max(b.maxY, pos.y); } } } bounds[0] = b; } How can I translate that into a threaded version without loops?