[2.6.1]Render to texture questions

Hello,

Please help me with these questions.

  1. I want to implement LOD for my objects by rendering them to texture. So outside some radius from the player everything visible should be rendered to texture. The question is what are the steps? I put the object I want to render, render, get the texture, make the objects invisible, place the bilboard with the rendered texture?

  2. Can I render to texture particles?

  3. I am trying implement this shading
    They say

" (scattering) integral is calculated by reading from the draw buffer the previous splat result and using it for the current splat which is blended back into the buffer …The camera to be placed in the sun’s position, viewing the cloud center and the projection should map the cloud onto the whole viewport."

And doing it with these code:

//we setup an orthographic projection
    //the view volume will thus be a box and it will fit the cloud perfectly
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(-Cloud->Radius-pr, Cloud->Radius+pr, -Cloud->Radius-pr, Cloud->Radius+pr, d - r, d + r);
        
    //setup the camera to lookat the cloud center and be positioned on the sun
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();        
    gluLookAt(Sun.x, Sun.y, Sun.z, Cloud->Center.x, Cloud->Center.y, Cloud->Center.z, 0, 1, 0);
        
    glPushAttrib(GL_VIEWPORT_BIT);
    glViewport(0, 0, SplatBufferSize, SplatBufferSize);
        
    //clear our buffer make it fully bright
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //your standard up and right vector extraction
    float mat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, mat);
        
    Vector3 vx(mat[0], mat[4], mat[8] );
    Vector3 vy(mat[1], mat[5], mat[9] );    
    
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, PuffTexture);

    float SolidAngle = 0.09f, Area;
    unsigned Pixels;
    double mp[16], mm[16];
    int vp[4];
    float *buf, avg;
        
    //used for projection
    glGetDoublev(GL_MODELVIEW_MATRIX, mm);
    glGetDoublev(GL_PROJECTION_MATRIX, mp);
    glGetIntegerv(GL_VIEWPORT, vp);        

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, PuffTexture);
        
    //our blending is enabled
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0);
    
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    
    Color4 LightColor(1.0f, 1.0f, 1.0f, 1.0f), ParticleColor;
    float factor = 1.0f;
    int ReadX, ReadY;
    
    Vector3 Light = Normalize(Sun);

    factor = SolidAngle / (4 * PI);
    
    for (i = 0; i < Cloud->Puffs.size(); i++)
    {        
        //find the particle's projected coordinates
        double CenterX, CenterY, CenterZ;
        gluProject(Cloud->Puffs[i].Position.x, 
            Cloud->Puffs[i].Position.y, 
            Cloud->Puffs[i].Position.z, 
            mm, mp, vp, &CenterX, &CenterY, &CenterZ);
        
        //area = dist * dist * angle
        Area = Cloud->Puffs[i].DistanceToCam * SolidAngle;
        Pixels = (int)(sqrt(Area) * SplatBufferSize / (2 * Cloud->Radius));
        if (Pixels < 1) Pixels = 1;
        
        //make sure we're not reading from outside the viewport, that's Undefined
        ReadX = (int)(CenterX-Pixels/2);
        if (ReadX < 0) ReadX = 0;
        ReadY = (int)(CenterY-Pixels/2);
        if (ReadY < 0) ReadY = 0;
        
        buf = new float[Pixels * Pixels];
        //we only need the red component since this is greyscale
        glReadBuffer(GL_BACK);
        glReadPixels(ReadX, ReadY, Pixels, Pixels, GL_RED, GL_FLOAT, buf);
            
        avg = 0.0f;
        for (j = 0; j < Pixels * Pixels; j++) avg += buf[j];
        avg /= (Pixels * Pixels);
        
        delete [] buf;
        
        //Light color * 
        // average color from solid angle (sum * solidangle / (pixels^2 * 4pi)) 
        // * albedo * extinction 
        // * rayleigh scattering in the direction of the sun (1.5f) (only for rendering, don't store)
        
        ParticleColor.R = LightColor.R * Albedo * Extinction * avg * factor;
        ParticleColor.G = LightColor.G * Albedo * Extinction * avg * factor;
        ParticleColor.B = LightColor.B * Albedo * Extinction * avg * factor;
        ParticleColor.A = 1.0f - exp(-Extinction);
        
        Cloud->Puffs[i].Color = ParticleColor;
        Cloud->Puffs[i].Color.Clamp();

        //the phase function (it's always 1.5f when we're looking from the sun)
        ParticleColor = ParticleColor * 1.5f;
        ParticleColor.Clamp();
                
        glColor4fv(!ParticleColor);
        
        glBegin(GL_QUADS);
                
        glTexCoord2f(1.0f, 0.0f);
        glVertex3fv(!(Cloud->Puffs[i].Position + (vx + vy) * -Cloud->Puffs[i].Size));        
        glTexCoord2f(0.0f, 0.0f);         
        glVertex3fv(!(Cloud->Puffs[i].Position + (vx - vy) *  Cloud->Puffs[i].Size));        
        glTexCoord2f(0.0f, 1.0f);         
        glVertex3fv(!(Cloud->Puffs[i].Position + (vx + vy) *  Cloud->Puffs[i].Size));         
        glTexCoord2f(1.0f, 1.0f);         
        glVertex3fv(!(Cloud->Puffs[i].Position + (vy - vx) *  Cloud->Puffs[i].Size));
        
        glEnd();                
    }

Any tip how can I mimic this in unity via shader?

Thanks!

Freaking bump, please help to start up, this is for my hobby project