Jump to content
  • Advertisement
Sign in to follow this  
Dunkansdk

Vertex Shader - Shadows

This topic is 2589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font="Arial"][color="#333333"]
Hello! I am developing a 2D graphics engine in Visual Basic DirectX8 and I wanted to do a query.

I came to the following system of dynamic shadows, the lighting system I have it done, would fail to handle vertex shadows.

I know they are trigonometric functions but could not achieve yet.

The video shows the effect is as follows:



Pseudo-code:

1 - Check that the distance between the light and character, so I think it would be:

Sqr (((Y1 - Y2) ^ 2 + (X1 - X2) ^ 2))[/quote]

2 - Angle Light that looks like Cut Off.

I use this function:

Public Function Engine_GetAngle(ByVal centerX As Integer, ByVal centerY As Integer, ByVal TargetX As Integer, ByVal TargetY As Integer) As Single
'************************************************************
'Gets the angle between two points in a 2d plane
'More info: http://www.vbgore.co...meClient.TileEn ... e_GetAngle" class="postlink" rel="nofollow" onClick="window.open(this.href);return false;
'************************************************************
Dim SideA As Single
Dim SideC As Single

On Error GoTo ErrOut

'Check for horizontal lines (90 or 270 degrees)
If centerY = TargetY Then

'Check for going right (90 degrees)
If centerX < TargetX Then
Engine_GetAngle = 90

'Check for going left (270 degrees)
Else
Engine_GetAngle = 270
End If

'Exit the function
Exit Function

End If

'Check for horizontal lines (360 or 180 degrees)
If centerX = TargetX Then

'Check for going up (360 degrees)
If centerY > TargetY Then
Engine_GetAngle = 360

'Check for going down (180 degrees)
Else
Engine_GetAngle = 180
End If

'Exit the function
Exit Function

End If

'Calculate Side C
SideC = Sqr(Abs(TargetX - centerX) ^ 2 + Abs(TargetY - centerY) ^ 2)

'Side B = CenterY

'Calculate Side A
SideA = Sqr(Abs(TargetX - centerX) ^ 2 + TargetY ^ 2)

'Calculate the angle
Engine_GetAngle = (SideA ^ 2 - centerY ^ 2 - SideC ^ 2) / (centerY * SideC * -2)
Engine_GetAngle = (Atn(-Engine_GetAngle / Sqr(-Engine_GetAngle * Engine_GetAngle + 1)) + 1.5708) * 57.29583

'If the angle is >180, subtract from 360
If TargetX < centerX Then Engine_GetAngle = 360 - Engine_GetAngle

'Exit function

Exit Function

'Check for error
ErrOut:

'Return a 0 saying there was an error
Engine_GetAngle = 0

Exit Function

End Function[/quote]

Do not know if it might be possible to give me a hand with the formulas thatgo in the vertex, the textures load as follows:[/font]
[font="Arial"][color="#333333"] [/font]
[font="Arial"][color="#333333"]
' * v1 * v3
' |\ |
' | \ |
' | \ |
' | \ |
' | \|
' * v0 * v2
Thank you very much everyone for your time!

Translated by: Google Translator.[/font]
[font="Arial"][color="#333333"] [/font]
[font="Arial"][color="#333333"]POST ORIGINAL EN ESPAÑOL:[/font]
[font="Arial"][color="#333333"]

Hola! Estoy desarrollando un motor gráfico en 2D con DirectX8 en Visual Basic y les quería hacer una consulta.

Se me ocurrió hacer el siguiente sistema de sombras dinámicas, el sistema de luces ya lo tengo hecho, faltaría manejar los vertex para hacer las sombras.

Sé que son funciones trigonométricas pero no lo pude lograr aún.

El video que muestra el efecto es el siguiente:


Pseudo-código:

1 - Averiguar que distancia hay entre la luz y el personaje, sería así creo:

Sqr(((Y1 - Y2) ^ 2 + (X1 - X2) ^ 2))

2 - Angulo al que mira la Luz estilo Cut Off.

Utilizo esta función:

No se si podría ser posible que me den una mano con las fórmulas que irían en los vertex, las texturas las carga de la siguiente manera:

Muchas gracias a todos por su tiempo!

Traducido por: Google Traductor.[/quote]
[/font]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!