Welcome, Guest! Login | Register
Godrays camera effect tweaking question
Info
Report
60 Posts

Hi rad people

i was wondering if there is a script or tutorial on tweaking the godrays camera effect, so that the rays emit from a point of origin , like a light source, and then scatter in one direction.

i want to create a volumetric light effect in 3d rad

https://docs.unrealengine.com/en-us/Engine/Rendering/LightingAndShadows/VolumetricFog

as you can see in the link above the godrays effect is coming from the left of the screen and scattering according to the light direction, and not just scattering to the camera, like the current godrays do in 3d rad.

maybe a script can help achieve this in 3d rad?

thanks for reading. have a good weekend.
Created on: 2 months ago
Edited on: 2 months ago
Info
Report
19 Posts

I remember i did this at some point there's this "float2set()" or something that does it. Let me dig around my files maybe i'll find it


EDIT: Found it!


Here's the code for you!

OBJ_0 is a skinmesh from where the ray will be rendered









////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Post-process shader: display deformation and color manipulation
////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*HLSLSTART GodRays

float2 ViewportSize = {1280, 720};
//*****************************************************************************
//EDITIABLE VALUES
//*****************************************************************************
float2    screenLightPos    =float2(0.5,1);
float    Weight      = 0.02f;
float    Decay      = 0.977f;
#define SAMPLES 32

//--------------------------------------------------------------------------------------------
//Textures
//--------------------------------------------------------------------------------------------
texture screenTexture;

sampler screenTextureSampler =
sampler_state
{
    Texture = <screenTexture>;
    MinFilter = POINT;
    MagFilter = POINT;

    AddressU = Clamp;
    AddressV = Clamp;
};

texture ProcessedTexture;

sampler2D ProcessedTargetSampler =
sampler_state
{
    Texture = <ProcessedTexture>;
    MinFilter = POINT;  
    MagFilter = POINT;

    AddressU = Clamp;
    AddressV = Clamp;
};

//--------------------------------------------------------------------------------------------
//Struct's
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
//Pixel Shader
//--------------------------------------------------------------------------------------------
float4 DefaultRender(in float2 textureUV : TEXCOORD0) : COLOR
{
  
    // Set up illumination decay factor.  
    half illuminationDecay = 0.7f;  

    // Store initial sample.  
    half3 color = tex2D(screenTextureSampler, textureUV.xy);

    // Calculate vector from pixel to light source in screen space.  
    half2 deltaTexCoord = (textureUV - screenLightPos.xy);  

    // Divide by number of samples and scale by control factor.  
    deltaTexCoord *= 1.0f / SAMPLES * 1;    //change to change range

   // Evaluate summation from Equation 3 NUM_SAMPLES iterations.  
    for (int i = 0; i < SAMPLES; i++)  
    {  
       // Step sample location along ray.  
       textureUV -= deltaTexCoord;  

       // Retrieve sample from depthmask  
       half3 sample = tex2D(screenTextureSampler, textureUV );

       // Output sample as original rendered/colored objects not just depthmask, comment out if only light is wanted
       if (sample.r+sample.g+sample.b < 2.0f) sample.rgb=0;
       //else sample=1.0f;   //enable to output just white

       // Apply sample attenuation scale/decay factors.  
       sample *= illuminationDecay * Weight;  

       // Accumulate combined color.  
       color += sample;

       // Update exponential decay factor.  
       illuminationDecay *= Decay;  
   }
  
   // Output final color
    return float4( color, 1.0f);

}

//--------------------------------------------------------------------------------------------
//Technique
//--------------------------------------------------------------------------------------------

technique PostProcessing
{
    pass p0
    {        
        PixelShader = compile ps_3_0 DefaultRender();
    }

}



HLSLEND*/

//////////////////////////////////////////////////////////////////////////////////

//The following is our regular script code which sets and manipulates the shader above

float Time = 0;
   Vector3 skin, ret, a;
void Main()
{
   iObjectLocation(OBJ_0, skin);
   i3DLocationToScreen(ret,skin,OBJ_22);
   a.x = ret.x / 32 + 0.5;
   a.y = ret.y / -24 + 0.5;
   iShaderFloat2Set(OBJ_22,"screenLightPos", a.x,a.y);

   if (iInitializing())
   {
      iShaderSet(OBJ_22,"GodRays");
   }
   iShaderFloatSet(OBJ_22,"time",Time);
   Time += 0.08;
}
Created on: 1 month ago
Edited on: 1 month ago
Info
Report
60 Posts

cool. will give it a go
Created on: 1 month ago
Info
Report
99 Posts

Couldn't have uploaded a text file with the code instead of this loooooooooooooooooong post huh
Created on: 1 month ago
Info
Report
19 Posts

that's also a point but im too bust you know :P
Created on: 1 month ago
Info
Report
5 Posts

I made this tweak for a game I was making, mostly to use as sun rays, WhyNotYT's script is nearly there.
But I remember I added an extra few lines to modify the direction of the rays relative to the observer, to make it move correctly when the observer moves, relative to the light.

I'll post the script when I get home, but here's a day/night cycle video that has the effect in it, I don't know if the effect is pronounced, but you can see it during sunrise and sunset

https://youtu.be/-k7O3aZBZLU
Created on: 1 month ago
Info
Report
60 Posts

@hawk  looks good. funny videos on your channel
Created on: 1 month ago
Info
Report
60 Posts

Thanks guys for the scripts. they work well. now I just need to stack the bloom shader with the godrays shader.
Created on: 2 weeks ago
Reply
Preview
Post
Or use the advanced reply form here...
Sponsored