Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sushobhit

Pages: 1 2 [3] 4 5 ... 8
31
Support / Re: Shadow Maker Shader
« on: May 30, 2014, 12:06:00 pm »
Thank 's A pow(Ton,100) Thomas & Egon

I googled for around 2 days but it didnt point to this stuff. It's really very useful.

Now I am stuck @ here (as it's pure GL) and i am using JPCT as the renderer.

I have the VS & FS for creating the Depth texture :
Code: [Select]
// Vertex shader to generate the Depth Map
// Used for shadow mapping - generates depth map from the light's viewpoint

// model-view projection matrix
uniform mat4 uMVPMatrix;

// position of the vertices
attribute vec4 aPosition;

varying vec4 position;

void main() {

position = uMVPMatrix * aPosition;
gl_Position = uMVPMatrix * aPosition;
}

Code: [Select]
// Pixel shader to generate the Depth Map
// Used for shadow mapping - generates depth map from the light's viewpoint
precision highp float;

varying vec4 position;

// taken from Fabien Sangalard's DEngine
vec4 pack (float depth)
{
const vec4 bitSh = vec4(256.0 * 256.0 * 256.0,
256.0 * 256.0,
256.0,
1.0);
const vec4 bitMsk = vec4(0,
1.0 / 256.0,
1.0 / 256.0,
1.0 / 256.0);
vec4 comp = fract(depth * bitSh);
comp -= comp.xxyz * bitMsk;
return comp;
}

void main() {
// the depth
float normalizedDistance  = position.z / position.w;
normalizedDistance = (normalizedDistance + 1.0) / 2.0;

// bias
normalizedDistance += 0.0005;

// pack value into 32-bit RGBA texture
gl_FragColor = pack(normalizedDistance);  // I am stuck here

}

And then I have the Phong shader that takes Input Texture from the above shader to create shadows.

Code: [Select]
// Vertex shader Phong Shading - Per-pixel lighting

uniform mat4 uMVPMatrix;
uniform mat4 normalMatrix;

// the shadow projection matrix
uniform mat4 shadowProjMatrix;

// eye pos
uniform vec3 eyePos;

// position and normal of the vertices
attribute vec4 aPosition;
attribute vec3 aNormal;

// texture variables
uniform float hasTexture;
varying float tex;
attribute vec2 textureCoord;
varying vec2 tCoord;

// lighting
uniform vec4 lightPos;
uniform vec4 lightColor;

// material
uniform vec4 matAmbient;
uniform vec4 matDiffuse;
uniform vec4 matSpecular;
uniform float matShininess;

// to pass on
varying vec3 vNormal;
varying vec3 EyespaceNormal;
varying vec4 shadowCoord;

varying vec3 lightDir, eyeVec;

void main() {
// pass on texture variables
tex = hasTexture;
tCoord = textureCoord;

// normal
EyespaceNormal = vec3(normalMatrix * vec4(aNormal, 1.0));

// the vertex position
vec4 position = uMVPMatrix * aPosition;

// light dir
lightDir = lightPos.xyz - position.xyz;
eyeVec = -position.xyz;

// shadow coordinates
mat4 bias2 = mat4(0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.0, 0.5,
0.0, 0.0, 0.0, 1.0);

mat4 bias = mat4(0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.0, 0.5,
0.5, 0.5, 0.5, 1.0);
mat4 shadowProjMatrix2 = bias * shadowProjMatrix;
shadowCoord = shadowProjMatrix * aPosition;

gl_Position = position;//uMVPMatrix * aPosition;
}

Code: [Select]
// Frag shader Phong Shading - Per-pixel lighting

precision highp float;

// texture variables
uniform sampler2D shadowTexture; // depth texture
uniform sampler2D texture1; // color texture


varying float tex;
varying vec2 tCoord;

varying vec3 vNormal;
varying vec3 EyespaceNormal;

// light
uniform vec4 lightPos;
uniform vec4 lightColor;

// shadow projection matrix
uniform mat4 shadowProjMatrix;

// material
uniform vec4 matAmbient;
uniform vec4 matDiffuse;
uniform vec4 matSpecular;
uniform float matShininess;

// eye pos
uniform vec3 eyePos;

// from vertex s
varying vec3 lightDir, eyeVec;

// shadow coordinates
varying vec4 shadowCoord;


float getShadowFactor(vec4 lightZ)
{
vec4 packedZValue = texture2D(shadowTexture, lightZ.st);

// unpack
const vec4 bitShifts = vec4(1.0 / (256.0 * 256.0 * 256.0),
1.0 / (256.0 * 256.0),
1.0 / 256.0,
1);
float shadow = dot(packedZValue , bitShifts);

return float(shadow > lightZ.z);
}

void main() {
// Just to show them being used
//vec4 a = lightPos;
    vec4 b = lightColor;
    vec4 c = matAmbient;
    vec4 d = matDiffuse;
    vec4 e = matSpecular;
    vec3 g = eyePos;
    float f = matShininess;

vec3 N = normalize(EyespaceNormal);
    vec3 E = normalize(eyeVec);
   
    vec3 L = normalize(lightDir);
   
    // Reflect the vector. Use this or reflect(incidentV, N);
    vec3 reflectV = reflect(-L, N);
   
    // Get lighting terms
    vec4 ambientTerm;
    if (tex >= 1.0) {
    ambientTerm = texture2D(texture1, tCoord);
    }
    else
        ambientTerm = matAmbient * lightColor;
   
    vec4 diffuseTerm = matDiffuse * max(dot(N, L), 0.0);
    vec4 specularTerm = matSpecular * pow(max(dot(reflectV, E), 0.0), matShininess);
   
   
    // Shadow
    float sValue = 1.0;
    float sValue2 = 1.0;
    if (shadowCoord.w > 0.0) {
    vec4 lightZ = shadowCoord / shadowCoord.w;
lightZ = (lightZ + 1.0) /2.0;

sValue = getShadowFactor(lightZ);

// scale the value from 0.5-1.0 to get a "softer" shadow for ambient
float newMin = 0.5;
float v1 = (1.0)/(1.0 - newMin);
float v2 = sValue/v1;
sValue2 = sValue + newMin;//v2 + newMin;
}
   
    gl_FragColor =  ( ambientTerm * sValue2 + (diffuseTerm + specularTerm) * sValue) ;
}

Issues I am facing :
1. How do I pass the Depth Texture to the Phong shader so that it processes the shadow.
2. Which shader should be set for which object. (I have a Plane , a Cube , a Sphere and a Cone. The cone , the sphere , and the cube lies on the plane.)
3. Do I have to use world.setglobalshader(shader)

32
Support / Re: Shadow Maker Shader
« on: May 29, 2014, 01:37:16 pm »
and how do i get the depth map ????

33
Support / Re: Shadow Maker Shader
« on: May 29, 2014, 01:00:20 pm »
If I got you right you mean render the every frame onto a depth map (is it something like the height map) a greyscale image of the texture. And then using this depthmap I blend it into second texture of the plane object.

Is there no way to find if a object is being interfering between light and plane object in glsl ??

34
Support / Re: Cel Shader
« on: May 29, 2014, 08:11:26 am »
Thanks

35
Support / Shadow Maker Shader
« on: May 29, 2014, 08:09:55 am »
Hi ,

I want to implement a shader for a Plane object which shows shadows of all the objects placed on it.
I know about blob shadows but that wont solve the pourpose that i am trying to achieve.

I have a rough sketch in my mind which is something like this : The shader of the plane would be a perpixel light shader
and it illuminates all of the plane falling under light. Now if an object falls in between the position of the light and the position of the object(plane) i.e the vertex if simply does gl_FragColor = shadowcolor * texturecolor; and if there is no object between light & plane it simply does gl_FragColor = textureColor;

All is going fine till now , I am able to get gl_FragColor = textureColor ; but how do i find out if there is an object between light and the plane.... plz help !!!

Do I have to set a uniform for each individual object if yes which matrix I have to pass that contains positions of all vertex of the object.

Very desparate to get this one working cause this is the last thing i have left to learn regarding game programming.....


36
Feedback / Web GL
« on: May 28, 2014, 11:27:37 am »
Anyway I could PORT my jpct java code to work on Browser (WEBGL)

37
Support / Cel Shader
« on: May 27, 2014, 12:18:51 pm »
Hi Egon ,

I was wondering if you have a decent cell shader code VERTEx + Frag.
Made one myself , got the silhoutte right but am unable to get
a good effect of the texture i.e the textures are not flattening properly

Just by chance if you have one handy it would save me a lot of time.

Regards.

(p.s) - who says jpct is just for small-medium projects , i dont think the same way a reviewed on mobilegameengines
           it is as good for large and very large projects.:0

38
Support / Re: How to create textures for glshader
« on: May 23, 2014, 01:23:38 pm »
also what is the programming that goes in the other two glsl files ??? plz hlp

39
Support / How to create textures for glshader
« on: May 23, 2014, 01:23:01 pm »
hi egon ,

I would like to learn the shader and while going through the example provided with jpct-ae(hello shader) i came across 3 files one the real image , second normal (bluish version of the same image) and third (a greyish version). An you combine these 3 to make the shader.

?? So if i have a image , how can I get the bluish one and the greyish one so that the texture could be applied?


40
Projects / Re: Armada Gameplay video
« on: April 26, 2014, 07:14:13 am »
looks cool would love to try my hands on this one ...
by the way right now i am already playing (completed nearly half) a spaceship game if you want some inspirations do check it out it's  called Alpha Zero check it out on google play

41
Projects / Another Demo Project to Get you Started
« on: April 23, 2014, 07:43:54 am »
Hi Friends ,

Just completed another project using my engine
This ones really cool ... A windmill Simulator program
The graphics are inspired by a popular game Dokuro

Here are the sources :

http://speedy.sh/rZAMz/windmill.zip

42
Projects / Re: LAZYLION 2D ENGINE
« on: April 19, 2014, 11:55:06 am »
Well there are no executables to be scared (its in zip) and rest are JAVA files you can examine the code and then run it....
Abt CAPS LOCK (hmmmmm....)

43
Projects / LAZYLION 2D ENGINE
« on: April 19, 2014, 08:02:59 am »
                                               
A SET OF CLASSES USING JPCT'S FRAMEBUFFER & BLIT PROCEDURE TO CREATE 2D WORLD ,
OBJECTS , LIGHTS.   
OPEN SOURCE 2D ENGINE BASED ON JPCT FORMAT. STILL HAS LOT OF POSSIBILITIES OF IMPROVEMENT

FEATURES :
1.SPRITE ANIMATION
2.COULD ALSO BE USED FOR DESIGNING GAME MENUS
3. 2D GAMES
4. INTERACTIVE PRESENTATIONS
5. LOW ON SYSTEM RESOURCES.

Download Links :

http://speedy.sh/RdH2U/2dengine.zip
http://www.filedropper.com/2dengine
http://wikisend.com/download/108818/2dengine.zip

44
Support / Re: Lens Flare
« on: April 18, 2014, 10:31:07 am »
Just wanted to confirm is somewhere in the programming of Lens Flare WHITE is set as an Additional Color (For transparency)

45
Support / Re: Lens Flare
« on: April 16, 2014, 07:08:45 am »
Thanks Work's Just the Way I wanted it be. 8)

Pages: 1 2 [3] 4 5 ... 8