Jump to content

Recommended Posts

Posted

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

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Posted

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:


//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;
[/Code]

 

are not available and Need to be calculated from the depth/normal buffer provided via a lua part of the post process effect.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...