Jump to content

Recommended Posts

Posted (edited)

I try to convert an hlsl Sky shader to glsl and cant figure out how to do a proper NdotL calculation. :)

So, what else for tools are usable to write/debug glshaders ?

 

Currently iam just using the material editor and 3DLabs glsl validator and leaning from

lighthouse3d and clockworkcoders.

 

If you want to take a look into the shader iam messing around with

 

#extension GL_ARB_draw_buffers : enable

uniform sampler2D texture0;
uniform float apptime;

uniform vec3 lightdir;
uniform vec3 sunpos;

varying vec2 texcoord0;
varying vec3 vertexposition;

varying vec3 N;

void main(void) {

   vec3 sunvector = normalize(-vertexposition.xyz + lightdir);

   vec2 TexCoord = vec2(apptime/40000.0, texcoord0.y * 2.0);
   vec4 color = texture2D( texture0, TexCoord );

   float glowfactor = 0.2; // 0.6
   float dotproduct = max(dot(-N, sunvector), 0.0); 
   float sunglow = pow(dotproduct, 2.0) * glowfactor;

   if (dotproduct > 0.0) // near to sun
   {
     float sun = pow(dotproduct, 128.0) * 0.6;  // * 0.6
     color.rgb += sun + sunglow;                // * sunglow
   }
   else // reverse side
   {
     float intensity = 0.299 * color.r + 0.578 * color.g + 0.114 * color.b;
     color.rgb -= sunglow/2.0;
     color = mix(color, vec4(intensity, intensity, intensity, color.a), sunglow);
   }

   gl_FragData[0] = color;
   gl_FragData[1] = vec4(1.0,1.0,1.0,0.0);
   gl_FragData[2] = vec4(0.0);
   gl_FragData[3] = vec4(0.0);
}

 

material file is calling

shader="abstract::mesh_diffuse.vert","abstract::SkySphere.frag"

 

and the image mapped to a sphere model

skyScatter128.png

 

[edit]

passing vars to shader

//pass shader
TShader scatterShader = GetMaterialShader(scatterMat);

//from Renderer::DrawEffectGodRays
TVec3 lightdir;
lightdir = TFormNormal(Vec3(0,0,1), sun, fw.GetMain().GetCamera() );

TVec3 sunPos;
sunPos = EntityPosition (sun);

SetShaderFloat(scatterShader, "apptime", AppTime() );
SetShaderVec3 (scatterShader, "lightdir", lightdir );
SetShaderVec3 (scatterShader, "sunpos", sunPos );

 

It suppose to look like this

FrameLuaSampleScatterSimple

but the sun is moving with the cameraPos atm.

 

any help on wrapping my head around LE`s glsl very welcome.

Edited by TLD

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

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...