Jump to content

  • Log In with Google      Sign In   
  • Create Account

enigmagame

Member Since 09 Oct 2007
Offline Last Active Today, 02:01 AM

Topics I've Started

Linear gradient shader ( Photoshop-like)

Yesterday, 07:22 AM

I'm searching a way to implement a linear gradient shader that behaves as the linear gradient in Photoshop (only the vertical case is necessary). It will be applied to 2D sprites.

Currently I'm passing to the pixel shader these parameters:

  • StartColor.
  • EndColor.
  • Offset: the gradient starting point.
  • Length: the gradient length (the range inside where the colors will be interpolated).
  • isFixed: a boolean parameter that indicates if the gradient must be influenced by the camera position or not.

Here a first attempt of the vertex shader and the pixel shader that I've implemented:

struct VsInput
{
    float3 position : VES_POSITION;
    float2 uv	    : VES_TEXCOORD0;
    float4 color    : VES_COLOR;
};

struct VsOutput
{
    float4 position : HPOS;
    float2 uv	    : TEXCOORD0;
    float4 color    : COLOR0;
    float4 outPos   : TEXCOORD1;
};

VsOutput main(VsInput input)
{
    VsOutput vsOutput;
    vsOutput.position = MUL(float4(input.position, 1.0f), WorldViewProjection);
    vsOutput.uv = input.uv;
    vsOutput.color = input.color;
    vsOutput.outPos = vsOutput.position;

    return vsOutput;
}
struct PsInput
{
    float4 Position : HPOS;
    float2 UV	    : TEXCOORD0;
    float4 Color    : COLOR0;
    float4 outPos   : TEXCOORD1;
};

float4 startColor;
float4 endColor;
float offset;
float len;
bool isFixed;

float4 main(PsInput psInput) : COLOR
{
    psInput.outPos = psInput.outPos / psInput.outPos.w;
    float yScreenSize = 900.0f;
    float yPixelCoordinate = 0.0f;
    if (isFixed)
    {
	yPixelCoordinate = 0.5f * (1.0f - psInput.UV.y) * yScreenSize;
    }
    else
    {
        yPixelCoordinate = 0.5f * (psInput.outPos.y + 1.0f) * yScreenSize;
    }

    float gradient = (yPixelCoordinate + offset) / len;
    gradient = clamp(gradient, 0.0f, 1.0f);
    return lerp(startColor, endColor, gradient);
}
I think something's wrong, for example, with an offset of 0.0, the gradient starts from the bottom of the window and not from the bottom of the sprite. Another issue is that there is no correlation between the fixed and non-fixed mode.
 
I'm pretty sure that there's something correct and something wrong in my approach, so I'm here for any suggestions.
 
Thanks.

Move a directional light according to the camera movement

25 October 2012 - 02:33 AM

Given a light direction, how can I move it according to the camera movement, in a shader?
Think that an artist has setup a scene (e.g., in 3DSMax) with a mesh in center of that and a directional light with a position and a target. From this position and target I've calculated the light direction. Now I want to use the same direction in my lighting equation but, obviously, I want that this light moves correctly with the camera.
Thanks.

How to reproduce the 3ds Max Gradient Ramp effect?

07 August 2012 - 01:27 AM

The material definition of a mesh is composed of these three components: Self-Illumunation, Refletcion and Refraction. Each of these components has a Gradient Ramp as a map and the mapping mode is set to spherical environment.
I'm searching for a way to reproduce these effects in a shader (the shader language doesn't matter). Is it possible?
My first idea was to save the Gradient Ramp as a texture: you can see the result in the image below:
Posted Image

It seems to be a Blinn/Newell Latitude Map instead of a Spherical Map, but using the math behind the first, the result isn't correct.
Thanks.

Design a character animation system

04 May 2012 - 12:39 PM

I'm searching for suggestions and resources on the possible ways to design a character animation system. I mean a system built on top of the graphics engine (as graphics engine I use Ogre3D, that provide an animation layer), and that's must be in contact with the logic of the game.
More in detail I'm searching about the action state mechines (or animation state machines), that is build on top of the animation pipeline already provided by the graphics engine. So, a state-driver animation interface for use by virtually all higher-level game code.


It's for a sports title, maybe the question is non trivial.

Bowling physic parameters

02 June 2011 - 10:03 AM

Hi guys, I'm working on a simple bowling game, using Ogre as rendering engine and Bullet as physics engine.
I'm at the point to tune all the physical parameters, but how? Where I can find those?
For example:
- Ball friction
- Ball restitution
- Ball angular damping
- Ball linear damping
- Ball, any other...
- Pins parameters
- Lane friction
- Lane restitution
Thanks.

PARTNERS