Let me get this straight. You pick a position on your “terrain”, which at present seems to be only variable in x and z with a constant z, and want to apply color linearly blended with current color within a radius around the intersectio point. Correct? Am I right in assuming you’re attempting to write a real-time heightmap editor?
For this purpose, you probably want to use projective texturing, i.e. a projector hovering above your terrain looking straight down, focusing on your center point with a symmetrical frustum and and an orthographic projection. If that’s too confusing, let us know.
In short: When projectively texturing, you map world-space coordinates (or generally coordinates in any space as long as they are properly invertible to world-space) to the texture-space (i.e. projected x/y in [0,1]) of a so called projector. Think overhead projector like in a class room that projects some slide on the wall. You (or the camera in your scene) sees parts of the wall, you then transform those parts of the wall into the texture-space of the projector. Say your slide is your texture. After projection to texture-space, you know the texture coordinate of each fragment in the projected area of the wall. Using these texture coordinatesy, you then simply map texels from the slide to little portions of the wall by assigning the wall fragments those texels. In your case, the slide would simply contain a circle and the rest of the texels could be black with 0 alpha-values. The good thing is, all you need is the corresponding projection matrix of the projector and the texture to lookup. You can do the terrain texturing and the projection in one step. Actually this is almost the same as shadow mapping, only that the values of depth texture values are usually used as a factor weighting light contribution and not fragment color.
Somehow I can’t explain it better without drawing something but it’s really a lot easier than it sounds. I think Alfonse’s tutorial speaks for itself though. Come back if you got some specific problems.
EDIT: When you got the basic approach, we can talk about performance.
I have cursor in middle of screen cause position.x, y is some in .tes calculated or .tcs, there is also texCoords which I must use, but I don’t see brush when I use formula “texCoords.x - cursorPos.x”
EDIT: I need cursor position from World space right? mean 2D coords to 3D (terrain pos)
But still I need your help!
My actual problem is my brushRadius is very big, In my function to changeTerrain(raise) is radius 10.0f and with uniform in fragment shader there is also 10.0f! But size is very big, why? (You can see radius on followed picture)
Look on picture, there is also raised terrain, I think u figure it out!
First of all: derp! I feel like an idiot for suggesting projective texturing for this. It’s applicable, no doubt, but way to much overhead by comparison. The solution you have is much easier.
But size is very big, why?
Probably because you pass in 10.f? If you want a reduced radius, just pass a smaller value to brushRadius.
EDIT: Thx for recognizing that I “have again true”.