tjheldna Posted November 13, 2015 Share Posted November 13, 2015 I'm trying to convert this shader to leadwerks, but cant quite get there. Here is the original shader code. #version 330 layout(location = 0) out vec4 out_color; uniform vec3 light_position; uniform vec3 eye_position; uniform sampler2D texture1; //can pass them as uniforms const vec3 DiffuseLight = vec3(0.15, 0.05, 0.0); const vec3 RimColor = vec3(0.2, 0.2, 0.2); //higher gamma to get a darker image const float gamma = 1.0/0.6; in vec3 world_pos; in vec3 world_normal; in vec2 texcoord; void main(){ vec3 tex1 = texture(texture1, texcoord).rgb; //get light an view directions vec3 L = normalize( light_position - world_pos); vec3 V = normalize( eye_position - world_pos); //diffuse lighting vec3 diffuse = DiffuseLight * max(0, dot(L,world_normal)); //rim lighting float rim = 1 - max(dot(V, world_normal), 0.0); rim = smoothstep(0.6, 1.0, rim); vec3 finalRim = RimColor * vec3(rim, rim, rim); //get all lights and texture vec3 finalColor = finalRim + diffuse + tex1; vec3 finalColorGamma = vec3(pow(finalColor.r, gamma), pow(finalColor.g, gamma), pow(finalColor.b, gamma)); out_color = vec4(finalColorGamma, 1); Here is my attempt #version 400 uniform sampler2D texture1; uniform bool isbackbuffer; uniform vec2 buffersize; //Inputs in vec2 ex_texcoords0; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_VertexCameraPosition; in vec3 ex_normal; in vec3 ex_tangent; in vec3 ex_binormal; in float clipdistance0; const vec3 RimColor = vec3(0.2, 0.2, 0.2); const float gamma = 1.0/0.6; uniform vec4 lighting_ambient; out vec4 fragData0; //Could possiibly be uniforms to control the effect const float EdgeWidth = 0.3; const float EdgeIntensity = 2.0; const float NormalThreshold = 0.1; const float DepthThreshold = 1.9; const float NormalSensitivity = 0.5; const float DepthSensitivity = 0.1; void main(void) { vec2 tcoord = vec2(gl_FragCoord.xy/buffersize); if (isbackbuffer) tcoord.y = 1.0 - tcoord.y; //Get diffuse color vec4 scene = texture(texture1,tcoord); vec3 tex1 = texture(texture1, tcoord).rgb; //rim lighting float rim = 1 - max(dot(ex_VertexCameraPosition, ex_normal), 0.0); rim = smoothstep(0.6, 1.0, rim); vec3 finalRim = RimColor * vec3(rim, rim, rim); //get all lights and texture //vec3 finalColor = finalRim + diffuse + tex1; scene.rgb = finalRim + scene.rgb; vec3 finalColorGamma = vec3(pow(scene.r , gamma), pow(scene.g , gamma), pow(scene.b, gamma)); //Render fragData0 = vec4(finalColorGamma, 1); } I'm positive the problem lies in this line float rim = 1 - max(dot(ex_VertexCameraPosition, ex_normal), 0.0); Anyone know where I'm going wrong? Cheers Quote Link to comment Share on other sites More sharing options...
klepto2 Posted November 13, 2015 Share Posted November 13, 2015 Hi, it looks like you're mixing a matrial shader and a postprocess shader. should this shader work per instance or as a post process shader? If it should be a postprocess shader: These variables: //Inputsin vec2 ex_texcoords0;in vec4 ex_color;in float ex_selectionstate;in vec3 ex_VertexCameraPosition;in vec3 ex_normal;in vec3 ex_tangent;in vec3 ex_binormal;in float clipdistance0;[/Code] are not available and Need to be calculated from the depth/normal buffer provided via a lua part of the post process effect. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
tjheldna Posted November 13, 2015 Author Share Posted November 13, 2015 Hmm I've only been coping from the post process folder, strange. I'll give it another shot with your suggestion. Cheers Quote Link to comment Share on other sites More sharing options...
shadmar Posted November 13, 2015 Share Posted November 13, 2015 Here is a way to mod an existing shader to produce fresnel (rim) http://www.leadwerks.com/werkspace/topic/9312-rim-lightening/#entry70608 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
tjheldna Posted November 13, 2015 Author Share Posted November 13, 2015 Didn't realise it's been done before, I'll check it out, thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.