Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
i don't even add comments on this crap anyway no one need this [img]https://i.ibb.co/ckV |
||||
|
|
||||
|
i forget about screen resolution |
||||
|
but the forum doesn't allow me to add a fixed code now |
||||
|
var fragmentShader = "uniform sampler2D myTexture; \n" + "uniform float radius; \n" + "uniform float softness; \n" + "uniform vec2 screen; \n" + "varying float depth; \n" + "varying vec3 fragToCam; \n" + "varying vec3 fragNormal; \n" + "void main(void) { \n" + " vec2 texCoord = gl_TexCoord[0].st; \n" + " vec4 col = texture2D(myTexture, texCoord); \n" + " vec3 normal = normalize(fragNormal); \n" + " vec3 lightDir = normalize(fragToCam); \n" + " float intensity = max(dot(normal, lightDir), 0.0); \n" + " vec2 st = gl_FragCoord.xy / vec2(screen.x, screen.y); \n" + " vec2 center = vec2(0.5, 0.5); \n" + " float dist = length(st - center) * depth; \n" + " float smoothStep = smoothstep(radius + softness, radius - softness, dist); \n" + " col.rgb *= intensity; \n" + " col.rgb -= mix(depth, depth / 50, smoothStep) / 50; \n" + " gl_FragColor = col; \n" + "}"; var shaderCallBack = function(){ let pos = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "PositionAbs"); let radius = ccbGetCopperCubeVariable(name + ".radius"); let softness = ccbGetCopperCubeVariable(name + ".softness"); ccbSetShaderConstant(1, "camPos", pos.x, pos.y, pos.z, null); ccbSetShaderConstant(2, "radius", radius, null, null, null); ccbSetShaderConstant(2, "softness", softness, null, null, null); ccbSetShaderConstant(2, "screen", ccbGetScreenWidth(), ccbGetScreenHeight(), null, null); }; |
||||
|
One major drawback with flashlight shaders and any shader is that they don't work with realtime shadows or any other inbuilt dynamic lighting, I mean I don't want to use flashlight alone, but also want that all the lights in the scene remains active with the flashlight. |
||||
|
@SamGrady, please post a project demo ccb. Thanks. |
||||
|
Guru wrote: One major drawback with flashlight shaders and any shader is that they don't work with realtime shadows or any other inbuilt dynamic lighting, I mean I don't want to use flashlight alone, but also want that all the lights in the scene remains active with the flashlight. I could be wrong but I think this should work with JIC's Screen shader such that all backend lighting is calculated as normal and only the render to texture in front of the camera adds in the spotlight so they merge together as one....at least I think it should work, started working on this idea yesterday....let you know... |
||||
|
@guru, Yup, you guys can create flashlight and any effect that deals with the screen, though am not sure if it will be able to simulate the actual depth effect or not but definitely it can be used with any kind of post processing and basic shaders like flashlight and all. |
||||
|
I found the same thing JIC mentioned - whatever object you select as the effected node will be used to send through the vertex positions, so if you use a 3d plane mesh in front of the camera then it will look at that and not the actual scene behind it so you cannot get any depth info from that as it will be fixed. No wonder I never could get depth info from post processing shader code in CC either. The only way at the moment I think is to get depth info yourself and send that into the shader - will not be vertex by vertex position but a general distance amount only where the line collides with the scene in front of the camera. I have done this before as a test and it works ok....not a true flashlight but not bad either. |
|