algorithm - Detect light position on a post-process GLSL shader -


i'm trying apply volumetric scattering post-process extracted nvidia gpu gems 3 have this:

 float4 main(float2 texcoord : texcoord0) : color0   {   // calculate vector pixel light source in screen space.   half2 deltatexcoord = (texcoord - screenlightpos.xy);   // divide number of samples , scale control factor.   deltatexcoord *= 1.0f / num_samples * density;   // store initial sample.   half3 color = tex2d(framesampler, texcoord);   // set illumination decay factor.   half illuminationdecay = 1.0f;   // evaluate summation equation 3 num_samples iterations.   (int = 0; < num_samples; i++)   {   // step sample location along ray.   texcoord -= deltatexcoord;   // retrieve sample @ new location.   half3 sample = tex2d(framesampler, texcoord);   // apply sample attenuation scale/decay factors.   sample *= illuminationdecay * weight;   // accumulate combined color.   color += sample;   // update exponential decay factor.   illuminationdecay *= decay;   }   // output final color further scale control factor.   return float4( color * exposure, 1);   }   

but shader needs uniform light pos, i'm thinking if it's possible detect post-process material position of light in screen , how can this. ideas?

the word 'detect' makes sounds you're trying estimate position of light using information in framebuffer. there's no way this.

instead, use gluniform (in opengl application) pass position of light shader. you'll need declare light position near top of shader:

uniform vec2 screenlightpos; 

if light never moves, can have position constant in shader:

const vec2 screenlightpos = vec2(0.5, 0.5); 

or, if light moves predictably, can calculate it's position function of time:

vec2 screenlightpos = vec2(sin(time), cos(time)); 

basically, need know light before shader runs. true whether you're doing post-processing or surface lighting.

if there absolutely no other way, might able use compute shader or, worse yet, pixel reading detect bright areas on framebuffer. horribly slow, , you'll still need use gluniform pass position in once you've figured out light is. if somehow not option, use nested loop in shader search through whole framebuffer bright spots. i'm not going explain how or why it's horrible idea.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -