Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/366665112087572482
deleted 25 characters in body; edited tags
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

edit2: I am using xna

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

edit2: I am using xna

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}
added 29 characters in body
Source Link
Hasse Iona
  • 157
  • 2
  • 9

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

edit2: I am using xna

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

edit2: I am using xna

added 50 characters in body
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input) { //some other vertexshaderstuff

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}

}

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input) { //some other vertexshaderstuff

float4 lightPoint = {-3, -2, -2, 0};

output.lightDir = normalize(input.Position3D) - lightPoint;

output.lambertLightDir = float4(30, 30, 20, 0);

return output;

}

I have a World with a 3D model of a head in it and that World rotates, like such:

protected override void Update(GameTime gameTime)
{
    //other stuff

    angle += 0.00005f;

    //more other stuff
}

protected override void Draw(GameTime gameTime)
{
    //other stuff
    Matrix rotation = Matrix.CreateRotationY(3 * angle);
    effect.Parameters["World"].SetValue(rotation * Matrix.CreateScale(10.0f));

    // other stuff
}

And then in my Effects file I create a spotlight:

float4 SimplePixelShader(VertexShaderOutput input) : COLOR0
{
    float4 lightDirection = { 1, 1, 1, 0 };
    float theta = 10.0f;
    float phi = 30.0f;
    float4 color;
    float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir));

    float angle = acos(dot(input.lightDir, normalize(lightDirection)));
    if(angle > radians(phi))
        color = AmbientColor * AmbientIntensity;
    else if(angle < radians(theta))
        color = lambert;
    else
        color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert);
    
    return color;
}

And naturally this spotlight also rotates with the world. However, I dont want it to rotate. I tried everything, multiplying, adding, subtracting the rotation matrix and/or the angle from the different lightdirections and angles and nothing works.

Now I could rotate just the model and not the world, that would even be a sensible thing to do, but I have no clue how :P So I'm either looking for a good way to rotate the model or a way to 'counter rotate' the spotlight so it seems to stand still.

Edit: my vertexshader:

VertexShaderOutput SimpleVertexShader(VertexShaderInput input)
{
//some other vertexshaderstuff

    float4 lightPoint = {-3, -2, -2, 0};

    output.lightDir = normalize(input.Position3D) - lightPoint;

    output.lambertLightDir = float4(30, 30, 20, 0);

    return output;
}
added 320 characters in body
Source Link
Hasse Iona
  • 157
  • 2
  • 9
Loading
added 155 characters in body; edited title
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273
Loading
Source Link
Hasse Iona
  • 157
  • 2
  • 9
Loading